X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src2%2FcreaImageIOTreeNode.cpp;h=a8cf7929dc6a04e589c0cf228eb3486cbc90a8c3;hb=76f7c62a930e60f9a569ede29b9546a179875d2c;hp=6bb7d3a7d8bc42ce3d0eda23e3ef8332691f2171;hpb=bae4df8a3e1ea669400c3a6c44ef4aa8d90fa1ed;p=creaImageIO.git diff --git a/src2/creaImageIOTreeNode.cpp b/src2/creaImageIOTreeNode.cpp index 6bb7d3a..a8cf792 100644 --- a/src2/creaImageIOTreeNode.cpp +++ b/src2/creaImageIOTreeNode.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include namespace creaImageIO @@ -17,16 +17,16 @@ namespace creaImageIO { if (parent) { + GimmickDebugMessage(6,"Default Node constructor (level "<GetChildrenList().push_back(this); - // Initialize attributes - LevelDescriptor::AttributeDescriptorListType::const_iterator a; - for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin(); - a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end(); - ++a) - { - UnsafeSetAttribute( a->GetKey(), "" ); - } + InitializeAttributeMap(); + parent->GetChildrenList().push_back(this); + } + else + { + GimmickDebugMessage(6,"Default Node constructor without parent" + << std::endl); } } //============================================================= @@ -38,7 +38,9 @@ namespace creaImageIO mData(0), mChildrenLoaded(false) { - if (parent) + GimmickDebugMessage(6,"Node constructor (level "<GetChildrenList().push_back(this); @@ -48,7 +50,15 @@ namespace creaImageIO a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end(); ++a) { - UnsafeSetAttribute( a->GetKey(), attr[a->GetKey()] ); + std::string v; + AttributeMapType::const_iterator i = attr.find(a->GetKey()); + if ( i != attr.end() ) + { + v = i->second; + } + GimmickDebugMessage(6,"Setting attribute '"<GetName()<<"' = '" + <GetKey(), v ); } } @@ -59,6 +69,8 @@ namespace creaImageIO //============================================================= Node::~Node() { + GimmickDebugMessage(6,"Node destructor" + << std::endl); ChildrenListType::iterator i; for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++) { @@ -72,8 +84,53 @@ namespace creaImageIO } //============================================================= - //============================================================= - void Node::RemoveChildrenFromList(Node* node) + + //============================================================= + /// Initializes the attribute map i.e. creates the entries + void Node::InitializeAttributeMap() + { + // Initialize attributes + LevelDescriptor::AttributeDescriptorListType::const_iterator a; + for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin(); + a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end(); + ++a) + { + UnsafeSetAttribute( a->GetKey(), "" ); + } + } + //============================================================= + + //============================================================= + /// Returns the level descriptor of the node + const LevelDescriptor& Node::GetLevelDescriptor() const + { + return GetTree()->GetLevelDescriptor(GetLevel()); + } + + //============================================================= + + //============================================================= + /// Returns the attribute descriptor of the passed parameter + const AttributeDescriptor& Node::GetAttributeDescriptor(const std::string& k)const + { + LevelDescriptor::AttributeDescriptorListType::const_iterator a; + for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin(); + a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end(); + ++a) + { + + if(a->GetKey()==k) + { + return *a; + } + + } + return *a; + } + //============================================================= + + //============================================================= + int Node::RemoveChildrenFromList(Node* node) { ChildrenListType::iterator i = find(GetChildrenList().begin(), GetChildrenList().end(), @@ -82,6 +139,7 @@ namespace creaImageIO { GetChildrenList().erase(i); } + return GetChildrenList().size(); } //============================================================= @@ -118,12 +176,70 @@ namespace creaImageIO //============================================================= //============================================================= - bool Node::Matches( const AttributeMapType& ) const + bool Node::Matches( const AttributeMapType& m ) const + { + GimmickDebugMessage(2,"'"<& id + = GetLevelDescriptor().GetIdentifierList(); + std::vector::const_iterator i; + for (i = id.begin(); i != id.end(); ++i) + { + if (mAttributeMap.find(*i)->second != m.find(*i)->second ) + { + GimmickDebugMessage(2,"IDENTIFIER '"<<*i<<"' values do not match"<Print(); + } + } + //============================================================= + + //============================================================= + std::string Node::GetLabel() const { - // TO DO - return false; + std::string l; + const std::vector& label + = GetLevelDescriptor().GetLabelList(); + + std::vector::const_iterator i; + for (i = label.begin(); i != label.end(); ) + { + GimmickDebugMessage(9,"LABEL '"<<*i<<"'"<second; + ++i; + if (i != label.end()) l += "|"; + } + else + { + GimmickError("Node::GetLabel() : LABEL attribute '" + <<*i + <<"' is not in node attribute map (should be!)" ); + } + } + if (l.size()==0) l="?"; + return l; } //============================================================= + } }