#include "stdafx.h" #include "CharacterDoc.h" CCharacterDoc::~CCharacterDoc() { Destroy(); } void CCharacterDoc::Destroy() { isMapDoc::iterator itr = m_mapCharDoc.begin(); for(;itr != m_mapCharDoc.end(); ++itr) { delete itr->second; } m_mapCharDoc.clear(); m_listServerInfo.clear(); } unsigned long CCharacterDoc::PushCharDocInfo(CharDocInfo* lpCharDocInfo) { m_mapCharDoc.insert(std::make_pair(++m_dwKey, lpCharDocInfo)); lpCharDocInfo->m_dwDocKey = m_dwKey; return m_dwKey; } CCharacterDoc::CharDocInfo* CCharacterDoc::GetCharDocInfo(unsigned long dwKey) { isMapDoc::iterator itr = m_mapCharDoc.find(dwKey); if(itr != m_mapCharDoc.end()) { return itr->second; } return NULL; } bool CCharacterDoc::DeleteCharDocInfo(unsigned long dwKey) { isMapDoc::iterator itr = m_mapCharDoc.find(dwKey); if(itr != m_mapCharDoc.end()) { delete itr->second; m_mapCharDoc.erase(itr); return true; } return false; } void CCharacterDoc::PushServerGroup(CString strServerName, unsigned long dwServerIndex) { m_listServerInfo.push_back(ServerInfo(strServerName, dwServerIndex)); } bool CCharacterDoc::GetServerIndex(CString strServerName, unsigned long& dwServerIndex) { islistServerInfo::iterator pos = m_listServerInfo.begin(); while(pos != m_listServerInfo.end()) { if(!_tcsicmp((*pos).m_strServerName, strServerName)) { dwServerIndex = (*pos).m_dwServerIndex; return true; } ++pos; } return false; } bool CCharacterDoc::GetServerName(unsigned long dwServerGroup, CString& strServerName) { islistServerInfo::iterator pos = m_listServerInfo.begin(); while(pos != m_listServerInfo.end()) { if((*pos).m_dwServerIndex == dwServerGroup) { strServerName = (*pos).m_strServerName; return true; } ++pos; } strServerName = _T("UNKNOWN"); return false; }