34 namespace cloe::actions {
37 T from_string(
const std::string& s);
40 inline double from_string<double>(
const std::string& s) {
45 inline int from_string<int>(
const std::string& s) {
50 inline bool from_string<bool>(
const std::string& s) {
53 }
else if (s ==
"false") {
56 throw std::out_of_range(
"cannot parse into boolean: " + s);
64 explicit SetVariableAction(
const std::string& action_name,
const std::string& data_name,
66 :
Action(action_name), data_name_(data_name), data_ptr_(data_ptr), value_(value) {}
67 ActionPtr
clone()
const override {
68 return std::make_unique<SetVariableAction>(
name(), data_name_, data_ptr_, value_);
72 return CallbackResult::Ok;
75 void to_json(Json& j)
const override {
82 std::string data_name_;
92 const std::string& data_name, T* data_ptr)
93 :
ActionFactory(action_name, action_desc), data_name_(data_name), data_ptr_(data_ptr) {}
95 auto value = c.
get<T>(data_name_);
96 return std::make_unique<SetVariableAction<T>>(
name(), data_name_, data_ptr_, value);
98 ActionPtr
make(
const std::string& s)
const override {
99 auto value = from_string<T>(s);
106 std::string data_name_;
142 #define DEFINE_SET_STATE_ACTION(xName, xname, xdescription, xState, xOperatorBlock) \
143 class xName : public ::cloe::Action { \
145 xName(const std::string& name, xState* ptr) : ::cloe::Action(name), ptr_(ptr) {} \
146 ::cloe::ActionPtr clone() const override { return std::make_unique<xName>(name(), ptr_); } \
147 ::cloe::CallbackResult operator()(const ::cloe::Sync&, ::cloe::TriggerRegistrar&) override { \
149 return ::cloe::CallbackResult::Ok; \
151 void to_json(::cloe::Json&) const override {} \
157 class _X_FACTORY(xName) : public ::cloe::ActionFactory { \
159 using ActionType = xName; \
161 _X_FACTORY(xName)(xState * ptr) : ::cloe::ActionFactory(xname, xdescription), ptr_(ptr) {} \
163 ::cloe::ActionPtr make(const ::cloe::Conf&) const override { \
164 return std::make_unique<xName>(name(), ptr_); \
167 ::cloe::ActionPtr make(const std::string&) const override { \
168 return std::make_unique<xName>(name(), ptr_); \
210 #define DEFINE_SET_DATA_ACTION(xName, xActionName, xActionDesc, xDataType, xAttributeName, \
211 xAttributeType, xOperatorBlock) \
212 class xName : public ::cloe::Action { \
214 xName(const std::string& action_name, xDataType* ptr, const std::string& attribute_name, \
215 const xAttributeType attribute_value) \
216 : ::cloe::Action(action_name) \
218 , name_(attribute_name) \
219 , value_(attribute_value) {} \
220 ::cloe::ActionPtr clone() const override { \
221 return std::make_unique<xName>(name(), ptr_, name_, value_); \
223 ::cloe::CallbackResult operator()(const ::cloe::Sync&, ::cloe::TriggerRegistrar&) override { \
225 return ::cloe::CallbackResult::Ok; \
227 bool is_significant() const override { return false; } \
228 void to_json(::cloe::Json& j) const override { \
237 xAttributeType value_; \
240 class _X_FACTORY(xName) : public ::cloe::ActionFactory { \
242 using ActionType = xName; \
244 (xDataType * ptr) : ::cloe::ActionFactory(xActionName, xActionDesc), ptr_(ptr) {} \
246 ::cloe::ActionPtr make(const ::cloe::Conf& c) const override { \
247 auto value = c.get<xAttributeType>(xAttributeName); \
248 return std::make_unique<xName>(name(), ptr_, xAttributeName, value); \
251 ::cloe::ActionPtr make(const std::string& s) const override { \
252 auto value = ::cloe::actions::from_string<xAttributeType>(s); \
253 return make(::fable::Conf{::fable::Json{ \
254 {xAttributeName, value}, \
Definition: trigger.hpp:619
const std::string & name() const
Definition: entity.hpp:67
Definition: trigger.hpp:290
Definition: trigger.hpp:437
Definition: set_action.hpp:88
ActionPtr make(const std::string &s) const override
Definition: set_action.hpp:98
ActionPtr make(const Conf &c) const override
Definition: set_action.hpp:94
Definition: set_action.hpp:62
ActionPtr clone() const override
Definition: set_action.hpp:67
bool is_significant() const override
Definition: set_action.hpp:74
CallbackResult operator()(const Sync &, TriggerRegistrar &) override
Definition: set_action.hpp:70
T get() const
Definition: conf.hpp:297
CallbackResult
Definition: trigger.hpp:514