diff --git a/include/fsm_cxx/fsm-sm.hh b/include/fsm_cxx/fsm-sm.hh index 4acdab5..89a53e7 100644 --- a/include/fsm_cxx/fsm-sm.hh +++ b/include/fsm_cxx/fsm-sm.hh @@ -65,13 +65,13 @@ namespace fsm_cxx { namespace fsm_cxx { // struct dummy_event {}; - namespace detail{ + namespace detail { inline std::string shorten(std::string const &s) { auto pos = s.rfind("::"); return pos == std::string::npos ? s : s.substr(pos + 2); } - } - + } // namespace detail + struct event_t { virtual ~event_t() {} virtual std::string to_string() const { return ""; } @@ -112,13 +112,13 @@ namespace fsm_cxx { friend std::ostream &operator<<(std::ostream &os, payload_t const &o) { return os << o.to_string(); } bool _ok; }; - + template struct payload_type : public payload_t { virtual ~payload_type() {} std::string to_string() const { return detail::shorten(std::string(debug::type_name())); } }; - + } // namespace fsm_cxx #define FSM_DEFINE_EVENT(n) \ @@ -541,7 +541,7 @@ namespace fsm_cxx { _ctx.reset(_initial); return (*this); } - + machine_t &on_transition(OnAction &&fn) { _on_action = fn; return (*this); @@ -767,6 +767,16 @@ namespace fsm_cxx { return is; } + public: + template>::value && + !std::is_same::value, + bool> = true> + machine_t &operator<<(Evt const &ev) { + step_by(ev); + return (*this); + } + private: ContextT _ctx{}; StateT _initial{}, _terminated{}, _error{}; diff --git a/tests/basic.cc b/tests/basic.cc index a953caf..57d1c04 100644 --- a/tests/basic.cc +++ b/tests/basic.cc @@ -158,11 +158,7 @@ namespace fsm_cxx { namespace test { // processing - m.step_by(begin{}); - m.step_by(open{}); - m.step_by(close{}); - m.step_by(open{}); - m.step_by(end{}); + m << begin{} << open{} << close{} << open{} << end{}; std::printf("---- END OF test_state_meta_2()\n\n\n"); }