1 #ifndef __creaImageIOTreeNode_h_INCLUDED__
2 #define __creaImageIOTreeNode_h_INCLUDED__
4 #include <creaImageIOTreeDescriptor.h>
5 #include <creaImageIOTreeComparators.h>
14 //=====================================================================
15 /// Forward declaration of Tree
17 //=====================================================================
19 //=====================================================================
20 /// Abstract class to store user data on a tree node
24 virtual ~NodeData() {}
26 //=====================================================================
29 //=====================================================================
30 /// Node of an attributed tree structure
36 /// Virtual destructor
40 /// Returns the level descriptor of the node
41 const LevelDescriptor& GetLevelDescriptor() const;
44 /// Returns the tree to which the node belongs
45 virtual Tree* GetTree() { return mParent->GetTree(); }
46 /// Returns the tree to which the node belongs
47 virtual const Tree* GetTree() const { return mParent->GetTree(); }
48 /// Returns the level of the node in the tree
49 virtual int GetLevel() const { return mParent->GetLevel()+1; }
51 /// Returns the parent of the node
52 Node* GetParent() const { return mParent; }
54 /// Returns the number of children of the node.
55 /// Warning : if the children are not loaded then might return 0
56 /// even if the node has children !
57 /// see TreeHandler::GetNumberOfChildren
58 unsigned int GetNumberOfChildren() const { return mChildren.size(); }
60 /// Returns true iff the node's children are loaded
61 bool GetChildrenLoaded() const { return mChildrenLoaded; }
63 /// Sets the node's children
64 void SetChildrenLoaded(bool l) { mChildrenLoaded = l; }
66 /// The type of children container
67 typedef std::vector<Node*> ChildrenListType;
68 /// Returns the list of children
69 ChildrenListType& GetChildrenList() { return mChildren; }
70 /// Returns the list of children (const)
71 const ChildrenListType& GetChildrenList() const { return mChildren; }
73 /// Remove the given children from the children list
74 void RemoveChildrenFromList(Node*);
76 typedef std::map<std::string,std::string> AttributeMapType;
78 AttributeMapType& GetAttributeMap() { return mAttributeMap; }
79 const AttributeMapType& GetAttributeMap() const { return mAttributeMap; }
80 const std::string& GetAttribute(const std::string& k) const;
81 const std::string& GetCleanAttribute(const std::string& k) const;
82 const std::string& UnsafeGetAttribute(const std::string& k) const
83 { return mAttributeMap.find(k)->second; }
84 void SetAttribute(const std::string& k, const std::string& v);
85 void UnsafeSetAttribute(const std::string& k, const std::string& v)
86 { mAttributeMap[k] = v; }
88 const AttributeDescriptor& GetAttributeDescriptor(const std::string& k)
90 // { return GetTypeDescription().GetFieldDescription(k); }
94 /// Returns the node data casted into the type T
95 template<class T> T GetData() const
96 { if (mData!=0) return dynamic_cast<T>(mData); return 0; }
98 /// Sets the node data. Deletes existing data if any.
99 void SetData(NodeData* d) { if (mData) delete mData; mData = d; }
101 /// Sorts the children of the node
102 void SortChildren(const LexicographicalComparator&);
105 virtual void Print() const;
106 std::string GetLabel() const;
107 int ImageGetRows() const;
108 int ImageGetColumns() const;
109 int ImageGetFrames() const;
110 const std::string& ImageGetFullFileName() const { return UnsafeGetAttribute("FullFileName"); }
114 /// The parent of the node
116 /// The list of children
117 ChildrenListType mChildren;
118 /// The map of attributes
119 AttributeMapType mAttributeMap;
122 /// Are the children loaded ?
123 bool mChildrenLoaded;
124 /// The number of children
125 // int mNumberOfChildren;
128 //=====================================================================
133 } // namespace creaImageIO
137 #endif // #ifndef __creaImageIOTreeNode_h_INCLUDED__