1 #ifndef __creaImageIOTreeNode_h_INCLUDED__
2 #define __creaImageIOTreeNode_h_INCLUDED__
4 #include <creaImageIOTreeDescriptor.h>
5 #include <creaImageIOTreeComparators.h>
17 //=====================================================================
18 /// Forward declaration of Tree
20 //=====================================================================
22 //=====================================================================
23 /// Abstract class to store user data on a Tree node
27 virtual ~NodeData() {}
29 //=====================================================================
32 //=====================================================================
33 /// Node of an attributed Tree structure
37 typedef std::map<std::string,std::string> AttributeMapType;
42 /// Ctor with parent and attributes map
43 Node(Node* parent, const AttributeMapType& );
44 /// Virtual destructor
47 /// Initializes the attribute map i.e. creates the entries
48 void InitializeAttributeMap();
50 /// Returns the level descriptor of the node
51 const LevelDescriptor& GetLevelDescriptor() const;
54 /// Returns the tree to which the node belongs
55 virtual Tree* GetTree() { return mParent->GetTree(); }
56 /// Returns the tree to which the node belongs
57 virtual const Tree* GetTree() const { return mParent->GetTree(); }
58 /// Returns the level of the node in the tree
59 virtual int GetLevel() const { return mParent->GetLevel()+1; }
61 /// Returns the parent of the node
62 Node* GetParent() const { return mParent; }
64 /// Returns the number of children of the node.
65 /// Warning : if the children are not loaded then might return 0
66 /// even if the node has children !
67 /// see TreeHandler::GetNumberOfChildren
68 unsigned int GetNumberOfChildren() const { return mChildren.size(); }
70 /// Returns true iff the node's children are loaded
71 bool GetChildrenLoaded() const { return mChildrenLoaded; }
73 /// Sets the node's children
74 void SetChildrenLoaded(bool l) { mChildrenLoaded = l; }
76 /// The type of children container
77 typedef std::vector<Node*> ChildrenListType;
78 /// Returns the list of children
79 ChildrenListType& GetChildrenList() { return mChildren; }
80 /// Returns the list of children (const)
81 const ChildrenListType& GetChildrenList() const { return mChildren; }
83 /// Remove the given children from the children list
84 int RemoveChildrenFromList(Node*);
87 /// Get the Attributes Map
88 AttributeMapType& GetAttributeMap() { return mAttributeMap; }
90 /// Get the Attributes Map
91 const AttributeMapType& GetAttributeMap() const { return mAttributeMap; }
93 /// Get the Attribute for a specific key
94 const std::string& GetAttribute(const std::string& k) const;
96 /// Get the Attribute for a specific key without OS dependance (not implemented)
97 // TODO : backslash OS uniformity
98 const std::string& GetCleanAttribute(const std::string& k) const;
100 /// Set an Attribute for a specific key
101 void SetAttribute(const std::string& k, const std::string& v);
103 /// Set an Attribute for a specific key(unsafe mode)
104 void UnsafeSetAttribute(const std::string& k, const std::string& v)
105 { mAttributeMap[k] = v; }
107 /// Get Descriptor for an Attribute
108 const AttributeDescriptor& GetAttributeDescriptor(const std::string& k)const;
110 /// Returns true if the KEY attributes of the node match those of the map provided
111 bool Matches( const AttributeMapType& ) const;
113 /// Returns the node data casted into the type T
114 template<class T> T GetData() const
115 { if (mData!=0) return dynamic_cast<T>(mData); return 0; }
117 /// Sets the node data. Deletes existing data if any.
118 void SetData(NodeData* d) { if (mData) delete mData; mData = d; }
120 /// Sorts the children of the node
121 void SortChildren(const LexicographicalComparator&);
124 virtual void Print() const;
126 /// Get the Label of the node
127 std::string GetLabel() const;
131 /// The parent of the node
133 /// The list of children
134 ChildrenListType mChildren;
135 /// The map of attributes
136 AttributeMapType mAttributeMap;
139 /// Are the children loaded ?
140 bool mChildrenLoaded;
141 /// The number of children
142 // int mNumberOfChildren;
145 //=====================================================================
150 } // namespace creaImageIO
154 #endif // #ifndef __creaImageIOTreeNode_h_INCLUDED__