Added new class CCDBManager, which encapsulates the separate CDB components into a easily (re)usable database solution. Also made CCDBSynchronized and CInterfaceManager use it.

This commit is contained in:
dfighter1985 2012-04-27 22:49:38 +02:00
parent d2d4838252
commit 5f041538c8
6 changed files with 358 additions and 244 deletions

View file

@ -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

View file

@ -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 ) );
}
}

View file

@ -58,7 +58,7 @@ uint32 NbDatabaseChanges = 0;
// CCDBSynchronised
//
//-----------------------------------------------
CCDBSynchronised::CCDBSynchronised() : _Database(0), _InitInProgress(true), _InitDeltaReceived(0), bankHandler( NB_CDB_BANKS )
CCDBSynchronised::CCDBSynchronised() : _InitInProgress(true), _InitDeltaReceived(0), CCDBManager( "SERVER", NB_CDB_BANKS )
{
}
@ -82,6 +82,7 @@ void CCDBSynchronised::init( const string &fileName, NLMISC::IProgressCallback &
//Parse the parser output!!!
bankHandler.resetNodeBankMapping(); // in case the game is restarted from start
bankHandler.fillBankNames( CDBBankNames, INVALID_CDB_BANK + 1 );
if( _Database == NULL )
_Database = new CCDBNodeBranch( "SERVER" );
_Database->init( read.getRootNode (), progressCallBack, true, &bankHandler );
}
@ -305,7 +306,7 @@ void CCDBSynchronised::clear()
{
_Database->clear();
delete _Database;
_Database = 0;
_Database = NULL;
}
// clear CCDBNodeBranch static data
@ -324,93 +325,6 @@ void CCDBSynchronised::writeInitInProgressIntoUIDB()
}
void CCDBSynchronised::resetBank( uint gc, uint bank ){
_Database->resetNode( gc, bankHandler.getUIDForBank( bank ) );
}
void CCDBSynchronised::addBranchObserver( const char *branchName, NLMISC::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 CCDBSynchronised::addBranchObserver( NLMISC::CCDBNodeBranch *branch, NLMISC::ICDBNode::IPropertyObserver *observer, const std::vector< std::string >& positiveLeafNameFilter )
{
if( branch == NULL )
return;
branchObservingHandler.addBranchObserver( branch, observer, positiveLeafNameFilter );
}
void CCDBSynchronised::addBranchObserver( const char *branchName, const char *dbPathFromThisNode, NLMISC::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 CCDBSynchronised::addBranchObserver( NLMISC::CCDBNodeBranch *branch, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer, const char **positiveLeafNameFilter, uint positiveLeafNameFilterSize )
{
if( branch == NULL )
return;
branchObservingHandler.addBranchObserver( branch, dbPathFromThisNode, observer, positiveLeafNameFilter, positiveLeafNameFilterSize );
}
void CCDBSynchronised::removeBranchObserver( const char *branchName, NLMISC::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 CCDBSynchronised::removeBranchObserver( NLMISC::CCDBNodeBranch *branch, NLMISC::ICDBNode::IPropertyObserver* observer )
{
if( branch == NULL )
return;
branchObservingHandler.removeBranchObserver( branch, observer );
}
void CCDBSynchronised::removeBranchObserver( const char *branchName, const char *dbPathFromThisNode, NLMISC::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 CCDBSynchronised::removeBranchObserver( NLMISC::CCDBNodeBranch *branch, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer )
{
if( branch == NULL )
return;
branchObservingHandler.removeBranchObserver( branch, dbPathFromThisNode, observer );
}
void CCDBSynchronised::addFlushObserver( NLMISC::CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer )
{
if( observer == NULL )
return;
branchObservingHandler.addFlushObserver( observer );
}
void CCDBSynchronised::removeFlushObserver( NLMISC::CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer )
{
if( observer == NULL )
return;
branchObservingHandler.removeFlushObserver( observer );
}
void CCDBSynchronised::flushObserverCalls()
{
branchObservingHandler.flushObserverCalls();
}
#ifdef TRACE_READ_DELTA
#undef TRACE_READ_DELTA
#endif

View file

@ -22,8 +22,7 @@
#include "nel/misc/cdb.h"
#include "nel/misc/cdb_branch.h"
#include "nel/misc/cdb_bank_handler.h"
#include "nel/misc/cdb_branch_observing_handler.h"
#include "nel/misc/cdb_manager.h"
/**
* Class to manage a database of properties
@ -31,11 +30,8 @@
* \author Nevrax France
* \date 2002
*/
class CCDBSynchronised
class CCDBSynchronised : public NLMISC::CCDBManager
{
/// database
NLMISC::CRefPtr<NLMISC::CCDBNodeBranch> _Database;
/// string associations
std::map<uint32,std::string> _Strings;
@ -146,8 +142,6 @@ public:
}
}
void resetBank( uint gc, uint bank );
private:
friend void impulseDatabaseInitPlayer( NLMISC::CBitMemStream &impulse );
@ -157,22 +151,6 @@ private:
bool allInitPacketReceived() const { return _InitDeltaReceived == 2; } // Classic database + inventory
void writeInitInProgressIntoUIDB();
NLMISC::CCDBBankHandler bankHandler;
NLMISC::CCDBBranchObservingHandler branchObservingHandler;
public:
void addBranchObserver( const char *branchName, NLMISC::ICDBNode::IPropertyObserver *observer, const std::vector< std::string >& positiveLeafNameFilter = std::vector< std::string >() );
void addBranchObserver( NLMISC::CCDBNodeBranch *branch, NLMISC::ICDBNode::IPropertyObserver *observer, const std::vector< std::string >& positiveLeafNameFilter = std::vector< std::string >() );
void addBranchObserver( const char *branchName, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer, const char **positiveLeafNameFilter = NULL, uint positiveLeafNameFilterSize = 0 );
void addBranchObserver( NLMISC::CCDBNodeBranch *branch, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer, const char **positiveLeafNameFilter, uint positiveLeafNameFilterSize );
void removeBranchObserver( const char *branchName, NLMISC::ICDBNode::IPropertyObserver* observer );
void removeBranchObserver( NLMISC::CCDBNodeBranch *branch, NLMISC::ICDBNode::IPropertyObserver* observer );
void removeBranchObserver( const char *branchName, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer );
void removeBranchObserver( NLMISC::CCDBNodeBranch *branch, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer );
void addFlushObserver( NLMISC::CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer );
void removeFlushObserver( NLMISC::CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer );
void flushObserverCalls();
};

View file

@ -103,6 +103,8 @@
#include "../client_chat_manager.h" // for emotes
#include "../entities.h"
#include "../../common/src/game_share/ryzom_database_banks.h"
#include "chat_text_manager.h"
#include "../npc_icon.h"
@ -253,10 +255,9 @@ int CInterfaceManager::DebugTrackGroupsGetId( CInterfaceGroup *pIG )
#endif // AJM_DEBUG_TRACK_INTERFACE_GROUPS
// ------------------------------------------------------------------------------------------------
CInterfaceManager::CInterfaceManager()
CInterfaceManager::CInterfaceManager() : NLMISC::CCDBManager( "ROOT", NB_CDB_BANKS )
{
_Instance = this;
_DbRootNode = new CCDBNodeBranch("ROOT");
interfaceLinkUpdater = new CInterfaceLink::CInterfaceLinkUpdater();
_ScreenW = _ScreenH = 0;
_LastInGameScreenW = _LastInGameScreenH = 0;
@ -361,10 +362,11 @@ CInterfaceManager::~CInterfaceManager()
_Templates.clear();
_Instance = NULL;
if (_DbRootNode)
if (_Database)
{
delete _DbRootNode;
_DbRootNode = NULL;
_Database->clear();
delete _Database;
_Database = NULL;
}
// release the local string mapper
@ -502,7 +504,7 @@ void CInterfaceManager::uninitLogin()
CInterfaceLink::removeAllLinks();
ICDBNode::CTextId textId("UI");
_DbRootNode->removeNode(textId);
_Database->removeNode(textId);
{
uninitActions();
@ -597,7 +599,7 @@ void CInterfaceManager::uninitOutGame()
disableModalWindow();
//_DbRootNode->display("");
//_Database->display("");
CBotChatManager::getInstance()->setCurrPage(NULL);
CInterfaceItemEdition::getInstance()->setCurrWindow(NULL);
@ -627,7 +629,7 @@ void CInterfaceManager::uninitOutGame()
//nlinfo ("%d seconds for removeAllLinks", (uint32)(ryzomGetLocalTime ()-initStart)/1000);
initStart = ryzomGetLocalTime ();
ICDBNode::CTextId textId("UI");
_DbRootNode->removeNode(textId);
_Database->removeNode(textId);
//nlinfo ("%d seconds for removeNode", (uint32)(ryzomGetLocalTime ()-initStart)/1000);
// Init the action manager
@ -1160,7 +1162,7 @@ void CInterfaceManager::uninitInGame1 ()
// remove DB entry
ICDBNode::CTextId textId("UI");
_DbRootNode->removeNode(textId);
_Database->removeNode(textId);
// Uninit the action manager
{
@ -3327,13 +3329,13 @@ void CInterfaceManager::updateAllLocalisedElements()
// ------------------------------------------------------------------------------------------------
bool CInterfaceManager::addDBObserver (ICDBNode::IPropertyObserver* observer, ICDBNode::CTextId id)
{
return _DbRootNode->addObserver(observer, id);
return _Database->addObserver(observer, id);
}
// ------------------------------------------------------------------------------------------------
bool CInterfaceManager::removeDBObserver (ICDBNode::IPropertyObserver* observer, ICDBNode::CTextId id)
{
return _DbRootNode->removeObserver(observer, id);
return _Database->removeObserver(observer, id);
}
// ------------------------------------------------------------------------------------------------
@ -3431,26 +3433,13 @@ sint32 CInterfaceManager::getDbValue32 (const std::string & name)
// ------------------------------------------------------------------------------------------------
CCDBNodeLeaf* CInterfaceManager::getDbProp(const std::string & name, bool bCreate)
{
if (name.empty()) return NULL;
CCDBNodeLeaf *pDBNL = NULL;
pDBNL = dynamic_cast<CCDBNodeLeaf*>(_DbRootNode->getNode( ICDBNode::CTextId(name), bCreate ));
return pDBNL;
return getDbLeaf( name, bCreate );
}
// ------------------------------------------------------------------------------------------------
void CInterfaceManager::delDbProp(const std::string & name)
{
if (name.empty()) return;
_DbRootNode->removeNode( ICDBNode::CTextId(name) );
}
// ------------------------------------------------------------------------------------------------
CCDBNodeBranch *CInterfaceManager::getDbBranch(const std::string &name)
{
if (name.empty()) return NULL;
CCDBNodeBranch *nodeBranch;
nodeBranch = dynamic_cast<CCDBNodeBranch*>(_DbRootNode->getNode( ICDBNode::CTextId(name), false ));
return nodeBranch;
delDbNode( name );
}
// ------------------------------------------------------------------------------------------------
@ -6113,7 +6102,7 @@ void CInterfaceManager::createLocalBranch(const std::string &fileName, NLMISC::I
//Parse the parser output!!!
CCDBNodeBranch *localNode = new CCDBNodeBranch("LOCAL");
localNode->init( read.getRootNode (), progressCallBack );
_DbRootNode->attachChild(localNode,"LOCAL");
_Database->attachChild(localNode,"LOCAL");
// Create the observers for auto-copy SERVER->LOCAL of inventory
ServerToLocalAutoCopyInventory.init("INVENTORY");
@ -6652,85 +6641,3 @@ bool CInterfaceManager::parseTokens(ucstring& ucstr)
return true;;
}
void CInterfaceManager::addBranchObserver( const char *branchName, NLMISC::ICDBNode::IPropertyObserver *observer, const std::vector< std::string >& positiveLeafNameFilter )
{
CCDBNodeBranch *b = dynamic_cast< CCDBNodeBranch* >( _DbRootNode->getNode( ICDBNode::CTextId( std::string( branchName ) ), false ) );
if( b == NULL )
return;
branchObservingHandler.addBranchObserver( b, observer, positiveLeafNameFilter );
}
void CInterfaceManager::addBranchObserver( NLMISC::CCDBNodeBranch *branch, NLMISC::ICDBNode::IPropertyObserver *observer, const std::vector< std::string >& positiveLeafNameFilter )
{
if( branch == NULL )
return;
branchObservingHandler.addBranchObserver( branch, observer, positiveLeafNameFilter );
}
void CInterfaceManager::addBranchObserver( const char *branchName, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer, const char **positiveLeafNameFilter, uint positiveLeafNameFilterSize )
{
CCDBNodeBranch *b = dynamic_cast< CCDBNodeBranch* >( _DbRootNode->getNode( ICDBNode::CTextId( std::string( branchName ) ), false ) );
if( b == NULL )
return;
branchObservingHandler.addBranchObserver( b, dbPathFromThisNode, observer, positiveLeafNameFilter, positiveLeafNameFilterSize );
}
void CInterfaceManager::addBranchObserver( NLMISC::CCDBNodeBranch *branch, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer, const char **positiveLeafNameFilter, uint positiveLeafNameFilterSize )
{
if( branch == NULL )
return;
branchObservingHandler.addBranchObserver( branch, dbPathFromThisNode, observer, positiveLeafNameFilter, positiveLeafNameFilterSize );
}
void CInterfaceManager::removeBranchObserver( const char *branchName, NLMISC::ICDBNode::IPropertyObserver* observer )
{
CCDBNodeBranch *b = dynamic_cast< CCDBNodeBranch* >( _DbRootNode->getNode( ICDBNode::CTextId( std::string( branchName ) ), false ) );
if( b == NULL )
return;
branchObservingHandler.removeBranchObserver( b, observer );
}
void CInterfaceManager::removeBranchObserver( NLMISC::CCDBNodeBranch *branch, NLMISC::ICDBNode::IPropertyObserver* observer )
{
if( branch == NULL )
return;
branchObservingHandler.removeBranchObserver( branch, observer );
}
void CInterfaceManager::removeBranchObserver( const char *branchName, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer )
{
CCDBNodeBranch *b = dynamic_cast< CCDBNodeBranch* >( _DbRootNode->getNode( ICDBNode::CTextId( std::string( branchName ) ), false ) );
if( b == NULL )
return;
branchObservingHandler.removeBranchObserver( b, dbPathFromThisNode, observer );
}
void CInterfaceManager::removeBranchObserver( NLMISC::CCDBNodeBranch *branch, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer )
{
if( branch == NULL )
return;
branchObservingHandler.removeBranchObserver( branch, dbPathFromThisNode, observer );
}
void CInterfaceManager::addFlushObserver( NLMISC::CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer )
{
if( observer == NULL )
return;
branchObservingHandler.addFlushObserver( observer );
}
void CInterfaceManager::removeFlushObserver( NLMISC::CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer )
{
if( observer == NULL )
return;
branchObservingHandler.removeFlushObserver( observer );
}
void CInterfaceManager::flushObserverCalls()
{
branchObservingHandler.flushObserverCalls();
}

View file

@ -20,6 +20,7 @@
#define NL_INTERFACE_MANAGER_H
#include "nel/misc/types_nl.h"
#include "nel/misc/cdb_manager.h"
#include "nel/3d/u_texture.h"
#include "nel/3d/u_text_context.h"
#include "interface_group.h"
@ -77,7 +78,7 @@ class CGroupMenu;
* \author Nevrax France
* \date 2002
*/
class CInterfaceManager : public CInterfaceParser
class CInterfaceManager : public CInterfaceParser, public NLMISC::CCDBManager
{
public:
@ -229,12 +230,10 @@ public:
/// Get the root of the database
NLMISC::CCDBNodeBranch *getDB() const { return _DbRootNode; }
NLMISC::CCDBNodeBranch *getDB() const { return _Database; }
// yoyo: should avoid to try creating DbPropr with this system... very dangerous
NLMISC::CCDBNodeLeaf* getDbProp (const std::string & name, bool bCreate=true);
void delDbProp(const std::string & name);
// get a Db Branch by its name. NULL if don't exist or not a branch (never try to create it)
NLMISC::CCDBNodeBranch *getDbBranch(const std::string &name);
// return the DB as an int32. return 0 if the DB does not exist (never create)
sint32 getDbValue32 (const std::string & name);
@ -959,9 +958,6 @@ private:
NLMISC::CRGBA _GlobalColor;
sint32 _LastInGameScreenW, _LastInGameScreenH; // Resolution used for last InGame interface
// root node for interfaces properties in the databases
NLMISC::CCDBNodeBranch *_DbRootNode;
// List of active Anims
std::vector<CInterfaceAnim*> _ActiveAnims;
@ -1065,20 +1061,6 @@ private:
void updateTooltipCoords(CCtrlBase *newCtrl);
CInterfaceLink::CInterfaceLinkUpdater *interfaceLinkUpdater;
NLMISC::CCDBBranchObservingHandler branchObservingHandler;
public:
void addBranchObserver( const char *branchName, NLMISC::ICDBNode::IPropertyObserver *observer, const std::vector< std::string >& positiveLeafNameFilter = std::vector< std::string >() );
void addBranchObserver( NLMISC::CCDBNodeBranch *branch, NLMISC::ICDBNode::IPropertyObserver *observer, const std::vector< std::string >& positiveLeafNameFilter = std::vector< std::string >() );
void addBranchObserver( const char *branchName, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer, const char **positiveLeafNameFilter = NULL, uint positiveLeafNameFilterSize = 0 );
void addBranchObserver( NLMISC::CCDBNodeBranch *branch, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer, const char **positiveLeafNameFilter, uint positiveLeafNameFilterSize );
void removeBranchObserver( const char *branchName, NLMISC::ICDBNode::IPropertyObserver* observer );
void removeBranchObserver( NLMISC::CCDBNodeBranch *branch, NLMISC::ICDBNode::IPropertyObserver* observer );
void removeBranchObserver( const char *branchName, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer );
void removeBranchObserver( NLMISC::CCDBNodeBranch *branch, const char *dbPathFromThisNode, NLMISC::ICDBNode::IPropertyObserver &observer );
void addFlushObserver( NLMISC::CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer );
void removeFlushObserver( NLMISC::CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer );
void flushObserverCalls();
};
#endif // NL_INTERFACE_MANAGER_H