Icarus
Vehicle Simulation as a Transformable Computational Graph, built on Vulcan and Janus
Loading...
Searching...
No Matches
icarus::ComponentFactory< Scalar > Class Template Reference

Factory for creating components from configuration. More...

#include <ComponentFactory.hpp>

Public Types

using Creator = std::function<std::unique_ptr<Component<Scalar>>(const ComponentConfig &)>
 Creator function type: takes full ComponentConfig, returns component.

Public Member Functions

void Register (const std::string &type_name, Creator creator)
 Register a component type with custom creator.
std::unique_ptr< Component< Scalar > > Create (const ComponentConfig &config)
 Create a component from config.
bool HasType (const std::string &type_name) const
 Check if a type is registered.
std::vector< std::string > GetRegisteredTypes () const
 Get list of registered type names.
std::size_t NumRegistered () const
 Get number of registered types.
void Clear ()
 Clear all registrations (for testing).

Static Public Member Functions

static ComponentFactory & Instance ()
 Get singleton instance.

Detailed Description

template<typename Scalar>
class icarus::ComponentFactory< Scalar >

Factory for creating components from configuration.

Components register themselves using the ICARUS_REGISTER_COMPONENT macro. The factory creates components by type name from ComponentConfig.

Example usage:

// In component file - register with factory
// In Simulator - create from config
auto component = factory.Create(config); // config has type, name, scalars, etc.
#define ICARUS_REGISTER_COMPONENT(ComponentType)
Register a component type with the factory (both backends).
Definition ComponentFactory.hpp:156
static ComponentFactory & Instance()
Get singleton instance.
Definition ComponentFactory.hpp:109

Member Typedef Documentation

◆ Creator

template<typename Scalar>
using icarus::ComponentFactory< Scalar >::Creator = std::function<std::unique_ptr<Component<Scalar>>(const ComponentConfig &)>

Creator function type: takes full ComponentConfig, returns component.

Member Function Documentation

◆ Clear()

template<typename Scalar>
void icarus::ComponentFactory< Scalar >::Clear ( )
inline

Clear all registrations (for testing).

◆ Create()

template<typename Scalar>
std::unique_ptr< Component< Scalar > > icarus::ComponentFactory< Scalar >::Create ( const ComponentConfig & config)
inlinenodiscard

Create a component from config.

The creator receives the full ComponentConfig including:

  • name: Component instance name
  • entity: Entity namespace (if any)
  • scalars: Scalar parameter values
  • vectors: Vector parameter values
  • strings: String parameter values
Parameters
configComponent configuration
Returns
Unique pointer to created component
Exceptions
ConfigErrorif type is not registered

◆ GetRegisteredTypes()

template<typename Scalar>
std::vector< std::string > icarus::ComponentFactory< Scalar >::GetRegisteredTypes ( ) const
inlinenodiscard

Get list of registered type names.

◆ HasType()

template<typename Scalar>
bool icarus::ComponentFactory< Scalar >::HasType ( const std::string & type_name) const
inlinenodiscard

Check if a type is registered.

◆ Instance()

template<typename Scalar>
ComponentFactory & icarus::ComponentFactory< Scalar >::Instance ( )
inlinestatic

Get singleton instance.

◆ NumRegistered()

template<typename Scalar>
std::size_t icarus::ComponentFactory< Scalar >::NumRegistered ( ) const
inlinenodiscard

Get number of registered types.

◆ Register()

template<typename Scalar>
void icarus::ComponentFactory< Scalar >::Register ( const std::string & type_name,
Creator creator )
inline

Register a component type with custom creator.

Parameters
type_nameType name used in config files
creatorFunction that creates the component from config

The documentation for this class was generated from the following file: