stringpool.cpp
来自「天之炼狱1服务器端源文件游戏服务端不完整」· C++ 代码 · 共 117 行
CPP
117 行
///////////////////////////////////////////////////////////// Filename : StringPool.cpp///////////////////////////////////////////////////////////#include "StringPool.h"#include "DB.h"StringPool::StringPool() throw(Error){ __BEGIN_TRY __END_CATCH}StringPool::~StringPool() throw(Error){ __BEGIN_TRY clear(); __END_CATCH}void StringPool::clear() throw(Error){ __BEGIN_TRY m_Strings.clear(); __END_CATCH}void StringPool::load() throw(Error){ __BEGIN_TRY clear(); Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); Result* pResult = pStmt->executeQuery( "SELECT ID, String FROM SSStringPool" ); while ( pResult->next() ) { int i = 0; uint strID = pResult->getInt( ++i ); string str = pResult->getString( ++i ); addString( strID, str ); } } END_DB(pStmt) __END_CATCH}void StringPool::addString( uint strID, string sString ) throw( DuplicatedException, Error ){ __BEGIN_TRY StringHashMapItor itr = m_Strings.find( strID ); if ( itr != m_Strings.end() ) { throw DuplicatedException("StringPool::addString()"); } m_Strings[ strID ] = sString; __END_CATCH}string StringPool::getString( uint strID ) throw( NoSuchElementException, Error ){ __BEGIN_TRY StringHashMapItor itr = m_Strings.find( strID ); if ( itr == m_Strings.end() ) { throw NoSuchElementException("StringPool::getStrind()"); } return itr->second; __END_CATCH}const char* StringPool::c_str( uint strID ) throw( NoSuchElementException, Error ){ __BEGIN_TRY StringHashMapItor itr = m_Strings.find( strID ); if ( itr == m_Strings.end() ) { throw NoSuchElementException("StringPool::getStrind()"); } return itr->second.c_str(); __END_CATCH}StringPool* g_pStringPool = NULL;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?