00001 #ifndef __creaImageIOTreeHandler_h_INCLUDED__ 00002 #define __creaImageIOTreeHandler_h_INCLUDED__ 00003 00004 #include <creaImageIOTree.h> 00005 00006 namespace creaImageIO 00007 { 00008 00009 00010 //======================================================================= 00011 //class TreeHandlerStatistics; 00012 //======================================================================= 00016 //======================================================================= 00017 00019 class TreeHandler 00020 { 00021 public: 00022 00023 //==================================================================== 00024 // typedef TreeHandlerStatistics Statistics; 00025 //==================================================================== 00026 00027 //==================================================================== 00029 TreeHandler() {} 00031 virtual ~TreeHandler() {} 00032 //==================================================================== 00033 00034 //==================================================================== 00036 tree::Tree& GetTree() { return mTree; } 00038 const tree::Tree& GetTree() const { return mTree; } 00039 //==================================================================== 00040 00041 //==================================================================== 00042 // QUERY METHODS 00044 virtual bool IsReadable() { return false; } 00046 virtual bool IsWritable() { return false; } 00047 //==================================================================== 00048 00049 00050 //==================================================================== 00051 // INITIALIZATION / FINALIZATION 00052 //==================================================================== 00053 00054 //==================================================================== 00056 // Default mode is read only 00057 // If IsWritable and writable==true then opens in read/write mode 00058 virtual bool Open(bool writable = false) { return false; } 00060 virtual bool Close() { return false; } 00062 // Default mode is read only 00063 // If IsWritable and writable==true then opens in read/write mode 00064 virtual bool Create(bool writable = false) { return false; } 00066 virtual bool Destroy() { return false; } 00068 virtual void BeginTransaction(){} 00070 virtual void EndTransaction(){} 00071 //==================================================================== 00072 00073 00074 //==================================================================== 00075 // READ METHODS 00076 //==================================================================== 00077 00078 00079 //==================================================================== 00081 // REM : The Tree itself is a Node and asking for its number of 00082 // children returns the number of children of level 1. 00083 virtual unsigned int GetNumberOfChildren(tree::Node* n) { return 0; } 00084 //==================================================================== 00085 00086 //==================================================================== 00088 virtual void GetAttribute(std::string levelDescriptor, 00089 std::string searchParam, 00090 std::string searchVal, 00091 std::string key, 00092 std::string& result){} 00093 //==================================================================== 00094 00095 //==================================================================== 00097 // is reached. 00098 // If maxlevel <= 0 then loads all the sub-tree rooted at parent 00099 // If parent == NULL or parent == tree then starts with the 'children' of 00100 // the tree itself. 00101 // Returns the total number of children loaded. 00102 virtual int LoadChildren(tree::Node* parent, int maxlevel) 00103 { return 0; } 00104 //==================================================================== 00105 00106 //==================================================================== 00108 // WITHOUT altering the source, e.g. the database 00109 virtual void UnLoad(tree::Node* n) { return; } 00110 //==================================================================== 00111 00112 //==================================================================== 00114 virtual void GetTopLevelNodeId(const std::string& searchParam, 00115 const std::string& searchValue, 00116 std::string& parent_id){ return; } 00118 00119 00120 //==================================================================== 00121 // WRITE METHODS : WORK ONLY IN WRITE MODE 00122 //==================================================================== 00123 typedef tree::Node::AttributeMapType AttributeMapType; 00125 // returns the Level in the tree where the branch was connected 00126 // (-1 for error, 0 for top level, etc. ) 00127 // Of course the branch is loaded on exit 00128 virtual int AddBranch( const AttributeMapType& ) { return -1; } 00130 virtual bool Remove(tree::Node*) { return false; } 00132 virtual bool SetAttribute(tree::Node*, 00133 const std::string& key, 00134 const std::string& value) { return false; } 00135 // Sets an attribute 00136 virtual void SetAttribute(const std::string& levelDescriptor, 00137 const std::string& key, 00138 const std::string& value, 00139 const std::string& searchParam, 00140 const std::string& searchVal){} 00141 //Deletes the tuple that matches the parameters given 00142 virtual void DeleteTuple(std::string levelDescriptor, std::string key, std::string value){} 00143 //Deletes the entries that match the parameters given 00144 virtual void RemoveEntries(const std::string i_table, 00145 const std::string i_attribute, 00146 const std::string i_operand, 00147 const std::string i_val){} 00148 00149 //==================================================================== 00151 virtual void getAllAttributes(std::string i_filename, std::map<std::string, std::string> &i_results) =0; 00152 00153 private: 00155 tree::Tree mTree; 00156 00157 }; 00158 // EO class TreeHandler 00159 //======================================================================= 00160 /* 00161 //======================================================================= 00163 // (nodes created, removed, ...) 00164 class TreeHandlerStatistics 00165 { 00166 public: 00167 //==================================================================== 00169 TreeHandler(TreeHandler* tree) : mTreeHandler(tree) { Reset(); } 00171 ~TreeHandler() {} 00173 void Reset(); 00175 void Print(); 00176 00178 void CreateNode(int level) { mNumberCreatedNode[level]++; } 00179 void DeleteNode(int level) { mNumberDeletedNode[level]++; } 00180 00181 protected: 00182 TreeHandler* mTreeHandler; 00183 std::vector<int> mNumberCreatedNode; 00184 std::vector<int> mNumberDeletedNode; 00185 00186 00188 }; 00189 // EO class TreeHandlerStatistics 00190 //======================================================================= 00191 */ 00192 00193 } // EO namespace creaImageIO 00194 00195 // EOF 00196 #endif 00197