1 #include <creaImageIOTreeNode.h>
2 #include <creaImageIOTree.h>
3 #include <creaImageIOSystem.h>
11 //=============================================================
13 Node::Node(Node* parent)
14 : mParent(parent),//mData(0),
15 mChildrenLoaded(false)
19 GimmickDebugMessage(6,"Default Node constructor (level "<<GetLevel()<<")"
21 // Insert into parent's children list
22 InitializeAttributeMap();
23 parent->GetChildrenList().push_back(this);
27 GimmickDebugMessage(6,"Default Node constructor without parent"
31 //=============================================================
33 //=============================================================
34 /// Ctor with parent and attributes map
35 Node::Node(Node* parent, const AttributeMapType& attr)
36 : mParent(parent),//mData(0),
37 mChildrenLoaded(false)
39 GimmickDebugMessage(6,"Node constructor (level "<<GetLevel()<<")"
44 // Insert into parent's children list
45 parent->GetChildrenList().push_back(this);
46 // Initialize attributes
47 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
48 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
49 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
53 AttributeMapType::const_iterator i = attr.find(a->GetKey());
54 if ( i != attr.end() )
58 GimmickDebugMessage(6,"Setting attribute '"<<a->GetName()<<"' = '"
60 UnsafeSetAttribute( a->GetKey(), v );
65 //=============================================================
68 //=============================================================
71 GimmickDebugMessage(6,"Node destructor"
73 ChildrenListType::iterator i;
74 for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
80 //=============================================================
83 //=============================================================
84 /// Initializes the attribute map i.e. creates the entries
85 void Node::InitializeAttributeMap()
87 // Initialize attributes
88 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
89 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
90 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
93 UnsafeSetAttribute( a->GetKey(), "" );
96 //=============================================================
98 //=============================================================
99 /// Returns the level descriptor of the node
100 const LevelDescriptor& Node::GetLevelDescriptor() const
102 return GetTree()->GetLevelDescriptor(GetLevel());
105 //=============================================================
107 //=============================================================
108 /// Returns the attribute descriptor of the passed parameter
109 const AttributeDescriptor& Node::GetAttributeDescriptor(const std::string& k)const
111 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
112 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
113 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
125 //=============================================================
127 //=============================================================
128 int Node::RemoveChildrenFromList(Node* node)
130 ChildrenListType::iterator i = find(GetChildrenList().begin(),
131 GetChildrenList().end(),
133 if (i != GetChildrenList().end())
135 GetChildrenList().erase(i);
137 return GetChildrenList().size();
139 //=============================================================
141 //=============================================================
142 const std::string& Node::GetAttribute(const std::string& k) const
144 // std::cout << "this = "<<(void*)this<<std::endl;
145 // std::cout << "mFieldValueMap="<<(void*)(&mFieldValueMap)<<std::endl;
146 AttributeMapType::const_iterator i = mAttributeMap.find(k);
147 if (i == mAttributeMap.end())
149 static std::string def("");
151 // CREAIMAGEIO_ERROR("DicomNode::GetFieldValue : no field with key '"<<k<<"'");
155 //=============================================================
157 //=============================================================
158 void Node::SetAttribute(const std::string& k,
159 const std::string& v)
161 AttributeMapType::iterator i = mAttributeMap.find(k);
162 if (i==mAttributeMap.end())
164 std::cout<<"[Gimmick!] Node::SetAttribute : no attribute with key '"
166 creaError( "[Gimmick!] Node::SetAttribute : no attribute with key '"
171 //=============================================================
173 //=============================================================
174 bool Node::Matches( const AttributeMapType& m ) const
176 GimmickDebugMessage(2,"'"<<GetLabel()<<"' matching..."<<std::endl);
177 const std::vector<std::string>& id
178 = GetLevelDescriptor().GetIdentifierList();
179 std::vector<std::string>::const_iterator i;
180 for (i = id.begin(); i != id.end(); ++i)
182 if (mAttributeMap.find(*i)->second != m.find(*i)->second )
184 GimmickDebugMessage(2,"IDENTIFIER '"<<*i<<"' values do not match"<<std::endl);
187 GimmickDebugMessage(2,"IDENTIFIER '"<<*i<<"' values match"<<std::endl);
191 //=============================================================
193 //=============================================================
194 void Node::Print() const
197 for (int i = 0; i<GetLevel(); ++i) mess += " ";
198 mess += "|_ " + GetLabel();
199 GimmickMessage(1,mess<<std::endl);
200 ChildrenListType::const_iterator j;
201 for (j=GetChildrenList().begin(); j!=GetChildrenList().end(); j++)
206 //=============================================================
208 //=============================================================
209 std::string Node::GetLabel() const
212 const std::vector<std::string>& label
213 = GetLevelDescriptor().GetLabelList();
215 std::vector<std::string>::const_iterator i;
216 for (i = label.begin(); i != label.end(); )
218 GimmickDebugMessage(9,"LABEL '"<<*i<<"'"<<std::endl);
219 AttributeMapType::const_iterator j = mAttributeMap.find(*i);
220 if (j != mAttributeMap.end())
224 if (i != label.end()) l += "|";
228 GimmickError("Node::GetLabel() : LABEL attribute '"
230 <<"' is not in node attribute map (should be!)" );
233 if (l.size()==0) l="?";
236 //=============================================================