$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:212

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 
)

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:144

This will define the following classes for us:

  • Abort
  • AbortFactory

This action can be registered with the register_action helper function.