File indexing completed on 2026-08-17 08:50:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_MSM_BACKMP11_HISTORY_IMPL_H
0013 #define BOOST_MSM_BACKMP11_HISTORY_IMPL_H
0014
0015 #include <boost/msm/front/history_policies.hpp>
0016 #include <boost/mp11.hpp>
0017
0018 namespace boost::msm::backmp11
0019 {
0020 namespace detail
0021 {
0022
0023
0024
0025 template<typename History, int NumberOfRegions>
0026 class history_impl;
0027
0028 template <int NumberOfRegions>
0029 class history_impl<front::no_history, NumberOfRegions>
0030 {
0031 public:
0032 void reset_active_state_ids(const std::array<int, NumberOfRegions>& initial_state_ids)
0033 {
0034 m_initial_state_ids = initial_state_ids;
0035 }
0036
0037 template <class Event>
0038 const std::array<int, NumberOfRegions>& on_entry(Event const&)
0039 {
0040 return m_initial_state_ids;
0041 }
0042
0043 void on_exit(const std::array<int, NumberOfRegions>&)
0044 {
0045
0046 }
0047
0048
0049 template <class Event>
0050 bool process_deferred_events(Event const&) const
0051 {
0052 return false;
0053 }
0054
0055 private:
0056
0057 template<typename T, int N>
0058 friend void serialize(T&, history_impl<front::no_history, N>&);
0059
0060 std::array<int, NumberOfRegions> m_initial_state_ids;
0061 };
0062
0063 template <int NumberOfRegions>
0064 class history_impl<front::always_shallow_history, NumberOfRegions>
0065 {
0066 public:
0067 void reset_active_state_ids(const std::array<int, NumberOfRegions>& initial_state_ids)
0068 {
0069 m_last_active_state_ids = initial_state_ids;
0070 }
0071
0072 template <class Event>
0073 const std::array<int, NumberOfRegions>& on_entry(Event const& )
0074 {
0075 return m_last_active_state_ids;
0076 }
0077
0078 void on_exit(const std::array<int, NumberOfRegions>& active_state_ids)
0079 {
0080 m_last_active_state_ids = active_state_ids;
0081 }
0082
0083
0084 template <class Event>
0085 bool process_deferred_events(Event const&)const
0086 {
0087 return true;
0088 }
0089
0090 private:
0091
0092 template<typename T, int N>
0093 friend void serialize(T&, history_impl<front::always_shallow_history, N>&);
0094
0095 std::array<int, NumberOfRegions> m_last_active_state_ids;
0096 };
0097
0098 template <typename... Events, int NumberOfRegions>
0099 class history_impl<front::shallow_history<Events...>, NumberOfRegions>
0100 {
0101 using events_mp11 = mp11::mp_list<Events...>;
0102
0103 public:
0104 void reset_active_state_ids(const std::array<int, NumberOfRegions>& initial_state_ids)
0105 {
0106 m_initial_state_ids = initial_state_ids;
0107 m_last_active_state_ids = initial_state_ids;
0108 }
0109
0110 template <class Event>
0111 const std::array<int, NumberOfRegions>& on_entry(Event const&)
0112 {
0113 if constexpr (mp11::mp_contains<events_mp11,Event>::value)
0114 {
0115 return m_last_active_state_ids;
0116 }
0117 return m_initial_state_ids;
0118 }
0119
0120 void on_exit(const std::array<int, NumberOfRegions>& active_state_ids)
0121 {
0122 m_last_active_state_ids = active_state_ids;
0123 }
0124
0125
0126 template <class Event>
0127 bool process_deferred_events(Event const&) const
0128 {
0129 return mp11::mp_contains<events_mp11,Event>::value;
0130 }
0131
0132 private:
0133
0134 template<typename T, typename... Es, int N>
0135 friend void serialize(T&, history_impl<front::shallow_history<Es...>, N>&);
0136
0137 std::array<int, NumberOfRegions> m_initial_state_ids;
0138 std::array<int, NumberOfRegions> m_last_active_state_ids;
0139 };
0140
0141 }
0142
0143 }
0144
0145 #endif