1 #ifndef BOOST_STATECHART_DETAIL_STATE_BASE_HPP_INCLUDED
2 #define BOOST_STATECHART_DETAIL_STATE_BASE_HPP_INCLUDED
3 //////////////////////////////////////////////////////////////////////////////
4 // Copyright 2002-2008 Andreas Huber Doenni
5 // Distributed under the Boost Software License, Version 1.0. (See accompany-
6 // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 //////////////////////////////////////////////////////////////////////////////
11 #include <boost/statechart/result.hpp>
12 #include <boost/statechart/event.hpp>
14 #include <boost/statechart/detail/counted_base.hpp>
16 #include <boost/intrusive_ptr.hpp>
17 #include <boost/noncopyable.hpp>
18 #include <boost/assert.hpp>
19 #include <boost/config.hpp> // BOOST_MSVC
21 #include <boost/detail/workaround.hpp>
22 #include <boost/detail/allocator_utilities.hpp>
25 # pragma warning( push )
26 # pragma warning( disable: 4702 ) // unreachable code (in release mode only)
32 # pragma warning( pop )
46 template< class Allocator, class RttiPolicy >
48 template< class Allocator, class RttiPolicy >
49 class node_state_base;
51 typedef unsigned char orthogonal_position_type;
55 //////////////////////////////////////////////////////////////////////////////
56 template< class Allocator, class RttiPolicy >
61 public RttiPolicy::template rtti_base_type<
62 // Derived class objects will be created, handled and destroyed by exactly
63 // one thread --> locking is not necessary
64 counted_base< false > >
66 typedef typename RttiPolicy::template rtti_base_type<
67 counted_base< false > > base_type;
70 //////////////////////////////////////////////////////////////////////////
73 virtual const state_base * outer_state_ptr() const = 0;
76 //////////////////////////////////////////////////////////////////////////
77 state_base( typename RttiPolicy::id_provider_type idProvider ) :
78 base_type( idProvider ),
79 deferredEvents_( false )
83 #if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT( 4 ) )
84 // We make the destructor virtual for GCC because with this compiler there
85 // is currently no way to disable the "has virtual functions but
86 // non-virtual destructor" warning on a class by class basis. Although it
87 // can be done on the compiler command line with -Wno-non-virtual-dtor,
88 // this is undesirable as this would also suppress legitimate warnings for
89 // types that are not states.
90 virtual ~state_base() {}
92 // This destructor is not virtual for performance reasons. The library
93 // ensures that a state object is never deleted through a state_base
94 // pointer but only through a pointer to the most-derived type.
99 //////////////////////////////////////////////////////////////////////////
100 // The following declarations should be private.
101 // They are only protected because many compilers lack template friends.
102 //////////////////////////////////////////////////////////////////////////
105 deferredEvents_ = true;
108 bool deferred_events() const
110 return deferredEvents_;
113 template< class Context >
114 void set_context( orthogonal_position_type position, Context * pContext )
116 pContext->add_inner_state( position, this );
120 //////////////////////////////////////////////////////////////////////////
121 // The following declarations should be private.
122 // They are only public because many compilers lack template friends.
123 //////////////////////////////////////////////////////////////////////////
124 virtual detail::reaction_result react_impl(
125 const event_base & evt,
126 typename RttiPolicy::id_type eventType ) = 0;
128 typedef intrusive_ptr< node_state_base< Allocator, RttiPolicy > >
129 node_state_base_ptr_type;
130 typedef intrusive_ptr< leaf_state< Allocator, RttiPolicy > >
134 typename boost::detail::allocator::rebind_to<
135 Allocator, leaf_state_ptr_type >::type
138 virtual void remove_from_state_list(
139 typename state_list_type::iterator & statesEnd,
140 node_state_base_ptr_type & pOutermostUnstableState,
141 bool performFullExit ) = 0;
144 //////////////////////////////////////////////////////////////////////////
145 bool deferredEvents_;
150 #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
151 } // namespace detail
152 } // namespace statechart
157 template< class Allocator, class RttiPolicy >
158 inline void intrusive_ptr_add_ref(
159 const ::boost::statechart::detail::state_base< Allocator, RttiPolicy > * pBase )
164 template< class Allocator, class RttiPolicy >
165 inline void intrusive_ptr_release(
166 const ::boost::statechart::detail::state_base< Allocator, RttiPolicy > * pBase )
168 if ( pBase->release() )
170 // The state_base destructor is *not* virtual for performance reasons
171 // but intrusive_ptr< state_base > objects are nevertheless used to point
172 // to states. This assert ensures that such a pointer is never the last
173 // one referencing a state object.
174 BOOST_ASSERT( false );
180 #ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
181 } // namespace detail
182 } // namespace statechart