1 #ifndef __creaImageIOTreeHandler_h_INCLUDED__
2 #define __creaImageIOTreeHandler_h_INCLUDED__
4 #include <creaImageIOTree.h>
10 //=======================================================================
11 //class TreeHandlerStatistics;
12 //=======================================================================
16 //=======================================================================
17 /// Abstract class which 'handles' a Tree structure
22 ///====================================================================
23 // typedef TreeHandlerStatistics Statistics;
24 ///====================================================================
26 ///====================================================================
30 virtual ~TreeHandler() {}
31 ///====================================================================
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 ///====================================================================
40 ///====================================================================
42 /// Is the 'source' readable ?
43 virtual bool IsReadable() { return false; }
44 /// Is the 'source' writable ?
45 virtual bool IsWritable() { return false; }
46 ///====================================================================
49 ///====================================================================
50 /// INITIALIZATION / FINALIZATION
51 ///====================================================================
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 ///====================================================================
69 ///====================================================================
71 ///====================================================================
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 ///====================================================================
81 ///====================================================================
82 /// Recursively loads the children of node 'parent' until maxlevel
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
87 /// Returns the total number of children loaded.
88 virtual int LoadChildren(tree::Node* parent, int maxlevel)
90 ///====================================================================
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 ///====================================================================
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 ///====================================================================
122 // EO class TreeHandler
123 //=======================================================================
125 //=======================================================================
126 /// Memorizes statistics on operations done by a tree handler
127 /// (nodes created, removed, ...)
128 class TreeHandlerStatistics
131 ///====================================================================
133 TreeHandler(TreeHandler* tree) : mTreeHandler(tree) { Reset(); }
142 void CreateNode(int level) { mNumberCreatedNode[level]++; }
143 void DeleteNode(int level) { mNumberDeletedNode[level]++; }
146 TreeHandler* mTreeHandler;
147 std::vector<int> mNumberCreatedNode;
148 std::vector<int> mNumberDeletedNode;
151 ///====================================================================
153 // EO class TreeHandlerStatistics
154 //=======================================================================
157 } // EO namespace creaImageIO