Fork me on GitHub

Project Notes


Initial tests with [Boost].SML - a C++14 State Machine Library.


[Boost].SML is a C++14 State Machine Library delivered in a single header file with no dependencies.

It provides a pattern for defining events, guards and states. The transition table is described with an eUML style DSL.


It’s a single file:


Events Example

See events.cpp for a trivial example that experiments with the library. See the source for my annotations that clarify (read: helped me learn) how it fits together.

The output traces the state transitions (successful and failed):

$ make
c++ -std=c++17 -g -Wall -O3    events.cpp   -o events
$ ./events
// create state machine with logger
// e2: ignored: e2 can't transition from initial idle state
[N12_GLOBAL__N_16eventsE][process_event] N12_GLOBAL__N_12e2E
// e1: transitions to s1
[N12_GLOBAL__N_16eventsE][process_event] N12_GLOBAL__N_12e1E
[N12_GLOBAL__N_16eventsE][transition] idle -> s1
// e2{false}: fails s1 to s2 guard condition
[N12_GLOBAL__N_16eventsE][process_event] N12_GLOBAL__N_12e2E
[N12_GLOBAL__N_16eventsE][guard] ZNK12_GLOBAL__N_16eventsclEvEUlRKNS_2e2EE_ N12_GLOBAL__N_12e2E [Reject]
// e2{}: passes s1 to s2 guard condition
[N12_GLOBAL__N_16eventsE][process_event] N12_GLOBAL__N_12e2E
[N12_GLOBAL__N_16eventsE][guard] ZNK12_GLOBAL__N_16eventsclEvEUlRKNS_2e2EE_ N12_GLOBAL__N_12e2E [OK]
[N12_GLOBAL__N_16eventsE][transition] s1 -> s2
// e3: on-the-fly event transitions from s2 to s3
[N12_GLOBAL__N_16eventsE][process_event] N5boost3sml6v1_1_03aux6stringIcJLc101ELc51EEEE
[N12_GLOBAL__N_16eventsE][transition] s2 -> s3
// e4{33}: fails s3 exit guard
[N12_GLOBAL__N_16eventsE][process_event] N12_GLOBAL__N_12e4E
[N12_GLOBAL__N_16eventsE][guard] ZNK12_GLOBAL__N_16eventsclEvEUlRKNS_2e4EE_ N12_GLOBAL__N_12e4E [Reject]
// e4{42}: spasses s3 guard and transitions to terminate state X
[N12_GLOBAL__N_16eventsE][process_event] N12_GLOBAL__N_12e4E
[N12_GLOBAL__N_16eventsE][guard] ZNK12_GLOBAL__N_16eventsclEvEUlRKNS_2e4EE_ N12_GLOBAL__N_12e4E [OK]
[N12_GLOBAL__N_16eventsE][transition] s3 -> terminate
[N12_GLOBAL__N_16eventsE][action] ZNK12_GLOBAL__N_16eventsclEvEUlRKT_E_ N12_GLOBAL__N_12e4E
// ignored - state machine has terminated
[N12_GLOBAL__N_16eventsE][process_event] N12_GLOBAL__N_12e4E

Credits and References

About LCK#73 C++
Project Source on GitHub Return to the Project Catalog

This page is a web-friendly rendering of my project notes shared in the LittleCodingKata GitHub repository.

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.