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
34 typedef std::map<std::string,std::string> AttributeMapType;
39 /// Ctor with parent and attributes map
40 Node(Node* parent, const AttributeMapType& );
41 /// Virtual destructor
45 /// Returns the level descriptor of the node
46 const LevelDescriptor& GetLevelDescriptor() const;
49 /// Returns the tree to which the node belongs
50 virtual Tree* GetTree() { return mParent->GetTree(); }
51 /// Returns the tree to which the node belongs
52 virtual const Tree* GetTree() const { return mParent->GetTree(); }
53 /// Returns the level of the node in the tree
54 virtual int GetLevel() const { return mParent->GetLevel()+1; }
56 /// Returns the parent of the node
57 Node* GetParent() const { return mParent; }
59 /// Returns the number of children of the node.
60 /// Warning : if the children are not loaded then might return 0
61 /// even if the node has children !
62 /// see TreeHandler::GetNumberOfChildren
63 unsigned int GetNumberOfChildren() const { return mChildren.size(); }
65 /// Returns true iff the node's children are loaded
66 bool GetChildrenLoaded() const { return mChildrenLoaded; }
68 /// Sets the node's children
69 void SetChildrenLoaded(bool l) { mChildrenLoaded = l; }
71 /// The type of children container
72 typedef std::vector<Node*> ChildrenListType;
73 /// Returns the list of children
74 ChildrenListType& GetChildrenList() { return mChildren; }
75 /// Returns the list of children (const)
76 const ChildrenListType& GetChildrenList() const { return mChildren; }
78 /// Remove the given children from the children list
79 void RemoveChildrenFromList(Node*);
82 AttributeMapType& GetAttributeMap() { return mAttributeMap; }
83 const AttributeMapType& GetAttributeMap() const { return mAttributeMap; }
84 const std::string& GetAttribute(const std::string& k) const;
85 const std::string& GetCleanAttribute(const std::string& k) const;
86 const std::string& UnsafeGetAttribute(const std::string& k) const
87 { return mAttributeMap.find(k)->second; }
88 void SetAttribute(const std::string& k, const std::string& v);
89 void UnsafeSetAttribute(const std::string& k, const std::string& v)
90 { mAttributeMap[k] = v; }
92 const AttributeDescriptor& GetAttributeDescriptor(const std::string& k)
94 // { return GetTypeDescription().GetFieldDescription(k); }
97 /// Returns true iff the KEY attributes of the node match those of the map provided
98 bool Matches( const AttributeMapType& ) const;
100 /// Returns the node data casted into the type T
101 template<class T> T GetData() const
102 { if (mData!=0) return dynamic_cast<T>(mData); return 0; }
104 /// Sets the node data. Deletes existing data if any.
105 void SetData(NodeData* d) { if (mData) delete mData; mData = d; }
107 /// Sorts the children of the node
108 void SortChildren(const LexicographicalComparator&);
111 virtual void Print() const;
112 std::string GetLabel() const;
113 int ImageGetRows() const;
114 int ImageGetColumns() const;
115 int ImageGetFrames() const;
116 const std::string& ImageGetFullFileName() const { return UnsafeGetAttribute("FullFileName"); }
120 /// The parent of the node
122 /// The list of children
123 ChildrenListType mChildren;
124 /// The map of attributes
125 AttributeMapType mAttributeMap;
128 /// Are the children loaded ?
129 bool mChildrenLoaded;
130 /// The number of children
131 // int mNumberOfChildren;
134 //=====================================================================
139 } // namespace creaImageIO
143 #endif // #ifndef __creaImageIOTreeNode_h_INCLUDED__