creaImageIO_lib
creaImageIOTreeNode.h
Go to the documentation of this file.
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
16 #
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
21 # liability.
22 #
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27 
28 
29 #ifndef __creaImageIOTreeNode_h_INCLUDED__
30 #define __creaImageIOTreeNode_h_INCLUDED__
31 
34 #include<boost/filesystem/operations.hpp>
35 #include <vector>
36 #include <map>
37 
38 
39 namespace creaImageIO
40 {
41 
42  namespace tree
43  {
47  //=====================================================================
49  class Tree;
50  //=====================================================================
51 
52  //=====================================================================
54  struct NodeData
55  {
56  NodeData() {}
57  virtual ~NodeData() {}
58  };
59  //=====================================================================
60 
61 
62  //=====================================================================
64  class Node
65  {
66  public:
67  typedef std::map<std::string,std::string> AttributeMapType;
68 
69 
71  Node(Node* parent);
73  Node(Node* parent, const AttributeMapType& );
75  virtual ~Node();
76 
79 
81  const LevelDescriptor& GetLevelDescriptor() const;
82 
83 
85  virtual Tree* GetTree() { return mParent->GetTree(); }
87  virtual const Tree* GetTree() const { return mParent->GetTree(); }
89  virtual int GetLevel() const { return mParent->GetLevel()+1; }
90 
91 
93  Node* GetParent() const { return mParent; }
94 
99  unsigned int GetNumberOfChildren() const { return (int)mChildren.size(); }
100 
102  bool GetChildrenLoaded() const { return mChildrenLoaded; }
103 
105  void SetChildrenLoaded(bool l) { mChildrenLoaded = l; }
106 
108  typedef std::vector<Node*> ChildrenListType;
112  const ChildrenListType& GetChildrenList() const { return mChildren; }
113 
116 
117 
120 
122  const AttributeMapType& GetAttributeMap() const { return mAttributeMap; }
123 
125  const std::string& GetAttribute(const std::string& k) const;
126 
128  // TODO : backslash OS uniformity
129  const std::string& GetCleanAttribute(const std::string& k) const;
130 
132  void SetAttribute(const std::string& k, const std::string& v);
133 
135  void UnsafeSetAttribute(const std::string& k, const std::string& v)
136  { mAttributeMap[k] = v; }
137 
139  const AttributeDescriptor& GetAttributeDescriptor(const std::string& k)const;
140 
142  bool Matches( const AttributeMapType& ) const;
143 
145  template<class T> T GetData() const
146  { if (mData!=0) return dynamic_cast<T>(mData); return 0; }
147 
149  void SetData(boost::shared_ptr<NodeData> d) {mData.reset(); mData = d; }//{ if (mData) delete mData; mData = d; }
150 
153 
155  virtual void Print() const;
156 
158  std::string GetLabel() const;
159 
160 
161  private:
169  boost::shared_ptr<NodeData> mData;
173  // int mNumberOfChildren;
174 
175  }; // class Node
176  //=====================================================================
177 
178  } // namespace tree
179 
180 
181 } // namespace creaImageIO
182 
183 
184 
185 #endif // #ifndef __creaImageIOTreeNode_h_INCLUDED__