1+ #pragma once
2+ #include < iostream>
3+ #include < fstream>
4+
5+ namespace sml = boost::sml;
6+
7+ template <class T >
8+ void dump_transition (std::ofstream &ofs) noexcept
9+ {
10+ auto src_state = std::string{ sml::aux::string<typename T::src_state>{}.c_str () };
11+ auto dst_state = std::string{ sml::aux::string<typename T::dst_state>{}.c_str () };
12+ if (dst_state == " X" ) {
13+ dst_state = " [*]" ;
14+ }
15+
16+ if (T::initial) {
17+ ofs << " [*] --> " << src_state << " \n " ;
18+ }
19+
20+ const auto has_event = !sml::aux::is_same<typename T::event, sml::anonymous>::value;
21+ const auto has_guard = !sml::aux::is_same<typename T::guard, sml::front::always>::value;
22+ const auto has_action = !sml::aux::is_same<typename T::action, sml::front::none>::value;
23+
24+ const auto is_entry = sml::aux::is_same<typename T::event, sml::back::on_entry<sml::_, sml::_>>::value;
25+ const auto is_exit = sml::aux::is_same<typename T::event, sml::back::on_exit<sml::_, sml::_>>::value;
26+
27+ if (is_entry || is_exit) {
28+ ofs << src_state;
29+ } else {// state to state transition
30+ ofs << src_state << " --> " << dst_state;
31+ }
32+
33+ if (has_event || has_guard || has_action) {
34+ ofs << " :" ;
35+ }
36+
37+ if (has_event) {
38+ auto event = std::string (boost::sml::aux::get_type_name<typename T::event>());
39+ if (is_entry) {
40+ event = " entry" ;
41+ } else if (is_exit) {
42+ event = " exit" ;
43+ }
44+ ofs << " " << event;
45+ }
46+
47+ if (has_guard) {
48+ ofs << " [" << boost::sml::aux::get_type_name<typename T::guard::type>() << " ]" ;
49+ }
50+
51+ if (has_action) {
52+ ofs << " / " << boost::sml::aux::get_type_name<typename T::action::type>();
53+ }
54+
55+ ofs << " \n " ;
56+ }
57+
58+ template <template <class ...> class T , class ... Ts>
59+ void dump_transitions (std::ofstream &ofs, const T<Ts...> &) noexcept
60+ {
61+ int _[]{ 0 , (dump_transition<Ts>(ofs), 0 )... };
62+ (void )_;
63+ }
64+
65+ template <class SM >
66+ void dump (const SM &) noexcept
67+ {
68+ std::ofstream ofs (" stateMachine.plantuml" );
69+ ofs << " @startuml\n\n " ;
70+ dump_transitions (ofs, typename SM::transitions{});
71+ ofs << std::endl
72+ << " @enduml\n " ;
73+ }
0 commit comments