00001 #ifndef __creaImageIOTreeNode_h_INCLUDED__ 00002 #define __creaImageIOTreeNode_h_INCLUDED__ 00003 00004 #include <creaImageIOTreeDescriptor.h> 00005 #include <creaImageIOTreeComparators.h> 00006 #include<boost/filesystem/operations.hpp> 00007 #include <vector> 00008 #include <map> 00009 00010 00011 namespace creaImageIO 00012 { 00013 00014 namespace tree 00015 { 00019 //===================================================================== 00021 class Tree; 00022 //===================================================================== 00023 00024 //===================================================================== 00026 struct NodeData 00027 { 00028 NodeData() {} 00029 virtual ~NodeData() {} 00030 }; 00031 //===================================================================== 00032 00033 00034 //===================================================================== 00036 class Node 00037 { 00038 public: 00039 typedef std::map<std::string,std::string> AttributeMapType; 00040 00041 00043 Node(Node* parent); 00045 Node(Node* parent, const AttributeMapType& ); 00047 virtual ~Node(); 00048 00050 void InitializeAttributeMap(); 00051 00053 const LevelDescriptor& GetLevelDescriptor() const; 00054 00055 00057 virtual Tree* GetTree() { return mParent->GetTree(); } 00059 virtual const Tree* GetTree() const { return mParent->GetTree(); } 00061 virtual int GetLevel() const { return mParent->GetLevel()+1; } 00062 00063 00065 Node* GetParent() const { return mParent; } 00066 00071 unsigned int GetNumberOfChildren() const { return mChildren.size(); } 00072 00074 bool GetChildrenLoaded() const { return mChildrenLoaded; } 00075 00077 void SetChildrenLoaded(bool l) { mChildrenLoaded = l; } 00078 00080 typedef std::vector<Node*> ChildrenListType; 00082 ChildrenListType& GetChildrenList() { return mChildren; } 00084 const ChildrenListType& GetChildrenList() const { return mChildren; } 00085 00087 int RemoveChildrenFromList(Node*); 00088 00089 00091 AttributeMapType& GetAttributeMap() { return mAttributeMap; } 00092 00094 const AttributeMapType& GetAttributeMap() const { return mAttributeMap; } 00095 00097 const std::string& GetAttribute(const std::string& k) const; 00098 00100 // TODO : backslash OS uniformity 00101 const std::string& GetCleanAttribute(const std::string& k) const; 00102 00104 void SetAttribute(const std::string& k, const std::string& v); 00105 00107 void UnsafeSetAttribute(const std::string& k, const std::string& v) 00108 { mAttributeMap[k] = v; } 00109 00111 const AttributeDescriptor& GetAttributeDescriptor(const std::string& k)const; 00112 00114 bool Matches( const AttributeMapType& ) const; 00115 00117 template<class T> T GetData() const 00118 { if (mData!=0) return dynamic_cast<T>(mData); return 0; } 00119 00121 void SetData(boost::shared_ptr<NodeData> d) {mData.reset(); mData = d; }//{ if (mData) delete mData; mData = d; } 00122 00124 void SortChildren(const LexicographicalComparator&); 00125 00127 virtual void Print() const; 00128 00130 std::string GetLabel() const; 00131 00132 00133 private: 00135 Node* mParent; 00137 ChildrenListType mChildren; 00139 AttributeMapType mAttributeMap; 00141 boost::shared_ptr<NodeData> mData; 00143 bool mChildrenLoaded; 00145 // int mNumberOfChildren; 00146 00147 }; // class Node 00148 //===================================================================== 00149 00150 } // namespace tree 00151 00152 00153 } // namespace creaImageIO 00154 00155 00156 00157 #endif // #ifndef __creaImageIOTreeNode_h_INCLUDED__