1 #ifndef __creaImageIOTreeNode_h_INCLUDED__
2 #define __creaImageIOTreeNode_h_INCLUDED__
4 #include <creaImageIOTreeDescriptor.h>
5 #include <creaImageIOTreeComparators.h>
6 #include<boost/filesystem/operations.hpp>
19 //=====================================================================
20 /// Forward declaration of Tree
22 //=====================================================================
24 //=====================================================================
25 /// Abstract class to store user data on a Tree node
29 virtual ~NodeData() {}
31 //=====================================================================
34 //=====================================================================
35 /// Node of an attributed Tree structure
39 typedef std::map<std::string,std::string> AttributeMapType;
44 /// Ctor with parent and attributes map
45 Node(Node* parent, const AttributeMapType& );
46 /// Virtual destructor
49 /// Initializes the attribute map i.e. creates the entries
50 void InitializeAttributeMap();
52 /// Returns the level descriptor of the node
53 const LevelDescriptor& GetLevelDescriptor() const;
56 /// Returns the tree to which the node belongs
57 virtual Tree* GetTree() { return mParent->GetTree(); }
58 /// Returns the tree to which the node belongs
59 virtual const Tree* GetTree() const { return mParent->GetTree(); }
60 /// Returns the level of the node in the tree
61 virtual int GetLevel() const { return mParent->GetLevel()+1; }
63 /// Returns the parent of the node
64 Node* GetParent() const { return mParent; }
66 /// Returns the number of children of the node.
67 /// Warning : if the children are not loaded then might return 0
68 /// even if the node has children !
69 /// see TreeHandler::GetNumberOfChildren
70 unsigned int GetNumberOfChildren() const { return mChildren.size(); }
72 /// Returns true iff the node's children are loaded
73 bool GetChildrenLoaded() const { return mChildrenLoaded; }
75 /// Sets the node's children
76 void SetChildrenLoaded(bool l) { mChildrenLoaded = l; }
78 /// The type of children container
79 typedef std::vector<Node*> ChildrenListType;
80 /// Returns the list of children
81 ChildrenListType& GetChildrenList() { return mChildren; }
82 /// Returns the list of children (const)
83 const ChildrenListType& GetChildrenList() const { return mChildren; }
85 /// Remove the given children from the children list
86 int RemoveChildrenFromList(Node*);
89 /// Get the Attributes Map
90 AttributeMapType& GetAttributeMap() { return mAttributeMap; }
92 /// Get the Attributes Map
93 const AttributeMapType& GetAttributeMap() const { return mAttributeMap; }
95 /// Get the Attribute for a specific key
96 const std::string& GetAttribute(const std::string& k) const;
98 /// Get the Attribute for a specific key without OS dependance (not implemented)
99 // TODO : backslash OS uniformity
100 const std::string& GetCleanAttribute(const std::string& k) const;
102 /// Set an Attribute for a specific key
103 void SetAttribute(const std::string& k, const std::string& v);
105 /// Set an Attribute for a specific key(unsafe mode)
106 void UnsafeSetAttribute(const std::string& k, const std::string& v)
107 { mAttributeMap[k] = v; }
109 /// Get Descriptor for an Attribute
110 const AttributeDescriptor& GetAttributeDescriptor(const std::string& k)const;
112 /// Returns true if the KEY attributes of the node match those of the map provided
113 bool Matches( const AttributeMapType& ) const;
115 /// Returns the node data casted into the type T
116 template<class T> T GetData() const
117 { if (mData!=0) return dynamic_cast<T>(mData); return 0; }
119 /// Sets the node data. Deletes existing data if any.
120 void SetData(boost::shared_ptr<NodeData> d) { mData = d; }//{ if (mData) delete mData; mData = d; }
122 /// Sorts the children of the node
123 void SortChildren(const LexicographicalComparator&);
126 virtual void Print() const;
128 /// Get the Label of the node
129 std::string GetLabel() const;
133 /// The parent of the node
135 /// The list of children
136 ChildrenListType mChildren;
137 /// The map of attributes
138 AttributeMapType mAttributeMap;
140 boost::shared_ptr<NodeData> mData;
141 /// Are the children loaded ?
142 bool mChildrenLoaded;
143 /// The number of children
144 // int mNumberOfChildren;
147 //=====================================================================
152 } // namespace creaImageIO
156 #endif // #ifndef __creaImageIOTreeNode_h_INCLUDED__