]> Creatis software - creaImageIO.git/blob - src2/creaImageIOTreeHandler.h
9b7c4db9eb8ba36b297e81e287f9e60909e2b77a
[creaImageIO.git] / src2 / creaImageIOTreeHandler.h
1 #ifndef __creaImageIOTreeHandler_h_INCLUDED__
2 #define __creaImageIOTreeHandler_h_INCLUDED__
3
4 #include <creaImageIOTree.h>
5
6 namespace creaImageIO
7 {
8
9
10   //=======================================================================
11   //class TreeHandlerStatistics;
12   //=======================================================================
13   /**
14    * \ingroup Model
15    */
16   //=======================================================================
17
18   /// Abstract class which 'handles' a Tree structure 
19   class TreeHandler
20   {
21   public:
22
23     //====================================================================
24     //  typedef TreeHandlerStatistics Statistics;
25     //====================================================================
26
27     //====================================================================
28     /// Ctor
29     TreeHandler() {}
30     /// Virtual dtor
31     virtual ~TreeHandler() {}
32     //====================================================================
33
34     //====================================================================
35     /// Returns the Tree handled 
36     tree::Tree& GetTree() { return mTree; }
37     /// Returns the Tree handled (const)
38     const tree::Tree& GetTree() const { return mTree; }
39     //====================================================================
40
41     //====================================================================
42     // QUERY METHODS
43     /// Is the 'source' readable ?
44     virtual bool IsReadable() { return false; }
45     /// Is the 'source' writable ?
46     virtual bool IsWritable() { return false; }
47     //====================================================================
48
49
50     //====================================================================
51     // INITIALIZATION / FINALIZATION
52     //====================================================================
53
54     //====================================================================
55     /// Opens an existing 'source' 
56     // Default mode is read only 
57     // If IsWritable and writable==true then opens in read/write mode
58     virtual bool Open(bool writable = false) { return false; }
59     /// Closes the 'source'
60     virtual bool Close() { return false; }
61     /// Creates a new 'source' 
62     // Default mode is read only 
63     // If IsWritable and writable==true then opens in read/write mode
64     virtual bool Create(bool writable = false) { return false; }
65     /// Destroys the 'source'
66     virtual bool Destroy() { return false; }
67     //====================================================================
68
69
70     //====================================================================
71     // READ METHODS
72     //====================================================================
73
74
75     //====================================================================
76     /// Returns the number of children of the Node *WITHOUT LOADING THEM*
77     // REM : The Tree itself is a Node and asking for its number of 
78     //       children returns the number of children of level 1.
79     virtual unsigned int GetNumberOfChildren(tree::Node* n) { return 0; }
80     //====================================================================
81
82         //====================================================================
83     /// Returns the attribute requested. Useful for synchronization.
84         virtual void GetAttribute(std::string levelDescriptor,
85                                                                            std::string searchParam, 
86                                                                            std::string searchVal, 
87                                                                            std::string key, 
88                                                                            std::string& result){}
89     //====================================================================
90
91     //====================================================================
92     /// Recursively loads the children of node 'parent' until maxlevel 
93     // is reached.
94     // If maxlevel <= 0 then loads all the sub-tree rooted at parent 
95     // If parent == NULL or parent == tree then starts with the 'children' of 
96     // the tree itself.
97     // Returns the total number of children loaded.
98     virtual int LoadChildren(tree::Node* parent, int maxlevel) 
99     { return 0; }
100     //====================================================================
101
102     //====================================================================
103     /// Unloads the Node and its descendants
104     // WITHOUT altering the source, e.g. the database
105     virtual void UnLoad(tree::Node* n) { return; }
106     //====================================================================
107
108         //====================================================================
109     /// Returns the top level node id for the given search param and search value
110     virtual void GetTopLevelNodeId(const std::string& searchParam, 
111                                                                                         const std::string& searchValue, 
112                                                                                         std::string& parent_id){ return; }
113     ///====================================================================
114
115
116     //====================================================================
117     // WRITE METHODS : WORK ONLY IN WRITE MODE
118     //====================================================================
119     typedef tree::Node::AttributeMapType AttributeMapType;
120     /// Adds a branch in the tree with the attributes provided
121     // returns the Level in the tree where the branch was connected 
122     // (-1 for error, 0 for top level, etc. ) 
123     // Of course the branch is loaded on exit
124     virtual int AddBranch( const AttributeMapType& ) { return -1; }
125     /// Removes the node and its descendants 
126     virtual bool Remove(tree::Node*)  { return false; }
127     /// Sets an attribute of a Node
128     virtual bool SetAttribute(tree::Node*, 
129                               const std::string& key,
130                               const std::string& value) { return false; }
131         // Sets an attribute
132     virtual void SetAttribute(const std::string& levelDescriptor, 
133                               const std::string& key,
134                               const std::string& value,
135                                   const std::string& searchParam, 
136                                   const std::string& searchVal){}
137         //Deletes the tuple that matches the parameters given
138         virtual void DeleteTuple(std::string levelDescriptor, std::string key, std::string value){}
139  
140     //====================================================================
141
142
143   private:
144     /// The handled tree
145     tree::Tree mTree;
146
147   };
148   // EO class TreeHandler
149   //=======================================================================
150   /*
151   //=======================================================================
152   /// Memorizes statistics on operations done by a tree handler
153   // (nodes created, removed, ...)
154   class TreeHandlerStatistics
155   {
156   public:
157     //====================================================================
158     /// Ctor
159     TreeHandler(TreeHandler* tree) : mTreeHandler(tree) { Reset(); }
160     /// Dtor
161     ~TreeHandler() {}
162     /// Resets the stats
163     void Reset();
164     /// Prints the stats
165     void Print();
166
167     /// 
168     void CreateNode(int level) { mNumberCreatedNode[level]++; }
169     void DeleteNode(int level) { mNumberDeletedNode[level]++; }
170
171   protected:
172       TreeHandler* mTreeHandler;
173     std::vector<int> mNumberCreatedNode;
174     std::vector<int> mNumberDeletedNode;
175     
176     
177     ///====================================================================
178   };
179   // EO class TreeHandlerStatistics
180   //=======================================================================
181   */
182
183 } // EO namespace creaImageIO
184
185 // EOF
186 #endif  
187