]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOTreeHandler.h
Starting version 2
[creaImageIO.git] / src2 / creaImageIOTreeHandler.h
diff --git a/src2/creaImageIOTreeHandler.h b/src2/creaImageIOTreeHandler.h
new file mode 100644 (file)
index 0000000..c88bbc9
--- /dev/null
@@ -0,0 +1,114 @@
+#ifndef __creaImageIOTreeHandler_h_INCLUDED__
+#define __creaImageIOTreeHandler_h_INCLUDED__
+
+#include <creaImageIOTree.h>
+
+namespace creaImageIO
+{
+
+
+  //=======================================================================
+  /// Abstract class which 'handles' a Tree structure 
+  class TreeHandler
+  {
+  public:
+    ///====================================================================
+    /// Ctor
+    TreeHandler() {}
+    /// Virtual dtor
+    virtual ~TreeHandler() {}
+    ///====================================================================
+
+    ///====================================================================
+    /// Returns the Tree handled 
+    tree::Tree& GetTree() { return mTree; }
+    /// Returns the Tree handled (const)
+    const tree::Tree& GetTree() const { return mTree; }
+    ///====================================================================
+
+    ///====================================================================
+    /// QUERY METHODS
+    /// Is the 'source' readable ?
+    virtual bool IsReadable() { return false; }
+    /// Is the 'source' writable ?
+    virtual bool IsWritable() { return false; }
+    ///====================================================================
+
+
+    ///====================================================================
+    /// INITIALIZATION / FINALIZATION
+    ///====================================================================
+
+    ///====================================================================
+    /// Opens an existing 'source' 
+    /// Default mode is read only 
+    /// If IsWritable and writable==true then opens in read/write mode
+    virtual bool Open(bool writable = false) { return false; }
+    /// Closes the 'source'
+    virtual bool Close() { return false; }
+    /// Creates a new 'source' 
+    /// Default mode is read only 
+    /// If IsWritable and writable==true then opens in read/write mode
+    virtual bool Create(bool writable = false) { return false; }
+    /// Destroys the 'source'
+    virtual bool Destroy() { return false; }
+    ///====================================================================
+
+
+    ///====================================================================
+    // READ METHODS
+    ///====================================================================
+
+
+    ///====================================================================
+    /// Returns the number of children of the Node *WITHOUT LOADING THEM*
+    /// REM : The Tree itself is a Node and asking for its number of 
+    ///       children returns the number of children of level 1.
+    virtual unsigned int GetNumberOfChildren(tree::Node* n) { return 0; }
+    ///====================================================================
+
+    ///====================================================================
+    /// Recursively loads the children of node 'parent' until maxlevel 
+    /// is reached.
+    /// If parent == NULL or parent == tree then starts with the 'children' of 
+    /// the tree itself.
+    /// Returns the total number of children loaded.
+    virtual int LoadChildren(tree::Node* parent, int maxlevel) 
+    { return 0; }
+    ///====================================================================
+
+    ///====================================================================
+    /// Unloads the Node and its descendants
+    /// WITHOUT altering the source, e.g. the database
+    virtual void UnLoad(tree::Node* n) { return; }
+    ///====================================================================
+
+
+    ///====================================================================
+    /// WRITE METHODS : WORK ONLY IN WRITE MODE
+    ///====================================================================
+    /// Adds a branch in the tree with the attributes provided
+    /// returns the Level in the tree where the branch was connected 
+    /// (-1 for error, 0 for top level, etc. ) 
+    /// Of course the branch is loaded on exit
+    virtual int AddBranch
+    ( const std::map<std::string,std::string>& attr ) { return -1; }
+    /// Removes the node and its descendants 
+    bool Remove(tree::Node*)  { return false; }
+    ///====================================================================
+
+
+  private:
+    /// The handled tree
+    tree::Tree mTree;
+
+  };
+  // EO class TreeHandler
+  //=======================================================================
+
+
+} // EO namespace creaImageIO
+
+// EOF
+#endif  
+