PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/TGame/TCommon/Gene/GeneFactoryImp.h

http://awoe.googlecode.com/
C++ Header | 65 lines | 42 code | 15 blank | 8 comment | 1 complexity | 211a6bb8b40fc2788ed50dd440be45c9 MD5 | raw file
 1#ifndef		__GENE_FACTORY__IMP__
 2#define		__GENE_FACTORY__IMP__
 3
 4#include "GeneFactoryIf.h"
 5
 6class TCOM_API  GeneFactoryImp: public IGeneFactory
 7{
 8public:
 9	GeneFactoryImp();
10	virtual ~GeneFactoryImp();
11
12	//
13	//	initialize the factory
14	//
15	virtual void	initialize();
16
17	//
18	//	gene create
19	//	require an gene identifier : group id + id
20	//	require an gene create dynamic data
21	//
22	virtual IGene*	create(IGeneCreateData& createData );
23
24protected:
25	class IGeneCreator
26	{
27	public:
28		virtual ~IGeneCreator(){}
29
30		virtual IGene* create() = 0;
31	};
32
33
34	template<class GENE>
35	class GeneCreatorByTemplate : public IGeneCreator
36	{
37		virtual IGene* create()
38		{
39			return new GENE;
40		}
41	};
42
43
44	typedef stdext::hash_map<int, IGeneCreator*>	GeneClass2Creator;
45
46
47	template<class GENE>
48	void	registerGene(const int& nCls)
49	{
50		GeneClass2Creator::iterator it = m_theCreators.find(nCls);
51		if (it==m_theCreators.end())
52		{
53			m_theCreators.insert(make_pair(nCls, new GeneCreatorByTemplate<GENE>));
54		}
55		else
56		{
57
58		}
59	}
60private:
61	GeneClass2Creator	m_theCreators;
62};
63
64
65#endif