ImFusion SDK 4.3
DataComponentFactory Class Reference

#include <ImFusion/Base/DataComponentFactory.h>

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

+ Inheritance diagram for DataComponentFactory:

Detailed Description

Factory singleton for creating DataComponents from string IDs.

Every DataComponent implements the id() method returning a unique string identifier for that specific type of DataComponent. DataComponents have to be registered with DataComponentFactory using this string ID and a factory method for instantiating a DataComponent of such type. During registration DataComponentFactory ensures the uniqueness of the registered DataComponents and otherwise raises an assertion/logs a warning.

See also
DataComponentBase ,

Public Types

using FactoryMethod = std::function<std::unique_ptr<DataComponentBase>()>
 Alias for a DataComponentFactory factory method creating a specific DataComponent.
 

Public Member Functions

void registerComponent (const std::string &id, FactoryMethod factoryMethod)
 Registers a DataComponent with the DataComponentFactory.
 
std::unique_ptr< DataComponentBasecreateComponent (const std::string &id, const Properties *p=nullptr)
 Instantiates a DataComponent specified by the given ID.
 
std::vector< std::stringregisteredComponentIds () const
 Returns the Unique IDs of all DataComponents registered with this factory.
 
- 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 DataComponentFactoryget ()
 Returns the DataComponentFactory 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

◆ registerComponent()

void registerComponent ( const std::string & id,
FactoryMethod factoryMethod )

Registers a DataComponent with the DataComponentFactory.

Note
The string IDs of DataComponents 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 DataComponent to register.
factoryMethodMethod to use for instantiating the DataComponent to register.

◆ createComponent()

std::unique_ptr< DataComponentBase > createComponent ( const std::string & id,
const Properties * p = nullptr )

Instantiates a DataComponent specified by the given ID.

Parameters
idUnique ID of the DataComponent to create.
pOptional pointer to a Properties object. If not 0, it will used to configure the newly created DataComponent.

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