#include <darts/factory.h>
template<typename Object, typename... Args>
Factory class
Abstract factory used to construct objects by name.
Public static functions
- static auto create_instance(const std::string& name, Args && ... args) -> Object
- Construct an object from the class of the given
name
and passargs
to the registered constructor. - static void register_type(const std::string& name, const Constructor constructor)
- Register an object constructor with the object factory.
- static auto registered_types() -> std::set<string>
- Return a set of all classes registered with this factory (useful for debugging).
Protected static functions
- static auto type_registry() -> std::map<std::string, Constructor>&
- Singleton pattern that prevents "static initialization order fiasco".
Function documentation
template<typename Object, typename... Args>
static Object Factory<Object, Args>:: create_instance(const std::string& name,
Args && ... args)
Construct an object from the class of the given name
and pass args
to the registered constructor.
Parameters | |
---|---|
name | An internal name that is associated with this class. For darts scenes, this is the 'type' field found in the scene json file. |
args | Variadic list of arguments to forward to the registered constructor. |
template<typename Object, typename... Args>
static void Factory<Object, Args>:: register_type(const std::string& name,
const Constructor constructor)
Register an object constructor with the object factory.
Parameters | |
---|---|
name | An internal name that is associated with this class. For darts scenes, this is the 'type' field found in the scene json file. |
constructor | A function that is able to call the constructor of the class. |
This function is called by the macro DARTS_