Back to home page

EIC code displayed by LXR

 
 

    


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 // Copyright 2002-2008 Andreas Huber Doenni
0005 // Distributed under the Boost Software License, Version 1.0. (See accompany-
0006 // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
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 ) // unreachable code (in release mode only)
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     // Derived class objects will be created, handled and destroyed by exactly
0063     // one thread --> locking is not necessary
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     // We make the destructor virtual for GCC because with this compiler there
0085     // is currently no way to disable the "has virtual functions but
0086     // non-virtual destructor" warning on a class by class basis. Although it
0087     // can be done on the compiler command line with -Wno-non-virtual-dtor,
0088     // this is undesirable as this would also suppress legitimate warnings for
0089     // types that are not states.
0090     virtual ~state_base() {}
0091     #else
0092     // This destructor is not virtual for performance reasons. The library
0093     // ensures that a state object is never deleted through a state_base
0094     // pointer but only through a pointer to the most-derived type.
0095     ~state_base() {}
0096     #endif
0097 
0098   protected:
0099     //////////////////////////////////////////////////////////////////////////
0100     // The following declarations should be private.
0101     // They are only protected because many compilers lack template friends.
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     // The following declarations should be private.
0122     // They are only public because many compilers lack template friends.
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 } // namespace detail
0152 } // namespace statechart
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     // The state_base destructor is *not* virtual for performance reasons
0171     // but intrusive_ptr< state_base > objects are nevertheless used to point
0172     // to states. This assert ensures that such a pointer is never the last
0173     // one referencing a state object.
0174     BOOST_ASSERT( false );
0175   }
0176 }
0177 
0178 
0179 
0180 #ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
0181 } // namespace detail
0182 } // namespace statechart
0183 #endif
0184 
0185 
0186 
0187 } // namespace boost
0188 
0189 
0190 
0191 #endif