PageRenderTime 25ms CodeModel.GetById 22ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/TGame/TCommon/Message/MsgFactoryByMap.h

http://awoe.googlecode.com/
C++ Header | 38 lines | 21 code | 11 blank | 6 comment | 0 complexity | 9df0f1eca5f06f7996e10ea13a09eadc MD5 | raw file
 1#ifndef		__MSG_FACTORY__BYMAP__
 2#define		__MSG_FACTORY__BYMAP__
 3
 4#include "MsgFactoryIf.h"
 5
 6typedef IMsg* (*MessageFunctor)();
 7
 8//
 9//	Message Factory
10//
11
12class TCOM_API  MsgFactoryByMap: public IMsgFactory
13{
14public:
15	MsgFactoryByMap();
16	virtual ~MsgFactoryByMap();
17
18
19	//
20	//	create a message base on message category and message id
21	//
22	virtual	IMsg*	createMsg(int nMsgCate, int nMsgID);
23
24
25	template<class Msg>
26	static IMsg*	create()
27	{
28		return new Msg;
29	}
30
31	void registerMsg(int nCate, int nID, MessageFunctor func);
32protected:
33	typedef	stdext::hash_map<int, MessageFunctor>	MessageCreatorMap;
34	MessageCreatorMap m_theMap;
35};
36
37#endif
38