1 #include <creaImageIOTreeNode.h>
2 #include <creaImageIOTree.h>
3 #include <creaImageIOSystem.h>
11 //=============================================================
12 /// Ctor with parent Why does it enter once while charging?
13 Node::Node(Node* parent)
16 mChildrenLoaded(false)
20 GimmickDebugMessage(6,"Default Node constructor (level "<<GetLevel()<<")"
22 // Insert into parent's children list
23 InitializeAttributeMap();
24 parent->GetChildrenList().push_back(this);
28 GimmickDebugMessage(6,"Default Node constructor without parent"
32 //=============================================================
34 //=============================================================
35 /// Ctor with parent and attributes map
36 Node::Node(Node* parent, const AttributeMapType& attr)
39 mChildrenLoaded(false)
41 GimmickDebugMessage(6,"Node constructor (level "<<GetLevel()<<")"
45 // Insert into parent's children list
46 parent->GetChildrenList().push_back(this);
47 // Initialize attributes
48 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
49 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
50 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
54 AttributeMapType::const_iterator i = attr.find(a->GetKey());
55 if ( i != attr.end() )
59 GimmickDebugMessage(6,"Setting attribute '"<<a->GetName()<<"' = '"
61 UnsafeSetAttribute( a->GetKey(), v );
66 //=============================================================
69 //=============================================================
72 GimmickDebugMessage(6,"Node destructor"
74 ChildrenListType::iterator i;
75 for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
85 //=============================================================
88 //=============================================================
89 /// Initializes the attribute map i.e. creates the entries
90 void Node::InitializeAttributeMap()
92 // Initialize attributes
93 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
94 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
95 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
98 UnsafeSetAttribute( a->GetKey(), "" );
101 //=============================================================
103 //=============================================================
104 /// Returns the level descriptor of the node
105 const LevelDescriptor& Node::GetLevelDescriptor() const
107 return GetTree()->GetLevelDescriptor(GetLevel());
110 //=============================================================
112 //=============================================================
113 /// Returns the attribute descriptor of the passed parameter
114 const AttributeDescriptor& Node::GetAttributeDescriptor(const std::string& k)const
116 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
117 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
118 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
130 //=============================================================
132 //=============================================================
133 void Node::RemoveChildrenFromList(Node* node)
135 ChildrenListType::iterator i = find(GetChildrenList().begin(),
136 GetChildrenList().end(),
138 if (i != GetChildrenList().end())
140 GetChildrenList().erase(i);
143 //=============================================================
145 //=============================================================
146 const std::string& Node::GetAttribute(const std::string& k) const
148 // std::cout << "this = "<<(void*)this<<std::endl;
149 // std::cout << "mFieldValueMap="<<(void*)(&mFieldValueMap)<<std::endl;
150 AttributeMapType::const_iterator i = mAttributeMap.find(k);
151 if (i == mAttributeMap.end())
153 static std::string def("");
155 // CREAIMAGEIO_ERROR("DicomNode::GetFieldValue : no field with key '"<<k<<"'");
159 //=============================================================
161 //=============================================================
162 void Node::SetAttribute(const std::string& k,
163 const std::string& v)
165 AttributeMapType::iterator i = mAttributeMap.find(k);
166 if (i==mAttributeMap.end())
168 std::cout<<"[Gimmick!] Node::SetAttribute : no attribute with key '"
170 creaError( "[Gimmick!] Node::SetAttribute : no attribute with key '"
175 //=============================================================
177 //=============================================================
178 bool Node::Matches( const AttributeMapType& m ) const
180 GimmickDebugMessage(2,"'"<<GetLabel()<<"' matching..."<<std::endl);
181 const std::vector<std::string>& id
182 = GetLevelDescriptor().GetIdentifierList();
183 std::vector<std::string>::const_iterator i;
184 for (i = id.begin(); i != id.end(); ++i)
186 if (mAttributeMap.find(*i)->second != m.find(*i)->second )
188 GimmickDebugMessage(2,"IDENTIFIER '"<<*i<<"' values do not match"<<std::endl);
191 GimmickDebugMessage(2,"IDENTIFIER '"<<*i<<"' values match"<<std::endl);
195 //=============================================================
197 //=============================================================
198 void Node::Print() const
201 for (int i = 0; i<GetLevel(); ++i) mess += " ";
202 mess += "|_ " + GetLabel();
203 GimmickMessage(1,mess<<std::endl);
204 ChildrenListType::const_iterator j;
205 for (j=GetChildrenList().begin(); j!=GetChildrenList().end(); j++)
210 //=============================================================
212 //=============================================================
213 std::string Node::GetLabel() const
216 const std::vector<std::string>& label
217 = GetLevelDescriptor().GetLabelList();
219 std::vector<std::string>::const_iterator i;
220 for (i = label.begin(); i != label.end(); )
222 GimmickDebugMessage(9,"LABEL '"<<*i<<"'"<<std::endl);
223 AttributeMapType::const_iterator j = mAttributeMap.find(*i);
224 if (j != mAttributeMap.end())
228 if (i != label.end()) l += "|";
232 GimmickError("Node::GetLabel() : LABEL attribute '"
234 <<"' is not in node attribute map (should be!)" );
237 if (l.size()==0) l="?";
240 //=============================================================