📄 simple_state.hpp
字号:
}
};
friend struct context_ptr_impl_my_context;
struct context_impl_other_context
{
template< class OtherContext, class State >
static OtherContext & context_impl( State & stt )
{
// This assert fails when an attempt is made to access an outer
// context from a constructor of a state that is *not* a subtype of
// state<>. To correct this, derive from state<> instead of
// simple_state<>.
BOOST_ASSERT( get_pointer( stt.pContext_ ) != 0 );
return stt.pContext_->template context< OtherContext >();
}
};
friend struct context_impl_other_context;
struct context_impl_this_context
{
template< class OtherContext, class State >
static OtherContext & context_impl( State & stt )
{
return *polymorphic_downcast< MostDerived * >( &stt );
}
};
friend struct context_impl_this_context;
template< class DestinationState,
class TransitionContext,
class TransitionAction >
result transit_impl( const TransitionAction & transitionAction )
{
typedef typename mpl::find_if<
context_type_list,
mpl::contains<
typename DestinationState::context_type_list,
mpl::placeholders::_ > >::type common_context_iter;
typedef typename mpl::deref< common_context_iter >::type
common_context_type;
typedef typename mpl::distance<
typename mpl::begin< context_type_list >::type,
common_context_iter >::type termination_state_position;
typedef typename mpl::push_front< context_type_list, MostDerived >::type
possible_transition_contexts;
typedef typename mpl::at<
possible_transition_contexts,
termination_state_position >::type termination_state_type;
termination_state_type & terminationState(
context< termination_state_type >() );
const typename
common_context_type::inner_context_ptr_type pCommonContext(
terminationState.context_ptr< common_context_type >() );
outermost_context_base_type & outermostContextBase(
pCommonContext->outermost_context_base() );
#ifdef BOOST_STATECHART_RELAX_TRANSITION_CONTEXT
typedef typename mpl::distance<
typename mpl::begin< possible_transition_contexts >::type,
typename mpl::find<
possible_transition_contexts, TransitionContext >::type
>::type proposed_transition_context_position;
typedef typename mpl::plus<
termination_state_position,
mpl::long_< 1 >
>::type uml_transition_context_position;
typedef typename mpl::deref< typename mpl::max_element<
mpl::list<
proposed_transition_context_position,
uml_transition_context_position >,
mpl::greater< mpl::placeholders::_, mpl::placeholders::_ >
>::type >::type real_transition_context_position;
typedef typename mpl::at<
possible_transition_contexts,
real_transition_context_position >::type real_transition_context_type;
#ifdef BOOST_MSVC
# pragma warning( push )
# pragma warning( disable: 4127 ) // conditional expression is constant
#endif
if ( ( proposed_transition_context_position::value == 0 ) &&
( inner_initial_list_size::value == 0 ) )
{
transitionAction( *polymorphic_downcast< MostDerived * >( this ) );
outermostContextBase.terminate_as_part_of_transit( terminationState );
}
else if ( proposed_transition_context_position::value >=
uml_transition_context_position::value )
{
real_transition_context_type & transitionContext =
context< real_transition_context_type >();
outermostContextBase.terminate_as_part_of_transit( terminationState );
transitionAction( transitionContext );
}
else
{
typename real_transition_context_type::inner_context_ptr_type
pTransitionContext = context_ptr< real_transition_context_type >();
outermostContextBase.terminate_as_part_of_transit(
*pTransitionContext );
transitionAction( *pTransitionContext );
pTransitionContext = 0;
outermostContextBase.terminate_as_part_of_transit( terminationState );
}
#ifdef BOOST_MSVC
# pragma warning( pop )
#endif
#else
outermostContextBase.terminate_as_part_of_transit( terminationState );
transitionAction( *pCommonContext );
#endif
typedef typename detail::make_context_list<
common_context_type, DestinationState >::type context_list_type;
// If you receive a
// "use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>'" or
// similar compiler error here then you tried to make an invalid
// transition between different orthogonal regions.
BOOST_STATIC_ASSERT( ( mpl::equal_to<
typename termination_state_type::orthogonal_position,
typename mpl::front< context_list_type >::type::orthogonal_position
>::value ) );
detail::constructor<
context_list_type, outermost_context_base_type >::construct(
pCommonContext, outermostContextBase );
return detail::result_utility::make_result( detail::do_discard_event );
}
struct local_react_impl_non_empty
{
template< class ReactionList, class State >
static detail::reaction_result local_react_impl(
State & stt,
const event_base_type & evt,
typename rtti_policy_type::id_type eventType )
{
detail::reaction_result reactionResult =
mpl::front< ReactionList >::type::react(
*polymorphic_downcast< MostDerived * >( &stt ),
evt, eventType );
if ( reactionResult == detail::no_reaction )
{
reactionResult = stt.template local_react<
typename mpl::pop_front< ReactionList >::type >(
evt, eventType );
}
return reactionResult;
}
};
friend struct local_react_impl_non_empty;
struct local_react_impl_empty
{
template< class ReactionList, class State >
static detail::reaction_result local_react_impl(
State &, const event_base_type &, typename rtti_policy_type::id_type )
{
return detail::do_forward_event;
}
};
template< class ReactionList >
detail::reaction_result local_react(
const event_base_type & evt,
typename rtti_policy_type::id_type eventType )
{
typedef typename mpl::if_<
mpl::empty< ReactionList >,
local_react_impl_empty,
local_react_impl_non_empty
>::type impl;
return impl::template local_react_impl< ReactionList >(
*this, evt, eventType );
}
struct outer_state_ptr_impl_non_outermost
{
template< class State >
static const state_base_type * outer_state_ptr_impl( const State & stt )
{
return get_pointer( stt.pContext_ );
}
};
friend struct outer_state_ptr_impl_non_outermost;
struct outer_state_ptr_impl_outermost
{
template< class State >
static const state_base_type * outer_state_ptr_impl( const State & )
{
return 0;
}
};
struct deep_construct_inner_impl_non_empty
{
template< class InnerList >
static void deep_construct_inner_impl(
const inner_context_ptr_type & pInnerContext,
outermost_context_base_type & outermostContextBase )
{
typedef typename mpl::front< InnerList >::type current_inner;
// If you receive a
// "use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>'" or
// similar compiler error here then there is a mismatch between the
// orthogonal position of a state and its position in the inner
// initial list of its outer state.
BOOST_STATIC_ASSERT( ( is_same<
current_inner,
typename mpl::at<
typename current_inner::context_type::inner_initial_list,
typename current_inner::orthogonal_position >::type >::value ) );
current_inner::deep_construct( pInnerContext, outermostContextBase );
deep_construct_inner< typename mpl::pop_front< InnerList >::type >(
pInnerContext, outermostContextBase );
}
};
struct deep_construct_inner_impl_empty
{
template< class InnerList >
static void deep_construct_inner_impl(
const inner_context_ptr_type &, outermost_context_base_type & ) {}
};
struct check_store_shallow_history_impl_no
{
template< class State >
static void check_store_shallow_history_impl( State & ) {}
};
struct check_store_shallow_history_impl_yes
{
template< class State >
static void check_store_shallow_history_impl( State & stt )
{
stt.outermost_context_base().template store_shallow_history<
MostDerived >();
}
};
friend struct check_store_shallow_history_impl_yes;
template< class StoreShallowHistory >
void check_store_shallow_history()
{
typedef typename mpl::if_<
StoreShallowHistory,
check_store_shallow_history_impl_yes,
check_store_shallow_history_impl_no
>::type impl;
impl::check_store_shallow_history_impl( *this );
}
struct check_store_deep_history_impl_no
{
template< class State >
static void check_store_deep_history_impl( State & ) {}
};
struct check_store_deep_history_impl_yes
{
template< class State >
static void check_store_deep_history_impl( State & stt )
{
stt.store_deep_history_impl< MostDerived >();
}
};
friend struct check_store_deep_history_impl_yes;
template< class StoreDeepHistory >
void check_store_deep_history()
{
typedef typename mpl::if_<
StoreDeepHistory,
check_store_deep_history_impl_yes,
check_store_deep_history_impl_no
>::type impl;
impl::check_store_deep_history_impl( *this );
}
context_ptr_type pContext_;
};
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
} // namespace statechart
#endif
template< class MostDerived, class Context,
class InnerInitial, history_mode historyMode >
inline void intrusive_ptr_release( const ::boost::statechart::simple_state<
MostDerived, Context, InnerInitial, historyMode > * pBase )
{
if ( pBase->release() )
{
// The cast is necessary because the simple_state destructor is non-
// virtual (and inaccessible from this context)
delete polymorphic_downcast< const MostDerived * >( pBase );
}
}
#ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
} // namespace statechart
#endif
} // namespace boost
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -