X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src2%2FcreaImageIOTreeHandler.h;h=5a7cecd32f644aa3f9cb1fb47a70b7417b824cb6;hb=71365e2ce56b1ccf93054818d5d5cf64bcbaafb4;hp=368c519c637e54fbe352ded1b3e16bb9ba056138;hpb=bae4df8a3e1ea669400c3a6c44ef4aa8d90fa1ed;p=creaImageIO.git diff --git a/src2/creaImageIOTreeHandler.h b/src2/creaImageIOTreeHandler.h index 368c519..5a7cecd 100644 --- a/src2/creaImageIOTreeHandler.h +++ b/src2/creaImageIOTreeHandler.h @@ -8,94 +8,129 @@ namespace creaImageIO //======================================================================= + //class TreeHandlerStatistics; + //======================================================================= + /** + * \ingroup Model + */ + //======================================================================= + /// Abstract class which 'handles' a Tree structure class TreeHandler { public: - ///==================================================================== + + //==================================================================== + // typedef TreeHandlerStatistics Statistics; + //==================================================================== + + //==================================================================== /// 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 + //==================================================================== + // QUERY METHODS /// Is the 'source' readable ? virtual bool IsReadable() { return false; } /// Is the 'source' writable ? virtual bool IsWritable() { return false; } - ///==================================================================== + //==================================================================== - ///==================================================================== - /// INITIALIZATION / FINALIZATION - ///==================================================================== + //==================================================================== + // INITIALIZATION / FINALIZATION + //==================================================================== - ///==================================================================== + //==================================================================== /// Opens an existing 'source' - /// Default mode is read only - /// If IsWritable and writable==true then opens in read/write mode + // 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 + // 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. + // 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; } - ///==================================================================== - - ///==================================================================== + //==================================================================== + + //==================================================================== + /// Returns the attribute requested. Useful for synchronization. + virtual void GetAttribute(std::string levelDescriptor, + std::string searchParam, + std::string searchVal, + std::string key, + std::string& result){} + //==================================================================== + + //==================================================================== /// 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. + // is reached. + // If maxlevel <= 0 then loads all the sub-tree rooted at parent + // 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 + // WITHOUT altering the source, e.g. the database virtual void UnLoad(tree::Node* n) { return; } - ///==================================================================== + //==================================================================== - ///==================================================================== - /// WRITE METHODS : WORK ONLY IN WRITE MODE - ///==================================================================== + //==================================================================== + // WRITE METHODS : WORK ONLY IN WRITE MODE + //==================================================================== typedef tree::Node::AttributeMapType AttributeMapType; - /// 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 + /// 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 AttributeMapType& ) { return -1; } /// Removes the node and its descendants - bool Remove(tree::Node*) { return false; } - ///==================================================================== + virtual bool Remove(tree::Node*) { return false; } + /// Sets an attribute of a Node + virtual bool SetAttribute(tree::Node*, + const std::string& key, + const std::string& value) { return false; } + // Sets an attribute + virtual void SetAttribute(const std::string& levelDescriptor, + const std::string& key, + const std::string& value, + const std::string& searchParam, + const std::string& searchVal){} + //Deletes the tuple that matches the parameters given + virtual void DeleteTuple(std::string levelDescriptor, std::string key, std::string value){} + + //==================================================================== private: @@ -105,7 +140,38 @@ namespace creaImageIO }; // EO class TreeHandler //======================================================================= - + /* + //======================================================================= + /// Memorizes statistics on operations done by a tree handler + // (nodes created, removed, ...) + class TreeHandlerStatistics + { + public: + //==================================================================== + /// Ctor + TreeHandler(TreeHandler* tree) : mTreeHandler(tree) { Reset(); } + /// Dtor + ~TreeHandler() {} + /// Resets the stats + void Reset(); + /// Prints the stats + void Print(); + + /// + void CreateNode(int level) { mNumberCreatedNode[level]++; } + void DeleteNode(int level) { mNumberDeletedNode[level]++; } + + protected: + TreeHandler* mTreeHandler; + std::vector mNumberCreatedNode; + std::vector mNumberDeletedNode; + + + ///==================================================================== + }; + // EO class TreeHandlerStatistics + //======================================================================= + */ } // EO namespace creaImageIO