Red Baron

POST : Program

code snippet [Network Service Factory]

class CServerBase{
protected:
std::wstring m_strName;
u_short m_usPort;
public:
virtual bool Open( void ) = 0;
virtual bool Open( u_short usPort , std::wstring strName ) = 0;
};

class CNetworkServer2 : public CServerBase{
public:
bool Open ( void ){
std::cout << "Network2 Open" << std::endl;
return true;
}
bool Open ( u_short usPort , std::wstring strName ){
this->m_strName = strName;
this->m_usPort = usPort;
std::cout << "Network2 Open:"<<usPort <<"NAME:"<< std::endl;
return true;
}
};
class CNetServiceBase{
public:
void NewServer ( u_short usPort , std::wstring  strName ){
SMART_PTR_SHARED(REF_COUNT , CServerBase) spServer = CreateServer(usPort , strName);
m_vServerList[strName] = spServer;
spServer->Open(usPort , strName);
}
virtual SMART_PTR_SHARED(REF_COUNT , CServerBase) CreateServer ( u_short usPort , std::wstring strName ) = 0;
private:
std::map <std::wstring, SMART_PTR_SHARED( REF_COUNT ,CServerBase ) >  m_vServerList;
};

template < class ServerType > 
class CNetService : public CNetServiceBase {
public:
virtual SMART_PTR_SHARED(REF_COUNT , CServerBase) CreateServer( u_short usPort , std::wstring strName ){
return (SMART_PTR_SHARED(REF_COUNT , CServerBase))new ServerType;
}
};


top

posted at

2010. 3. 23. 14:50


CONTENTS

Red Baron
BLOG main image

RSS 2.0Tattertools
공지 아카이브
최근 글 최근 댓글 최근 트랙백
카테고리 태그 구름사이트 링크