1 #include <creaImageIOTreeNode.h>
2 #include <creaImageIOTree.h>
3 #include <creaImageIOSystem.h>
4 #include <creaMessageManager.h>
12 //=============================================================
14 Node::Node(Node* parent)
17 mChildrenLoaded(false)
21 GimmickMessage(5,"Default Node constructor (level "<<GetLevel()<<")"
23 // Insert into parent's children list
24 parent->GetChildrenList().push_back(this);
25 InitializeAttributeMap();
29 GimmickMessage(5,"Default Node constructor without parent"
33 //=============================================================
35 //=============================================================
36 /// Ctor with parent and attributes map
37 Node::Node(Node* parent, const AttributeMapType& attr)
40 mChildrenLoaded(false)
42 GimmickMessage(5,"Node constructor (level "<<GetLevel()<<")"
46 // Insert into parent's children list
47 parent->GetChildrenList().push_back(this);
48 // Initialize attributes
49 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
50 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
51 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
55 AttributeMapType::const_iterator i = attr.find(a->GetKey());
56 if ( i != attr.end() )
60 GimmickMessage(5,"Setting attribute '"<<a->GetName()<<"' = '"
62 UnsafeSetAttribute( a->GetKey(), v );
67 //=============================================================
70 //=============================================================
73 GimmickMessage(5,"Node destructor"
75 ChildrenListType::iterator i;
76 for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
86 //=============================================================
89 //=============================================================
90 /// Initializes the attribute map i.e. creates the entries
91 void Node::InitializeAttributeMap()
93 // Initialize attributes
94 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
95 for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
96 a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
99 UnsafeSetAttribute( a->GetKey(), "" );
102 //=============================================================
104 //=============================================================
105 /// Returns the level descriptor of the node
106 const LevelDescriptor& Node::GetLevelDescriptor() const
108 return GetTree()->GetLevelDescriptor(GetLevel());
110 //=============================================================
112 //=============================================================
113 void Node::RemoveChildrenFromList(Node* node)
115 ChildrenListType::iterator i = find(GetChildrenList().begin(),
116 GetChildrenList().end(),
118 if (i != GetChildrenList().end())
120 GetChildrenList().erase(i);
123 //=============================================================
125 //=============================================================
126 const std::string& Node::GetAttribute(const std::string& k) const
128 // std::cout << "this = "<<(void*)this<<std::endl;
129 // std::cout << "mFieldValueMap="<<(void*)(&mFieldValueMap)<<std::endl;
130 AttributeMapType::const_iterator i = mAttributeMap.find(k);
131 if (i == mAttributeMap.end())
133 static std::string def("");
135 // CREAIMAGEIO_ERROR("DicomNode::GetFieldValue : no field with key '"<<k<<"'");
139 //=============================================================
141 //=============================================================
142 void Node::SetAttribute(const std::string& k,
143 const std::string& v)
145 AttributeMapType::iterator i = mAttributeMap.find(k);
146 if (i==mAttributeMap.end())
148 std::cout<<"[Gimmick!] Node::SetAttribute : no attribute with key '"
150 creaError( "[Gimmick!] Node::SetAttribute : no attribute with key '"
155 //=============================================================
157 //=============================================================
158 bool Node::Matches( const AttributeMapType& m ) const
160 GimmickMessage(2,"'"<<GetLabel()<<"' matching..."<<std::endl);
161 const std::vector<std::string>& id
162 = GetLevelDescriptor().GetIdentifierList();
163 std::vector<std::string>::const_iterator i;
164 for (i = id.begin(); i != id.end(); ++i)
166 if (mAttributeMap.find(*i)->second != m.find(*i)->second )
168 GimmickMessage(2,"IDENTIFIER '"<<*i<<"' values do not match"<<std::endl);
171 GimmickMessage(2,"IDENTIFIER '"<<*i<<"' values match"<<std::endl);
175 //=============================================================
177 //=============================================================
178 void Node::Print() const
181 for (int i = 0; i<GetLevel(); ++i) mess += " ";
182 mess += "|--" + GetLabel();
183 GimmickMessage(1,mess<<std::endl);
184 ChildrenListType::const_iterator i;
185 for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
190 //=============================================================
192 //=============================================================
193 std::string Node::GetLabel() const
196 const std::vector<std::string>& label
197 = GetLevelDescriptor().GetLabelList();
199 std::vector<std::string>::const_iterator i;
200 for (i = label.begin(); i != label.end(); )
202 GimmickMessage(3,"LABEL '"<<*i<<"'"<<std::endl);
203 AttributeMapType::const_iterator j = mAttributeMap.find(*i);
204 if (j != mAttributeMap.end())
208 if (i != label.end()) l += "|";
212 GimmickError("Node::GetLabel() : LABEL attribute '"
214 <<"' is not in node attribute map (should be!)" );
217 if (l.size()==0) l="?";
220 //=============================================================