Maki
Loading...
Searching...
No Matches
state_set.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_STATE_SET_HPP
8#define MAKI_STATE_SET_HPP
9
10#include "state_mold.hpp"
11#include "detail/friendly_impl.hpp"
12#include "detail/set.hpp"
13
14namespace maki
15{
16
21template<class Impl>
22class state_set;
23
24namespace detail
25{
26 template<class Impl>
27 constexpr auto make_state_set_from_impl(const Impl& impl)
28 {
29 return state_set<Impl>{impl};
30 }
31}
32
33template<class Impl>
34class state_set
35{
36public:
37 constexpr state_set(const state_set& other) = default;
38 constexpr state_set(state_set&& other) = default;
39
40 ~state_set() = default;
41
42 constexpr state_set& operator=(const state_set& other) = default;
43 constexpr state_set& operator=(state_set&& other) = default;
44
45private:
46 MAKI_DETAIL_FRIENDLY_IMPL
47
48 using impl_type = Impl;
49
50 template<class Impl2>
51 friend constexpr auto detail::make_state_set_from_impl(const Impl2&);
52
53 explicit constexpr state_set(const Impl& impl):
54 impl_(impl)
55 {
56 }
57
58 impl_type impl_;
59};
60
61#ifdef MAKI_DETAIL_DOXYGEN
66inline constexpr auto all_states = IMPLEMENTATION_DETAIL;
67#else
68inline constexpr auto all_states = detail::make_state_set_from_impl
69(
70 detail::make_set_including_all()
71);
72#endif
73
74#ifdef MAKI_DETAIL_DOXYGEN
79inline constexpr auto no_state = IMPLEMENTATION_DETAIL;
80#else
81inline constexpr auto no_state = detail::make_state_set_from_impl
82(
83 detail::make_set_excluding_all()
84);
85#endif
86
92template<class Impl>
93constexpr auto operator!(const state_set<Impl>& stt_set)
94{
95 return detail::make_state_set_from_impl
96 (
97 detail::inverse_set(detail::impl_of(stt_set))
98 );
99}
100
106template<class StateMoldImpl>
107constexpr auto operator!(const state_mold<StateMoldImpl>& stt_mold)
108{
109 return detail::make_state_set_from_impl
110 (
111 detail::make_set_excluding(&stt_mold)
112 );
113}
114
120template<class LhsImpl, class RhsImpl>
121constexpr auto operator||
122(
123 const state_set<LhsImpl>& lhs,
124 const state_set<RhsImpl>& rhs
125)
126{
127 return detail::make_state_set_from_impl
128 (
129 detail::make_set_union(detail::impl_of(lhs), detail::impl_of(rhs))
130 );
131}
132
138template<class StateSetImpl, class StateMoldImpl>
139constexpr auto operator||
140(
141 const state_set<StateSetImpl>& stt_set,
142 const state_mold<StateMoldImpl>& stt_mold
143)
144{
145 return detail::make_state_set_from_impl
146 (
147 detail::make_set_union(detail::impl_of(stt_set), &stt_mold)
148 );
149}
150
156template<class StateMoldImpl, class StateSetImpl>
157constexpr auto operator||
158(
159 const state_mold<StateMoldImpl>& stt_mold,
160 const state_set<StateSetImpl>& stt_set
161)
162{
163 return stt_set || stt_mold;
164}
165
171template<class LhsStateMoldImpl, class RhsStateMoldImpl>
172constexpr auto operator||
173(
176)
177{
178 return detail::make_state_set_from_impl
179 (
180 detail::make_set_including(&lhs, &rhs)
181 );
182}
183
189template<class LhsImpl, class RhsImpl>
190constexpr auto operator&&
191(
192 const state_set<LhsImpl>& lhs,
193 const state_set<RhsImpl>& rhs
194)
195{
196 return detail::make_state_set_from_impl
197 (
198 detail::make_set_intersection(detail::impl_of(lhs) && detail::impl_of(rhs))
199 );
200}
201
202namespace detail
203{
204 template<class StateMoldImpl, class StateMoldImpl2>
205 constexpr bool contained_in(const state_mold<StateMoldImpl>& lhs, const state_mold<StateMoldImpl2>* rhs)
206 {
207 return equals(&lhs, rhs);
208 }
209
210 template<class StateMoldImpl, class... Predicates>
211 constexpr bool contained_in(const state_mold<StateMoldImpl>& stt_mold, const state_set<Predicates>&... state_sets)
212 {
213 return (contains(impl_of(state_sets), &stt_mold) || ...);
214 }
215
216 template<class T>
217 struct is_state_set
218 {
219 static constexpr auto value = false;
220 };
221
222 template<class Predicate>
223 struct is_state_set<state_set<Predicate>>
224 {
225 static constexpr auto value = true;
226 };
227
228 template<class T>
229 constexpr auto is_state_set_v = is_state_set<T>::value;
230}
231
232} //namespace
233
234#endif
State mold.
Definition state_mold.hpp:43
Represents a state set.
Definition state_set.hpp:35
constexpr auto no_state
An empty maki::state_set.
Definition state_set.hpp:79
constexpr auto operator!(const state_mold< StateMoldImpl > &stt_mold)
Creates a maki::state_set that contains all the states but the ones created by stt_mold.
Definition state_set.hpp:107
constexpr auto all_states
An infinite maki::state_set that contains all the states.
Definition state_set.hpp:66
constexpr auto operator!(const state_set< Impl > &stt_set)
Creates a maki::state_set that contains all the states that are not contained in stt_set.
Definition state_set.hpp:93
The Maki library.