Closed kuuse closed 4 years ago
Not exactly an answer to my own question, but more an example how to use Guards to resolve the "mapping" problem between an integer an event. Note thay the example does not use Tag Dispatching (empty structs) as event type, though.
The attach source code validates a set of PIN code, using both Guards and Actions (both with and without the 'event' argument). I think only 'test_recursive.cpp' uses an Action with argument in a similar fashion. I found it by coincidence. Tip: Mention Argument(event) and Guards in the documentation.
There are better ways to validate a PIN code, but I think this may be a useful example for usage of 'fsmlite'.
Feel free to do as you please with the source code.
Thanks for your interest, but using distinct types as events is one of the basic concepts of this library. If you want to use enums without any extra data as input, there are probably other state machine implementations better suited to your needs.
Hi,
Is there a way to "map" an event defined as an empty struct to a simple type such as int? I cannot find any example or anything in the docs which describes what I want to achieve, so I explain with a couple of examples:
Using a switch works, but makes the code redundant, as any added event to the
player
class (declaration and transition_table antry) would also require an switch state:Instead of using a switch, I would like "map" an integer to en event, like this: (note this is pseudo-code, and I am not sure it is even possible to do it that way):
Or, if there is an undocumented way of doing this in another way, I would appreciate knowing about that.
BR, Johan