Skip to content

Commit

Permalink
doc: added more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jfayot committed Aug 27, 2024
1 parent eb9097c commit 300b789
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,5 @@ int main()
| self transition | ![self_transition](http://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/jfayot/dynamic-state-machine/master/resources/self_transition.puml) | [self_transition.cpp](./examples/self_transition.cpp) |
| composite state | ![composite_state](http://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/jfayot/dynamic-state-machine/master/resources/composite_state.puml) | [composite_state.cpp](./examples/composite_state.cpp) |
| shallow history | ![shallow_history](http://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/jfayot/dynamic-state-machine/master/resources/shallow_history.puml) | [shallow_history.cpp](./examples/shallow_history.cpp) |
| deep history | ![deep_history](http://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/jfayot/dynamic-state-machine/master/resources/deep_history.puml) | [deep_history.cpp](./examples/deep_history.cpp) |
| deep history | ![deep_history](http://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/jfayot/dynamic-state-machine/master/resources/deep_history.puml) | [deep_history.cpp](./examples/deep_history.cpp) |
| orthogonal regions | ![orthogonal_regions](http://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/jfayot/dynamic-state-machine/master/resources/orthogonal_regions.puml) | [orthogonal_regions.cpp](./examples/orthogonal_regions.cpp) |
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_executable(self_transition self_transition.cpp)
add_executable(composite_state composite_state.cpp)
add_executable(shallow_history shallow_history.cpp)
add_executable(deep_history deep_history.cpp)
add_executable(orthogonal_regions orthogonal_regions.cpp)

target_link_libraries(minimal_flat PRIVATE dsm::dsm)
target_link_libraries(minimal_enclosed PRIVATE dsm::dsm)
Expand All @@ -19,6 +20,7 @@ target_link_libraries(self_transition PRIVATE dsm::dsm)
target_link_libraries(composite_state PRIVATE dsm::dsm)
target_link_libraries(shallow_history PRIVATE dsm::dsm)
target_link_libraries(deep_history PRIVATE dsm::dsm)
target_link_libraries(orthogonal_regions PRIVATE dsm::dsm)

set_target_properties(minimal_flat PROPERTIES FOLDER examples)
set_target_properties(minimal_enclosed PROPERTIES FOLDER examples)
Expand All @@ -29,3 +31,4 @@ set_target_properties(self_transition PROPERTIES FOLDER examples)
set_target_properties(composite_state PROPERTIES FOLDER examples)
set_target_properties(shallow_history PROPERTIES FOLDER examples)
set_target_properties(deep_history PROPERTIES FOLDER examples)
set_target_properties(orthogonal_regions PROPERTIES FOLDER examples)
47 changes: 47 additions & 0 deletions examples/orthogonal_regions.cpp
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;
}
13 changes: 13 additions & 0 deletions resources/orthogonal_regions.puml
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

0 comments on commit 300b789

Please sign in to comment.