Skip to content

Commit 95ea64f

Browse files
committed
Merged PR 10: fixed plantuml generation
fixed plantuml generation
2 parents 470d034 + 1d8a5c5 commit 95ea64f

5 files changed

Lines changed: 29 additions & 15 deletions

File tree

src/sml/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
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)
22
TARGET_LINK_LIBRARIES(test_sml PRIVATE CONAN_PKG::sml CONAN_PKG::spdlog)

src/sml/actions.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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;

src/sml/main.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,23 @@
1010
#include "logger.h"
1111
#include "states.h"
1212
#include "events.h"
13+
#include "actions.h"
1314
#include "plantumlDump.h"
1415

1516
using namespace std::chrono_literals;
1617

1718
namespace ReallyCoolSM {
1819

19-
std::chrono::time_point<std::chrono::steady_clock> startTime;
2020

2121
struct 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>

src/sml/plantumlDump.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
#include <iostream>
32
#include <fstream>
43

54
namespace sml = boost::sml;

src/sml/states.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#pragma once
22

3+
struct TurnedOff
4+
{
5+
};
6+
37
struct Idle
48
{
59
};

0 commit comments

Comments
 (0)