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