File indexing completed on 2025-01-18 09:52:31
0001 #ifndef BOOST_STATECHART_DETAIL_STATE_BASE_HPP_INCLUDED
0002 #define BOOST_STATECHART_DETAIL_STATE_BASE_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <boost/statechart/result.hpp>
0012 #include <boost/statechart/event.hpp>
0013
0014 #include <boost/statechart/detail/counted_base.hpp>
0015
0016 #include <boost/intrusive_ptr.hpp>
0017 #include <boost/noncopyable.hpp>
0018 #include <boost/assert.hpp>
0019 #include <boost/config.hpp> // BOOST_MSVC
0020
0021 #include <boost/detail/workaround.hpp>
0022 #include <boost/detail/allocator_utilities.hpp>
0023
0024 #ifdef BOOST_MSVC
0025 # pragma warning( push )
0026 # pragma warning( disable: 4702 )
0027 #endif
0028
0029 #include <list>
0030
0031 #ifdef BOOST_MSVC
0032 # pragma warning( pop )
0033 #endif
0034
0035
0036
0037 namespace boost
0038 {
0039 namespace statechart
0040 {
0041 namespace detail
0042 {
0043
0044
0045
0046 template< class Allocator, class RttiPolicy >
0047 class leaf_state;
0048 template< class Allocator, class RttiPolicy >
0049 class node_state_base;
0050
0051 typedef unsigned char orthogonal_position_type;
0052
0053
0054
0055
0056 template< class Allocator, class RttiPolicy >
0057 class state_base :
0058 #ifndef NDEBUG
0059 noncopyable,
0060 #endif
0061 public RttiPolicy::template rtti_base_type<
0062
0063
0064 counted_base< false > >
0065 {
0066 typedef typename RttiPolicy::template rtti_base_type<
0067 counted_base< false > > base_type;
0068
0069 public:
0070
0071 void exit() {}
0072
0073 virtual const state_base * outer_state_ptr() const = 0;
0074
0075 protected:
0076
0077 state_base( typename RttiPolicy::id_provider_type idProvider ) :
0078 base_type( idProvider ),
0079 deferredEvents_( false )
0080 {
0081 }
0082
0083 #if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT( 4 ) )
0084
0085
0086
0087
0088
0089
0090 virtual ~state_base() {}
0091 #else
0092
0093
0094
0095 ~state_base() {}
0096 #endif
0097
0098 protected:
0099
0100
0101
0102
0103 void defer_event()
0104 {
0105 deferredEvents_ = true;
0106 }
0107
0108 bool deferred_events() const
0109 {
0110 return deferredEvents_;
0111 }
0112
0113 template< class Context >
0114 void set_context( orthogonal_position_type position, Context * pContext )
0115 {
0116 pContext->add_inner_state( position, this );
0117 }
0118
0119 public:
0120
0121
0122
0123
0124 virtual detail::reaction_result react_impl(
0125 const event_base & evt,
0126 typename RttiPolicy::id_type eventType ) = 0;
0127
0128 typedef intrusive_ptr< node_state_base< Allocator, RttiPolicy > >
0129 node_state_base_ptr_type;
0130 typedef intrusive_ptr< leaf_state< Allocator, RttiPolicy > >
0131 leaf_state_ptr_type;
0132 typedef std::list<
0133 leaf_state_ptr_type,
0134 typename boost::detail::allocator::rebind_to<
0135 Allocator, leaf_state_ptr_type >::type
0136 > state_list_type;
0137
0138 virtual void remove_from_state_list(
0139 typename state_list_type::iterator & statesEnd,
0140 node_state_base_ptr_type & pOutermostUnstableState,
0141 bool performFullExit ) = 0;
0142
0143 private:
0144
0145 bool deferredEvents_;
0146 };
0147
0148
0149
0150 #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
0151 }
0152 }
0153 #endif
0154
0155
0156
0157 template< class Allocator, class RttiPolicy >
0158 inline void intrusive_ptr_add_ref(
0159 const ::boost::statechart::detail::state_base< Allocator, RttiPolicy > * pBase )
0160 {
0161 pBase->add_ref();
0162 }
0163
0164 template< class Allocator, class RttiPolicy >
0165 inline void intrusive_ptr_release(
0166 const ::boost::statechart::detail::state_base< Allocator, RttiPolicy > * pBase )
0167 {
0168 if ( pBase->release() )
0169 {
0170
0171
0172
0173
0174 BOOST_ASSERT( false );
0175 }
0176 }
0177
0178
0179
0180 #ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
0181 }
0182 }
0183 #endif
0184
0185
0186
0187 }
0188
0189
0190
0191 #endif