1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
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/>.
21 #include "nel/misc/cdb_manager.h"
29 CCDBManager::CCDBManager( const char *rootNodeName
, uint maxBanks
) : bankHandler( maxBanks
)
31 _Database
= new CCDBNodeBranch( std::string( rootNodeName
) );
34 CCDBManager::~CCDBManager()
36 if( _Database
!= NULL
)
44 CCDBNodeLeaf
* CCDBManager::getDbLeaf( const std::string
&name
, bool create
)
49 CCDBNodeLeaf
*leaf
= NULL
;
50 leaf
= dynamic_cast< CCDBNodeLeaf
* >( _Database
->getNode( ICDBNode::CTextId( name
), create
) );
54 CCDBNodeBranch
* CCDBManager::getDbBranch( const std::string
&name
)
59 CCDBNodeBranch
*branch
= NULL
;
60 branch
= dynamic_cast< CCDBNodeBranch
* >( _Database
->getNode( ICDBNode::CTextId( name
), false ) );
65 void CCDBManager::delDbNode( const std::string
&name
)
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 ) );
78 branchObservingHandler
.addBranchObserver( b
, observer
, positiveLeafNameFilter
);
81 void CCDBManager::addBranchObserver( CCDBNodeBranch
*branch
, ICDBNode::IPropertyObserver
*observer
, const std::vector
< std::string
>& positiveLeafNameFilter
)
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 ) );
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
)
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 ) );
108 branchObservingHandler
.removeBranchObserver( b
, observer
);
111 void CCDBManager::removeBranchObserver( CCDBNodeBranch
*branch
, ICDBNode::IPropertyObserver
* observer
)
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 ) );
123 branchObservingHandler
.removeBranchObserver( b
, dbPathFromThisNode
, observer
);
126 void CCDBManager::removeBranchObserver( CCDBNodeBranch
*branch
, const char *dbPathFromThisNode
, ICDBNode::IPropertyObserver
&observer
)
130 branchObservingHandler
.removeBranchObserver( branch
, dbPathFromThisNode
, observer
);
133 void CCDBManager::addFlushObserver( CCDBBranchObservingHandler::IBranchObserverCallFlushObserver
*observer
)
135 if( observer
== NULL
)
137 branchObservingHandler
.addFlushObserver( observer
);
140 void CCDBManager::removeFlushObserver( CCDBBranchObservingHandler::IBranchObserverCallFlushObserver
*observer
)
142 if( observer
== NULL
)
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
);