Added new class CCDBManager, which encapsulates the separate CDB components into a easily (re)usable database solution. Also made CCDBSynchronized and CInterfaceManager use it.
--HG-- branch : cdb-refactoringhg/feature/sse2
parent
982c57b70f
commit
10f7241449
@ -0,0 +1,184 @@
|
||||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#ifndef CDB_MANAGER_H
|
||||
#define CDB_MANAGER_H
|
||||
|
||||
#include "nel/misc/cdb_branch.h"
|
||||
#include "nel/misc/cdb_leaf.h"
|
||||
#include "nel/misc/cdb_bank_handler.h"
|
||||
#include "nel/misc/cdb_branch_observing_handler.h"
|
||||
|
||||
namespace NLMISC{
|
||||
|
||||
/// Class that encapsulates the separate CDB components
|
||||
class CCDBManager{
|
||||
|
||||
public:
|
||||
/**
|
||||
The constructor
|
||||
@param maxBanks - The maximum number of banks to be used
|
||||
|
||||
*/
|
||||
CCDBManager( const char *rootNodeName, uint maxBanks );
|
||||
|
||||
~CCDBManager();
|
||||
|
||||
|
||||
/**
|
||||
Returns the specified leaf node from the database.
|
||||
@param name The name of the leaf node.
|
||||
@param create Specifies if the node should be created if it doesn't exist yet.
|
||||
|
||||
*/
|
||||
CCDBNodeLeaf* getDbLeaf( const std::string &name, bool create = true );
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Returns the specified branch node from the database.
|
||||
@param name The name of the branch.
|
||||
|
||||
*/
|
||||
CCDBNodeBranch* getDbBranch( const std::string &name );
|
||||
|
||||
|
||||
/**
|
||||
Deletes the specified database node.
|
||||
@param name The name of the database node.
|
||||
|
||||
*/
|
||||
void delDbNode( const std::string &name );
|
||||
|
||||
/**
|
||||
Adds an observer to a branch of the database.
|
||||
@param branchName The name of the branch we want to observe
|
||||
@param observer The observer we want to add
|
||||
@param positiveLeafNameFilter A vector of strings containing the names of the leaves we want to observe
|
||||
|
||||
*/
|
||||
void addBranchObserver( const char *branchName, ICDBNode::IPropertyObserver *observer, const std::vector< std::string >& positiveLeafNameFilter = std::vector< std::string >() );
|
||||
|
||||
/**
|
||||
Adds an observer to a branch of the database.
|
||||
@param branch The branch we want to observe
|
||||
@param observer The observer we want to add
|
||||
@param positiveLeafNameFilter A vector of strings containing the names of the leaves we want to observe
|
||||
|
||||
*/
|
||||
void addBranchObserver( CCDBNodeBranch *branch, ICDBNode::IPropertyObserver *observer, const std::vector< std::string >& positiveLeafNameFilter = std::vector< std::string >() );
|
||||
|
||||
|
||||
/**
|
||||
Adds an observer to a branch of the database.
|
||||
@param branchName The name of the branch we start from
|
||||
@param dbPathFromThisNode The path to the branch we want to observe
|
||||
@param observer The observer we want to add
|
||||
@param positiveLeafNameFilter An array of strings containing the names of the leaves we want to observe
|
||||
@param positiveLeafNameFilterSize The size of the array
|
||||
|
||||
*/
|
||||
void addBranchObserver( const char *branchName, const char *dbPathFromThisNode, ICDBNode::IPropertyObserver &observer, const char **positiveLeafNameFilter = NULL, uint positiveLeafNameFilterSize = 0 );
|
||||
|
||||
|
||||
/**
|
||||
Adds an observer to a branch of the database.
|
||||
@param branch The branch we start from
|
||||
@param dbPathFromThisNode The path to the branch we want to observe
|
||||
@param observer The observer we want to add
|
||||
@param positiveLeafNameFilter An array of strings containing the names of the leaves we want to observe
|
||||
@param positiveLeafNameFilterSize The size of the array
|
||||
|
||||
*/
|
||||
void addBranchObserver( CCDBNodeBranch *branch, const char *dbPathFromThisNode, ICDBNode::IPropertyObserver &observer, const char **positiveLeafNameFilter, uint positiveLeafNameFilterSize );
|
||||
|
||||
|
||||
/**
|
||||
Removes an observer from a branch in the database.
|
||||
@param branchName The name of the branch
|
||||
@param observer The observer we want to remove
|
||||
|
||||
*/
|
||||
void removeBranchObserver( const char *branchName, ICDBNode::IPropertyObserver* observer );
|
||||
|
||||
|
||||
/**
|
||||
Removes an observer from a branch in the database.
|
||||
@param branch The branch
|
||||
@param observer The observer we want to remove
|
||||
|
||||
*/
|
||||
void removeBranchObserver( CCDBNodeBranch *branch, ICDBNode::IPropertyObserver* observer );
|
||||
|
||||
|
||||
/**
|
||||
Removes an observer from a branch in the database.
|
||||
@param branchName The name of the branch we start from
|
||||
@param dbPathFromThisNode The path to the branch we want to observe from the starting branch
|
||||
@param observer The observer we want to remove
|
||||
|
||||
*/
|
||||
void removeBranchObserver( const char *branchName, const char *dbPathFromThisNode, ICDBNode::IPropertyObserver &observer );
|
||||
|
||||
|
||||
/**
|
||||
Removes an observer from a branch in the database.
|
||||
@param branchName The name of the branch we start from
|
||||
@param dbPathFromThisNode The path to the branch we want to observe from the starting branch
|
||||
@param observer The observer we want to remove
|
||||
|
||||
*/
|
||||
void removeBranchObserver( CCDBNodeBranch *branch, const char *dbPathFromThisNode, ICDBNode::IPropertyObserver &observer );
|
||||
|
||||
|
||||
/**
|
||||
Adds a branch observer call flush observer. ( These are notified after the branch observers are notified )
|
||||
@param observer The observer
|
||||
|
||||
*/
|
||||
void addFlushObserver( CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer );
|
||||
|
||||
|
||||
/**
|
||||
Removes a branch observer call flush observer.
|
||||
@param observer The observer
|
||||
*/
|
||||
void removeFlushObserver( CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer );
|
||||
|
||||
/**
|
||||
Notifies the observers whose observed branches were updated.
|
||||
*/
|
||||
void flushObserverCalls();
|
||||
|
||||
/**
|
||||
Resets the specified bank.
|
||||
@param gc GameCycle ( no idea what it is exactly, probably some time value )
|
||||
@param bank The banks we want to reset
|
||||
|
||||
*/
|
||||
void resetBank( uint gc, uint bank );
|
||||
|
||||
protected:
|
||||
CCDBBankHandler bankHandler;
|
||||
CCDBBranchObservingHandler branchObservingHandler;
|
||||
CRefPtr< CCDBNodeBranch > _Database;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,149 @@
|
||||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "nel/misc/cdb_manager.h"
|
||||
|
||||
namespace NLMISC{
|
||||
|
||||
CCDBManager::CCDBManager( const char *rootNodeName, uint maxBanks ) : bankHandler( maxBanks )
|
||||
{
|
||||
_Database = new CCDBNodeBranch( std::string( rootNodeName ) );
|
||||
}
|
||||
|
||||
CCDBManager::~CCDBManager()
|
||||
{
|
||||
if( _Database != NULL )
|
||||
{
|
||||
_Database->clear();
|
||||
delete _Database;
|
||||
_Database = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
CCDBNodeLeaf* CCDBManager::getDbLeaf( const std::string &name, bool create )
|
||||
{
|
||||
if( name.empty() )
|
||||
return NULL;
|
||||
|
||||
CCDBNodeLeaf *leaf = NULL;
|
||||
leaf = dynamic_cast< CCDBNodeLeaf* >( _Database->getNode( ICDBNode::CTextId( name ), create ) );
|
||||
return leaf;
|
||||
}
|
||||
|
||||
CCDBNodeBranch* CCDBManager::getDbBranch( const std::string &name )
|
||||
{
|
||||
if( name.empty() )
|
||||
return NULL;
|
||||
|
||||
CCDBNodeBranch *branch = NULL;
|
||||
branch = dynamic_cast< CCDBNodeBranch* >( _Database->getNode( ICDBNode::CTextId( name ), false ) );
|
||||
return branch;
|
||||
}
|
||||
|
||||
|
||||
void CCDBManager::delDbNode( const stlpx_std::string &name )
|
||||
{
|
||||
if( name.empty() )
|
||||
return;
|
||||
|
||||
_Database->removeNode( ICDBNode::CTextId( name ) );
|
||||
}
|
||||
|
||||
void CCDBManager::addBranchObserver( const char *branchName, ICDBNode::IPropertyObserver *observer, const std::vector< std::string >& positiveLeafNameFilter )
|
||||
{
|
||||
CCDBNodeBranch *b = dynamic_cast< CCDBNodeBranch* >( _Database->getNode( ICDBNode::CTextId( std::string( branchName ) ), false ) );
|
||||
if( b == NULL )
|
||||
return;
|
||||
branchObservingHandler.addBranchObserver( b, observer, positiveLeafNameFilter );
|
||||
}
|
||||
|
||||
void CCDBManager::addBranchObserver( CCDBNodeBranch *branch, ICDBNode::IPropertyObserver *observer, const std::vector< std::string >& positiveLeafNameFilter )
|
||||
{
|
||||
if( branch == NULL )
|
||||
return;
|
||||
branchObservingHandler.addBranchObserver( branch, observer, positiveLeafNameFilter );
|
||||
}
|
||||
|
||||
void CCDBManager::addBranchObserver( const char *branchName, const char *dbPathFromThisNode, ICDBNode::IPropertyObserver &observer, const char **positiveLeafNameFilter, uint positiveLeafNameFilterSize )
|
||||
{
|
||||
CCDBNodeBranch *b = dynamic_cast< CCDBNodeBranch* >( _Database->getNode( ICDBNode::CTextId( std::string( branchName ) ), false ) );
|
||||
if( b == NULL )
|
||||
return;
|
||||
branchObservingHandler.addBranchObserver( b, dbPathFromThisNode, observer, positiveLeafNameFilter, positiveLeafNameFilterSize );
|
||||
}
|
||||
|
||||
void CCDBManager::addBranchObserver( CCDBNodeBranch *branch, const char *dbPathFromThisNode, ICDBNode::IPropertyObserver &observer, const char **positiveLeafNameFilter, uint positiveLeafNameFilterSize )
|
||||
{
|
||||
if( branch == NULL )
|
||||
return;
|
||||
branchObservingHandler.addBranchObserver( branch, dbPathFromThisNode, observer, positiveLeafNameFilter, positiveLeafNameFilterSize );
|
||||
}
|
||||
|
||||
void CCDBManager::removeBranchObserver( const char *branchName, ICDBNode::IPropertyObserver* observer )
|
||||
{
|
||||
CCDBNodeBranch *b = dynamic_cast< CCDBNodeBranch* >( _Database->getNode( ICDBNode::CTextId( std::string( branchName ) ), false ) );
|
||||
if( b == NULL )
|
||||
return;
|
||||
branchObservingHandler.removeBranchObserver( b, observer );
|
||||
}
|
||||
|
||||
void CCDBManager::removeBranchObserver( CCDBNodeBranch *branch, ICDBNode::IPropertyObserver* observer )
|
||||
{
|
||||
if( branch == NULL )
|
||||
return;
|
||||
branchObservingHandler.removeBranchObserver( branch, observer );
|
||||
}
|
||||
|
||||
void CCDBManager::removeBranchObserver( const char *branchName, const char *dbPathFromThisNode, ICDBNode::IPropertyObserver &observer )
|
||||
{
|
||||
CCDBNodeBranch *b = dynamic_cast< CCDBNodeBranch* >( _Database->getNode( ICDBNode::CTextId( std::string( branchName ) ), false ) );
|
||||
if( b == NULL )
|
||||
return;
|
||||
branchObservingHandler.removeBranchObserver( b, dbPathFromThisNode, observer );
|
||||
}
|
||||
|
||||
void CCDBManager::removeBranchObserver( CCDBNodeBranch *branch, const char *dbPathFromThisNode, ICDBNode::IPropertyObserver &observer )
|
||||
{
|
||||
if( branch == NULL )
|
||||
return;
|
||||
branchObservingHandler.removeBranchObserver( branch, dbPathFromThisNode, observer );
|
||||
}
|
||||
|
||||
void CCDBManager::addFlushObserver( CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer )
|
||||
{
|
||||
if( observer == NULL )
|
||||
return;
|
||||
branchObservingHandler.addFlushObserver( observer );
|
||||
}
|
||||
|
||||
void CCDBManager::removeFlushObserver( CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer )
|
||||
{
|
||||
if( observer == NULL )
|
||||
return;
|
||||
branchObservingHandler.removeFlushObserver( observer );
|
||||
}
|
||||
|
||||
void CCDBManager::flushObserverCalls()
|
||||
{
|
||||
branchObservingHandler.flushObserverCalls();
|
||||
}
|
||||
|
||||
void CCDBManager::resetBank( uint gc, uint bank )
|
||||
{
|
||||
_Database->resetNode( gc, bankHandler.getUIDForBank( bank ) );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue