I have edited my post by adding an example. You can find the header, source, and main on this link. Minimized:
#include <boost/sml.hpp>
#include <iostream>
using namespace boost::sml;
struct Start {};
struct GoNested {};
struct Ts3 {
auto operator()() {
return make_transition_table(
*"nested_s3"_s + event<Start> = "Ts3_1"_s,
"nested_s3"_s + boost::sml::on_entry<_> / [] { std::puts("---- nested_s3 ----"); },
"Ts3_1"_s + boost::sml::on_entry<_> / [] { std::puts("---- Ts3_1 ----"); }
);
}
};
struct Ts2 {
auto operator()() {
return make_transition_table(
*"nested_s2"_s + event<Start> = "Ts2_1"_s,
"Ts2_1"_s + event<GoNested> = state<Ts3>,
"nested_s2"_s + boost::sml::on_entry<_> / [] { std::puts("---- nested_s2 ----"); },
"Ts2_1"_s + boost::sml::on_entry<_> / [] { std::puts("---- Ts2_1 ----"); });
}
};
struct Ts1 {
auto operator()() {
return make_transition_table(
*"s1"_s + event<Start> = "s2"_s,
"s2"_s + event<GoNested> = state<Ts2>,
"s1"_s + boost::sml::on_entry<_> / [] { std::puts("---- s1 ----"); },
"s2"_s + boost::sml::on_entry<_> / [] { std::puts("---- s2 ----"); }
);
}
};
int main() {
boost::sml::sm<Ts1, Ts2, Ts3> sMachine_;
auto print = [&] {
auto vis = [](auto state) { std::cout << "Current state = " << state.c_str() << std::endl; };
sMachine_.visit_current_states(vis);
};
print(); sMachine_.process_event(Start{});
print(); sMachine_.process_event(GoNested{});
print(); sMachine_.process_event(Start{});
print(); sMachine_.process_event(GoNested{});
print(); sMachine_.process_event(Start{});
print();
}
Printing
---- s1 ----
Current state = s1
---- s2 ----
Current state = s2
---- nested_s2 ----
Current state = boost::ext::sml::v1_1_6::back::sm<boost::ext::sml::v1_1_6::back::sm_policy<Ts2> >
---- Ts2_1 ----
Current state = boost::ext::sml::v1_1_6::back::sm<boost::ext::sml::v1_1_6::back::sm_policy<Ts2> >
---- nested_s3 ----
Current state = boost::ext::sml::v1_1_6::back::sm<boost::ext::sml::v1_1_6::back::sm_policy<Ts2> >
---- Ts3_1 ----
Current state = boost::ext::sml::v1_1_6::back::sm<boost::ext::sml::v1_1_6::back::sm_policy<Ts2> >
I have 3 nested transitions tables (Ts#), each of them at a given level => Ts1(Ts2(Ts3)))
Meaning that the highest and first transition table called is Ts1 and the more the program move further, the more the state machine goes into Ts2 and then Ts3. Obviously, each transition table has its own state.
I am trying to get the current state from a given transition table but I don't succeed to get it if it is in ts2 or ts3.
This below piece of code
sMachine_.visit_current_states([](auto state) {
std::cout << state.c_str() << std::endl; });
works only if I am at the first transition table (Ts1), otherwise, I got the following string instead of the state name:
boost::ext::sml::v1_1_4::back::sm<boost::ext::sml::v1_1_4::back::sm_policy<Ts2> >
Do you have any solution to get it correctly?
The above reproducible example depicts the problem by building and running the "testsSM.cpp" main file.
Many thanks in advance,