2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
29 #ifndef __creaImageIOTreeNode_h_INCLUDED__
30 #define __creaImageIOTreeNode_h_INCLUDED__
32 #include <creaImageIOTreeLevelDescriptor.h>
33 #include <creaImageIOTreeComparators.h>
34 #include<boost/filesystem/operations.hpp>
47 //=====================================================================
48 /// Forward declaration of Tree
50 //=====================================================================
52 //=====================================================================
53 /// Abstract class to store user data on a Tree node
57 virtual ~NodeData() {}
59 //=====================================================================
62 //=====================================================================
63 /// Node of an attributed Tree structure
67 typedef std::map<std::string,std::string> AttributeMapType;
72 /// Ctor with parent and attributes map
73 Node(Node* parent, const AttributeMapType& );
74 /// Virtual destructor
77 /// Initializes the attribute map i.e. creates the entries
78 void InitializeAttributeMap();
80 /// Returns the level descriptor of the node
81 const LevelDescriptor& GetLevelDescriptor() const;
84 /// Returns the tree to which the node belongs
85 virtual Tree* GetTree() { return mParent->GetTree(); }
86 /// Returns the tree to which the node belongs
87 virtual const Tree* GetTree() const { return mParent->GetTree(); }
88 /// Returns the level of the node in the tree
89 virtual int GetLevel() const { return mParent->GetLevel()+1; }
92 /// Returns the parent of the node
93 Node* GetParent() const { return mParent; }
95 /// Returns the number of children of the node.
96 /// Warning : if the children are not loaded then might return 0
97 /// even if the node has children !
98 /// see TreeHandler::GetNumberOfChildren
99 unsigned int GetNumberOfChildren() const { return (int)mChildren.size(); }
101 /// Returns true iff the node's children are loaded
102 bool GetChildrenLoaded() const { return mChildrenLoaded; }
104 /// Sets the node's children
105 void SetChildrenLoaded(bool l) { mChildrenLoaded = l; }
107 /// The type of children container
108 typedef std::vector<Node*> ChildrenListType;
109 /// Returns the list of children
110 ChildrenListType& GetChildrenList() { return mChildren; }
111 /// Returns the list of children (const)
112 const ChildrenListType& GetChildrenList() const { return mChildren; }
114 /// Remove the given children from the children list
115 int RemoveChildrenFromList(Node*);
118 /// Get the Attributes Map
119 AttributeMapType& GetAttributeMap() { return mAttributeMap; }
121 /// Get the Attributes Map
122 const AttributeMapType& GetAttributeMap() const { return mAttributeMap; }
124 /// Get the Attribute for a specific key
125 const std::string& GetAttribute(const std::string& k) const;
127 /// Get the Attribute for a specific key without OS dependance (not implemented)
128 // TODO : backslash OS uniformity
129 const std::string& GetCleanAttribute(const std::string& k) const;
131 /// Set an Attribute for a specific key
132 void SetAttribute(const std::string& k, const std::string& v);
134 /// Set an Attribute for a specific key(unsafe mode)
135 void UnsafeSetAttribute(const std::string& k, const std::string& v)
136 { mAttributeMap[k] = v; }
138 /// Get Descriptor for an Attribute
139 const AttributeDescriptor& GetAttributeDescriptor(const std::string& k)const;
141 /// Returns true if the KEY attributes of the node match those of the map provided
142 bool Matches( const AttributeMapType& ) const;
144 /// Returns the node data casted into the type T
145 template<class T> T GetData() const
146 { if (mData!=0) return dynamic_cast<T>(mData); return 0; }
148 /// Sets the node data. Deletes existing data if any.
149 void SetData(boost::shared_ptr<NodeData> d) {mData.reset(); mData = d; }//{ if (mData) delete mData; mData = d; }
151 /// Sorts the children of the node
152 void SortChildren(const LexicographicalComparator&);
155 virtual void Print() const;
157 /// Get the Label of the node
158 std::string GetLabel() const;
162 /// The parent of the node
164 /// The list of children
165 ChildrenListType mChildren;
166 /// The map of attributes
167 AttributeMapType mAttributeMap;
169 boost::shared_ptr<NodeData> mData;
170 /// Are the children loaded ?
171 bool mChildrenLoaded;
172 /// The number of children
173 // int mNumberOfChildren;
176 //=====================================================================
181 } // namespace creaImageIO
185 #endif // #ifndef __creaImageIOTreeNode_h_INCLUDED__