zonegroupinfomanager.cpp
来自「天之炼狱1服务器端源文件游戏服务端不完整」· C++ 代码 · 共 216 行
CPP
216 行
//----------------------------------------------------------------------//// Filename : ZoneGroupInfoManager.cpp// Written By : Reiot// Description :////----------------------------------------------------------------------// include files#include "ZoneGroupInfoManager.h"#include "database/DatabaseManager.h"#include "database/Connection.h"#include "database/Statement.h"#include "database/Result.h"//----------------------------------------------------------------------// constructor//----------------------------------------------------------------------ZoneGroupInfoManager::ZoneGroupInfoManager () throw (){} //----------------------------------------------------------------------// destructor//----------------------------------------------------------------------ZoneGroupInfoManager::~ZoneGroupInfoManager () throw (){ // hashmap 救狼 阿 pair 狼 second, 溜 ZoneGroupInfo 按眉父阑 昏力窍绊 // pair 磊眉绰 弊措肺 敌促. (ZoneGroupInfo啊 赛俊 积己登绢 乐促绰 巴俊 // 蜡狼窍扼. 溜 鞘混昏力甫 秦具 茄促. 窍变, ZGIM捞 destruct 等促绰 巴篮 // 肺弊牢 辑滚啊 妓促款等促绰 巴阑 狼固窍聪瘪.. - -; ) for ( HashMapZoneGroupInfo::iterator itr = m_ZoneGroupInfos.begin() ; itr != m_ZoneGroupInfos.end() ; itr ++ ) { delete itr->second; itr->second = NULL; } // 捞力 秦浆甘救俊 乐绰 葛电 pair 甸阑 昏力茄促. m_ZoneGroupInfos.clear();} //----------------------------------------------------------------------// initialize GSIM//----------------------------------------------------------------------void ZoneGroupInfoManager::init () throw ( Error ){ __BEGIN_TRY // just load data from ZoneGroupInfo table load(); // just print to cout cout << toString() << endl; __END_CATCH}//----------------------------------------------------------------------// load data from database//----------------------------------------------------------------------void ZoneGroupInfoManager::load () throw ( Error ){ __BEGIN_TRY Statement * pStmt; try { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); Result * pResult = pStmt->executeQuery( "SELECT ZoneGroupID , ServerID FROM ZoneGroupInfo" ); while ( pResult->next() ) { ZoneGroupInfo * pZoneGroupInfo = new ZoneGroupInfo(); pZoneGroupInfo->setZoneGroupID( pResult->getWORD(1) ); pZoneGroupInfo->setServerID( pResult->getWORD(2) ); addZoneGroupInfo( pZoneGroupInfo ); } } catch ( SQLQueryException & sqe ) { // 鞘混 昏力! delete pStmt; throw Error(sqe.toString()); } // 鞘混 昏力! delete pStmt; __END_CATCH}//----------------------------------------------------------------------// add info //----------------------------------------------------------------------void ZoneGroupInfoManager::addZoneGroupInfo ( ZoneGroupInfo * pZoneGroupInfo ) throw ( DuplicatedException ){ __BEGIN_TRY HashMapZoneGroupInfo::iterator itr = m_ZoneGroupInfos.find( pZoneGroupInfo->getZoneGroupID() ); if ( itr != m_ZoneGroupInfos.end() ) throw DuplicatedException("duplicated zone id"); m_ZoneGroupInfos[ pZoneGroupInfo->getZoneGroupID() ] = pZoneGroupInfo; __END_CATCH} //----------------------------------------------------------------------// delete info//----------------------------------------------------------------------void ZoneGroupInfoManager::deleteZoneGroupInfo ( ZoneGroupID_t zoneGroupID ) throw ( NoSuchElementException ){ __BEGIN_TRY HashMapZoneGroupInfo::iterator itr = m_ZoneGroupInfos.find( zoneGroupID ); if ( itr != m_ZoneGroupInfos.end() ) { // ZoneGroupInfo 甫 昏力茄促. delete itr->second; // pair甫 昏力茄促. m_ZoneGroupInfos.erase( itr ); } else { // not found StringStream msg; msg << "ZoneGroupID : " << zoneGroupID; throw NoSuchElementException(msg.toString()); } __END_CATCH} //----------------------------------------------------------------------// get info//----------------------------------------------------------------------ZoneGroupInfo * ZoneGroupInfoManager::getZoneGroupInfo ( ZoneGroupID_t zoneGroupID ) const throw ( NoSuchElementException ){ __BEGIN_TRY ZoneGroupInfo * pZoneGroupInfo = NULL; HashMapZoneGroupInfo::const_iterator itr = m_ZoneGroupInfos.find( zoneGroupID ); if ( itr != m_ZoneGroupInfos.end() ) { pZoneGroupInfo = itr->second; } else { // not found StringStream msg; msg << "ZoneGroupID : " << zoneGroupID; throw NoSuchElementException( msg.toString() ); } return pZoneGroupInfo; __END_CATCH}//----------------------------------------------------------------------// get debug string//----------------------------------------------------------------------string ZoneGroupInfoManager::toString () const throw (){ __BEGIN_TRY StringStream msg; msg << "ZoneGroupInfoManager("; if ( m_ZoneGroupInfos.empty() ) { msg << "EMPTY"; } else { //-------------------------------------------------- // *OPTIMIZATION* // // for_each()甫 荤侩且 巴 //-------------------------------------------------- for ( HashMapZoneGroupInfo::const_iterator itr = m_ZoneGroupInfos.begin() ; itr != m_ZoneGroupInfos.end() ; itr ++ ) msg << itr->second->toString(); } msg << ")"; return msg.toString(); __END_CATCH}// global variable definitionZoneGroupInfoManager * g_pZoneGroupInfoManager = NULL;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?