File indexing completed on 2025-01-18 09:41:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_MSM_BACK_HISTORY_POLICIES_H
0012 #define BOOST_MSM_BACK_HISTORY_POLICIES_H
0013
0014 #include <boost/mpl/contains.hpp>
0015
0016 namespace boost { namespace msm { namespace back
0017 {
0018
0019
0020
0021
0022 template <int NumberOfRegions>
0023 class NoHistoryImpl
0024 {
0025 public:
0026 NoHistoryImpl(){}
0027 ~NoHistoryImpl(){}
0028 void set_initial_states(int* const initial_states)
0029 {
0030 for (int i=0;i<NumberOfRegions;++i)
0031 m_initialStates[i] = initial_states[i];
0032 }
0033 void history_exit(int* const )
0034 {
0035
0036 }
0037
0038 template <class Event>
0039 const int* history_entry(Event const& )
0040 {
0041
0042 return m_initialStates;
0043 }
0044 NoHistoryImpl<NumberOfRegions>& operator=(NoHistoryImpl<NumberOfRegions> const& rhs)
0045 {
0046 for (int i=0; i<NumberOfRegions;++i)
0047 {
0048 m_initialStates[i] = rhs.m_initialStates[i];
0049 }
0050 return *this;
0051 }
0052
0053 template <class Event>
0054 bool process_deferred_events(Event const&)const
0055 {
0056 return false;
0057 }
0058 template<class Archive>
0059 void serialize(Archive & ar, const unsigned int)
0060 {
0061 ar & m_initialStates;
0062 }
0063 private:
0064 int m_initialStates[NumberOfRegions];
0065 };
0066
0067
0068 template <int NumberOfRegions>
0069 class AlwaysHistoryImpl
0070 {
0071 public:
0072 AlwaysHistoryImpl(){}
0073 ~AlwaysHistoryImpl(){}
0074 void set_initial_states(int* const initial_states)
0075 {
0076 for (int i=0;i<NumberOfRegions;++i)
0077 m_initialStates[i] = initial_states[i];
0078 }
0079 void history_exit(int* const current_states)
0080 {
0081 for (int i=0;i<NumberOfRegions;++i)
0082 m_initialStates[i] = current_states[i];
0083 }
0084
0085 template <class Event>
0086 const int* history_entry(Event const& )
0087 {
0088
0089 return m_initialStates;
0090 }
0091 AlwaysHistoryImpl<NumberOfRegions>& operator=(AlwaysHistoryImpl<NumberOfRegions> const& rhs)
0092 {
0093 for (int i=0; i<NumberOfRegions;++i)
0094 {
0095 m_initialStates[i] = rhs.m_initialStates[i];
0096 }
0097 return *this;
0098 }
0099
0100 template <class Event>
0101 bool process_deferred_events(Event const&)const
0102 {
0103 return true;
0104 }
0105
0106 template<class Archive>
0107 void serialize(Archive & ar, const unsigned int)
0108 {
0109 ar & m_initialStates;
0110 }
0111 private:
0112 int m_initialStates[NumberOfRegions];
0113 };
0114
0115
0116 template <class Events,int NumberOfRegions>
0117 class ShallowHistoryImpl
0118 {
0119 public:
0120 ShallowHistoryImpl(){}
0121 ~ShallowHistoryImpl(){}
0122 void set_initial_states(int* const initial_states)
0123 {
0124 for (int i=0;i<NumberOfRegions;++i)
0125 {
0126 m_currentStates[i] = initial_states[i];
0127 m_initialStates[i] = initial_states[i];
0128 }
0129 }
0130 void history_exit(int* const current_states)
0131 {
0132 for (int i=0;i<NumberOfRegions;++i)
0133 m_currentStates[i] = current_states[i];
0134 }
0135
0136 template <class Event>
0137 const int* history_entry(Event const&)
0138 {
0139 if ( ::boost::mpl::contains<Events,Event>::value)
0140 {
0141 return m_currentStates;
0142 }
0143
0144 return m_initialStates;
0145 }
0146 ShallowHistoryImpl<Events,NumberOfRegions>& operator=(ShallowHistoryImpl<Events,NumberOfRegions> const& rhs)
0147 {
0148 for (int i=0; i<NumberOfRegions;++i)
0149 {
0150 m_initialStates[i] = rhs.m_initialStates[i];
0151 m_currentStates[i] = rhs.m_currentStates[i];
0152 }
0153 return *this;
0154 }
0155
0156 template <class Event>
0157 bool process_deferred_events(Event const&)const
0158 {
0159 return ::boost::mpl::contains<Events,Event>::value;
0160 }
0161 template<class Archive>
0162 void serialize(Archive & ar, const unsigned int)
0163 {
0164 ar & m_initialStates;
0165 ar & m_currentStates;
0166 }
0167 private:
0168 int m_initialStates[NumberOfRegions];
0169 int m_currentStates[NumberOfRegions];
0170 };
0171
0172 struct NoHistory
0173 {
0174 typedef int history_policy;
0175 template <int NumberOfRegions>
0176 struct apply
0177 {
0178 typedef NoHistoryImpl<NumberOfRegions> type;
0179 };
0180 };
0181 struct AlwaysHistory
0182 {
0183 typedef int history_policy;
0184 template <int NumberOfRegions>
0185 struct apply
0186 {
0187 typedef AlwaysHistoryImpl<NumberOfRegions> type;
0188 };
0189 };
0190 template <class Events>
0191 struct ShallowHistory
0192 {
0193 typedef int history_policy;
0194 template <int NumberOfRegions>
0195 struct apply
0196 {
0197 typedef ShallowHistoryImpl<Events,NumberOfRegions> type;
0198 };
0199 };
0200 } } }
0201 #endif