]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOTreeNode.cpp
*** empty log message ***
[creaImageIO.git] / src2 / creaImageIOTreeNode.cpp
index 6bb7d3a7d8bc42ce3d0eda23e3ef8332691f2171..4335dfe05b365e30de98d43ee5c4737e014854fd 100644 (file)
@@ -1,5 +1,6 @@
 #include <creaImageIOTreeNode.h>
 #include <creaImageIOTree.h>
+#include <creaImageIOSystem.h>
 #include <creaMessageManager.h>
 #include <algorithm>
 
@@ -17,16 +18,16 @@ namespace creaImageIO
     {
       if (parent) 
        {
+         GimmickMessage(5,"Default Node constructor (level "<<GetLevel()<<")"
+                        << std::endl);
          // Insert into parent's children list
          parent->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();
+       }
+      else
+       {
+         GimmickMessage(5,"Default Node constructor without parent"    
+                        << std::endl);
        }
     }
     //=============================================================
@@ -38,7 +39,9 @@ namespace creaImageIO
        mData(0),
        mChildrenLoaded(false)
     {
-      if (parent) 
+      GimmickMessage(5,"Node constructor (level "<<GetLevel()<<")"
+                    << std::endl);
+     if (parent) 
        {
          // Insert into parent's children list
          parent->GetChildrenList().push_back(this);
@@ -48,7 +51,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;
+               }
+             GimmickMessage(5,"Setting attribute '"<<a->GetName()<<"' = '"
+                            <<v<<"'"<<std::endl);
+             UnsafeSetAttribute( a->GetKey(), v );
            }
        }
       
@@ -59,6 +70,8 @@ namespace creaImageIO
     //=============================================================
     Node::~Node()
     {
+      GimmickMessage(5,"Node destructor"
+                    << std::endl);
       ChildrenListType::iterator i;
       for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
        {
@@ -72,7 +85,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(),
@@ -118,12 +155,70 @@ namespace creaImageIO
     //=============================================================
 
     //=============================================================
-    bool Node::Matches(  const AttributeMapType& ) const
+    bool Node::Matches(  const AttributeMapType& ) const
     {
-      // TO DO 
-      return false;
+      GimmickMessage(2,"'"<<GetLabel()<<"' matching..."<<std::endl);
+      const std::vector<std::string>& id 
+       = GetLevelDescriptor().GetIdentifierList();
+      std::vector<std::string>::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"<<std::endl);
+             return false;
+           }
+         GimmickMessage(2,"IDENTIFIER '"<<*i<<"' values match"<<std::endl);
+       }
+      return true;
+    }
+    //=============================================================
+    
+    //=============================================================
+    void Node::Print() const
+    {
+      std::string mess;
+      for (int i = 0; i<GetLevel(); ++i) mess += " ";
+      mess += "|--" + GetLabel();
+      GimmickMessage(1,mess<<std::endl);
+      ChildrenListType::const_iterator i;
+      for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
+       {
+         (*i)->Print();
+       } 
     }
     //=============================================================
+
+    //=============================================================
+    std::string Node::GetLabel() const
+    {
+      std::string l;
+      const std::vector<std::string>& label 
+       = GetLevelDescriptor().GetLabelList();
+      
+      std::vector<std::string>::const_iterator i;
+      for (i = label.begin(); i != label.end(); )
+       {
+         GimmickMessage(3,"LABEL '"<<*i<<"'"<<std::endl);
+         AttributeMapType::const_iterator j = mAttributeMap.find(*i);
+         if (j != mAttributeMap.end())
+           {
+             l += j->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;
+    }
+    //=============================================================
+
   }
 
 }