creaImageIO_lib
creaImageIOTreeHandler.h
Go to the documentation of this file.
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # pour la Santé)
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
9 #
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.
16 #
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
21 # liability.
22 #
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 # ------------------------------------------------------------------------
26 */
27 
28 #ifndef __creaImageIOTreeHandler_h_INCLUDED__
29 #define __creaImageIOTreeHandler_h_INCLUDED__
30 
31 #include <creaImageIOTree.h>
32 
33 namespace creaImageIO
34 {
35 
36 
37  //=======================================================================
38  //class TreeHandlerStatistics;
39  //=======================================================================
43  //=======================================================================
44 
47  {
48  public:
49 
50  //====================================================================
51  // typedef TreeHandlerStatistics Statistics;
52  //====================================================================
53 
54  //====================================================================
58  virtual ~TreeHandler() {}
59  //====================================================================
60 
61  //====================================================================
63  tree::Tree& GetTree() { return mTree; }
65  const tree::Tree& GetTree() const { return mTree; }
66  //====================================================================
67 
68  //====================================================================
69  // QUERY METHODS
71  virtual bool IsReadable() { return false; }
73  virtual bool IsWritable() { return false; }
74  //====================================================================
75 
76 
77  //====================================================================
78  // INITIALIZATION / FINALIZATION
79  //====================================================================
80 
81  //====================================================================
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; }
87  virtual bool Close() { return false; }
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; }
93  virtual bool Destroy() { return false; }
95  virtual void BeginTransaction(){}
97  virtual void EndTransaction(){}
98  //====================================================================
99 
100 
101  //====================================================================
102  // READ METHODS
103  //====================================================================
104 
105 
106  //====================================================================
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  //====================================================================
112 
113  //====================================================================
115  virtual void GetAttribute(std::string levelDescriptor,
116  std::string searchParam,
117  std::string searchVal,
118  std::string key,
119  std::string& result){}
120  //====================================================================
121 
122  //====================================================================
124  // is reached.
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
127  // the tree itself.
128  // Returns the total number of children loaded.
129  virtual int LoadChildren(tree::Node* parent, int maxlevel)
130  { return 0; }
131  //====================================================================
132 
133  //====================================================================
135  // WITHOUT altering the source, e.g. the database
136  virtual void UnLoad(tree::Node* n) { return; }
137  //====================================================================
138 
139  //====================================================================
141  virtual void GetTopLevelNodeId(const std::string& searchParam,
142  const std::string& searchValue,
143  std::string& parent_id){ return; }
145 
146 
147  //====================================================================
148  // WRITE METHODS : WORK ONLY IN WRITE MODE
149  //====================================================================
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; }
157  virtual bool Remove(tree::Node*) { return false; }
159  virtual bool SetAttribute(tree::Node*,
160  const std::string& key,
161  const std::string& value) { return false; }
162  // Sets an attribute
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){}
175 
176  //====================================================================
178  virtual void getAllAttributes(std::string i_filename, std::map<std::string, std::string> &i_results) =0;
179 
180  private:
183 
184  };
185  // EO class TreeHandler
186  //=======================================================================
187  /*
188  //=======================================================================
190  // (nodes created, removed, ...)
191  class TreeHandlerStatistics
192  {
193  public:
194  //====================================================================
196  TreeHandler(TreeHandler* tree) : mTreeHandler(tree) { Reset(); }
198  ~TreeHandler() {}
200  void Reset();
202  void Print();
203 
205  void CreateNode(int level) { mNumberCreatedNode[level]++; }
206  void DeleteNode(int level) { mNumberDeletedNode[level]++; }
207 
208  protected:
209  TreeHandler* mTreeHandler;
210  std::vector<int> mNumberCreatedNode;
211  std::vector<int> mNumberDeletedNode;
212 
213 
215  };
216  // EO class TreeHandlerStatistics
217  //=======================================================================
218  */
219 
220 } // EO namespace creaImageIO
221 
222 // EOF
223 #endif
224