]> Creatis software - creaImageIO.git/blob - src2/creaImageIOTreeHandler.h
Starting version 2
[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   /// Abstract class which 'handles' a Tree structure 
12   class TreeHandler
13   {
14   public:
15     ///====================================================================
16     /// Ctor
17     TreeHandler() {}
18     /// Virtual dtor
19     virtual ~TreeHandler() {}
20     ///====================================================================
21
22     ///====================================================================
23     /// Returns the Tree handled 
24     tree::Tree& GetTree() { return mTree; }
25     /// Returns the Tree handled (const)
26     const tree::Tree& GetTree() const { return mTree; }
27     ///====================================================================
28
29     ///====================================================================
30     /// QUERY METHODS
31     /// Is the 'source' readable ?
32     virtual bool IsReadable() { return false; }
33     /// Is the 'source' writable ?
34     virtual bool IsWritable() { return false; }
35     ///====================================================================
36
37
38     ///====================================================================
39     /// INITIALIZATION / FINALIZATION
40     ///====================================================================
41
42     ///====================================================================
43     /// Opens an existing 'source' 
44     /// Default mode is read only 
45     /// If IsWritable and writable==true then opens in read/write mode
46     virtual bool Open(bool writable = false) { return false; }
47     /// Closes the 'source'
48     virtual bool Close() { return false; }
49     /// Creates a new 'source' 
50     /// Default mode is read only 
51     /// If IsWritable and writable==true then opens in read/write mode
52     virtual bool Create(bool writable = false) { return false; }
53     /// Destroys the 'source'
54     virtual bool Destroy() { return false; }
55     ///====================================================================
56
57
58     ///====================================================================
59     // READ METHODS
60     ///====================================================================
61
62
63     ///====================================================================
64     /// Returns the number of children of the Node *WITHOUT LOADING THEM*
65     /// REM : The Tree itself is a Node and asking for its number of 
66     ///       children returns the number of children of level 1.
67     virtual unsigned int GetNumberOfChildren(tree::Node* n) { return 0; }
68     ///====================================================================
69
70     ///====================================================================
71     /// Recursively loads the children of node 'parent' until maxlevel 
72     /// is reached.
73     /// If parent == NULL or parent == tree then starts with the 'children' of 
74     /// the tree itself.
75     /// Returns the total number of children loaded.
76     virtual int LoadChildren(tree::Node* parent, int maxlevel) 
77     { return 0; }
78     ///====================================================================
79
80     ///====================================================================
81     /// Unloads the Node and its descendants
82     /// WITHOUT altering the source, e.g. the database
83     virtual void UnLoad(tree::Node* n) { return; }
84     ///====================================================================
85
86
87     ///====================================================================
88     /// WRITE METHODS : WORK ONLY IN WRITE MODE
89     ///====================================================================
90     /// Adds a branch in the tree with the attributes provided
91     /// returns the Level in the tree where the branch was connected 
92     /// (-1 for error, 0 for top level, etc. ) 
93     /// Of course the branch is loaded on exit
94     virtual int AddBranch
95     ( const std::map<std::string,std::string>& attr ) { return -1; }
96     /// Removes the node and its descendants 
97     bool Remove(tree::Node*)  { return false; }
98     ///====================================================================
99
100
101   private:
102     /// The handled tree
103     tree::Tree mTree;
104
105   };
106   // EO class TreeHandler
107   //=======================================================================
108
109
110 } // EO namespace creaImageIO
111
112 // EOF
113 #endif  
114