Skip to content

Instantly share code, notes, and snippets.

@pmf
Created June 28, 2024 12:19
Show Gist options
  • Save pmf/5512263bc9e32b17b3571ca417c3094b to your computer and use it in GitHub Desktop.
Save pmf/5512263bc9e32b17b3571ca417c3094b to your computer and use it in GitHub Desktop.
#include "sml/sml.hpp"
#include <deque>
#include <queue>
#include <iostream>
struct HandlerSml
{
struct ev_tick {};
struct ev_success {};
struct A {};
struct UnreachableDummy {};
struct ActionDispatch
{
void operator()(boost::sml::back::process<ev_success> processEvent)
{
// I do it unconditionally here, but the real example hav condition checks here, making it impossible to
// use process() in the transition table
std::cout << "tick" << std::endl;
processEvent(ev_success{});
}
};
auto operator()() const {
using namespace boost::sml;
// clang-format off
return make_transition_table(
* state<A> + event<ev_tick> / ActionDispatch{},
state<UnreachableDummy> + event<ev_success> = X
);
// clang-format on
}
};
struct HandlerSmlParent
{
struct ActionDoneWithSuccess
{
void operator()()
{
std::cout << "success (parent)" << std::endl;
}
};
auto operator()() const
{
using namespace boost::sml;
// clang-format off
return make_transition_table(
*state<HandlerSml> + event<HandlerSml::ev_success> / ActionDoneWithSuccess{}
);
// clang-format on
}
};
int main(int argc, char *argv[])
{
boost::sml::sm<HandlerSmlParent, boost::sml::defer_queue<std::deque>, boost::sml::process_queue<std::queue>> sm{};
sm.process_event(HandlerSml::ev_tick{});
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment