$darkmode
controller.hpp File Reference
#include <memory>
#include <type_traits>
#include <utility>
#include <cloe/model.hpp>
Include dependency graph for controller.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  cloe::Controller
 
class  cloe::ControllerFactory
 

Macros

#define DEFINE_CONTROLLER_FACTORY(xFactoryType, xConfigType, xName, xDescription)
 
#define DEFINE_CONTROLLER_FACTORY_MAKE(xFactoryType, xControllerType)
 

Detailed Description

See also
cloe/model.hpp

This file provides the base classes for controller models.

Macro Definition Documentation

◆ DEFINE_CONTROLLER_FACTORY

#define DEFINE_CONTROLLER_FACTORY (   xFactoryType,
  xConfigType,
  xName,
  xDescription 
)
Value:
class xFactoryType : public ::cloe::ControllerFactory { \
public: \
xFactoryType() : ::cloe::ControllerFactory(xName, xDescription) {} \
std::unique_ptr<::cloe::ControllerFactory> clone() const override { \
return std::make_unique<std::decay<decltype(*this)>::type>(*this); \
} \
\
std::unique_ptr<::cloe::Controller> make(const ::fable::Conf&) const override; \
\
protected: \
::cloe::Schema schema_impl() override { return config_.schema(); } \
\
private: \
xConfigType config_; \
};
Definition: controller.hpp:164
virtual std::unique_ptr< Controller > make(const fable::Conf &c) const =0
virtual std::unique_ptr< ControllerFactory > clone() const =0
virtual Schema schema_impl()
Definition: confable.cpp:84
Definition: schema.hpp:173

This macro defines a ControllerFactory 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<Controller> xFactoryType::make(const Conf& c) {
// implementation
}

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

◆ DEFINE_CONTROLLER_FACTORY_MAKE

#define DEFINE_CONTROLLER_FACTORY_MAKE (   xFactoryType,
  xControllerType 
)
Value:
std::unique_ptr<::cloe::Controller> xFactoryType::make(const ::fable::Conf& c) const { \
decltype(config_) conf{config_}; \
if (!c->is_null()) { \
conf.from_conf(c); \
} \
return std::make_unique<xControllerType>(this->name(), conf); \
}

This macro defines the xFactoryType::make method.

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

xControllerType(const std::string&, const xConfigType&)