Icarus
Vehicle Simulation as a Transformable Computational Graph, built on Vulcan and Janus
Loading...
Searching...
No Matches
ComponentFactory.hpp File Reference

Factory for creating components from configuration. More...

#include <icarus/core/Component.hpp>
#include <icarus/core/ComponentConfig.hpp>
#include <icarus/core/Error.hpp>
#include <janus/core/JanusTypes.hpp>
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
Include dependency graph for ComponentFactory.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  icarus::ComponentFactory< Scalar >
 Factory for creating components from configuration. More...

Namespaces

namespace  icarus

Macros

#define ICARUS_REGISTER_COMPONENT(ComponentType)
 Register a component type with the factory (both backends).
#define ICARUS_REGISTER_COMPONENT_IMPL2(ComponentType, TypeName, Counter)
 Register component with custom type name (both backends).
#define ICARUS_REGISTER_COMPONENT_IMPL(ComponentType, TypeName, Counter)
#define ICARUS_REGISTER_COMPONENT_AS(ComponentType, TypeName)
#define ICARUS_REGISTER_COMPONENT_WITH_CREATOR_IMPL2(TypeName, CreatorLambda, Counter)
 Register component with custom creator function (numeric backend only).
#define ICARUS_REGISTER_COMPONENT_WITH_CREATOR_IMPL(TypeName, CreatorLambda, Counter)
#define ICARUS_REGISTER_COMPONENT_WITH_CREATOR(TypeName, CreatorLambda)

Detailed Description

Factory for creating components from configuration.

Part of Phase 4.0.7: Configuration Infrastructure. Provides a singleton factory with component registration.

Updated to pass full ComponentConfig to creators, enabling components to read their scalars, vectors, and other configuration values.

Macro Definition Documentation

◆ ICARUS_REGISTER_COMPONENT

#define ICARUS_REGISTER_COMPONENT ( ComponentType)
Value:
namespace { \
static bool _reg_numeric_##ComponentType = []() { \
::icarus::ComponentFactory<janus::NumericScalar>::Instance().Register( \
#ComponentType, [](const ::icarus::ComponentConfig &config) { \
auto comp = std::make_unique<ComponentType<janus::NumericScalar>>(config.name, \
config.entity); \
comp->SetConfig(config); \
return comp; \
}); \
return true; \
}(); \
static bool _reg_symbolic_##ComponentType = []() { \
::icarus::ComponentFactory<janus::SymbolicScalar>::Instance().Register( \
#ComponentType, [](const ::icarus::ComponentConfig &config) { \
auto comp = std::make_unique<ComponentType<janus::SymbolicScalar>>(config.name, \
config.entity); \
comp->SetConfig(config); \
return comp; \
}); \
return true; \
}(); \
}

Register a component type with the factory (both backends).

The component class must have a constructor that accepts (name, entity): ComponentType(std::string name, std::string entity)

The factory will call SetConfig() after construction. Components read their configuration in Stage() via GetConfig().

Registers with both janus::NumericScalar (double) and janus::SymbolicScalar (casadi::MX) backends for full dual-backend support.

Usage in component header or cpp file (namespace scope):

#define ICARUS_REGISTER_COMPONENT(ComponentType)
Register a component type with the factory (both backends).
Definition ComponentFactory.hpp:156

◆ ICARUS_REGISTER_COMPONENT_AS

#define ICARUS_REGISTER_COMPONENT_AS ( ComponentType,
TypeName )
Value:
ICARUS_REGISTER_COMPONENT_IMPL(ComponentType, TypeName, __COUNTER__)
#define ICARUS_REGISTER_COMPONENT_IMPL(ComponentType, TypeName, Counter)
Definition ComponentFactory.hpp:214

◆ ICARUS_REGISTER_COMPONENT_IMPL

#define ICARUS_REGISTER_COMPONENT_IMPL ( ComponentType,
TypeName,
Counter )
Value:
ICARUS_REGISTER_COMPONENT_IMPL2(ComponentType, TypeName, Counter)
#define ICARUS_REGISTER_COMPONENT_IMPL2(ComponentType, TypeName, Counter)
Register component with custom type name (both backends).
Definition ComponentFactory.hpp:190

◆ ICARUS_REGISTER_COMPONENT_IMPL2

#define ICARUS_REGISTER_COMPONENT_IMPL2 ( ComponentType,
TypeName,
Counter )
Value:
namespace { \
static const bool _icarus_reg_numeric_##Counter = []() { \
::icarus::ComponentFactory<janus::NumericScalar>::Instance().Register( \
TypeName, [](const ::icarus::ComponentConfig &config) { \
auto comp = std::make_unique<ComponentType<janus::NumericScalar>>(config.name, \
config.entity); \
comp->SetConfig(config); \
return comp; \
}); \
return true; \
}(); \
static const bool _icarus_reg_symbolic_##Counter = []() { \
::icarus::ComponentFactory<janus::SymbolicScalar>::Instance().Register( \
TypeName, [](const ::icarus::ComponentConfig &config) { \
auto comp = std::make_unique<ComponentType<janus::SymbolicScalar>>(config.name, \
config.entity); \
comp->SetConfig(config); \
return comp; \
}); \
return true; \
}(); \
}

Register component with custom type name (both backends).

Registers with both janus::NumericScalar and janus::SymbolicScalar backends.

Usage (at namespace scope, inside the component's namespace):

ICARUS_REGISTER_COMPONENT_AS(PointMass3DOF, "PointMass3DOF")
#define ICARUS_REGISTER_COMPONENT_AS(ComponentType, TypeName)
Definition ComponentFactory.hpp:217

◆ ICARUS_REGISTER_COMPONENT_WITH_CREATOR

#define ICARUS_REGISTER_COMPONENT_WITH_CREATOR ( TypeName,
CreatorLambda )
Value:
ICARUS_REGISTER_COMPONENT_WITH_CREATOR_IMPL(TypeName, CreatorLambda, __COUNTER__)
#define ICARUS_REGISTER_COMPONENT_WITH_CREATOR_IMPL(TypeName, CreatorLambda, Counter)
Definition ComponentFactory.hpp:249

◆ ICARUS_REGISTER_COMPONENT_WITH_CREATOR_IMPL

#define ICARUS_REGISTER_COMPONENT_WITH_CREATOR_IMPL ( TypeName,
CreatorLambda,
Counter )
Value:
ICARUS_REGISTER_COMPONENT_WITH_CREATOR_IMPL2(TypeName, CreatorLambda, Counter)
#define ICARUS_REGISTER_COMPONENT_WITH_CREATOR_IMPL2(TypeName, CreatorLambda, Counter)
Register component with custom creator function (numeric backend only).
Definition ComponentFactory.hpp:240

◆ ICARUS_REGISTER_COMPONENT_WITH_CREATOR_IMPL2

#define ICARUS_REGISTER_COMPONENT_WITH_CREATOR_IMPL2 ( TypeName,
CreatorLambda,
Counter )
Value:
namespace { \
static bool _icarus_reg_creator_##Counter = []() { \
::icarus::ComponentFactory<janus::NumericScalar>::Instance().Register(TypeName, \
CreatorLambda); \
return true; \
}(); \
}

Register component with custom creator function (numeric backend only).

Use when component needs special construction logic. The creator lambda is responsible for calling SetConfig() on the component.

Note: This macro only registers with janus::NumericScalar. For dual-backend support with custom creators, use the factory directly.

Usage:

[](const ComponentConfig& cfg) {
auto comp = std::make_unique<CustomComponent<janus::NumericScalar>>(
cfg.name, cfg.entity);
comp->SetConfig(cfg);
return comp;
})
#define ICARUS_REGISTER_COMPONENT_WITH_CREATOR(TypeName, CreatorLambda)
Definition ComponentFactory.hpp:252