ImFusion SDK 4.3
GlObjectFactory Class Reference

#include <ImFusion/GL/GlObjectFactory.h>

Factory singleton for creating GlObject from string IDs. More...

+ Inheritance diagram for GlObjectFactory:

Detailed Description

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< GlObjectcreateObject (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.
 
- Public Member Functions inherited from FactoryBase
 FactoryBase ()
 No license check is performed for the module instantiated with this constructor.
 
 FactoryBase (std::string module, bool checkLicense=true)
 
std::string moduleName () const
 Returns the module name of the factory.
 

Static Public Member Functions

static GlObjectFactoryget ()
 Returns the GlObjectFactory singleton object.
 

Additional Inherited Members

- Protected Member Functions inherited from FactoryBase
virtual ~FactoryBase ()
 Virtual destructor.
 
std::string getComponentPath (const std::string &componentName) const
 Returns the path to the component referred to by name.
 
bool isLicensed (const std::string &name)
 Return true if the license allows the use of the component referred to by name.
 
- Static Protected Member Functions inherited from FactoryBase
static std::string getComponentPath (const std::string &moduleName, const std::string &componentName)
 Returns the path to the component referred to by name.
 
static bool isLicensed (const std::string &moduleName, const std::string &name)
 Return true if the license allows the use of the component referred to by name.
 
- Protected Attributes inherited from FactoryBase
std::string m_factoryModule
 
bool m_checkLicense
 

Member Function Documentation

◆ registerObject() [1/2]

void registerObject ( const std::string & id,
FactoryFunction factoryFunction,
CompatibilityFunction factoryCompatibilityFunction )

Registers a GlObject with the GlObjectFactory.

Note
The string IDs of GlObjects have to be unique. If you register an ID a second time, the previously registered factory method will be overwritten. Debug builds will also raise an assertion.
Parameters
idUnique string ID for the GlObject to register.
factoryFunctionMethod to use for instantiating the GlObject to register which takes reference data and potential objects to wrap.
factoryCompatibilityFunctionMethod to use for checking if the GlObject can be created with given data and potential objects to wrap.

◆ registerObject() [2/2]

void registerObject ( const std::string & id,
FactoryFunctionSimple factoryFunction )

Registers a GlObject with the GlObjectFactory which does not require Data of GlObjects.

Note
The string IDs of GlObjects have to be unique. If you register an ID a second time, the previously registered factory method will be overwritten. Debug builds will also raise an assertion.
Parameters
idUnique string ID for the GlObject to register.
factoryFunctionMethod to use for instantiating the GlObject to register.

◆ canCreateObject()

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.

Parameters
idUnique ID of the GlObject to create.
pOptional pointer to a Properties object. If not 0, it will used to configure the newly created GlObject.
dataData on which the GlObject relies (optional).
objectsGlObjects on which the GlObject relies (optional).

◆ createObject()

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.

Parameters
idUnique ID of the GlObject to create.
pOptional pointer to a Properties object. If not 0, it will used to configure the newly created GlObject.
dataData on which the GlObject relies (optional).
objectsGlObjects on which the GlObject relies (optional).

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close