diff --git a/example/plant_uml.cpp b/example/plant_uml.cpp index aae2e47d..843c9a5c 100644 --- a/example/plant_uml.cpp +++ b/example/plant_uml.cpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace sml = boost::sml; @@ -17,6 +18,7 @@ struct e1 {}; struct e2 {}; struct e3 {}; struct e4 {}; +struct e5 {}; struct guard { bool operator()() const { return true; } @@ -26,30 +28,71 @@ struct action { void operator()() {} } action; + +struct sub { + auto operator()() const noexcept { + using namespace sml; + // clang-format off + return make_transition_table( + *"idle"_s + event /action = "s1"_s + , "s1"_s + event / action = X + ); + // clang-format on + } +}; + struct plant_uml { auto operator()() const noexcept { using namespace sml; // clang-format off return make_transition_table( - *"idle"_s + event = "s1"_s - , "s1"_s + event [ guard ] / action = "s2"_s - , "s2"_s + event [ guard ] = "s1"_s - , "s2"_s + event / action = X + *"idle"_s + event = state + , "idle"_s + event = state + , state + event [ guard ] / action = "s2"_s + , "s2"_s + event [ guard ] = "s1"_s + , "s2"_s + event / action = X + + ,*"idle2"_s + event = "s17"_s + , "s17"_s + event = X ); // clang-format on } }; + +template +struct is_sub_state_machine : std::false_type +{}; + +template +struct is_sub_state_machine>> + : std::true_type +{}; + +using strset_t = std::set; + template -void dump_transition() noexcept { +void dump_transition(strset_t& substates_handled, int& starts) noexcept { auto src_state = std::string{sml::aux::string{}.c_str()}; auto dst_state = std::string{sml::aux::string{}.c_str()}; - if (dst_state == "X") { + if (dst_state == "terminate") { dst_state = "[*]"; } if (T::initial) { - std::cout << "[*] --> " << src_state << std::endl; + std::cout << (starts++ ? "--\n" : "") <<"[*] --> " << src_state << std::endl; + } + + if constexpr (is_sub_state_machine::value) { + + auto [loc, suc] = substates_handled.insert(dst_state); + + if (suc) { + std::cout << "\nstate " << dst_state << " {\n"; + int new_starts{0}; + dump_transitions(substates_handled, new_starts, typename T::dst_state::transitions{}); + std::cout << "}\n"; + } } std::cout << src_state << " --> " << dst_state; @@ -78,15 +121,18 @@ void dump_transition() noexcept { } template