Maki
Loading...
Searching...
No Matches
state.hpp
1//Copyright Florian Goujeon 2021 - 2026.
2//Distributed under the Boost Software License, Version 1.0.
3//(See accompanying file LICENSE or copy at
4//https://www.boost.org/LICENSE_1_0.txt)
5//Official repository: https://github.com/fgoujeon/maki
6
7#ifndef MAKI_REGION_STATE_HPP
8#define MAKI_REGION_STATE_HPP
9
10#include "detail/type_set.hpp"
11#include "detail/pretty_name.hpp"
12#include "detail/friendly_impl.hpp"
13#include "detail/tlu/left_fold.hpp"
14#include <string_view>
15#include <utility>
16
17namespace maki
18{
19
26template<class Impl>
27class state
28{
29public:
30#ifndef MAKI_DETAIL_DOXYGEN
31 template<class... Args>
32 constexpr state(Args&&... args):
33 impl_(std::forward<Args>(args)...)
34 {
35 }
36#endif
37
38 state(const state&) = delete;
39 state(state&&) = delete;
40 state& operator=(const state&) = delete;
41 state& operator=(state&&) = delete;
42 ~state() = default;
43
49 template<const auto& StateMold>
50 [[nodiscard]] const auto& substate() const
51 {
52 return impl_.template state<StateMold>();
53 }
54
59 template<int Index>
60 [[nodiscard]] const auto& region() const
61 {
62 return impl_.template region<Index>();
63 }
64
69 template<const auto& StateMold>
70 [[nodiscard]] bool is() const
71 {
72 return impl_.template is<StateMold>();
73 }
74
78 [[nodiscard]] const auto& context() const
79 {
80 return impl_.context();
81 }
82
91 [[nodiscard]] static std::string_view pretty_name()
92 {
93 return detail::pretty_name<Impl::mold>();
94 }
95
96private:
97 MAKI_DETAIL_FRIENDLY_IMPL
98
99 using impl_type = Impl;
100
101 impl_type impl_;
102};
103
104namespace detail
105{
106 template<class EventTypeSet, class State>
107 using state_type_list_event_type_set_operation_t = type_set_union_t
108 <
109 EventTypeSet,
110 typename impl_of_t<State>::event_type_set
111 >;
112
113 template<class StateTypeList>
114 using state_type_list_event_type_set_t = tlu::left_fold_t
115 <
116 StateTypeList,
117 state_type_list_event_type_set_operation_t,
118 empty_type_set_t
119 >;
120}
121
122} //namespace
123
124#endif
bool is() const
Returns whether the state created by StateMold is active. Only valid if state is composite and only m...
Definition state.hpp:70
const auto & substate() const
Returns the maki::state object created by StateMold (of type maki::state_mold). Only valid if state i...
Definition state.hpp:50
const auto & context() const
Returns the context instantiated at construction.
Definition state.hpp:78
const auto & region() const
Returns the maki::region object at index Index. Only valid if state is composite.
Definition state.hpp:60
static std::string_view pretty_name()
The pretty name of the state.
Definition state.hpp:91
The Maki library.