From c0a90cefa11d3de5fd87b4b7a37380a78f647547 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Thu, 24 May 2012 00:55:50 +0200 Subject: [PATCH] ADDED: #1471 added a global db manager for the GUI library, also added support for resizeing the CDB bank handler. --- code/nel/include/nel/gui/db_manager.h | 47 +++++++++++++++++ code/nel/include/nel/misc/cdb_bank_handler.h | 6 +++ code/nel/include/nel/misc/cdb_manager.h | 6 +++ code/nel/src/gui/db_manager.cpp | 53 ++++++++++++++++++++ code/nel/src/misc/cdb_bank_handler.cpp | 12 +++++ code/nel/src/misc/cdb_manager.cpp | 5 ++ 6 files changed, 129 insertions(+) create mode 100644 code/nel/include/nel/gui/db_manager.h create mode 100644 code/nel/src/gui/db_manager.cpp diff --git a/code/nel/include/nel/gui/db_manager.h b/code/nel/include/nel/gui/db_manager.h new file mode 100644 index 000000000..38e75a755 --- /dev/null +++ b/code/nel/include/nel/gui/db_manager.h @@ -0,0 +1,47 @@ +// Ryzom - MMORPG Framework +// 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 . + + +#ifndef DBMANAGER_H +#define DBMANAGER_H + +#include "nel/misc/cdb_manager.h" + +namespace NLGUI +{ + + class CDBManager : public NLMISC::CCDBManager + { + public: + static CDBManager* getInstance(); + static void release(); + + NLMISC::CCDBNodeLeaf* getDbProp( const std::string &name, bool create = true ); + void delDbProp( const std::string &name ); + sint32 getDbValue32( const std::string &name ); + NLMISC::CCDBNodeBranch* getDB() const; + + private: + CDBManager(); + ~CDBManager(); + + static CDBManager *instance; + + }; + +} + +#endif diff --git a/code/nel/include/nel/misc/cdb_bank_handler.h b/code/nel/include/nel/misc/cdb_bank_handler.h index 102026f4d..3a225c1cb 100644 --- a/code/nel/include/nel/misc/cdb_bank_handler.h +++ b/code/nel/include/nel/misc/cdb_bank_handler.h @@ -113,6 +113,12 @@ public: */ uint getServerToClientUIDMapping( uint bank, uint index ) const{ return _CDBBankToUnifiedIndexMapping[ bank ][ index ]; } + /** + @brief Resizes the bank holders. WARNING: Resets data contained. + @param newSize - The new maximum number of banks. + */ + void resize( uint newSize ); + private: /// Mapping from server database index to client database index (first-level nodes) std::vector< std::vector< uint > > _CDBBankToUnifiedIndexMapping; diff --git a/code/nel/include/nel/misc/cdb_manager.h b/code/nel/include/nel/misc/cdb_manager.h index de6ccd20f..af4914b9a 100644 --- a/code/nel/include/nel/misc/cdb_manager.h +++ b/code/nel/include/nel/misc/cdb_manager.h @@ -171,6 +171,12 @@ namespace NLMISC{ */ void resetBank( uint gc, uint bank ); + + /** + @brief Resizes the bank holders. WARNING: Resets data contained. + @param newSize - The new maximum number of banks. + */ + void resizeBanks( uint newSize ); protected: CCDBBankHandler bankHandler; diff --git a/code/nel/src/gui/db_manager.cpp b/code/nel/src/gui/db_manager.cpp new file mode 100644 index 000000000..293bd2aae --- /dev/null +++ b/code/nel/src/gui/db_manager.cpp @@ -0,0 +1,53 @@ +#include "nel/gui/db_manager.h" + +namespace NLGUI +{ + CDBManager* CDBManager::instance = NULL; + + CDBManager::CDBManager() : + NLMISC::CCDBManager( "ROOT", 0 ) + { + } + + CDBManager::~CDBManager() + { + } + + CDBManager* CDBManager::getInstance() + { + if( instance == NULL ) + instance = new CDBManager(); + return instance; + } + + void CDBManager::release() + { + nlassert( instance != NULL ); + delete instance; + instance = NULL; + } + + NLMISC::CCDBNodeLeaf* CDBManager::getDbProp( const std::string &name, bool create ) + { + return getDbLeaf( name, create ); + } + + void CDBManager::delDbProp( const std::string &name ) + { + delDbNode( name ); + } + + sint32 CDBManager::getDbValue32( const std::string &name ) + { + NLMISC::CCDBNodeLeaf *node = getDbProp( name, false ); + if( node != NULL ) + return node->getValue32(); + else + return 0; + } + + NLMISC::CCDBNodeBranch* CDBManager::getDB() const + { + return _Database; + } +} \ No newline at end of file diff --git a/code/nel/src/misc/cdb_bank_handler.cpp b/code/nel/src/misc/cdb_bank_handler.cpp index f090ece4c..48a832611 100644 --- a/code/nel/src/misc/cdb_bank_handler.cpp +++ b/code/nel/src/misc/cdb_bank_handler.cpp @@ -91,6 +91,18 @@ _FirstLevelIdBitsByBank( maxbanks ) _FirstLevelIdBitsByBank[ bank ] = idb; } } + + void CCDBBankHandler::resize( uint newSize ) + { + reset(); + + _CDBBankNames.clear(); + _CDBBankToUnifiedIndexMapping.clear(); + _FirstLevelIdBitsByBank.clear(); + + _CDBBankToUnifiedIndexMapping.reserve( newSize ); + _FirstLevelIdBitsByBank.reserve( newSize ); + } } diff --git a/code/nel/src/misc/cdb_manager.cpp b/code/nel/src/misc/cdb_manager.cpp index 8fc8a6897..e9b6e7283 100644 --- a/code/nel/src/misc/cdb_manager.cpp +++ b/code/nel/src/misc/cdb_manager.cpp @@ -146,4 +146,9 @@ namespace NLMISC{ _Database->resetNode( gc, bankHandler.getUIDForBank( bank ) ); } + void CCDBManager::resizeBanks( uint newSize ) + { + bankHandler.resize( newSize ); + } + }