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

#include <ImFusion/Base/DataComponentFactory.h>

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

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

Static Public Member Functions

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

Member Function Documentation

◆ registerComponent()

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