$darkmode
component.hpp File Reference
#include <cstdint>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include <fable/fable_fwd.hpp>
#include <cloe/model.hpp>
#include <cloe/sync.hpp>
#include <cloe/version.hpp>
Include dependency graph for component.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  cloe::Component
 
class  cloe::ComponentFactory
 

Macros

#define DEFINE_COMPONENT_FACTORY(xFactoryType, xConfigType, xName, xDescription)
 
#define DEFINE_COMPONENT_FACTORY_MAKE(xFactoryType, xComponentType, xInputType)
 

Detailed Description

See also
cloe/component.cpp
cloe/model.hpp
cloe/vehicle.hpp

This file provides the base classes for component models.

Macro Definition Documentation

◆ DEFINE_COMPONENT_FACTORY

#define DEFINE_COMPONENT_FACTORY (   xFactoryType,
  xConfigType,
  xName,
  xDescription 
)
Value:
class xFactoryType : public ::cloe::ComponentFactory { \
public: \
xFactoryType() : ComponentFactory(xName, xDescription) {} \
std::unique_ptr<::cloe::ComponentFactory> clone() const override { \
return std::make_unique<std::decay<decltype(*this)>::type>(*this); \
} \
std::unique_ptr<::cloe::Component> make( \
const ::fable::Conf&, std::vector<std::shared_ptr<::cloe::Component>>) const override; \
\
protected: \
::cloe::Schema schema_impl() override { return config_.schema(); } \
\
private: \
xConfigType config_; \
};
Definition: component.hpp:210
virtual std::unique_ptr< ComponentFactory > clone() const =0
virtual std::unique_ptr< Component > make(const fable::Conf &c, std::vector< std::shared_ptr< Component >>) const =0
virtual Schema schema_impl()
Definition: confable.cpp:84
Definition: schema.hpp:175

This macro defines a ComponentFactory named xFactoryType and with the configuration xConfigType. It should be used within the desired namespace.

The make method needs to be implemented:

std::unique_ptr<Component> xFactoryType::make(const Conf& c) {
// implementation
}

The DEFINE_COMPONENT_FACTORY_MAKE macro can also be used to use the default implementation.

◆ DEFINE_COMPONENT_FACTORY_MAKE

#define DEFINE_COMPONENT_FACTORY_MAKE (   xFactoryType,
  xComponentType,
  xInputType 
)
Value:
std::unique_ptr<::cloe::Component> xFactoryType::make( \
const ::fable::Conf& c, std::vector<std::shared_ptr<::cloe::Component>> comp) const { \
decltype(config_) conf{config_}; \
assert(comp.size() == 1); \
if (!c->is_null()) { \
conf.from_conf(c); \
} \
return std::make_unique<xComponentType>( \
this->name(), conf, std::dynamic_pointer_cast<xInputType>(std::move(comp.front()))); \
}

This macro defines the xFactoryType::make method for components with exactly one input component.

For this to work, the xComponentType must have a constructor with the following signature (see DEFINE_COMPONENT_FACTORY macro):

xComponentType(const std::string&, const xConfigType&, std::shared_ptr<xInputType>)