-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#define DSM_LOGGER Log::ConsoleLogger | ||
|
||
#include "dsm/dsm.hpp" | ||
|
||
using namespace dsm; | ||
|
||
struct e1 : Event<e1>{}; | ||
struct e2 : Event<e2>{}; | ||
struct e3 : Event<e3>{}; | ||
struct e4 : Event<e4>{}; | ||
|
||
struct sm : StateMachine<sm>{}; | ||
struct s0 : State<s0, sm>{}; | ||
struct s1 : State<s1, sm>{}; | ||
struct s2 : State<s2, sm>{}; | ||
struct s3 : State<s3, sm>{}; | ||
struct s4 : State<s4, sm>{}; | ||
|
||
int main() | ||
{ | ||
sm sm; | ||
|
||
sm.addState<s0, Entry>(); | ||
sm.addState<s0, s1, 0, Entry>(); | ||
sm.addState<s0, s2, 0>(); | ||
sm.addState<s0, s3, 1, Entry>(); | ||
sm.addState<s0, s4, 1>(); | ||
|
||
sm.addTransition<s1, e1, s2>(); | ||
sm.addTransition<s2, e2, s1>(); | ||
sm.addTransition<s3, e3, s4>(); | ||
sm.addTransition<s4, e4, s3>(); | ||
|
||
sm.start(); | ||
|
||
std::cout << sm << std::endl; | ||
|
||
sm.processEvent(e1{}); | ||
|
||
std::cout << sm << std::endl; | ||
|
||
sm.processEvent(e3{}); | ||
|
||
std::cout << sm << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@startuml | ||
hide empty description | ||
[*] -right-> s0 | ||
state s0 { | ||
[*] -right-> s1 | ||
s1 -right-> s2: e1 | ||
s2 -left-> s1: e2 | ||
-- | ||
[*] -right-> s3 | ||
s3 -right-> s4: e3 | ||
s4 -left-> s3: e4 | ||
} | ||
@enduml |