ImFusion C++ SDK 4.5.0
ImFusion::GlObjectFactory Class Reference

#include <ImFusion/GL/GlObjectFactory.h>

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

Inheritance diagram for ImFusion::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.

Static Public Member Functions

static GlObjectFactory & get ()
 Returns the GlObjectFactory singleton object.

Member Function Documentation

◆ registerObject() [1/2]

void ImFusion::GlObjectFactory::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 ImFusion::GlObjectFactory::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 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.

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 > 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.

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:
  • ImFusion/GL/GlObjectFactory.h
Search Tab / S to search, Esc to close