1 #include <creaImageIOTreeNode.h>
2 #include <creaImageIOTree.h>
3 #include <creaImageIOSystem.h>
5 #include <creaImageIOGimmick.h>
14 //=============================================================
16 Node::Node(Node* parent)
17 : mParent(parent),//mData(0),
18 mChildrenLoaded(false)
22 GimmickDebugMessage(6,"Default Node constructor (level "<<GetLevel()<<")"
24 // Insert into parent's children list
25 InitializeAttributeMap();
26 parent->GetChildrenList().push_back(this);
30 GimmickDebugMessage(6,"Default Node constructor without parent"
34 //=============================================================
36 //=============================================================
37 /// Ctor with parent and attributes map
38 Node::Node(Node* parent, const AttributeMapType& attr)
39 : mParent(parent),//mData(0),
40 mChildrenLoaded(false)
42 GimmickDebugMessage(6,"Node constructor (level "<<GetLevel()<<")"
47 // Insert into parent's children list
48 parent->GetChildrenList().push_back(this);
49 // Initialize attributes
50 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
51 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
52 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
56 AttributeMapType::const_iterator i = attr.find(a->GetKey());
57 if ( i != attr.end() )
61 GimmickDebugMessage(6,"Setting attribute '"<<a->GetName()<<"' = '"
63 UnsafeSetAttribute( a->GetKey(), v );
68 //=============================================================
71 //=============================================================
74 GimmickDebugMessage(6,"Node destructor"
76 ChildrenListType::iterator i;
77 for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
83 //=============================================================
86 //=============================================================
87 /// Initializes the attribute map i.e. creates the entries
88 void Node::InitializeAttributeMap()
90 // Initialize attributes
91 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
92 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
93 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
96 UnsafeSetAttribute( a->GetKey(), "" );
99 //=============================================================
101 //=============================================================
102 /// Returns the level descriptor of the node
103 const LevelDescriptor& Node::GetLevelDescriptor() const
105 return GetTree()->GetLevelDescriptor(GetLevel());
108 //=============================================================
110 //=============================================================
111 /// Returns the attribute descriptor of the passed parameter
112 const AttributeDescriptor& Node::GetAttributeDescriptor(const std::string& k)const
114 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
115 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
116 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
128 //=============================================================
130 //=============================================================
131 int Node::RemoveChildrenFromList(Node* node)
133 ChildrenListType::iterator i = find(GetChildrenList().begin(),
134 GetChildrenList().end(),
136 if (i != GetChildrenList().end())
138 GetChildrenList().erase(i);
140 return GetChildrenList().size();
142 //=============================================================
144 //=============================================================
145 const std::string& Node::GetAttribute(const std::string& k) const
147 // std::cout << "this = "<<(void*)this<<std::endl;
148 // std::cout << "mFieldValueMap="<<(void*)(&mFieldValueMap)<<std::endl;
149 AttributeMapType::const_iterator i = mAttributeMap.find(k);
150 if (i == mAttributeMap.end())
152 static std::string def("");
154 // CREAIMAGEIO_ERROR("DicomNode::GetFieldValue : no field with key '"<<k<<"'");
158 //=============================================================
160 //=============================================================
161 void Node::SetAttribute(const std::string& k,
162 const std::string& v)
164 AttributeMapType::iterator i = mAttributeMap.find(k);
165 if (i==mAttributeMap.end())
167 std::cout<<"[Gimmick!] Node::SetAttribute : no attribute with key '"
169 creaError( "[Gimmick!] Node::SetAttribute : no attribute with key '"
174 //=============================================================
176 //=============================================================
177 bool Node::Matches( const AttributeMapType& m ) const
179 GimmickDebugMessage(2,"'"<<GetLabel()<<"' matching..."<<std::endl);
180 const std::vector<std::string>& id
181 = GetLevelDescriptor().GetIdentifierList();
182 std::vector<std::string>::const_iterator i;
183 for (i = id.begin(); i != id.end(); ++i)
185 if (mAttributeMap.find(*i)->second != m.find(*i)->second )
187 GimmickDebugMessage(2,"IDENTIFIER '"<<*i<<"' values do not match"<<std::endl);
190 GimmickDebugMessage(2,"IDENTIFIER '"<<*i<<"' values match"<<std::endl);
194 //=============================================================
196 //=============================================================
197 void Node::Print() const
200 for (int i = 0; i<GetLevel(); ++i) mess += " ";
201 mess += "|_ " + GetLabel();
202 GimmickMessage(1,mess<<std::endl);
203 ChildrenListType::const_iterator j;
204 for (j=GetChildrenList().begin(); j!=GetChildrenList().end(); j++)
209 //=============================================================
211 //=============================================================
212 std::string Node::GetLabel() const
215 const std::vector<std::string>& label
216 = GetLevelDescriptor().GetLabelList();
218 std::vector<std::string>::const_iterator i;
219 for (i = label.begin(); i != label.end(); )
221 GimmickDebugMessage(9,"LABEL '"<<*i<<"'"<<std::endl);
222 AttributeMapType::const_iterator j = mAttributeMap.find(*i);
223 if (j != mAttributeMap.end())
227 if (i != label.end()) l += "|";
231 GimmickError("Node::GetLabel() : LABEL attribute '"
233 <<"' is not in node attribute map (should be!)" );
236 if (l.size()==0) l="?";
239 //=============================================================