sml icon indicating copy to clipboard operation
sml copied to clipboard

[Question] Can you know upfront if an event can be processed?

Open diiigle opened this issue 1 year ago • 0 comments

The return value of process_event is already nice to determine if an event has been processed or silently dropped.

bool sm::process_event(event)

When working with user interfaces though, you would like to know upfront what events are currently possible (to grey impossible ones out).

Is there a way to iterate over currently possible events?

sm.visit_current_events([](auto& event){ })

or have a way to test specific events without calling the action?

bool sm::can_process_event(event)

The latter could be achieved with same shared context and guards that would block if you are currently in "query mode". I am just wondering if there could be a reusable way of implementing it, without overloading all guards.

Edit: I did some digging and found https://github.com/boost-ext/sml/blob/58536b9e8818e4fdb4a73c7e2218b6a3783cc9d9/include/boost/sml.hpp#L2558-L2564 So an implementation of can_process_event could call this function with another template parameter, that would prevent calling the action a (call<TEvent, args_t<A, TEvent>,), whereas a call through process_event would allow it.

diiigle avatar Aug 17 '23 13:08 diiigle