Merge branch '138-toggle-free-look-with-hotkey' into 'main/atys-live'
[ryzomcore.git] / nel / src / misc / cdb_manager.cpp
blobc1e47e5f8f47445a879c47aa2072f60453edac8e
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdmisc.h"
21 #include "nel/misc/cdb_manager.h"
23 #ifdef DEBUG_NEW
24 #define new DEBUG_NEW
25 #endif
27 namespace NLMISC{
29 CCDBManager::CCDBManager( const char *rootNodeName, uint maxBanks ) : bankHandler( maxBanks )
31 _Database = new CCDBNodeBranch( std::string( rootNodeName ) );
34 CCDBManager::~CCDBManager()
36 if( _Database != NULL )
38 _Database->clear();
39 delete _Database;
40 _Database = NULL;
44 CCDBNodeLeaf* CCDBManager::getDbLeaf( const std::string &name, bool create )
46 if( name.empty() )
47 return NULL;
49 CCDBNodeLeaf *leaf = NULL;
50 leaf = dynamic_cast< CCDBNodeLeaf* >( _Database->getNode( ICDBNode::CTextId( name ), create ) );
51 return leaf;
54 CCDBNodeBranch* CCDBManager::getDbBranch( const std::string &name )
56 if( name.empty() )
57 return NULL;
59 CCDBNodeBranch *branch = NULL;
60 branch = dynamic_cast< CCDBNodeBranch* >( _Database->getNode( ICDBNode::CTextId( name ), false ) );
61 return branch;
65 void CCDBManager::delDbNode( const std::string &name )
67 if( name.empty() )
68 return;
70 _Database->removeNode( ICDBNode::CTextId( name ) );
73 void CCDBManager::addBranchObserver( const char *branchName, ICDBNode::IPropertyObserver *observer, const std::vector< std::string >& positiveLeafNameFilter )
75 CCDBNodeBranch *b = dynamic_cast< CCDBNodeBranch* >( _Database->getNode( ICDBNode::CTextId( std::string( branchName ) ), false ) );
76 if( b == NULL )
77 return;
78 branchObservingHandler.addBranchObserver( b, observer, positiveLeafNameFilter );
81 void CCDBManager::addBranchObserver( CCDBNodeBranch *branch, ICDBNode::IPropertyObserver *observer, const std::vector< std::string >& positiveLeafNameFilter )
83 if( branch == NULL )
84 return;
85 branchObservingHandler.addBranchObserver( branch, observer, positiveLeafNameFilter );
88 void CCDBManager::addBranchObserver( const char *branchName, const char *dbPathFromThisNode, ICDBNode::IPropertyObserver &observer, const char **positiveLeafNameFilter, uint positiveLeafNameFilterSize )
90 CCDBNodeBranch *b = dynamic_cast< CCDBNodeBranch* >( _Database->getNode( ICDBNode::CTextId( std::string( branchName ) ), false ) );
91 if( b == NULL )
92 return;
93 branchObservingHandler.addBranchObserver( b, dbPathFromThisNode, observer, positiveLeafNameFilter, positiveLeafNameFilterSize );
96 void CCDBManager::addBranchObserver( CCDBNodeBranch *branch, const char *dbPathFromThisNode, ICDBNode::IPropertyObserver &observer, const char **positiveLeafNameFilter, uint positiveLeafNameFilterSize )
98 if( branch == NULL )
99 return;
100 branchObservingHandler.addBranchObserver( branch, dbPathFromThisNode, observer, positiveLeafNameFilter, positiveLeafNameFilterSize );
103 void CCDBManager::removeBranchObserver( const char *branchName, ICDBNode::IPropertyObserver* observer )
105 CCDBNodeBranch *b = dynamic_cast< CCDBNodeBranch* >( _Database->getNode( ICDBNode::CTextId( std::string( branchName ) ), false ) );
106 if( b == NULL )
107 return;
108 branchObservingHandler.removeBranchObserver( b, observer );
111 void CCDBManager::removeBranchObserver( CCDBNodeBranch *branch, ICDBNode::IPropertyObserver* observer )
113 if( branch == NULL )
114 return;
115 branchObservingHandler.removeBranchObserver( branch, observer );
118 void CCDBManager::removeBranchObserver( const char *branchName, const char *dbPathFromThisNode, ICDBNode::IPropertyObserver &observer )
120 CCDBNodeBranch *b = dynamic_cast< CCDBNodeBranch* >( _Database->getNode( ICDBNode::CTextId( std::string( branchName ) ), false ) );
121 if( b == NULL )
122 return;
123 branchObservingHandler.removeBranchObserver( b, dbPathFromThisNode, observer );
126 void CCDBManager::removeBranchObserver( CCDBNodeBranch *branch, const char *dbPathFromThisNode, ICDBNode::IPropertyObserver &observer )
128 if( branch == NULL )
129 return;
130 branchObservingHandler.removeBranchObserver( branch, dbPathFromThisNode, observer );
133 void CCDBManager::addFlushObserver( CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer )
135 if( observer == NULL )
136 return;
137 branchObservingHandler.addFlushObserver( observer );
140 void CCDBManager::removeFlushObserver( CCDBBranchObservingHandler::IBranchObserverCallFlushObserver *observer )
142 if( observer == NULL )
143 return;
144 branchObservingHandler.removeFlushObserver( observer );
147 void CCDBManager::flushObserverCalls()
149 branchObservingHandler.flushObserverCalls();
152 void CCDBManager::resetBank( uint gc, uint bank )
154 _Database->resetNode( gc, bankHandler.getUIDForBank( bank ) );
157 void CCDBManager::resizeBanks( uint newSize )
159 bankHandler.resize( newSize );