1 #ifndef BOOST_STATECHART_SIMPLE_STATE_HPP_INCLUDED
2 #define BOOST_STATECHART_SIMPLE_STATE_HPP_INCLUDED
3 //////////////////////////////////////////////////////////////////////////////
4 // Copyright 2002-2010 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/event.hpp>
13 #include <boost/statechart/detail/leaf_state.hpp>
14 #include <boost/statechart/detail/node_state.hpp>
15 #include <boost/statechart/detail/constructor.hpp>
16 #include <boost/statechart/detail/memory.hpp>
18 #include <boost/mpl/eval_if.hpp>
19 #include <boost/mpl/if.hpp>
20 #include <boost/mpl/identity.hpp>
21 #include <boost/mpl/is_sequence.hpp>
22 #include <boost/mpl/list.hpp>
23 #include <boost/mpl/empty.hpp>
24 #include <boost/mpl/size.hpp>
25 #include <boost/mpl/front.hpp>
26 #include <boost/mpl/at.hpp>
27 #include <boost/mpl/find.hpp>
28 #include <boost/mpl/find_if.hpp>
29 #include <boost/mpl/contains.hpp>
30 #include <boost/mpl/distance.hpp>
31 #include <boost/mpl/deref.hpp>
32 #include <boost/mpl/pop_front.hpp>
33 #include <boost/mpl/push_front.hpp>
34 #include <boost/mpl/clear.hpp>
35 #include <boost/mpl/placeholders.hpp>
36 #include <boost/mpl/bool.hpp>
37 #include <boost/mpl/integral_c.hpp>
38 #include <boost/mpl/less.hpp>
39 #include <boost/mpl/equal_to.hpp>
40 #include <boost/mpl/not.hpp>
41 #include <boost/mpl/or.hpp>
43 #include <boost/mpl/plus.hpp>
44 #include <boost/mpl/max_element.hpp>
45 #include <boost/mpl/greater.hpp>
47 #include <boost/get_pointer.hpp>
48 #include <boost/intrusive_ptr.hpp>
49 #include <boost/assert.hpp>
50 #include <boost/type_traits/is_base_of.hpp>
51 #include <boost/type_traits/is_same.hpp>
52 #include <boost/static_assert.hpp>
53 #include <boost/polymorphic_cast.hpp> // boost::polymorphic_downcast
55 #include <cstddef> // std::size_t
68 //////////////////////////////////////////////////////////////////////////////
70 struct make_list : public mpl::eval_if<
71 mpl::is_sequence< T >,
73 mpl::identity< mpl::list< T > > > {};
75 //////////////////////////////////////////////////////////////////////////////
76 template< class MostDerived, class Context, class InnerInitial >
77 struct simple_state_base_type
80 typedef typename Context::outermost_context_base_type::allocator_type
82 typedef typename Context::outermost_context_base_type::rtti_policy_type
84 typedef typename detail::make_list< InnerInitial >::type
86 typedef typename mpl::size< inner_initial_list >::type
87 inner_initial_list_size;
90 typedef typename mpl::eval_if<
91 mpl::empty< inner_initial_list >,
92 mpl::identity< typename rtti_policy_type::
93 template rtti_derived_type< MostDerived, leaf_state<
95 rtti_policy_type > > >,
96 mpl::identity< typename rtti_policy_type::
97 template rtti_derived_type< MostDerived, node_state<
98 inner_initial_list_size,
100 rtti_policy_type > > > >::type type;
104 //////////////////////////////////////////////////////////////////////////////
105 struct no_transition_function
107 template< class CommonContext >
108 void operator()( CommonContext & ) const {}
111 template< class TransitionContext, class Event >
112 class transition_function
116 void ( TransitionContext::*pTransitionAction )( const Event & ),
119 pTransitionAction_( pTransitionAction ),
124 template< class CommonContext >
125 void operator()( CommonContext & commonContext ) const
127 ( commonContext.template context< TransitionContext >()
128 .*pTransitionAction_ )( evt_ );
132 // avoids C4512 (assignment operator could not be generated)
133 transition_function & operator=( const transition_function & );
135 void ( TransitionContext::*pTransitionAction_ )( const Event & );
140 template< bool contextHasInheritedDeepHistory, bool contextHasDeepHistory >
141 struct deep_history_storer
143 template< class HistorizedState, class LeafState, class Context >
144 static void store_deep_history( Context & ) {}
148 struct deep_history_storer< true, false >
150 template< class HistorizedState, class LeafState, class Context >
151 static void store_deep_history( Context & ctx )
153 ctx.template store_deep_history_impl< LeafState >();
158 struct deep_history_storer< true, true >
160 template< class HistorizedState, class LeafState, class Context >
161 static void store_deep_history( Context & ctx )
163 ctx.outermost_context_base().template store_deep_history<
164 HistorizedState, LeafState >();
165 ctx.template store_deep_history_impl< LeafState >();
171 } // namespace detail
175 //////////////////////////////////////////////////////////////////////////////
181 has_full_history // shallow & deep
186 //////////////////////////////////////////////////////////////////////////////
187 template< class MostDerived,
189 class InnerInitial = mpl::list<>,
190 history_mode historyMode = has_no_history >
191 class simple_state : public detail::simple_state_base_type< MostDerived,
192 typename Context::inner_context_type, InnerInitial >::type
194 typedef typename detail::simple_state_base_type<
195 MostDerived, typename Context::inner_context_type,
196 InnerInitial >::type base_type;
199 //////////////////////////////////////////////////////////////////////////
200 typedef mpl::list<> reactions;
202 typedef typename Context::inner_context_type context_type;
204 template< detail::orthogonal_position_type innerOrthogonalPosition >
207 typedef mpl::integral_c<
208 detail::orthogonal_position_type,
209 innerOrthogonalPosition > inner_orthogonal_position;
210 typedef MostDerived inner_context_type;
213 typedef typename context_type::outermost_context_type
214 outermost_context_type;
216 outermost_context_type & outermost_context()
218 // This assert fails when an attempt is made to access the state machine
219 // from a constructor of a state that is *not* a subtype of state<>.
220 // To correct this, derive from state<> instead of simple_state<>.
221 BOOST_ASSERT( get_pointer( pContext_ ) != 0 );
222 return pContext_->outermost_context();
225 const outermost_context_type & outermost_context() const
227 // This assert fails when an attempt is made to access the state machine
228 // from a constructor of a state that is *not* a subtype of state<>.
229 // To correct this, derive from state<> instead of simple_state<>.
230 BOOST_ASSERT( get_pointer( pContext_ ) != 0 );
231 return pContext_->outermost_context();
234 template< class OtherContext >
235 OtherContext & context()
237 typedef typename mpl::if_<
238 is_base_of< OtherContext, MostDerived >,
239 context_impl_this_context,
240 context_impl_other_context
242 return impl::template context_impl< OtherContext >( *this );
245 template< class OtherContext >
246 const OtherContext & context() const
248 typedef typename mpl::if_<
249 is_base_of< OtherContext, MostDerived >,
250 context_impl_this_context,
251 context_impl_other_context
253 return impl::template context_impl< OtherContext >( *this );
256 template< class Target >
257 Target state_cast() const
259 return outermost_context_base().template state_cast< Target >();
262 template< class Target >
263 Target state_downcast() const
265 return outermost_context_base().template state_downcast< Target >();
268 typedef typename context_type::state_base_type state_base_type;
269 typedef typename context_type::state_iterator state_iterator;
271 state_iterator state_begin() const
273 return outermost_context_base().state_begin();
276 state_iterator state_end() const
278 return outermost_context_base().state_end();
282 typedef typename context_type::event_base_ptr_type event_base_ptr_type;
284 void post_event( const event_base_ptr_type & pEvent )
286 outermost_context_base().post_event_impl( pEvent );
289 void post_event( const event_base & evt )
291 outermost_context_base().post_event_impl( evt );
294 result discard_event()
296 return detail::result_utility::make_result( detail::do_discard_event );
299 result forward_event()
301 return detail::result_utility::make_result( detail::do_forward_event );
306 this->state_base_type::defer_event();
307 return detail::result_utility::make_result( detail::do_defer_event );
310 template< class DestinationState >
313 return transit_impl< DestinationState, outermost_context_type >(
314 detail::no_transition_function() );
317 template< class DestinationState, class TransitionContext, class Event >
319 void ( TransitionContext::*pTransitionAction )( const Event & ),
322 return transit_impl< DestinationState, TransitionContext >(
323 detail::transition_function< TransitionContext, Event >(
324 pTransitionAction, evt ) );
329 outermost_context_base().terminate_as_reaction( *this );
330 return detail::result_utility::make_result( detail::do_discard_event );
334 class HistoryContext,
335 detail::orthogonal_position_type orthogonalPosition >
336 void clear_shallow_history()
338 outermost_context_base().template clear_shallow_history<
339 HistoryContext, orthogonalPosition >();
343 class HistoryContext,
344 detail::orthogonal_position_type orthogonalPosition >
345 void clear_deep_history()
347 outermost_context_base().template clear_deep_history<
348 HistoryContext, orthogonalPosition >();
351 const event_base * triggering_event() const
353 return outermost_context_base().triggering_event();
357 //////////////////////////////////////////////////////////////////////////
358 simple_state() : pContext_( 0 ) {}
362 // As a result of a throwing derived class constructor, this destructor
363 // can be called before the context is set.
364 if ( get_pointer( pContext_ ) != 0 )
366 if ( this->deferred_events() )
368 outermost_context_base().release_events();
371 pContext_->remove_inner_state( orthogonal_position::value );
376 //////////////////////////////////////////////////////////////////////////
377 // The following declarations should be private.
378 // They are only public because many compilers lack template friends.
379 //////////////////////////////////////////////////////////////////////////
380 typedef typename Context::inner_orthogonal_position orthogonal_position;
383 // "use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>'" or similar
384 // compiler error here then either this state resides in a non-existent
385 // orthogonal region of the outer state or the outer state does not have
387 BOOST_STATIC_ASSERT( ( mpl::less<
389 typename context_type::no_of_orthogonal_regions >::value ) );
391 typedef MostDerived inner_context_type;
392 typedef mpl::integral_c< detail::orthogonal_position_type, 0 >
393 inner_orthogonal_position;
395 typedef typename context_type::event_base_type event_base_type;
396 typedef typename context_type::rtti_policy_type rtti_policy_type;
398 typedef typename context_type::outermost_context_base_type
399 outermost_context_base_type;
400 typedef typename context_type::inner_context_ptr_type context_ptr_type;
401 typedef typename context_type::state_list_type state_list_type;
402 typedef intrusive_ptr< inner_context_type > inner_context_ptr_type;
403 typedef typename detail::make_list< InnerInitial >::type
405 typedef typename mpl::size< inner_initial_list >::type
406 inner_initial_list_size;
407 typedef mpl::integral_c<
408 detail::orthogonal_position_type,
409 inner_initial_list_size::value > no_of_orthogonal_regions;
410 typedef typename mpl::push_front<
411 typename context_type::context_type_list,
412 context_type >::type context_type_list;
415 // "use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>'" or similar
416 // compiler error here then the direct or indirect context of this state
417 // has deep history _and_ this state has two or more orthogonal regions.
418 // Boost.Statechart does not currently support deep history in a state whose
419 // direct or indirect inner states have two or more orthogonal regions.
420 // Please consult the documentation on how to work around this limitation.
421 BOOST_STATIC_ASSERT( ( mpl::or_<
423 no_of_orthogonal_regions,
424 mpl::integral_c< detail::orthogonal_position_type, 2 > >,
426 typename context_type::inherited_deep_history > >::value ) );
428 typedef mpl::bool_< ( historyMode & has_shallow_history ) != 0 >
430 typedef typename context_type::shallow_history stores_shallow_history;
432 typedef mpl::bool_< ( historyMode & has_deep_history ) != 0 >
434 typedef typename mpl::or_<
436 typename context_type::inherited_deep_history
437 >::type inherited_deep_history;
438 typedef typename mpl::and_<
439 inherited_deep_history,
440 mpl::empty< inner_initial_list > >::type stores_deep_history;
442 void * operator new( std::size_t size )
444 return detail::allocate< MostDerived,
445 typename outermost_context_type::allocator_type >( size );
448 void operator delete( void * pState )
450 detail::deallocate< MostDerived,
451 typename outermost_context_type::allocator_type >( pState );
454 outermost_context_base_type & outermost_context_base()
456 // This assert fails when an attempt is made to access the state machine
457 // from a constructor of a state that is *not* a subtype of state<>.
458 // To correct this, derive from state<> instead of simple_state<>.
459 BOOST_ASSERT( get_pointer( pContext_ ) != 0 );
460 return pContext_->outermost_context_base();
463 const outermost_context_base_type & outermost_context_base() const
465 // This assert fails when an attempt is made to access the state machine
466 // from a constructor of a state that is *not* a subtype of state<>.
467 // To correct this, derive from state<> instead of simple_state<>.
468 BOOST_ASSERT( get_pointer( pContext_ ) != 0 );
469 return pContext_->outermost_context_base();
472 virtual const state_base_type * outer_state_ptr() const
474 typedef typename mpl::if_<
475 is_same< outermost_context_type, context_type >,
476 outer_state_ptr_impl_outermost,
477 outer_state_ptr_impl_non_outermost
479 return impl::outer_state_ptr_impl( *this );
482 virtual detail::reaction_result react_impl(
483 const event_base_type & evt,
484 typename rtti_policy_type::id_type eventType )
486 typedef typename detail::make_list<
487 typename MostDerived::reactions >::type reaction_list;
488 detail::reaction_result reactionResult =
489 local_react< reaction_list >( evt, eventType );
491 // At this point we can only safely access pContext_ if the handler did
492 // not return do_discard_event!
493 if ( reactionResult == detail::do_forward_event )
495 // TODO: The following call to react_impl of our outer state should
496 // be made with a context_type:: prefix to call directly instead of
497 // virtually. For some reason the compiler complains...
498 reactionResult = pContext_->react_impl( evt, eventType );
501 return reactionResult;
504 virtual void exit_impl(
505 typename base_type::direct_state_base_ptr_type & pSelf,
506 typename state_base_type::node_state_base_ptr_type &
507 pOutermostUnstableState,
508 bool performFullExit )
510 inner_context_ptr_type pMostDerivedSelf =
511 polymorphic_downcast< MostDerived * >( this );
513 exit_impl( pMostDerivedSelf, pOutermostUnstableState, performFullExit );
517 inner_context_ptr_type & pSelf,
518 typename state_base_type::node_state_base_ptr_type &
519 pOutermostUnstableState,
520 bool performFullExit )
522 switch ( this->ref_count() )
525 if ( get_pointer( pOutermostUnstableState ) ==
526 static_cast< state_base_type * >( this ) )
528 pContext_->set_outermost_unstable_state(
529 pOutermostUnstableState );
538 if ( get_pointer( pOutermostUnstableState ) == 0 )
540 pContext_->set_outermost_unstable_state(
541 pOutermostUnstableState );
544 if ( performFullExit )
547 check_store_shallow_history< stores_shallow_history >();
548 check_store_deep_history< stores_deep_history >();
551 context_ptr_type pContext = pContext_;
554 pContext, pOutermostUnstableState, performFullExit );
562 void set_outermost_unstable_state(
563 typename state_base_type::node_state_base_ptr_type &
564 pOutermostUnstableState )
566 pOutermostUnstableState = this;
569 template< class OtherContext >
570 const typename OtherContext::inner_context_ptr_type & context_ptr() const
572 typedef typename mpl::if_<
573 is_same< OtherContext, context_type >,
574 context_ptr_impl_my_context,
575 context_ptr_impl_other_context
578 return impl::template context_ptr_impl< OtherContext >( *this );
581 static void initial_deep_construct(
582 outermost_context_base_type & outermostContextBase )
584 deep_construct( &outermostContextBase, outermostContextBase );
587 static void deep_construct(
588 const context_ptr_type & pContext,
589 outermost_context_base_type & outermostContextBase )
591 const inner_context_ptr_type pInnerContext(
592 shallow_construct( pContext, outermostContextBase ) );
593 deep_construct_inner< inner_initial_list >(
594 pInnerContext, outermostContextBase );
597 static inner_context_ptr_type shallow_construct(
598 const context_ptr_type & pContext,
599 outermost_context_base_type & outermostContextBase )
601 const inner_context_ptr_type pInnerContext( new MostDerived );
602 pInnerContext->set_context( pContext );
603 outermostContextBase.add( pInnerContext );
604 return pInnerContext;
607 void set_context( const context_ptr_type & pContext )
609 BOOST_ASSERT( get_pointer( pContext ) != 0 );
610 pContext_ = pContext;
611 base_type::set_context(
612 orthogonal_position::value, get_pointer( pContext ) );
615 template< class InnerList >
616 static void deep_construct_inner(
617 const inner_context_ptr_type & pInnerContext,
618 outermost_context_base_type & outermostContextBase )
620 typedef typename mpl::if_<
621 mpl::empty< InnerList >,
622 deep_construct_inner_impl_empty,
623 deep_construct_inner_impl_non_empty
625 impl::template deep_construct_inner_impl< InnerList >(
626 pInnerContext, outermostContextBase );
629 template< class LeafState >
630 void store_deep_history_impl()
632 detail::deep_history_storer<
633 context_type::inherited_deep_history::value,
634 context_type::deep_history::value
635 >::template store_deep_history< MostDerived, LeafState >(
640 //////////////////////////////////////////////////////////////////////////
641 struct context_ptr_impl_other_context
643 template< class OtherContext, class State >
644 static const typename OtherContext::inner_context_ptr_type &
645 context_ptr_impl( const State & stt )
647 // This assert fails when an attempt is made to access an outer
648 // context from a constructor of a state that is *not* a subtype of
649 // state<>. To correct this, derive from state<> instead of
651 BOOST_ASSERT( get_pointer( stt.pContext_ ) != 0 );
652 return stt.pContext_->template context_ptr< OtherContext >();
655 friend struct context_ptr_impl_other_context;
657 struct context_ptr_impl_my_context
659 template< class OtherContext, class State >
660 static const typename OtherContext::inner_context_ptr_type &
661 context_ptr_impl( const State & stt )
663 // This assert fails when an attempt is made to access an outer
664 // context from a constructor of a state that is *not* a subtype of
665 // state<>. To correct this, derive from state<> instead of
667 BOOST_ASSERT( get_pointer( stt.pContext_ ) != 0 );
668 return stt.pContext_;
671 friend struct context_ptr_impl_my_context;
673 struct context_impl_other_context
675 template< class OtherContext, class State >
676 static OtherContext & context_impl( State & stt )
678 // This assert fails when an attempt is made to access an outer
679 // context from a constructor of a state that is *not* a subtype of
680 // state<>. To correct this, derive from state<> instead of
682 BOOST_ASSERT( get_pointer( stt.pContext_ ) != 0 );
683 return stt.pContext_->template context< OtherContext >();
686 friend struct context_impl_other_context;
688 struct context_impl_this_context
690 template< class OtherContext, class State >
691 static OtherContext & context_impl( State & stt )
693 return *polymorphic_downcast< MostDerived * >( &stt );
696 friend struct context_impl_this_context;
698 template< class DestinationState,
699 class TransitionContext,
700 class TransitionAction >
701 result transit_impl( const TransitionAction & transitionAction )
703 typedef typename mpl::find_if<
706 typename DestinationState::context_type_list,
707 mpl::placeholders::_ > >::type common_context_iter;
708 typedef typename mpl::deref< common_context_iter >::type
710 typedef typename mpl::distance<
711 typename mpl::begin< context_type_list >::type,
712 common_context_iter >::type termination_state_position;
713 typedef typename mpl::push_front< context_type_list, MostDerived >::type
714 possible_transition_contexts;
715 typedef typename mpl::at<
716 possible_transition_contexts,
717 termination_state_position >::type termination_state_type;
719 termination_state_type & terminationState(
720 context< termination_state_type >() );
722 common_context_type::inner_context_ptr_type pCommonContext(
723 terminationState.template context_ptr< common_context_type >() );
724 outermost_context_base_type & outermostContextBase(
725 pCommonContext->outermost_context_base() );
727 #ifdef BOOST_STATECHART_RELAX_TRANSITION_CONTEXT
728 typedef typename mpl::distance<
729 typename mpl::begin< possible_transition_contexts >::type,
731 possible_transition_contexts, TransitionContext >::type
732 >::type proposed_transition_context_position;
734 typedef typename mpl::plus<
735 termination_state_position,
737 >::type uml_transition_context_position;
739 typedef typename mpl::deref< typename mpl::max_element<
741 proposed_transition_context_position,
742 uml_transition_context_position >,
743 mpl::greater< mpl::placeholders::_, mpl::placeholders::_ >
744 >::type >::type real_transition_context_position;
746 typedef typename mpl::at<
747 possible_transition_contexts,
748 real_transition_context_position >::type real_transition_context_type;
751 # pragma warning( push )
752 # pragma warning( disable: 4127 ) // conditional expression is constant
754 if ( ( proposed_transition_context_position::value == 0 ) &&
755 ( inner_initial_list_size::value == 0 ) )
757 transitionAction( *polymorphic_downcast< MostDerived * >( this ) );
758 outermostContextBase.terminate_as_part_of_transit( terminationState );
760 else if ( proposed_transition_context_position::value >=
761 uml_transition_context_position::value )
763 real_transition_context_type & transitionContext =
764 context< real_transition_context_type >();
765 outermostContextBase.terminate_as_part_of_transit( terminationState );
766 transitionAction( transitionContext );
770 typename real_transition_context_type::inner_context_ptr_type
771 pTransitionContext = context_ptr< real_transition_context_type >();
772 outermostContextBase.terminate_as_part_of_transit(
773 *pTransitionContext );
774 transitionAction( *pTransitionContext );
775 pTransitionContext = 0;
776 outermostContextBase.terminate_as_part_of_transit( terminationState );
779 # pragma warning( pop )
782 outermostContextBase.terminate_as_part_of_transit( terminationState );
783 transitionAction( *pCommonContext );
786 typedef typename detail::make_context_list<
787 common_context_type, DestinationState >::type context_list_type;
790 // "use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>'" or
791 // similar compiler error here then you tried to make an invalid
792 // transition between different orthogonal regions.
793 BOOST_STATIC_ASSERT( ( mpl::equal_to<
794 typename termination_state_type::orthogonal_position,
795 typename mpl::front< context_list_type >::type::orthogonal_position
799 context_list_type, outermost_context_base_type >::construct(
800 pCommonContext, outermostContextBase );
802 return detail::result_utility::make_result( detail::do_discard_event );
805 struct local_react_impl_non_empty
807 template< class ReactionList, class State >
808 static detail::reaction_result local_react_impl(
810 const event_base_type & evt,
811 typename rtti_policy_type::id_type eventType )
813 detail::reaction_result reactionResult =
814 mpl::front< ReactionList >::type::react(
815 *polymorphic_downcast< MostDerived * >( &stt ),
818 if ( reactionResult == detail::no_reaction )
820 reactionResult = stt.template local_react<
821 typename mpl::pop_front< ReactionList >::type >(
825 return reactionResult;
828 friend struct local_react_impl_non_empty;
830 struct local_react_impl_empty
832 template< class ReactionList, class State >
833 static detail::reaction_result local_react_impl(
834 State &, const event_base_type &, typename rtti_policy_type::id_type )
836 return detail::do_forward_event;
840 template< class ReactionList >
841 detail::reaction_result local_react(
842 const event_base_type & evt,
843 typename rtti_policy_type::id_type eventType )
845 typedef typename mpl::if_<
846 mpl::empty< ReactionList >,
847 local_react_impl_empty,
848 local_react_impl_non_empty
850 return impl::template local_react_impl< ReactionList >(
851 *this, evt, eventType );
854 struct outer_state_ptr_impl_non_outermost
856 template< class State >
857 static const state_base_type * outer_state_ptr_impl( const State & stt )
859 return get_pointer( stt.pContext_ );
862 friend struct outer_state_ptr_impl_non_outermost;
864 struct outer_state_ptr_impl_outermost
866 template< class State >
867 static const state_base_type * outer_state_ptr_impl( const State & )
873 struct deep_construct_inner_impl_non_empty
875 template< class InnerList >
876 static void deep_construct_inner_impl(
877 const inner_context_ptr_type & pInnerContext,
878 outermost_context_base_type & outermostContextBase )
880 typedef typename mpl::front< InnerList >::type current_inner;
883 // "use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>'" or
884 // similar compiler error here then there is a mismatch between the
885 // orthogonal position of a state and its position in the inner
886 // initial list of its outer state.
887 BOOST_STATIC_ASSERT( ( is_same<
890 typename current_inner::context_type::inner_initial_list,
891 typename current_inner::orthogonal_position >::type >::value ) );
893 current_inner::deep_construct( pInnerContext, outermostContextBase );
894 deep_construct_inner< typename mpl::pop_front< InnerList >::type >(
895 pInnerContext, outermostContextBase );
899 struct deep_construct_inner_impl_empty
901 template< class InnerList >
902 static void deep_construct_inner_impl(
903 const inner_context_ptr_type &, outermost_context_base_type & ) {}
906 struct check_store_shallow_history_impl_no
908 template< class State >
909 static void check_store_shallow_history_impl( State & ) {}
912 struct check_store_shallow_history_impl_yes
914 template< class State >
915 static void check_store_shallow_history_impl( State & stt )
917 stt.outermost_context_base().template store_shallow_history<
921 friend struct check_store_shallow_history_impl_yes;
923 template< class StoreShallowHistory >
924 void check_store_shallow_history()
926 typedef typename mpl::if_<
928 check_store_shallow_history_impl_yes,
929 check_store_shallow_history_impl_no
931 impl::check_store_shallow_history_impl( *this );
934 struct check_store_deep_history_impl_no
936 template< class State >
937 static void check_store_deep_history_impl( State & ) {}
940 struct check_store_deep_history_impl_yes
942 template< class State >
943 static void check_store_deep_history_impl( State & stt )
945 stt.template store_deep_history_impl< MostDerived >();
948 friend struct check_store_deep_history_impl_yes;
950 template< class StoreDeepHistory >
951 void check_store_deep_history()
953 typedef typename mpl::if_<
955 check_store_deep_history_impl_yes,
956 check_store_deep_history_impl_no
958 impl::check_store_deep_history_impl( *this );
962 context_ptr_type pContext_;
967 #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
968 } // namespace statechart
973 template< class MostDerived, class Context,
974 class InnerInitial, history_mode historyMode >
975 inline void intrusive_ptr_release( const ::boost::statechart::simple_state<
976 MostDerived, Context, InnerInitial, historyMode > * pBase )
978 if ( pBase->release() )
980 // The cast is necessary because the simple_state destructor is non-
981 // virtual (and inaccessible from this context)
982 delete polymorphic_downcast< const MostDerived * >( pBase );
988 #ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
989 } // namespace statechart