/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
- #ifndef __GENE_FACTORY__IMP__
- #define __GENE_FACTORY__IMP__
-
- #include "GeneFactoryIf.h"
-
- class TCOM_API GeneFactoryImp: public IGeneFactory
- {
- public:
- GeneFactoryImp();
- virtual ~GeneFactoryImp();
-
- //
- // initialize the factory
- //
- virtual void initialize();
-
- //
- // gene create
- // require an gene identifier : group id + id
- // require an gene create dynamic data
- //
- virtual IGene* create(IGeneCreateData& createData );
-
- protected:
- class IGeneCreator
- {
- public:
- virtual ~IGeneCreator(){}
-
- virtual IGene* create() = 0;
- };
-
-
- template<class GENE>
- class GeneCreatorByTemplate : public IGeneCreator
- {
- virtual IGene* create()
- {
- return new GENE;
- }
- };
-
-
- typedef stdext::hash_map<int, IGeneCreator*> GeneClass2Creator;
-
-
- template<class GENE>
- void registerGene(const int& nCls)
- {
- GeneClass2Creator::iterator it = m_theCreators.find(nCls);
- if (it==m_theCreators.end())
- {
- m_theCreators.insert(make_pair(nCls, new GeneCreatorByTemplate<GENE>));
- }
- else
- {
-
- }
- }
- private:
- GeneClass2Creator m_theCreators;
- };
-
-
- #endif