File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- ADD_EXECUTABLE (test_sml main.cpp logger.h states.h events.h plantumlDump.h )
1+ ADD_EXECUTABLE (test_sml main.cpp logger.h states.h events.h plantumlDump.h actions.h )
22TARGET_LINK_LIBRARIES (test_sml PRIVATE CONAN_PKG::sml CONAN_PKG::spdlog )
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ std::chrono::time_point<std::chrono::steady_clock> startTime;
4+
5+ struct turnOffAction
6+ {
7+ void operator ()() { spdlog::info (" turned off" ); }
8+ } turnOffAction;
9+
10+ struct startAction
11+ {
12+ void operator ()() { startTime = std::chrono::steady_clock::now (); }
13+ } startAction;
14+
15+ struct stopAction
16+ {
17+ void operator ()()
18+ {
19+ const auto diff = std::chrono::steady_clock::now () - startTime;
20+ spdlog::info (" Elasped time: {}s" , std::chrono::duration_cast<std::chrono::seconds>(diff).count ());
21+ }
22+ } stopAction;
Original file line number Diff line number Diff line change 1010#include " logger.h"
1111#include " states.h"
1212#include " events.h"
13+ #include " actions.h"
1314#include " plantumlDump.h"
1415
1516using namespace std ::chrono_literals;
1617
1718namespace ReallyCoolSM {
1819
19- std::chrono::time_point<std::chrono::steady_clock> startTime;
2020
2121struct StopWatchStateMachine
2222{
2323 auto operator ()() const noexcept
2424 {
2525 using namespace boost ::sml;
2626
27- auto turnOffAction = [](auto ) { spdlog::info (" turned off" ); };
28- auto startAction = [&startTime = startTime]() {
29- startTime = std::chrono::steady_clock::now ();
30- };
31- auto stopAction = [&startTime = startTime]() {
32- const auto diff = std::chrono::steady_clock::now () - startTime;
33- spdlog::info (" Elasped time: {}s" , std::chrono::duration_cast<std::chrono::seconds>(diff).count ());
34- };
35-
36- const auto turnedOff = state<class turnedOff >;
37-
3827 return make_transition_table (
3928 // clang-format off
40- *turnedOff + event<turnOn> = state<Idle>
29+ *state<TurnedOff> + event<turnOn> = state<Idle>
4130 , state<Idle> + event<start> / startAction = state<Running>
4231 , state<Running> + event<stop> / stopAction = state<Stopped>
4332 , state<Running> + event<reset> = state<Idle>
Original file line number Diff line number Diff line change 11#pragma once
2- #include < iostream>
32#include < fstream>
43
54namespace sml = boost::sml;
Original file line number Diff line number Diff line change 11#pragma once
22
3+ struct TurnedOff
4+ {
5+ };
6+
37struct Idle
48{
59};
You can’t perform that action at this time.
0 commit comments