2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
28 #ifndef __creaImageIOTreeHandler_h_INCLUDED__
29 #define __creaImageIOTreeHandler_h_INCLUDED__
31 #include <creaImageIOTree.h>
37 //=======================================================================
38 //class TreeHandlerStatistics;
39 //=======================================================================
43 //=======================================================================
45 /// Abstract class which 'handles' a Tree structure
50 //====================================================================
51 // typedef TreeHandlerStatistics Statistics;
52 //====================================================================
54 //====================================================================
58 virtual ~TreeHandler() {}
59 //====================================================================
61 //====================================================================
62 /// Returns the Tree handled
63 tree::Tree& GetTree() { return mTree; }
64 /// Returns the Tree handled (const)
65 const tree::Tree& GetTree() const { return mTree; }
66 //====================================================================
68 //====================================================================
70 /// Is the 'source' readable ?
71 virtual bool IsReadable() { return false; }
72 /// Is the 'source' writable ?
73 virtual bool IsWritable() { return false; }
74 //====================================================================
77 //====================================================================
78 // INITIALIZATION / FINALIZATION
79 //====================================================================
81 //====================================================================
82 /// Opens an existing 'source'
83 // Default mode is read only
84 // If IsWritable and writable==true then opens in read/write mode
85 virtual bool Open(bool writable = false) { return false; }
86 /// Closes the 'source'
87 virtual bool Close() { return false; }
88 /// Creates a new 'source'
89 // Default mode is read only
90 // If IsWritable and writable==true then opens in read/write mode
91 virtual bool Create(bool writable = false) { return false; }
92 /// Destroys the 'source'
93 virtual bool Destroy() { return false; }
94 /// Begins a transaction
95 virtual void BeginTransaction(){}
96 ///Commits results and ends transaction
97 virtual void EndTransaction(){}
98 //====================================================================
101 //====================================================================
103 //====================================================================
106 //====================================================================
107 /// Returns the number of children of the Node *WITHOUT LOADING THEM*
108 // REM : The Tree itself is a Node and asking for its number of
109 // children returns the number of children of level 1.
110 virtual unsigned int GetNumberOfChildren(tree::Node* n) { return 0; }
111 //====================================================================
113 //====================================================================
114 /// Returns the attribute requested. Useful for synchronization.
115 virtual void GetAttribute(std::string levelDescriptor,
116 std::string searchParam,
117 std::string searchVal,
119 std::string& result){}
120 //====================================================================
122 //====================================================================
123 /// Recursively loads the children of node 'parent' until maxlevel
125 // If maxlevel <= 0 then loads all the sub-tree rooted at parent
126 // If parent == NULL or parent == tree then starts with the 'children' of
128 // Returns the total number of children loaded.
129 virtual int LoadChildren(tree::Node* parent, int maxlevel)
131 //====================================================================
133 //====================================================================
134 /// Unloads the Node and its descendants
135 // WITHOUT altering the source, e.g. the database
136 virtual void UnLoad(tree::Node* n) { return; }
137 //====================================================================
139 //====================================================================
140 /// Returns the top level node id for the given search param and search value
141 virtual void GetTopLevelNodeId(const std::string& searchParam,
142 const std::string& searchValue,
143 std::string& parent_id){ return; }
144 ///====================================================================
147 //====================================================================
148 // WRITE METHODS : WORK ONLY IN WRITE MODE
149 //====================================================================
150 typedef tree::Node::AttributeMapType AttributeMapType;
151 /// Adds a branch in the tree with the attributes provided
152 // returns the Level in the tree where the branch was connected
153 // (-1 for error, 0 for top level, etc. )
154 // Of course the branch is loaded on exit
155 virtual int AddBranch( const AttributeMapType& ) { return -1; }
156 /// Removes the node and its descendants
157 virtual bool Remove(tree::Node*) { return false; }
158 /// Sets an attribute of a Node
159 virtual bool SetAttribute(tree::Node*,
160 const std::string& key,
161 const std::string& value) { return false; }
163 virtual void SetAttribute(const std::string& levelDescriptor,
164 const std::string& key,
165 const std::string& value,
166 const std::string& searchParam,
167 const std::string& searchVal){}
168 //Deletes the tuple that matches the parameters given
169 virtual void DeleteTuple(std::string levelDescriptor, std::string key, std::string value){}
170 //Deletes the entries that match the parameters given
171 virtual void RemoveEntries(const std::string i_table,
172 const std::string i_attribute,
173 const std::string i_operand,
174 const std::string i_val){}
176 //====================================================================
177 /// get all attributes for a file
178 virtual void getAllAttributes(std::string i_filename, std::map<std::string, std::string> &i_results) =0;
185 // EO class TreeHandler
186 //=======================================================================
188 //=======================================================================
189 /// Memorizes statistics on operations done by a tree handler
190 // (nodes created, removed, ...)
191 class TreeHandlerStatistics
194 //====================================================================
196 TreeHandler(TreeHandler* tree) : mTreeHandler(tree) { Reset(); }
205 void CreateNode(int level) { mNumberCreatedNode[level]++; }
206 void DeleteNode(int level) { mNumberDeletedNode[level]++; }
209 TreeHandler* mTreeHandler;
210 std::vector<int> mNumberCreatedNode;
211 std::vector<int> mNumberDeletedNode;
214 ///====================================================================
216 // EO class TreeHandlerStatistics
217 //=======================================================================
220 } // EO namespace creaImageIO