]> Creatis software - creaImageIO.git/blob - src2/creaImageIOTreeNode.cpp
8f03924236e30d7e0dd2b824d9d17e4a288028d2
[creaImageIO.git] / src2 / creaImageIOTreeNode.cpp
1 #include <creaImageIOTreeNode.h>
2 #include <creaImageIOTree.h>
3 #include <creaMessageManager.h>
4 #include <algorithm>
5
6 namespace creaImageIO
7 {
8   namespace tree
9   {
10
11     //=============================================================
12     /// Ctor with parent
13     Node::Node(Node* parent)
14       : mParent(parent),
15         mData(0),
16         mChildrenLoaded(false)
17     {
18       if (parent) 
19         {
20           // Insert into parent's children list
21           parent->GetChildrenList().push_back(this);
22           // Initialize attributes
23           LevelDescriptor::AttributeDescriptorListType::const_iterator a;
24           for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
25                a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
26                ++a)
27             {
28               UnsafeSetAttribute( a->GetName(), "" );
29             }
30         }
31     }
32     //=============================================================
33
34
35
36     //=============================================================
37     Node::~Node()
38     {
39       ChildrenListType::iterator i;
40       for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
41         {
42           delete *i;
43         }
44       if (mData) 
45         {
46           delete mData;
47           mData = 0;
48         }
49     }
50     //=============================================================
51
52   //=============================================================
53     void Node::RemoveChildrenFromList(Node* node)
54     {
55       ChildrenListType::iterator i = find(GetChildrenList().begin(),
56                                           GetChildrenList().end(),
57                                           node);
58       if (i != GetChildrenList().end())
59         {
60           GetChildrenList().erase(i);
61         }
62     }
63     //=============================================================
64
65     //=============================================================
66     const std::string& Node::GetAttribute(const std::string& k) const
67     {
68       //    std::cout << "this = "<<(void*)this<<std::endl;
69       //    std::cout << "mFieldValueMap="<<(void*)(&mFieldValueMap)<<std::endl;
70       AttributeMapType::const_iterator i = mAttributeMap.find(k);
71       if (i == mAttributeMap.end())
72         {
73           static std::string def("");
74           return def;
75           //    CREAIMAGEIO_ERROR("DicomNode::GetFieldValue : no field with key '"<<k<<"'");
76         }
77       return i->second;
78   }
79   //=============================================================
80
81   //=============================================================
82     void Node::SetAttribute(const std::string& k, 
83                                  const std::string& v)
84   {
85     AttributeMapType::iterator i = mAttributeMap.find(k);
86     if (i==mAttributeMap.end())
87       {
88         std::cout<<"[Gimmick!] Node::SetAttribute : no attribute with name '"
89                  <<k<<"'"<<std::endl;
90         creaError( "[Gimmick!] Node::SetAttribute : no attribute with name '"
91                    <<k<<"'");
92       }
93     i->second = v;
94   }
95   //=============================================================
96
97
98   }
99
100 }
101