Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef ModelFactory_H_INCLUDED
- #define ModelFactory_H_INCLUDED
- #include <map>
- template
- <
- typename AbstractModel,
- typename IdentifierType,
- typename ModelCreator
- >
- class ModelFactory
- {
- private:
- typedef std::map<IdentifierType,ModelCreator> AssociationMap;
- AssociationMap assocMap;
- public:
- bool Register(const IdentifierType& id, ModelCreator creator)
- {
- return this->assocMap.insert(AssociationMap::value_type(id,creator)).second;
- }
- bool Unregister(const IdentifierType& id)
- {
- return assocMap.erase(id) == 1;
- }
- AbstractModel* create(const IdentifierType& id)
- {
- typename AssociationMap::const_iterator iter = assocMap.find(id);
- if(iter != assocMap.end())
- {
- return (iter->second)();
- }
- }
- };
- #endif
Add Comment
Please, Sign In to add comment