fsm
include
fsmpp17
detail
state_container.h
Go to the documentation of this file.
1
12
#pragma once
13
14
#include <variant>
15
16
#include "../../base/type_traits.h"
17
18
#include "../access_context.h"
19
#include "
traits.h
"
20
21
namespace
escad::detail
22
{
23
29
template
<
class
States>
30
class
state_container
31
{
32
private
:
33
using
type_list =
typename
States::type_list;
34
35
public
:
41
template
<
class
State>
42
void
enter
()
43
{
44
states_.template emplace<State>();
45
}
46
53
template
<
class
State,
class
Context>
54
void
enter
(
Context
&ctx)
55
{
56
states_.template emplace<State>(ctx);
57
}
58
62
void
exit
()
63
{
64
states_.template emplace<std::monostate>();
65
}
66
67
template
<
class
F>
68
auto
visit(F &&fun)
69
{
70
std::visit(std::forward<F>(fun), states_);
71
}
72
73
template
<
class
State>
74
auto
is_in()
const
75
{
76
return
std::holds_alternative<State>(states_);
77
}
78
79
template
<
class
State>
80
auto
&
state
()
81
{
82
return
std::get<State>(states_);
83
}
84
85
private
:
86
// Prepend a list of states with std::monostate. We want to avoid a situation
87
// that State will be constructed by defaulted when created instance of this class.
88
// 1. maybe we want to defer creation of State object
89
// 2. first state does not necessarily have default constructor
90
using
states_variant_list =
typename
mpl::type_list_push_front<type_list, std::monostate>::result
;
91
92
// transform a type list to a corresponding variant
93
using
states_variant =
typename
mpl::type_list_rename<states_variant_list, std::variant>::result
;
94
95
states_variant states_;
96
};
97
98
}
// namespace fsm::detail
escad::detail::state_container::enter
void enter()
Enter 'State' state.
Definition:
state_container.h:42
Context
Definition:
testJsonContexts.cpp:18
traits.h
mpl::type_list_push_front
Append a type at the begining of the type_list.
Definition:
type_traits.h:405
escad::detail
Definition:
handle_result.h:14
escad::state
Denotes a state.
Definition:
states.h:61
escad::detail::state_container::enter
void enter(Context &ctx)
Enter 'State' state.
Definition:
state_container.h:54
mpl::type_list_rename
reanme typelist
Definition:
type_traits.h:393
escad::detail::state_container::exit
void exit()
Exit current state.
Definition:
state_container.h:62
escad::detail::state_container
Wrapper around std::variant, which is current implementation of states container. ...
Definition:
state_container.h:30
Generated by
1.8.13