![]() |
ImFusion C++ SDK 4.5.0
|
#include <ImFusion/GL/GlObjectFactory.h>
Factory singleton for creating GlObject from string IDs. More...
Factory singleton for creating GlObject from string IDs.
Every GlObject implements the typeName() method returning a unique string identifier for that specific type of GlObject. GlObjects have to be registered with GlObjectFactory using this string ID and a factory method for instantiating a GlObject of such type. During registration GlObjectFactory ensures the uniqueness of the registered GlObjects and otherwise raises an assertion/logs a warning.
Public Types | |
| using | CompatibilityFunction = std::function<bool(const Data* data, const std::vector<GlObject*>& objects)> |
| Alias for a function which checks if the corresponding FactoryFunction is compatible with the given input. | |
| using | FactoryFunctionSimple = std::function<std::unique_ptr<GlObject>()> |
| Alias for a GlObjectFactory factory function creating a specific GlObject. | |
| using | FactoryFunction = std::function<std::unique_ptr<GlObject>(const Data* data, const std::vector<GlObject*>& objects)> |
| Alias for a GlObjectFactory factory function creating a specific GlObject which can depend on Data and can wrap other GlObjects. | |
Public Member Functions | |
| void | registerObject (const std::string &id, FactoryFunction factoryFunction, CompatibilityFunction factoryCompatibilityFunction) |
| Registers a GlObject with the GlObjectFactory. | |
| void | registerObject (const std::string &id, FactoryFunctionSimple factoryFunction) |
| Registers a GlObject with the GlObjectFactory which does not require Data of GlObjects. | |
| bool | canCreateObject (const std::string &id, const Data *data=nullptr, const std::vector< GlObject * > &objects={}) |
| Test if a GlObject can be constructed with the given ID and the provided arguments. | |
| std::unique_ptr< GlObject > | createObject (const std::string &id, const Properties *p=nullptr, const Data *data=nullptr, const std::vector< GlObject * > &objects={}) |
| Instantiates a GlObject specified by the given ID. | |
Static Public Member Functions | |
| static GlObjectFactory & | get () |
| Returns the GlObjectFactory singleton object. | |
| void ImFusion::GlObjectFactory::registerObject | ( | const std::string & | id, |
| FactoryFunction | factoryFunction, | ||
| CompatibilityFunction | factoryCompatibilityFunction ) |
Registers a GlObject with the GlObjectFactory.
| id | Unique string ID for the GlObject to register. |
| factoryFunction | Method to use for instantiating the GlObject to register which takes reference data and potential objects to wrap. |
| factoryCompatibilityFunction | Method to use for checking if the GlObject can be created with given data and potential objects to wrap. |
| void ImFusion::GlObjectFactory::registerObject | ( | const std::string & | id, |
| FactoryFunctionSimple | factoryFunction ) |
Registers a GlObject with the GlObjectFactory which does not require Data of GlObjects.
| bool ImFusion::GlObjectFactory::canCreateObject | ( | const std::string & | id, |
| const Data * | data = nullptr, | ||
| const std::vector< GlObject * > & | objects = {} ) |
Test if a GlObject can be constructed with the given ID and the provided arguments.
| std::unique_ptr< GlObject > ImFusion::GlObjectFactory::createObject | ( | const std::string & | id, |
| const Properties * | p = nullptr, | ||
| const Data * | data = nullptr, | ||
| const std::vector< GlObject * > & | objects = {} ) |
Instantiates a GlObject specified by the given ID.