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 void RemoveChildrenFromList(Node*);
87 AttributeMapType& GetAttributeMap() { return mAttributeMap; }
88 const AttributeMapType& GetAttributeMap() const { return mAttributeMap; }
89 const std::string& GetAttribute(const std::string& k) const;
90 const std::string& GetCleanAttribute(const std::string& k) const;
91 const std::string& UnsafeGetAttribute(const std::string& k) const
92 { return mAttributeMap.find(k)->second; }
93 void SetAttribute(const std::string& k, const std::string& v);
94 void UnsafeSetAttribute(const std::string& k, const std::string& v)
95 { mAttributeMap[k] = v; }
97 const AttributeDescriptor& GetAttributeDescriptor(const std::string& k)
99 // { return GetTypeDescription().GetFieldDescription(k); }
102 /// Returns true iff the KEY attributes of the node match those of the map provided
103 bool Matches( const AttributeMapType& ) const;
105 /// Returns the node data casted into the type T
106 template<class T> T GetData() const
107 { if (mData!=0) return dynamic_cast<T>(mData); return 0; }
109 /// Sets the node data. Deletes existing data if any.
110 void SetData(NodeData* d) { if (mData) delete mData; mData = d; }
112 /// Sorts the children of the node
113 void SortChildren(const LexicographicalComparator&);
116 virtual void Print() const;
117 std::string GetLabel() const;
119 int ImageGetRows() const;
120 int ImageGetColumns() const;
121 int ImageGetFrames() const;
122 const std::string& ImageGetFullFileName() const { return UnsafeGetAttribute("FullFileName"); }
126 /// The parent of the node
128 /// The list of children
129 ChildrenListType mChildren;
130 /// The map of attributes
131 AttributeMapType mAttributeMap;
134 /// Are the children loaded ?
135 bool mChildrenLoaded;
136 /// The number of children
137 // int mNumberOfChildren;
140 //=====================================================================
145 } // namespace creaImageIO
149 #endif // #ifndef __creaImageIOTreeNode_h_INCLUDED__