### Arduino Setup Function Source: https://github.com/boost-ext/sml/blob/master/doc/cppcon-2021/index.html This is the standard setup function for Arduino projects, executed once at the beginning. ```cpp void setup(){} // Arduino's setup ``` -------------------------------- ### Hello World Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md A basic 'Hello World' example to demonstrate the fundamental structure of an SML state machine. ```cpp #include #include namespace sml = boost::sml; struct Hello { // state struct Hello {}; // initial state struct Initial { auto operator()() const { return sml::initial_state(); } }; }; int main() { // create state machine sml::sm hello; // process event hello.process_event(sml::event{}); return 0; } ``` -------------------------------- ### Add Subdirectory for Examples Source: https://github.com/boost-ext/sml/blob/master/CMakeLists.txt Includes the 'example' subdirectory for building examples, conditional on the SML_BUILD_EXAMPLES variable. ```cmake if (SML_BUILD_EXAMPLES) add_subdirectory(example) endif() ``` -------------------------------- ### Install and Run Static File Server Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2016/README.md Install the node-static package and run it to serve the master presentation from your local machine. ```bash npm install node-static ``` ```bash static ``` -------------------------------- ### Add Hello World Example Source: https://github.com/boost-ext/sml/blob/master/example/CMakeLists.txt Adds the 'hello_world' example target, which is always compiled. ```cmake add_example(hello_world example_hello_world hello_world.cpp) ``` -------------------------------- ### Per State Machine Dependencies: Initialization Example Source: https://github.com/boost-ext/sml/blob/master/doc/embo-2018/index.html An example demonstrating the initialization of multiple 'Connection' state machines, each with its own specific address, and processing events on them. ```cpp int main() { Context ctx{...}; Sender sender{...}; std::array connections = { sml::sm{Connection{"127.0.0.1"}, ctx, sender}, sml::sm{Connection{"127.0.0.2"}, ctx, sender}, sml::sm{Connection{"127.0.0.3"}, ctx, sender}, sml::sm{Connection{"127.0.0.4"}, ctx, sender} }; connections[0].process_event(connect{}); connections[1].process_event(established{}); connections[2].process_event(ping{42}); connections[3].process_event(disconnect{}); } ``` -------------------------------- ### Manual Dependency Injection Setup Source: https://github.com/boost-ext/sml/blob/master/doc/embo-2018/index.html Illustrates the manual setup of dependencies for a state machine, showing the creation of 'Context' and 'Sender' objects before initializing the state machine. ```cpp // Manual Dependency Injection Context ctx{}; ``` -------------------------------- ### Install and Run Socket.io Server Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2016/README.md Install dependencies and run the socket.io server to broadcast slide changes between master and client presentations. ```bash npm install ``` ```bash node plugin/multiplex ``` -------------------------------- ### Arduino Setup Function Source: https://github.com/boost-ext/sml/blob/master/doc/meeting-embedded-2020/index.html Placeholder for the Arduino setup function. This function is called once when the Arduino board starts up. ```cpp void setup(){} ``` -------------------------------- ### Install Dependencies Source: https://github.com/boost-ext/sml/blob/master/doc/cppcon-2018/reveal.js/README.md Install all necessary project dependencies using npm. This command should be run after navigating into the reveal.js directory. ```sh npm install ``` -------------------------------- ### Arduino Integration Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Shows an example of integrating SML with Arduino environments. ```cpp #include #include namespace sml = boost::sml; struct ArduinoIntegration { struct S1 {}; struct S2 {}; struct Ev1 {}; auto operator()() const { using namespace sml; return "ArduinoIntegration"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" = "S2" ); } }; int main() { sml::sm sm; sm.process_event(ArduinoIntegration::Ev1{}); return 0; } ``` -------------------------------- ### Arduino Setup Function Source: https://github.com/boost-ext/sml/blob/master/doc/denver-cpp-2020/index.html A placeholder for the Arduino `setup()` function, typically used for initialization tasks. ```cpp void setup(){} // Arduino's setup ``` -------------------------------- ### Logging Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Demonstrates how to integrate logging into an SML state machine. ```cpp #include #include namespace sml = boost::sml; struct Logging { struct S1 {}; struct S2 {}; struct Ev1 {}; // logger void log(const auto& event, auto /*state*/, auto /*sm*/){ std::cout << "Logging event: " << typeid(event).name() << "\n"; } auto operator()() const { using namespace sml; return "Logging"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" = "S2" ) .on_log(&Logging::log); } }; int main() { sml::sm sm; sm.process_event(Logging::Ev1{}); return 0; } ``` -------------------------------- ### Install Dependencies Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2016/README.md Install all project dependencies using npm. ```sh $ npm install ``` -------------------------------- ### Dependencies Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Shows how to manage dependencies within an SML state machine. ```cpp #include #include namespace sml = boost::sml; struct Dependencies { struct S1 {}; struct S2 {}; struct Ev1 {}; auto operator()() const { using namespace sml; return "Dependencies"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" = "S2" ); } }; int main() { sml::sm sm; sm.process_event(Dependencies::Ev1{}); return 0; } ``` -------------------------------- ### SDL2 Integration Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Demonstrates integrating SML with the SDL2 library. ```cpp #include #include namespace sml = boost::sml; struct SDL2Integration { struct S1 {}; struct S2 {}; struct Ev1 {}; auto operator()() const { using namespace sml; return "SDL2Integration"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" = "S2" ); } }; int main() { sml::sm sm; sm.process_event(SDL2Integration::Ev1{}); return 0; } ``` -------------------------------- ### Actions and Guards Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Shows how to implement actions and guards for transitions in SML. ```cpp #include #include namespace sml = boost::sml; struct ActionsGuards { // events struct Ev1 {}; struct Ev2 {}; // states struct S1 {}; struct S2 {}; struct S3 {}; // actions void action1() { std::cout << "Action 1 executed\n"; } void action2() { std::cout << "Action 2 executed\n"; } // guards bool guard1() const { return true; } bool guard2() const { return false; } auto operator()() const { using namespace sml; return "ActionsGuards"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" [ guard1 ] / action1 = "S2", "S2"_sml / "Ev2" [ guard2 ] / action2 = "S3", "S2"_sml / "Ev1" / action2 = "S3" ); } }; int main() { ActionsGuards ag; sml::sm sm; sm.process_event(Events::Ev1{}); sm.process_event(Events::Ev1{}); return 0; } ``` -------------------------------- ### Setup Speaker View Layout Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2019/reveal.js/plugin/notes/notes.html Calls the initial setup function for the speaker view layout. ```javascript setupLayout(); ``` -------------------------------- ### State Machine Transition Table Example Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2016/index.html An example of creating a state machine transition table using the make_transition_table utility with guards and actions. ```cpp auto play_song = [] { ... }; auto is_playing = [] { return true; } make_transition_table( state + play [is_playing] = state, state + play [!is_playing] / play_song = state, state + stop / (stop_song, reset_song) = state ); ``` -------------------------------- ### eUML Emulation Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Demonstrates how to emulate eUML behavior using SML. ```cpp #include #include namespace sml = boost::sml; struct EUML { struct S1 {}; struct S2 {}; struct Ev1 {}; auto operator()() const { using namespace sml; return "EUML"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" = "S2" ); } }; int main() { sml::sm sm; sm.process_event(EUML::Ev1{}); return 0; } ``` -------------------------------- ### Defer and Process Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Illustrates using defer and process event mechanisms in SML. ```cpp #include #include namespace sml = boost::sml; struct DeferProcess { struct S1 {}; struct S2 {}; struct Ev1 {}; struct Ev2 {}; auto operator()() const { using namespace sml; return "DeferProcess"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" = "S2", "S2"_sml / "Ev2" = "S1" ) .defer(); } }; int main() { sml::sm sm; sm.process_event(DeferProcess::Ev1{}); sm.process_event(DeferProcess::Ev2{}); return 0; } ``` -------------------------------- ### Dependency Injection Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Illustrates dependency injection patterns within SML state machines. ```cpp #include #include namespace sml = boost::sml; struct DependencyInjection { struct S1 {}; struct S2 {}; struct Ev1 {}; auto operator()() const { using namespace sml; return "DependencyInjection"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" = "S2" ); } }; int main() { sml::sm sm; sm.process_event(DependencyInjection::Ev1{}); return 0; } ``` -------------------------------- ### Transition Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Demonstrates defining transitions between states in an SML state machine. ```cpp #include #include namespace sml = boost::sml; struct Transitions { struct S1 {}; struct S2 {}; struct Ev1 {}; auto operator()() const { using namespace sml; return "Transitions"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" = "S2" ); } }; int main() { sml::sm sm; sm.process_event(Transitions::Ev1{}); return 0; } ``` -------------------------------- ### Connection State Machine Example Source: https://github.com/boost-ext/sml/blob/master/doc/embo-2017/index.html A realistic example demonstrating a 'Connection' state machine. It uses the transition table DSL to define states like 'Disconnected', 'Connecting', and 'Connected', along with transitions triggered by events like 'connect', 'established', and 'disconnect'. ```cpp struct Connection { auto operator()() const { return transition_table{ "Disconnected"_s(H) + connect / []{establish();} = "Connecting"_s, "Connecting"_s + established = "Connected"_s, "Connected"_s + ping [ is_valid ] / []{resetTimeout();} "Connected"_s + timeout / []{establish();} = "Connecting"_s, "Connected"_s + disconnect / []{close();} = "Disconnected"_s }; } }; ``` -------------------------------- ### PlantUML Integration Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Shows how to integrate SML with PlantUML for state machine visualization. ```cpp #include #include namespace sml = boost::sml; struct PlantUMLIntegration { struct S1 {}; struct S2 {}; struct Ev1 {}; auto operator()() const { using namespace sml; return "PlantUMLIntegration"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" = "S2" ); } }; int main() { sml::sm sm; sm.process_event(PlantUMLIntegration::Ev1{}); return 0; } ``` -------------------------------- ### Runtime Dispatcher Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Demonstrates the use of a runtime dispatcher for state transitions in SML. ```cpp #include #include namespace sml = boost::sml; struct RuntimeDispatcher { struct S1 {}; struct S2 {}; struct Ev1 {}; auto operator()() const { using namespace sml; return "RuntimeDispatcher"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" = "S2" ); } }; int main() { sml::sm sm; sm.process_event(RuntimeDispatcher::Ev1{}); return 0; } ``` -------------------------------- ### System State Machine Example Source: https://github.com/boost-ext/sml/blob/master/doc/embo-2017/index.html An example of a 'System' state machine that incorporates the 'Connection' state machine as a sub-state. It demonstrates transitions for power-up, suspend, and resume, and includes a 'Watchdog' sub-state. ```cpp struct System { auto operator()() const { return transition_table{ * "Idle"_s + power_up [ has_battery and is_healthy] / connect = state, state + suspend = "Suspended"_s, "Suspended"_s + resume = state, // ------------------------------------------------------------------------------------ * "Watchdog"_s + tick / resetTimeout "Watchdog"_s + timeout = X }; } }; ``` -------------------------------- ### Visitor Pattern Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Demonstrates using the visitor pattern with SML state machines. ```cpp #include #include namespace sml = boost::sml; struct Visitor { struct S1 {}; struct S2 {}; struct Ev1 {}; auto operator()() const { using namespace sml; return "Visitor"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" = "S2" ); } }; int main() { sml::sm sm; sm.process_event(Visitor::Ev1{}); return 0; } ``` -------------------------------- ### Guard Examples Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2016/index.html Demonstrates the creation and usage of boolean guards for state transitions. ```cpp auto true_ = [] { return true; }; auto false_ = [] { return false_; }; auto guards = (!true_ || (true_ && false_ || ![]{ return false; })); ``` -------------------------------- ### In-Place State Machine Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Demonstrates defining and using an SML state machine in-place. ```cpp #include #include namespace sml = boost::sml; struct InPlace { struct S1 {}; struct S2 {}; struct Ev1 {}; auto operator()() const { using namespace sml; return "InPlace"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" = "S2" ); } }; int main() { sml::sm sm; sm.process_event(InPlace::Ev1{}); return 0; } ``` -------------------------------- ### Main Function Start Source: https://github.com/boost-ext/sml/blob/master/doc/meeting-embedded-2020/index.html Marks the beginning of the main function for the implementation testing section. ```cpp int main() { ``` -------------------------------- ### Serve Presentation on Custom Port Source: https://github.com/boost-ext/sml/blob/master/doc/cppcon-2018/reveal.js/README.md Starts the reveal.js development server on a custom port, for example, 8001. This is an alternative to the default port. ```sh npm start -- --port=8001 ``` -------------------------------- ### Setup and Update Timer Source: https://github.com/boost-ext/sml/blob/master/doc/cppcon-2021/reveal.js/plugin/notes-server/notes.html Initializes and updates a timer displaying the elapsed time since presentation start, along with the current time. The timer resets on click. ```javascript /* * Create the timer and clock and start updating them * at an interval. */ function setupTimer() { var start = new Date(), timeEl = document.querySelector( '.speaker-controls-time' ), clockEl = timeEl.querySelector( '.clock-value' ), hoursEl = timeEl.querySelector( '.hours-value' ), minutesEl = timeEl.querySelector( '.minutes-value' ), secondsEl = timeEl.querySelector( '.seconds-value' ); function _updateTimer() { var diff, hours, minutes, seconds, now = new Date(); diff = now.getTime() - start.getTime(); hours = Math.floor( diff / ( 1000 * 60 * 60 ) ); minutes = Math.floor( ( diff / ( 1000 * 60 ) ) % 60 ); seconds = Math.floor( ( diff / 1000 ) % 60 ); clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } ); hoursEl.innerHTML = zeroPadInteger( hours ); hoursEl.className = hours > 0 ? '' : 'mute'; minutesEl.innerHTML = ':' + zeroPadInteger( minutes ); minutesEl.className = minutes > 0 ? '' : 'mute'; secondsEl.innerHTML = ':' + zeroPadInteger( seconds ); } // Update once directly _updateTimer(); // Then update every second setInterval( _updateTimer, 1000 ); timeEl.addEventListener( 'click', function() { start = new Date(); _updateTimer(); return false; } ); } ``` -------------------------------- ### Setup Timer and Clock Source: https://github.com/boost-ext/sml/blob/master/doc/embo-2017/plugin/notes/notes.html Initializes and updates a timer and clock display every second. It calculates the elapsed time since the presentation started and formats the current time. ```javascript /** * Create the timer and clock and start updating them * at an interval. */ function setupTimer() { var start = new Date(), timeEl = document.querySelector( '.speaker-controls-time' ), clockEl = timeEl.querySelector( '.clock-value' ), hoursEl = timeEl.querySelector( '.hours-value' ), minutesEl = timeEl.querySelector( '.minutes-value' ), secondsEl = timeEl.querySelector( '.seconds-value' ); function _updateTimer() { var diff, hours, minutes, seconds, now = new Date(); diff = now.getTime() - start.getTime(); hours = Math.floor( diff / ( 1000 * 60 * 60 ) ); minutes = Math.floor( ( diff / ( 1000 * 60 ) ) % 60 ); seconds = Math.floor( ( diff / 1000 ) % 60 ); clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } ); hoursEl.innerHTML = zeroPadInteger( hours ); hoursEl.className = hours > 0 ? '' : 'mute'; minutesEl.innerHTML = ':' + zeroPadInteger( minutes ); minutesEl.className = minutes > 0 ? '' : 'mute'; secondsEl.innerHTML = ':' + zeroPadInteger( seconds ); } // Update once directly _updateTimer(); // Then update every second setInterval( _updateTimer, 1000 ); timeEl.addEventListener( 'click', function() { start = new Date(); } ); } ``` -------------------------------- ### Setup Speaker Timer and Clock Source: https://github.com/boost-ext/sml/blob/master/doc/embo-2018/plugin/notes/notes.html Initializes the timer and clock, starting updates at an interval. It calculates and displays elapsed time and pacing information based on slide timings. ```javascript function setupTimer() { var start = new Date(), timeEl = document.querySelector( '.speaker-controls-time' ), clockEl = timeEl.querySelector( '.clock-value' ), hoursEl = timeEl.querySelector( '.hours-value' ), minutesEl = timeEl.querySelector( '.minutes-value' ), secondsEl = timeEl.querySelector( '.seconds-value' ), pacingTitleEl = timeEl.querySelector( '.pacing-title' ), pacingEl = timeEl.querySelector( '.pacing' ), pacingHoursEl = pacingEl.querySelector( '.hours-value' ), pacingMinutesEl = pacingEl.querySelector( '.minutes-value' ), pacingSecondsEl = pacingEl.querySelector( '.seconds-value' ); var timings = getTimings(); if (timings !== null) { pacingTitleEl.style.removeProperty('display'); pacingEl.style.removeProperty('display'); } function _displayTime( hrEl, minEl, secEl, time) { var sign = Math.sign(time) == -1 ? "-" : ""; time = Math.abs(Math.round(time / 1000)); var seconds = time % 60; var minutes = Math.floor( time / 60 ) % 60 ; var hours = Math.floor( time / ( 60 * 60 )) ; hrEl.innerHTML = sign + zeroPadInteger( hours ); if (hours == 0) { hrEl.classList.add( 'mute' ); } else { hrEl.classList.remove( 'mute' ); } minEl.innerHTML = ':' + zeroPadInteger( minutes ); if (hours == 0 && minutes == 0) { minEl.classList.add( 'mute' ); } else { minEl.classList.remove( 'mute' ); } secEl.innerHTML = ':' + zeroPadInteger( seconds ); } function _updateTimer() { var diff, hours, minutes, seconds, now = new Date(); diff = now.getTime() - start.getTime(); clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } ); _displayTime( hoursEl, minutesEl, secondsEl, diff ); if (timings !== null) { _updatePacing(diff); } } function _updatePacing(diff) { var slideEndTiming = getTimeAllocated(timings) * 1000; var currentSlide = Reveal.getSlidePastCount(); var currentSlideTiming = timings[currentSlide] * 1000; var timeLeftCurrentSlide = slideEndTiming - diff; if (timeLeftCurrentSlide < 0) { pacingEl.className = 'pacing behind'; } else if (timeLeftCurrentSlide < currentSlideTiming) { pacingEl.className = 'pacing on-track'; } else { pacingEl.className = 'pacing ahead'; } _displayTime( pacingHoursEl, pacingMinutesEl, pacingSecondsEl, timeLeftCurrentSlide ); } // Update once directly _updateTimer(); // Then update every second setInterval( _updateTimer, 1000 ); function _resetTimer() { if (timings == null) { start = new Date(); } else { // Reset timer to beginning of current slide var slideEndTiming = getTimeAllocated(timings) * 1000; var currentSlide = Reveal.getSlidePastCount(); var currentSlideTiming = timings[currentSlide] * 1000; var previousSlidesTiming = slideEndTiming - currentSlideTiming; var now = new Date(); start = new Date(now.getTime() - previousSlidesTiming); } _updateTimer(); } timeEl.addEventListener( 'click', function() { _resetTimer(); return false; } ); } ``` -------------------------------- ### State Machine Testing Setup Source: https://github.com/boost-ext/sml/blob/master/doc/cppsummit-2022/index.html Sets up a state machine for testing purposes using fake button and LED components. Asserts initial state and transition behavior. ```cpp "switcher"_test = [] { using button_t = button<0>; // fake button using led_t = led<1>; // fake led sm> sm{}; should("start in off state") = [sm] { expect(sm.is("off"_s)); }; should("turn on/off the led when button is switched") = [sm] { mut(sm).process_event(button_t::pressed); expect(sm.is("on"_s)); mut(sm).process_event(button_t::pressed); expect(sm.is("off"_s)); }; }; ``` -------------------------------- ### Setup and Update Timer/Clock Source: https://github.com/boost-ext/sml/blob/master/doc/embo-2018/plugin/notes-server/notes.html Initializes and updates a timer and clock display. The clock shows the current time, and the timer shows the elapsed time since the start. The timer can be reset by clicking on the time element. ```javascript /** * Create the timer and clock and start updating them * at an interval. */ function setupTimer() { var start = new Date(), timeEl = document.querySelector( '.speaker-controls-time' ), clockEl = timeEl.querySelector( '.clock-value' ), hoursEl = timeEl.querySelector( '.hours-value' ), minutesEl = timeEl.querySelector( '.minutes-value' ), secondsEl = timeEl.querySelector( '.seconds-value' ); function _updateTimer() { var diff, hours, minutes, seconds, now = new Date(); diff = now.getTime() - start.getTime(); hours = Math.floor( diff / ( 1000 * 60 * 60 ) ); minutes = Math.floor( ( diff / ( 1000 * 60 ) ) % 60 ); seconds = Math.floor( ( diff / 1000 ) % 60 ); clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } ); hoursEl.innerHTML = zeroPadInteger( hours ); hoursEl.className = hours > 0 ? '' : 'mute'; minutesEl.innerHTML = ':' + zeroPadInteger( minutes ); minutesEl.className = minutes > 0 ? '' : 'mute'; secondsEl.innerHTML = ':' + zeroPadInteger( seconds ); } // Update once directly _updateTimer(); // Then update every second setInterval( _updateTimer, 1000 ); timeEl.addEventListener( 'click', function() { start = new Date(); _updateTimer(); return false; } ); } ``` -------------------------------- ### Setup and Update Speaker Timer Source: https://github.com/boost-ext/sml/blob/master/doc/meeting-embedded-2020/reveal.js/plugin/notes-server/notes.html Initializes and updates a timer displaying the elapsed time since the presentation started, along with the current time. The timer updates every second and can be reset by clicking on the time element. ```javascript /** * Create the timer and clock and start updating them * at an interval. */ function setupTimer() { var start = new Date(), timeEl = document.querySelector( '.speaker-controls-time' ), clockEl = timeEl.querySelector( '.clock-value' ), hoursEl = timeEl.querySelector( '.hours-value' ), minutesEl = timeEl.querySelector( '.minutes-value' ), secondsEl = timeEl.querySelector( '.seconds-value' ); function _updateTimer() { var diff, hours, minutes, seconds, now = new Date(); diff = now.getTime() - start.getTime(); hours = Math.floor( diff / ( 1000 * 60 * 60 ) ); minutes = Math.floor( ( diff / ( 1000 * 60 ) ) % 60 ); seconds = Math.floor( ( diff / 1000 ) % 60 ); clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } ); hoursEl.innerHTML = zeroPadInteger( hours ); hoursEl.className = hours > 0 ? '' : 'mute'; minutesEl.innerHTML = ':' + zeroPadInteger( minutes ); minutesEl.className = minutes > 0 ? '' : 'mute'; secondsEl.innerHTML = ':' + zeroPadInteger( seconds ); } // Update once directly _updateTimer(); // Then update every second setInterval( _updateTimer, 1000 ); timeEl.addEventListener( 'click', function() { start = new Date(); _updateTimer(); return false; } ); } ``` -------------------------------- ### Reveal.js Event Listener Setup Source: https://github.com/boost-ext/sml/blob/master/doc/cppsummit-2022/reveal.js/test/test-iframe-backgrounds.html Sets up an event listener for the 'ready' event to ensure Reveal.js is initialized before running tests. It also defines a helper function to get iframe elements within slide backgrounds. ```javascript Reveal.addEventListener( 'ready', function() { function getIframe( index ) { return document.querySelectorAll( '.slide-background' ) [index].querySelector( 'iframe' ); } QUnit.module( 'Iframe' ); QUnit.test( 'Using default settings', function( assert ) { Reveal.slide(0); assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'not preloaded when within viewDistance' ); Reveal.slide(1); assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); Reveal.slide(0); assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'unloaded when slide becomes invisible' ); }); QUnit.test( 'Using data-preload', function( assert ) { Reveal.slide(1); assert.strictEqual( getIframe(2).hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); Reveal.slide(0); assert.strictEqual( getIframe(3).hasAttribute( 'src' ), false, 'unloads outside of viewDistance' ); }); QUnit.test( 'Using preloadIframes: true', function( assert ) { Reveal.configure({ preloadIframes: true }); Reveal.slide(1); assert.strictEqual( getIframe(0).hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); assert.strictEqual( getIframe(2).hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); }); QUnit.test( 'Using preloadIframes: false', function( assert ) { Reveal.configure({ preloadIframes: false }); Reveal.slide(0); assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'not preloaded within viewDistance' ); assert.strictEqual( getIframe(2).hasAttribute( 'src' ), false, 'not preloaded within viewDistance' ); Reveal.slide(1); assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); }); } ); ``` -------------------------------- ### Serve Presentation and Monitor Changes Source: https://github.com/boost-ext/sml/blob/master/doc/embo-2017/README.md Start a local web server to view the presentation and automatically reload on source file changes. ```sh grunt serve ``` -------------------------------- ### Serve Presentation and Monitor Changes Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2016/README.md Start a local web server to serve the reveal.js presentation and watch for file changes. ```sh $ grunt serve ``` -------------------------------- ### Add Example with SML (Conditional) Source: https://github.com/boost-ext/sml/blob/master/benchmark/simple/CMakeLists.txt Defines a benchmark example using the SML state machine implementation. This example is only added if the compiler is not MSVC 2015. ```cmake if (NOT IS_MSVC_2015) add_example(simple_sml benchmark_simple_sml sml.cpp) endif() ``` -------------------------------- ### Initialize Reveal.js with Configuration Source: https://github.com/boost-ext/sml/blob/master/doc/denver-cpp-2020/reveal.js/demo.html Configure Reveal.js with options for controls, progress, centering, hash navigation, transitions, and load necessary plugins. ```javascript // More info https://github.com/hakimel/reveal.js#configuration Reveal.initialize({ controls: true, progress: true, center: true, hash: true, transition: 'slide', // none/fade/slide/convex/concave/zoom // More info https://github.com/hakimel/reveal.js#dependencies dependencies: [ { src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: 'plugin/highlight/highlight.js' }, { src: 'plugin/search/search.js', async: true }, { src: 'plugin/zoom-js/zoom.js', async: true }, { src: 'plugin/notes/notes.js', async: true } ] }); ``` -------------------------------- ### Add Example with EUML Source: https://github.com/boost-ext/sml/blob/master/benchmark/simple/CMakeLists.txt Defines a benchmark example using the EUML state machine implementation. It temporarily sets the C++ standard to 11 for this example. ```cmake set(CURRENT_CXX_STANDARD ${CMAKE_CXX_STANDARD}) set(CMAKE_CXX_STANDARD 11) add_example(simple_euml benchmark_simple_euml euml.cpp) set(CMAKE_CXX_STANDARD ${CURRENT_CXX_STANDARD}) ``` -------------------------------- ### Create SM using DI framework Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2016/index.html Demonstrates how to create a state machine using the experimental Boost.DI framework. Ensure Boost.DI is set up correctly. ```cpp auto injector = di::make_injector(); ``` -------------------------------- ### Add Example Target Source: https://github.com/boost-ext/sml/blob/master/example/CMakeLists.txt Defines a CMake function to add a new example target. This function takes the example name, target name, and source file as arguments. ```cmake macro(add_example name target source) add_executable(${target} ${source}) target_link_libraries(${target} PRIVATE sml) endmacro() ``` -------------------------------- ### Testing Example Source: https://github.com/boost-ext/sml/blob/master/doc/examples.md Provides an example of how to test SML state machines. ```cpp #include #include namespace sml = boost::sml; struct Testing { struct S1 {}; struct S2 {}; struct Ev1 {}; auto operator()() const { using namespace sml; return "Testing"_sml .initial() .state() .transition_table( "S1"_sml / "Ev1" = "S2" ); } }; int main() { sml::sm sm; sm.process_event(Testing::Ev1{}); return 0; } ``` -------------------------------- ### Set C++ Standard for Example Source: https://github.com/boost-ext/sml/blob/master/benchmark/composite/CMakeLists.txt Temporarily sets the C++ standard to 11 for building a specific example, then restores the original standard. This ensures compatibility for examples requiring C++11 features. ```cmake set(CURRENT_CXX_STANDARD ${CMAKE_CXX_STANDARD}) set(CMAKE_CXX_STANDARD 11) ... set(CMAKE_CXX_STANDARD ${CURRENT_CXX_STANDARD}) ``` -------------------------------- ### Initialize Reveal.js with Configuration Source: https://github.com/boost-ext/sml/blob/master/doc/cppcon-2018/reveal.js/test/examples/slide-backgrounds.html Configure Reveal.js options during initialization. This example sets centering, transition, and background transition. ```javascript Reveal.initialize({ center: true, // rtl: true, transition: 'linear', // transitionSpeed: 'slow', // backgroundTransition: 'slide' }); ``` -------------------------------- ### Reveal.js Initialization with Options Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2017/test/examples/slide-backgrounds.html Initialize Reveal.js with various configuration options. This example shows settings for centering content, transition effects, and background transitions. ```javascript // Full list of configuration options available here: // https://github.com/hakimel/reveal.js#configuration Reveal.initialize({ center: true, // rtl: true, transition: 'linear', // transitionSpeed: 'slow', // backgroundTransition: 'slide' }); ``` -------------------------------- ### Transitions DSL: Connection Example Source: https://github.com/boost-ext/sml/blob/master/doc/embo-2018/index.html An example of a transition in the context of a connection, involving an event, a guard, and an action. ```cpp "Connected"_s + event [ is_valid ] / resetTimeout ``` -------------------------------- ### Serve Reveal.js Presentation Source: https://github.com/boost-ext/sml/blob/master/doc/embo-2018/README.md Use this npm command to start a local web server for your reveal.js presentation. It also monitors source files for changes. You can specify a different port using `-- --port=`. ```sh $ npm start ``` -------------------------------- ### Add Benchmark Example Target Source: https://github.com/boost-ext/sml/blob/master/benchmark/complex/CMakeLists.txt Adds a benchmark example target named 'complex_sc' built from 'sc.cpp'. ```cmake add_example(complex_sc benchmark_complex_sc sc.cpp) ``` -------------------------------- ### Boost.SML Basic Setup Source: https://github.com/boost-ext/sml/blob/master/doc/embo-2018/index.html Includes the necessary header for Boost.SML and defines a convenient alias for the namespace. No STL or Boost headers are required. ```cpp // one header; neither STL nor Boost required #include // convenient alias namespace sml = boost::sml; ``` -------------------------------- ### Add SML Benchmark Example Target Source: https://github.com/boost-ext/sml/blob/master/benchmark/complex/CMakeLists.txt Adds a benchmark example target for SML, conditionally compiled for non-MSVC 2015 compilers. ```cmake if (NOT IS_MSVC_2015) add_example(complex_sml benchmark_complex_sml sml.cpp) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") target_compile_options(complex_sml PRIVATE "-Wno-subobject-linkage" "-Wno-fatal-errors") endif() endif() ``` -------------------------------- ### Register and Initialize Plugins in reveal.js Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2019/reveal.js/test/test-plugins.html Demonstrates how to register plugins with reveal.js and initialize the presentation. Includes examples of plugins with and without an init method, and asynchronous initialization. ```javascript var initCounter = { PluginB: 0, PluginC: 0, PluginD: 0 }; // Plugin with no init method var PluginA = {}; // Plugin with init method var PluginB = { init: function() { initCounter['PluginB'] += 1; } }; // Async plugin with init method var PluginC = { init: function() { return new Promise(function( resolve ) { setTimeout( () => { initCounter['PluginC'] += 1; resolve(); }, 1000 ); }); } }; // Plugin initialized after reveal.js is ready var PluginD = { init: function() { initCounter['PluginD'] += 1; } }; var PluginE = {}; Reveal.registerPlugin( 'PluginA', PluginA ); Reveal.registerPlugin( 'PluginB', PluginB ); Reveal.registerPlugin( 'PluginC', PluginC ); Reveal.initialize(); ``` -------------------------------- ### Define Example Executable and Test Source: https://github.com/boost-ext/sml/blob/master/CMakeLists.txt A CMake function to simplify the creation of an executable for an example and link it against the SML library, also registering it as a test. ```cmake function(add_example exe_name bm_name src_name) add_executable(${exe_name} ${src_name}) target_link_libraries(${exe_name} PUBLIC sml) add_test(${bm_name} ${exe_name}) endfunction() ``` -------------------------------- ### Start Development Server Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2019/reveal.js/README.md Serve the presentation locally and watch for file changes. The default port is 8000. You can specify a different port using '-- --port='. ```sh npm start ``` ```sh npm start -- --port=8001 ``` -------------------------------- ### PlantUML Output Example Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2016/index.html Example PlantUML output generated from a state machine definition, visualizing states, transitions, events, guards, and actions. ```cpp @startuml [*] -> idle idle -> s1 : e1 s1 -> s2 : e2 [guard] / action s2 -> s1 : e3 [guard] s2 -> terminate : e4 / action @enduml ``` -------------------------------- ### Initialize Reveal.js with Configuration Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2019/reveal.js/demo.html Configure Reveal.js with options for controls, progress bars, centering, hash navigation, and transitions. Includes dependencies for plugins like Markdown, highlight, search, zoom, and notes. ```javascript // More info https://github.com/hakimel/reveal.js#configuration Reveal.initialize({ controls: true, progress: true, center: true, hash: true, transition: 'slide', // none/fade/slide/convex/concave/zoom // More info https://github.com/hakimel/reveal.js#dependencies dependencies: [ { src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: 'plugin/highlight/highlight.js', async: true }, { src: 'plugin/search/search.js', async: true }, { src: 'plugin/zoom-js/zoom.js', async: true }, { src: 'plugin/notes/notes.js', async: true } ] }); ``` -------------------------------- ### IIFE Usage Example Source: https://github.com/boost-ext/sml/blob/master/doc/cppsummit-2022/index.html Demonstrates calling the unroll IIFE to execute a lambda expression multiple times at compile time. This example prints a string. ```cpp int main() { unroll<2>([]{ std::puts("CppSummit 2022!"); }); } ``` -------------------------------- ### React Code Example Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2019/reveal.js/demo.html A simple React component demonstrating state management with the `useState` hook. This example shows a counter that increments when a button is clicked. ```javascript import React, { useState } from 'react'; function Example() { const [count, setCount] = useState(0); return (

You clicked {count} times

); } ``` -------------------------------- ### Instantiate and Use TCP Release State Machine Source: https://github.com/boost-ext/sml/blob/master/README.md Demonstrates how to instantiate the 'tcp_release' state machine, pass dependencies, process events, and assert the current state. This example shows the typical usage pattern. ```cpp int main() { using namespace sml; sender s{}; sm sm{s}; // pass dependencies via ctor assert(sm.is("established"_s)); sm.process_event(release{}); // complexity O(1) assert(sm.is("fin wait 1"_s)); sm.process_event(ack{true}); // prints 'send: 0' assert(sm.is("fin wait 2"_s)); sm.process_event(fin{42, true}); // prints 'send: 42' assert(sm.is("timed wait"_s)); sm.process_event(timeout{}); assert(sm.is(X)); // terminated } ``` -------------------------------- ### Add Example with SC Source: https://github.com/boost-ext/sml/blob/master/benchmark/simple/CMakeLists.txt Defines a benchmark example using the SC state machine implementation. This is a straightforward addition without C++ standard modifications. ```cmake add_example(simple_sc benchmark_simple_sc sc.cpp) ``` -------------------------------- ### Benchmark Setup: Main Function Source: https://github.com/boost-ext/sml/blob/master/doc/cppnow-2019/index.html The main function for running performance benchmarks. It generates random events and processes them through a 'Connection' state machine instance. ```cpp int main() { constexpr auto size = 1'000'000; std::array events = rand_events(); Connection connection{}; for (auto i = 0; i < size; ++i) { process_event(events[i]); } } ``` -------------------------------- ### Add Composite Example Source: https://github.com/boost-ext/sml/blob/master/benchmark/composite/CMakeLists.txt Adds a new example target for a composite benchmark. This function likely handles compilation and linking of the specified source file. ```cmake add_example(composite_euml benchmark_composite_euml euml.cpp) ``` ```cmake add_example(composite_sc benchmark_composite_sc sc.cpp) ``` ```cmake add_example(composite_sml benchmark_composite_sml sml.cpp) ```