zoneinfomanager.cpp

来自「天之炼狱1服务器端源文件游戏服务端不完整」· C++ 代码 · 共 215 行

CPP
215
字号
//----------------------------------------------------------------------//// Filename    : ZoneInfoManager.cpp// Written By  : Reiot// Description :////----------------------------------------------------------------------// include files#include "ZoneInfoManager.h"#include "database/DatabaseManager.h"#include "database/Connection.h"#include "database/Statement.h"#include "database/Result.h"//----------------------------------------------------------------------// constructor//----------------------------------------------------------------------ZoneInfoManager::ZoneInfoManager () 	throw (){}	//----------------------------------------------------------------------// destructor//----------------------------------------------------------------------ZoneInfoManager::~ZoneInfoManager () 	throw (){	// hashmap 救狼 阿 pair 狼 second, 溜 ZoneInfo 按眉父阑 昏力窍绊	// pair 磊眉绰 弊措肺 敌促. (ZoneInfo啊 赛俊 积己登绢 乐促绰 巴俊	// 蜡狼窍扼. 溜 鞘混昏力甫 秦具 茄促. 窍变, ZIM捞 destruct 等促绰 巴篮	// 肺弊牢 辑滚啊 妓促款等促绰 巴阑 狼固窍聪瘪.. - -; )	for ( HashMapZoneInfo::iterator itr = m_ZoneInfos.begin() ; 		  itr != m_ZoneInfos.end() ; 		  itr ++ ) {		delete itr->second;		itr->second = NULL;	}	// 捞力 秦浆甘救俊 乐绰 葛电 pair 甸阑 昏力茄促.	m_ZoneInfos.clear();}	//----------------------------------------------------------------------// initialize GSIM//----------------------------------------------------------------------void ZoneInfoManager::init ()	throw ( Error ){	__BEGIN_TRY	// just load data from ZoneInfo table	load();	// just print to cout	cout << toString() << endl;	__END_CATCH}//----------------------------------------------------------------------// load data from database//----------------------------------------------------------------------void ZoneInfoManager::load ()	throw ( Error ){	__BEGIN_TRY	Statement * pStmt;	try {		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		Result * pResult = pStmt->executeQuery(			"SELECT ZoneID , ZoneGroupID FROM ZoneInfo"		);		while ( pResult->next() ) {			ZoneInfo * pZoneInfo = new ZoneInfo();			pZoneInfo->setZoneID( pResult->getWORD(1) );			pZoneInfo->setZoneGroupID( pResult->getWORD(2) );			addZoneInfo( pZoneInfo );		}	} catch ( SQLQueryException & sqe ) {		// 鞘混 昏力!		delete pStmt;		throw Error(sqe.toString());	}	// 鞘混 昏力!	delete pStmt;	__END_CATCH}//----------------------------------------------------------------------// add info //----------------------------------------------------------------------void ZoneInfoManager::addZoneInfo ( ZoneInfo * pZoneInfo ) 	throw ( DuplicatedException ){	__BEGIN_TRY	HashMapZoneInfo::iterator itr = m_ZoneInfos.find( pZoneInfo->getZoneID() );		if ( itr != m_ZoneInfos.end() )		throw DuplicatedException("duplicated zone id");	m_ZoneInfos[ pZoneInfo->getZoneID() ] = pZoneInfo;	__END_CATCH}	//----------------------------------------------------------------------// delete info//----------------------------------------------------------------------void ZoneInfoManager::deleteZoneInfo ( ZoneID_t zoneID )	throw ( NoSuchElementException ){	__BEGIN_TRY			HashMapZoneInfo::iterator itr = m_ZoneInfos.find( zoneID );		if ( itr != m_ZoneInfos.end() ) {		// ZoneInfo 甫 昏力茄促.		delete itr->second;		// pair甫 昏力茄促.		m_ZoneInfos.erase( itr );	} else { // not found		StringStream msg;		msg << "ZoneID : " << zoneID;		throw NoSuchElementException(msg.toString());	}	__END_CATCH}	//----------------------------------------------------------------------// get info//----------------------------------------------------------------------ZoneInfo * ZoneInfoManager::getZoneInfo ( ZoneID_t zoneID ) const	throw ( NoSuchElementException ){	__BEGIN_TRY			ZoneInfo * pZoneInfo = NULL;	HashMapZoneInfo::const_iterator itr = m_ZoneInfos.find( zoneID );		if ( itr != m_ZoneInfos.end() ) {		pZoneInfo = itr->second;	} else { // not found		StringStream msg;		msg << "ZoneID : " << zoneID;		throw NoSuchElementException( msg.toString() );	}	return pZoneInfo;	__END_CATCH}//----------------------------------------------------------------------// get debug string//----------------------------------------------------------------------string ZoneInfoManager::toString () const	throw (){	__BEGIN_TRY	StringStream msg;	msg << "ZoneInfoManager(\n";	if ( m_ZoneInfos.empty() ) {		msg << "EMPTY";	} else {		//--------------------------------------------------		// *OPTIMIZATION*		//		// for_each()甫 荤侩且 巴		//--------------------------------------------------		for ( HashMapZoneInfo::const_iterator itr = m_ZoneInfos.begin() ; 			  itr != m_ZoneInfos.end() ; 			  itr ++ )			msg << itr->second->toString() << '\n';	}	msg << ")";	return msg.toString();	__END_CATCH}// global variable definitionZoneInfoManager * g_pZoneInfoManager = NULL;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?