1 #ifndef __creaImageIOTreeHandler_h_INCLUDED__
2 #define __creaImageIOTreeHandler_h_INCLUDED__
4 #include <creaImageIOTree.h>
10 //=======================================================================
11 //class TreeHandlerStatistics;
12 //=======================================================================
16 //=======================================================================
18 /// Abstract class which 'handles' a Tree structure
23 //====================================================================
24 // typedef TreeHandlerStatistics Statistics;
25 //====================================================================
27 //====================================================================
31 virtual ~TreeHandler() {}
32 //====================================================================
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 //====================================================================
41 //====================================================================
43 /// Is the 'source' readable ?
44 virtual bool IsReadable() { return false; }
45 /// Is the 'source' writable ?
46 virtual bool IsWritable() { return false; }
47 //====================================================================
50 //====================================================================
51 // INITIALIZATION / FINALIZATION
52 //====================================================================
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 //====================================================================
70 //====================================================================
72 //====================================================================
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 //====================================================================
82 //====================================================================
83 /// Recursively loads the children of node 'parent' until maxlevel
85 // If maxlevel <= 0 then loads all the sub-tree rooted at parent
86 // If parent == NULL or parent == tree then starts with the 'children' of
88 // Returns the total number of children loaded.
89 virtual int LoadChildren(tree::Node* parent, int maxlevel)
91 //====================================================================
93 //====================================================================
94 /// Unloads the Node and its descendants
95 // WITHOUT altering the source, e.g. the database
96 virtual void UnLoad(tree::Node* n) { return; }
97 //====================================================================
100 //====================================================================
101 // WRITE METHODS : WORK ONLY IN WRITE MODE
102 //====================================================================
103 typedef tree::Node::AttributeMapType AttributeMapType;
104 /// Adds a branch in the tree with the attributes provided
105 // returns the Level in the tree where the branch was connected
106 // (-1 for error, 0 for top level, etc. )
107 // Of course the branch is loaded on exit
108 virtual int AddBranch( const AttributeMapType& ) { return -1; }
109 /// Removes the node and its descendants
110 virtual bool Remove(tree::Node*) { return false; }
111 /// Sets an attribute of a Node
112 virtual bool SetAttribute(tree::Node*,
113 const std::string& key,
114 const std::string& value) { return false; }
115 //====================================================================
123 // EO class TreeHandler
124 //=======================================================================
126 //=======================================================================
127 /// Memorizes statistics on operations done by a tree handler
128 // (nodes created, removed, ...)
129 class TreeHandlerStatistics
132 //====================================================================
134 TreeHandler(TreeHandler* tree) : mTreeHandler(tree) { Reset(); }
143 void CreateNode(int level) { mNumberCreatedNode[level]++; }
144 void DeleteNode(int level) { mNumberDeletedNode[level]++; }
147 TreeHandler* mTreeHandler;
148 std::vector<int> mNumberCreatedNode;
149 std::vector<int> mNumberDeletedNode;
152 ///====================================================================
154 // EO class TreeHandlerStatistics
155 //=======================================================================
158 } // EO namespace creaImageIO