1 #include <creaImageIOTreeNode.h>
2 #include <creaImageIOTree.h>
3 #include <creaImageIOSystem.h>
11 //=============================================================
13 Node::Node(Node* parent)
16 mChildrenLoaded(false)
20 GimmickMessage(5,"Default Node constructor (level "<<GetLevel()<<")"
22 // Insert into parent's children list
23 parent->GetChildrenList().push_back(this);
24 InitializeAttributeMap();
28 GimmickMessage(5,"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 GimmickMessage(5,"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 GimmickMessage(5,"Setting attribute '"<<a->GetName()<<"' = '"
61 UnsafeSetAttribute( a->GetKey(), v );
66 //=============================================================
69 //=============================================================
72 GimmickMessage(5,"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();
121 GimmickMessage(1,"Hello my type is"<<a->GetType()<<std::endl);
122 GimmickMessage(1,"Hello my group is"<<a->GetGroup()<<std::endl);
123 GimmickMessage(1,"Hello my element is"<<a->GetElement()<<std::endl);
133 //=============================================================
135 //=============================================================
136 void Node::RemoveChildrenFromList(Node* node)
138 ChildrenListType::iterator i = find(GetChildrenList().begin(),
139 GetChildrenList().end(),
141 if (i != GetChildrenList().end())
143 GetChildrenList().erase(i);
146 //=============================================================
148 //=============================================================
149 const std::string& Node::GetAttribute(const std::string& k) const
151 // std::cout << "this = "<<(void*)this<<std::endl;
152 // std::cout << "mFieldValueMap="<<(void*)(&mFieldValueMap)<<std::endl;
153 AttributeMapType::const_iterator i = mAttributeMap.find(k);
154 if (i == mAttributeMap.end())
156 static std::string def("");
158 // CREAIMAGEIO_ERROR("DicomNode::GetFieldValue : no field with key '"<<k<<"'");
162 //=============================================================
164 //=============================================================
165 void Node::SetAttribute(const std::string& k,
166 const std::string& v)
168 AttributeMapType::iterator i = mAttributeMap.find(k);
169 if (i==mAttributeMap.end())
171 std::cout<<"[Gimmick!] Node::SetAttribute : no attribute with key '"
173 creaError( "[Gimmick!] Node::SetAttribute : no attribute with key '"
178 //=============================================================
180 //=============================================================
181 bool Node::Matches( const AttributeMapType& m ) const
183 GimmickMessage(2,"'"<<GetLabel()<<"' matching..."<<std::endl);
184 const std::vector<std::string>& id
185 = GetLevelDescriptor().GetIdentifierList();
186 std::vector<std::string>::const_iterator i;
187 for (i = id.begin(); i != id.end(); ++i)
189 if (mAttributeMap.find(*i)->second != m.find(*i)->second )
191 GimmickMessage(2,"IDENTIFIER '"<<*i<<"' values do not match"<<std::endl);
194 GimmickMessage(2,"IDENTIFIER '"<<*i<<"' values match"<<std::endl);
198 //=============================================================
200 //=============================================================
201 void Node::Print() const
204 for (int i = 0; i<GetLevel(); ++i) mess += " ";
205 mess += "|_ " + GetLabel();
206 GimmickMessage(1,mess<<std::endl);
207 ChildrenListType::const_iterator j;
208 for (j=GetChildrenList().begin(); j!=GetChildrenList().end(); j++)
213 //=============================================================
215 //=============================================================
216 std::string Node::GetLabel() const
219 const std::vector<std::string>& label
220 = GetLevelDescriptor().GetLabelList();
222 std::vector<std::string>::const_iterator i;
223 for (i = label.begin(); i != label.end(); )
225 GimmickMessage(3,"LABEL '"<<*i<<"'"<<std::endl);
226 AttributeMapType::const_iterator j = mAttributeMap.find(*i);
227 if (j != mAttributeMap.end())
231 if (i != label.end()) l += "|";
235 GimmickError("Node::GetLabel() : LABEL attribute '"
237 <<"' is not in node attribute map (should be!)" );
240 if (l.size()==0) l="?";
243 //=============================================================