fsm
transitions.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "../base/type_traits.h"
15 #include "detail/handle_result.h"
16 
17 namespace escad
18 {
19 
27 template<class... S>
28 class transitions {
29 private:
30  enum class result {
31  not_handled,
32  handled,
33  transition
34  };
35 
36 public:
46  constexpr transitions(transitions<> const& rhs) noexcept
47  : idx {0}
48  , outcome {rhs.outcome}
49  {
50  }
51 
57  template<class T>
59  : idx {mpl::type_list_index_v<T, list>}
60  , outcome {result::transition}
61  {
62  }
63 
64  template<class T>
65  transitions(transitions<T>) noexcept
66  : idx {mpl::type_list_index_v<T, list>}
67  , outcome {result::transition}
68  {}
69 
74  : idx {sizeof...(S)}
75  , outcome {result::handled}
76  {}
77 
82  : idx {sizeof...(S)}
83  , outcome {result::not_handled}
84  {}
85 
92  bool is_transition() const {
93  return outcome == result::transition;
94  }
95 
102  bool is_handled() const {
103  return outcome == result::handled;
104  }
105 
106  using list = mpl::type_list<S...>;
107 
108  std::size_t const idx;
109  result const outcome;
110 };
111 
112 } // namespace fsm
113 
transitions(detail::handled) noexcept
Construct a new transitions object indicating handled event.
Definition: transitions.h:73
Definition: handle_result.h:18
transitions(detail::not_handled) noexcept
Construct a new transitions object indicating not handled event.
Definition: transitions.h:81
bool is_transition() const
Check if this object is a transition type.
Definition: transitions.h:92
Definition: handle_result.h:19
Event handler return type.
Definition: transitions.h:28
Definition: compressed_pair.h:10
constexpr transitions(transitions<> const &rhs) noexcept
Construct new object from empty-listed transactions object.
Definition: transitions.h:46
bool is_handled() const
Check if the event was handled.
Definition: transitions.h:102
Alias template to facilitate the creation of named values.
Definition: type_traits.h:142
Definition: handle_result.h:17
transitions(detail::transition< T >) noexcept
Construct a new transitions object directly from detail::transition<>
Definition: transitions.h:58