Merge branch '138-toggle-free-look-with-hotkey' into 'main/atys-live'
[ryzomcore.git] / nel / src / misc / cdb_bank_handler.cpp
blobde1c43ef8860be8aee1e108c9ff5fa7a2702f952
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_bank_handler.h"
23 #ifdef DEBUG_NEW
24 #define new DEBUG_NEW
25 #endif
27 namespace NLMISC{
28 CCDBBankHandler::CCDBBankHandler(uint maxbanks) :
29 _CDBBankToUnifiedIndexMapping( maxbanks, std::vector< uint >() ),
30 _FirstLevelIdBitsByBank( maxbanks )
32 std::fill( _FirstLevelIdBitsByBank.begin(), _FirstLevelIdBitsByBank.end(), 0 );
33 maxBanks = maxbanks;
36 uint CCDBBankHandler::getUIDForBank( uint bank ) const
38 uint uid = static_cast< uint >( -1 );
40 for( uint i = 0; i < _UnifiedIndexToBank.size(); i++ )
41 if( _UnifiedIndexToBank[ i ] == bank )
42 return i;
44 return uid;
47 uint CCDBBankHandler::getBankByName( const std::string &name ) const
49 uint b = static_cast< uint >( -1 );
51 for( uint i = 0; i < _CDBBankNames.size(); i++ )
52 if( _CDBBankNames[ i ].compare( name ) == 0 )
53 return i;
55 return b;
58 void CCDBBankHandler::mapNodeByBank( const std::string &bankName )
60 uint b = getBankByName( bankName );
61 // no such bank
62 if( b == static_cast< uint >( -1 ) )
63 return;
65 _CDBBankToUnifiedIndexMapping[ b ].push_back( _CDBLastUnifiedIndex );
66 ++_CDBLastUnifiedIndex;
67 _UnifiedIndexToBank.push_back( b );
70 void CCDBBankHandler::fillBankNames( const char **strings, uint size )
72 _CDBBankNames.clear();
74 for( uint i = 0; i < size; i++ )
75 _CDBBankNames.push_back( std::string( strings[ i ] ) );
78 void CCDBBankHandler::reset()
80 for( std::vector< std::vector< uint > >::iterator itr =_CDBBankToUnifiedIndexMapping.begin();
81 itr != _CDBBankToUnifiedIndexMapping.end(); ++itr )
82 itr->clear();
84 _UnifiedIndexToBank.clear();
85 _CDBLastUnifiedIndex = 0;
88 void CCDBBankHandler::calcIdBitsByBank()
90 for( uint bank = 0; bank != maxBanks; bank++ )
92 uint nbNodesOfBank = static_cast< uint >( _CDBBankToUnifiedIndexMapping[ bank ].size() );
93 uint idb = 0;
95 if ( nbNodesOfBank > 0 )
96 for ( idb = 1; nbNodesOfBank > unsigned( 1 << idb ) ; idb++ )
99 _FirstLevelIdBitsByBank[ bank ] = idb;
103 void CCDBBankHandler::resize( uint newSize )
105 reset();
107 _CDBBankNames.clear();
108 _CDBBankToUnifiedIndexMapping.clear();
109 _FirstLevelIdBitsByBank.clear();
111 _CDBBankToUnifiedIndexMapping.reserve( newSize );
112 _FirstLevelIdBitsByBank.reserve( newSize );