-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexport_dot_nested.cpp
More file actions
44 lines (36 loc) · 2.19 KB
/
Copy pathexport_dot_nested.cpp
File metadata and controls
44 lines (36 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "CXXStateTree/StateTree.h"
#include <iostream>
#include <fstream>
using namespace CXXStateTree;
int main()
{
auto tree = StateTree::Builder()
.initial("Main")
.state("Main", [](State &s)
{ s.initial_substate("Idle")
.substate("Idle", [](State &s)
{ s.on("Start", "Running", nullptr, [](const std::any &)
{ std::cout << "Transition: Idle -> Running" << std::endl; }); })
.substate("Running", [](State &s)
{ s.on("Stop", "Idle", nullptr, [](const std::any &)
{ std::cout << "Transition: Running -> idle" << std::endl; }); })
.on("Switch", "Alternate", nullptr, [](const std::any &)
{ std::cout << "Transition: Main -> Alternate" << std::endl; }); })
.state("Alternate", [](State &s)
{ s.initial_substate("Idle")
.substate("Idle", [](State &s)
{ s.on("Start", "Running", nullptr, [](const std::any &)
{ std::cout << "Transition: Idle -> Running" << std::endl; }); })
.substate("Running", [](State &s)
{ s.on("Stop", "Idle", nullptr, [](const std::any &)
{ std::cout << "Transition: Running -> idle" << std::endl; }); })
.on("Switch", "Main", nullptr, [](const std::any &)
{ std::cout << "Transition: Alternate -> Main" << std::endl; }); })
.build();
// Export to DOT format and print
std::string dot = tree.export_dot();
std::cout << dot;
// Optionally write to file
std::ofstream("example_state_tree_nested.dot") << dot;
return 0;
}