Header only heterogeneous factory pattern with automated static registration
This library provide you a heterogeneous factory with a very convinient automated static registraion.
// Interface.h
struct Interface { ... };
// InterfaceFactory.h
using InterfaceFactory = HGSFactory<Interface>;
// Concrete.h
struct Concrete : public Interface {
Concrete(int, int) {}
static std::string factoryRegistrationName() { return "concrete"; }
};
// Concrete.cpp
REGISTER_IN_FACTORY_STATIC(InterfaceFactory, Concrete, int, int)
// ConcreteSecond.h
struct ConcreteSecond : public Interface {
Concrete(int) {}
static std::string factoryRegistrationName() { return "concrete_second"; }
};
// ConcreteSecond.cpp
REGISTER_IN_FACTORY_STATIC(InterfaceFactory, ConcreteSecond, int)
// logic.cpp
auto concrete = InterfaceFactory::create("concrete", 2, 3);
auto concreteSecond = InterfaceFactory::create("concrete_second", 10);
Please see the test to get more examples. Also documentation are available in source files.
CMake 3.6
C++17