Skip to content

Header only heterogeneous factory pattern with automated static registration

License

Notifications You must be signed in to change notification settings

farmovit/heterogeneous_factory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Heterogeneous factory

Status License


Header only heterogeneous factory pattern with automated static registration

About

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.

Requirements

CMake 3.6
C++17

About

Header only heterogeneous factory pattern with automated static registration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published