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