$darkmode
set_action.hpp File Reference
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <cloe/trigger.hpp>
#include <cloe/trigger/helper_macros.hpp>
Include dependency graph for set_action.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  cloe::actions::SetVariableAction< T >
 
class  cloe::actions::SetVariableActionFactory< T >
 

Macros

#define DEFINE_SET_STATE_ACTION(xName, xname, xdescription, xState, xOperatorBlock)
 
#define DEFINE_SET_DATA_ACTION(xName, xActionName, xActionDesc, xDataType, xAttributeName, xAttributeType, xOperatorBlock)
 

Functions

template<typename T >
cloe::actions::from_string (const std::string &s)
 
template<>
double cloe::actions::from_string< double > (const std::string &s)
 
template<>
int cloe::actions::from_string< int > (const std::string &s)
 
template<>
bool cloe::actions::from_string< bool > (const std::string &s)
 

Detailed Description

This file defines actions that set a given variable.

Macro Definition Documentation

◆ DEFINE_SET_DATA_ACTION

#define DEFINE_SET_DATA_ACTION (   xName,
  xActionName,
  xActionDesc,
  xDataType,
  xAttributeName,
  xAttributeType,
  xOperatorBlock 
)

Macro DEFINE_SET_DATA_ACTION defines an action that sets an attribute from the configuration.

Parameters
xNametype identifier for action
xActionNamestring identifier of action (lowercase)
xActionDescstring description of action
xDataTypetype identifier for member data pointer
xAttributeNamestring identifier of the attribute (defines configuration)
xAttributeTypetype identifier of the attribute
xOperatorBlockcode block that makes use of ptr_ and value_

Example

Given the type SimulationSync and the action "modify the simulation speed", we can create it in code like so:

DEFINE_SET_DATA_ACTION(RealtimeFactor, "realtime_factor", "modify simulation speed",
SimulationSync, "factor", double,
{
logger()->info("Setting target simulation speed: {}", value_);
ptr_->set_realtime_factor(value_);
})
#define DEFINE_SET_DATA_ACTION(xName, xActionName, xActionDesc, xDataType, xAttributeName, xAttributeType, xOperatorBlock)
Definition: set_action.hpp:206

This will define the following classes for us:

  • RealtimeFactor
  • RealtimeFactorFactory

This action can be registered with the register_action helper function. Refer to doc/reference/actions.rst for the configuration.

◆ DEFINE_SET_STATE_ACTION

#define DEFINE_SET_STATE_ACTION (   xName,
  xname,
  xdescription,
  xState,
  xOperatorBlock 
)
Value:
class xName : public ::cloe::Action { \
public: \
xName(const std::string& name, xState* ptr) : ::cloe::Action(name), ptr_(ptr) {} \
::cloe::ActionPtr clone() const override { return std::make_unique<xName>(name(), ptr_); } \
void operator()(const ::cloe::Sync&, ::cloe::TriggerRegistrar&) override { xOperatorBlock } \
void to_json(::cloe::Json&) const override {} \
\
private: \
xState* ptr_; \
}; \
\
class _X_FACTORY(xName) : public ::cloe::ActionFactory { \
public: \
using ActionType = xName; \
\
_X_FACTORY(xName)(xState * ptr) : ::cloe::ActionFactory(xname, xdescription), ptr_(ptr) {} \
\
::cloe::ActionPtr make(const ::cloe::Conf&) const override { \
return std::make_unique<xName>(name(), ptr_); \
} \
\
::cloe::ActionPtr make(const std::string&) const override { \
return std::make_unique<xName>(name(), ptr_); \
} \
\
private: \
xState* ptr_; \
};
Definition: trigger.hpp:607
virtual void operator()(const Sync &, TriggerRegistrar &)=0
virtual void to_json(fable::Json &j) const =0
virtual ActionPtr clone() const =0
const std::string & name() const
Definition: entity.hpp:67
Definition: trigger.hpp:290
Definition: trigger.hpp:433
TriggerFactory< Action > ActionFactory
Definition: cloe_fwd.hpp:77

Macro DEFINE_SET_STATE_ACTION defines an action that has only a single state and no configuration.

Parameters
xNametype identifier for event
xnamestring identifier of event (lowercase)
xdescriptionstring description of event
xStatetype identifier for member state pointer
xOperatorBlockcode block that makes use of ptr_

Example

Given the type Simulation and the action "abort the simulation", we can create it in code like so, note that the semicolon at the end is required.

DEFINE_SET_STATE_ACTION(Abort, "abort", "abort simulation", Simulation, {
ptr_->abort();
});
#define DEFINE_SET_STATE_ACTION(xName, xname, xdescription, xState, xOperatorBlock)
Definition: set_action.hpp:141

This will define the following classes for us:

  • Abort
  • AbortFactory

This action can be registered with the register_action helper function.