Files
fishtanks/src/Factory.h
T
Jace 3470a80f40 Revert "Indentation style changed to Horstmann"
This reverts commit f2259f712d.

Conflicts:

	src/GameWorld.cpp
	src/Systems/PhysicsSystem.cpp
2014-04-12 01:48:15 +02:00

35 lines
597 B
C++
Executable File

#ifndef ComponentFactory_h__
#define ComponentFactory_h__
#include <string>
#include <memory>
#include <functional>
#include <map>
template <typename T>
class Factory
{
public:
void Register(std::string name, std::function<T(void)> factoryFunction)
{
m_FactoryFunctions[name] = factoryFunction;
}
T Create(std::string name)
{
auto it = m_FactoryFunctions.find(name);
if (it != m_FactoryFunctions.end())
{
return it->second();
}
else
{
return nullptr;
}
}
private:
std::map<std::string, std::function<T(void)>> m_FactoryFunctions;
};
#endif // ComponentFactory_h__