X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src2%2FcreaImageIOTreeNode.cpp;h=6814203c004a77816090003b0bbeffde5ed4ab10;hb=b2bd47502b2ed48d4001e26bae3a961a3310c60d;hp=8f03924236e30d7e0dd2b824d9d17e4a288028d2;hpb=cbf693fa62cd51f4ca5c881838bbb609edc447b0;p=creaImageIO.git diff --git a/src2/creaImageIOTreeNode.cpp b/src2/creaImageIOTreeNode.cpp index 8f03924..6814203 100644 --- a/src2/creaImageIOTreeNode.cpp +++ b/src2/creaImageIOTreeNode.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include namespace creaImageIO @@ -16,6 +16,31 @@ namespace creaImageIO mChildrenLoaded(false) { if (parent) + { + GimmickMessage(5,"Default Node constructor (level "<GetChildrenList().push_back(this); + InitializeAttributeMap(); + } + else + { + GimmickMessage(5,"Default Node constructor without parent" + << std::endl); + } + } + //============================================================= + + //============================================================= + /// Ctor with parent and attributes map + Node::Node(Node* parent, const AttributeMapType& attr) + : mParent(parent), + mData(0), + mChildrenLoaded(false) + { + GimmickMessage(5,"Node constructor (level "<GetChildrenList().push_back(this); @@ -25,17 +50,27 @@ namespace creaImageIO a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end(); ++a) { - UnsafeSetAttribute( a->GetName(), "" ); + std::string v; + AttributeMapType::const_iterator i = attr.find(a->GetKey()); + if ( i != attr.end() ) + { + v = i->second; + } + GimmickMessage(5,"Setting attribute '"<GetName()<<"' = '" + <GetKey(), v ); } } + } //============================================================= - //============================================================= Node::~Node() { + GimmickMessage(5,"Node destructor" + << std::endl); ChildrenListType::iterator i; for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++) { @@ -49,7 +84,31 @@ namespace creaImageIO } //============================================================= - //============================================================= + + //============================================================= + /// 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()); + } + //============================================================= + + //============================================================= void Node::RemoveChildrenFromList(Node* node) { ChildrenListType::iterator i = find(GetChildrenList().begin(), @@ -85,15 +144,79 @@ namespace creaImageIO AttributeMapType::iterator i = mAttributeMap.find(k); if (i==mAttributeMap.end()) { - std::cout<<"[Gimmick!] Node::SetAttribute : no attribute with name '" + std::cout<<"[Gimmick!] Node::SetAttribute : no attribute with key '" <second = v; } - //============================================================= + //============================================================= + //============================================================= + bool Node::Matches( const AttributeMapType& m ) const + { + GimmickMessage(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 ) + { + GimmickMessage(2,"IDENTIFIER '"<<*i<<"' values do not match"<Print(); + } + } + //============================================================= + + //============================================================= + std::string Node::GetLabel() const + { + std::string l; + const std::vector& label + = GetLevelDescriptor().GetLabelList(); + + std::vector::const_iterator i; + for (i = label.begin(); i != label.end(); ) + { + GimmickMessage(3,"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; + } + //============================================================= }