Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 08:50:41

0001 // Copyright 2025 Christian Granzin
0002 // Copyright 2008 Christophe Henry
0003 // henry UNDERSCORE christophe AT hotmail DOT com
0004 // This is an extended version of the state machine available in the boost::mpl library
0005 // Distributed under the same license as the original.
0006 // Copyright for the original version:
0007 // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
0008 // under the Boost Software License, Version 1.0. (See accompanying
0009 // file LICENSE_1_0.txt or copy at
0010 // http://www.boost.org/LICENSE_1_0.txt)
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 // Implementations for history policies.
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         // ignore
0046     }
0047 
0048     // this policy deletes all waiting deferred events
0049     template <class Event>
0050     bool process_deferred_events(Event const&) const
0051     {
0052         return false;
0053     }
0054 
0055   private:
0056     // Allow access to private members for serialization.
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     // the history policy keeps all deferred events until next reentry
0084     template <class Event>
0085     bool process_deferred_events(Event const&)const
0086     {
0087         return true;
0088     }
0089 
0090 private:
0091     // Allow access to private members for serialization.
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     // the history policy keeps deferred events until next reentry if coming from our history event
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     // Allow access to private members for serialization.
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 } // detail
0142 
0143 } // boost::msm::backmp11
0144 
0145 #endif // BOOST_MSM_BACKMP11_HISTORY_IMPL_H