/usr/include/boost/msm/front/euml
Edit: /usr/include/boost/msm/front/euml/state_grammar.hpp (70475B)
// Copyright 2008 Christophe Henry
// henry UNDERSCORE christophe AT hotmail DOT com
// This is an extended version of the state machine available in the boost::mpl library
// Distributed under the same license as the original.
// Copyright for the original version:
// Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
// under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_MSM_FRONT_EUML_STATE_GRAMMAR_H
#define BOOST_MSM_FRONT_EUML_STATE_GRAMMAR_H
#ifdef BOOST_MSM_EUML_PHOENIX_SUPPORT
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
BOOST_MPL_HAS_XXX_TRAIT_DEF(attribute_tag)
BOOST_MPL_HAS_XXX_TRAIT_DEF(flag_create_tag)
BOOST_MPL_HAS_XXX_TRAIT_DEF(defer_create_tag)
BOOST_MPL_HAS_XXX_TRAIT_DEF(control_configure_tag)
namespace proto = boost::proto;
namespace boost { namespace msm { namespace front { namespace euml
{
// provides the typedefs and interface. Concrete states derive from it.
template,
class Flags = ::boost::mpl::vector0<>,
class Defer = ::boost::mpl::vector0<>,
class BASE = ::boost::msm::front::default_base_state>
struct func_state : public ::boost::msm::front::detail::state_base,
euml_state_intern >
{
func_state(){}
// grammar testing
BOOST_MPL_ASSERT_NOT(( boost::is_same ));
BOOST_MPL_ASSERT_NOT(( boost::is_same ));
typedef StateNameTag state_name_tag;
// flags
typedef Flags flag_list;
typedef ::boost::mpl::vector0<> internal_flag_list;
// deferred events
typedef Defer deferred_events;
template
void on_entry(Event const& evt,FSM& fsm)
{
EntryFunctor()(evt,fsm,*this);
}
template
void on_exit(Event const& evt,FSM& fsm)
{
ExitFunctor()(evt,fsm,*this);
}
};
// provides the typedefs and interface. Concrete states derive from it.
template,
class Flags = ::boost::mpl::vector0<>,
class Defer = ::boost::mpl::vector0<>,
class BASE = default_base_state>
struct entry_func_state : public ::boost::msm::front::detail::state_base,
euml_state_intern >
{
entry_func_state(){}
// grammar testing
BOOST_MPL_ASSERT_NOT(( boost::is_same ));
BOOST_MPL_ASSERT_NOT(( boost::is_same ));
typedef StateNameTag state_name_tag;
// tags
typedef int pseudo_entry;
enum {zone_index=ZoneIndex};
typedef int explicit_entry_state;
// flags
typedef Flags flag_list;
typedef ::boost::mpl::vector0<> internal_flag_list;
// deferred events
typedef Defer deferred_events;
template
void on_entry(Event const& evt,FSM& fsm)
{
EntryFunctor()(evt,fsm,*this);
}
template
void on_exit(Event const& evt,FSM& fsm)
{
ExitFunctor()(evt,fsm,*this);
}
};
// provides the typedefs and interface. Concrete states derive from it.
template,
class Flags = ::boost::mpl::vector0<>,
class Defer = ::boost::mpl::vector0<>,
class BASE = default_base_state>
struct explicit_entry_func_state : public ::boost::msm::front::detail::state_base,
public ::boost::msm::front::explicit_entry,
euml_state_intern >
{
explicit_entry_func_state(){}
// grammar testing
BOOST_MPL_ASSERT_NOT(( boost::is_same ));
BOOST_MPL_ASSERT_NOT(( boost::is_same ));
typedef StateNameTag state_name_tag;
// flags
typedef Flags flag_list;
typedef ::boost::mpl::vector0<> internal_flag_list;
// deferred events
typedef Defer deferred_events;
template
void on_entry(Event const& evt,FSM& fsm)
{
EntryFunctor()(evt,fsm,*this);
}
template
void on_exit(Event const& evt,FSM& fsm)
{
ExitFunctor()(evt,fsm,*this);
}
};
// provides the typedefs and interface. Concrete states derive from it.
template,
class Flags = ::boost::mpl::vector0<>,
class Defer = ::boost::mpl::vector0<>,
class BASE = default_base_state>
struct exit_func_state : public ::boost::msm::front::detail::state_base,
euml_state_intern >
{
exit_func_state(){}
// grammar testing
BOOST_MPL_ASSERT_NOT(( boost::is_same ));
BOOST_MPL_ASSERT_NOT(( boost::is_same ));
typedef StateNameTag state_name_tag;
// tags
typedef Event event;
typedef BASE Base;
typedef int pseudo_exit;
// flags
typedef Flags flag_list;
typedef ::boost::mpl::vector0<> internal_flag_list;
// deferred events
typedef Defer deferred_events;
template
void on_entry(Evt const& evt,FSM& fsm)
{
EntryFunctor()(evt,fsm,*this);
}
template
void on_exit(Evt const& evt,FSM& fsm)
{
ExitFunctor()(evt,fsm,*this);
}
};
struct BuildActions;
struct BuildGuards;
struct BuildActionSequence
: proto::or_<
proto::when <
BuildActions,
ActionSequence_()>()
>,
proto::when <
proto::comma,
ActionSequence_(),
BuildActions(proto::_right)>()>()
>,
proto::when <
proto::comma,
ActionSequence_(),
BuildActions(proto::_right) >() >()
>
>
{};
#ifdef BOOST_MSM_EUML_PHOENIX_SUPPORT
struct CustomPhoenixGrammar
: proto::switch_
{
template
struct case_
: proto::and_<
proto::not_ ,
proto::not_,
boost::phoenix::meta_grammar::case_
>
{};
};
#endif
struct GuardGrammar
: proto::or_<
#ifdef BOOST_MSM_EUML_PHOENIX_SUPPORT
proto::when<
CustomPhoenixGrammar ,
proto::_
>,
#endif
proto::when<
BuildGuards ,
BuildGuards
>
>
{};
struct ActionGrammar
: proto::or_<
#ifdef BOOST_MSM_EUML_PHOENIX_SUPPORT
proto::when<
CustomPhoenixGrammar ,
proto::_
>,
#endif
proto::when<
BuildActionSequence ,
BuildActionSequence
>
>
{};
struct BuildActionsCases
{
// The primary template matches nothing:
template
struct case_
: proto::not_
{};
};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::pre_inc,
Pre_inc_< BuildActions(proto::_child)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::pre_dec,
Pre_dec_< BuildActions(proto::_child)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::post_inc,
Post_inc_< BuildActions(proto::_child)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::post_dec,
Post_dec_< BuildActions(proto::_child)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::dereference,
Deref_< BuildActions(proto::_child)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::plus,
Plus_()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::minus,
Minus_()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::multiplies,
Multiplies_()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::divides,
Divides_()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::modulus,
Modulus_()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::bitwise_and,
Bitwise_And_()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::bitwise_or,
Bitwise_Or_()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::bitwise_xor,
Bitwise_Xor_()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::plus_assign,
Plus_Assign_< BuildActions(proto::_left),BuildActions(proto::_right)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::minus_assign,
Minus_Assign_()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::multiplies_assign,
Multiplies_Assign_< BuildActions(proto::_left),BuildActions(proto::_right)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::divides_assign,
Divides_Assign_< BuildActions(proto::_left),BuildActions(proto::_right)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::modulus_assign,
Modulus_Assign_< BuildActions(proto::_left),BuildActions(proto::_right)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::shift_left_assign,
ShiftLeft_Assign_< BuildActions(proto::_left),BuildActions(proto::_right)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::shift_right_assign,
ShiftRight_Assign_< BuildActions(proto::_left),BuildActions(proto::_right)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::shift_left,
ShiftLeft_< BuildActions(proto::_left),BuildActions(proto::_right)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::shift_right,
ShiftRight_< BuildActions(proto::_left),BuildActions(proto::_right)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::assign,
Assign_< BuildActions(proto::_left),BuildActions(proto::_right)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::subscript,
Subscript_< BuildActions(proto::_left),BuildActions(proto::_right)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::unary_plus,
Unary_Plus_< BuildActions(proto::_child)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::when<
proto::negate,
Unary_Minus_< BuildActions(proto::_child)>()
>
{};
template<>
struct BuildActionsCases::case_
: proto::or_<
proto::when<
proto::function,BuildGuards,BuildActionSequence,BuildActionSequence >,
If_Else_),
BuildActionSequence(proto::_child_c<2>),
BuildActionSequence(proto::_child_c<3>) >()
>,
proto::when<
proto::function,BuildGuards,BuildActionSequence >,
If_Then_),
BuildActionSequence(proto::_child_c<2>)>()
>,
proto::when<
proto::function,BuildGuards,BuildActionSequence >,
While_Do_),
BuildActionSequence(proto::_child_c<2>) >()
>,
proto::when<
proto::function,BuildGuards,BuildActionSequence >,
Do_While_),
BuildActionSequence(proto::_child_c<2>) >()
>,
proto::when<
proto::function,
BuildActionSequence,BuildGuards,BuildActionSequence,BuildActionSequence>,
For_Loop_),
BuildGuards(proto::_child_c<2>),
BuildActionSequence(proto::_child_c<3>),
BuildActionSequence(proto::_child_c<4>) >()
>,
proto::or_<
proto::when<
proto::function,BuildActions >,
get_fct,BuildActions(proto::_child_c<1>) >()
>,
proto::when<
proto::function >,
get_fct >()
>,
proto::when<
proto::function,BuildActions,BuildActions >,
get_fct,BuildActions(proto::_child_c<1>),BuildActions(proto::_child_c<2>) >()
>,
proto::when<
proto::function,BuildActions,BuildActions,BuildActions >,
get_fct,BuildActions(proto::_child_c<1>)
,BuildActions(proto::_child_c<2>),BuildActions(proto::_child_c<3>) >()
>,
proto::when<
proto::function,BuildActions,BuildActions,BuildActions,BuildActions >,
get_fct
,BuildActions(proto::_child_c<1>),BuildActions(proto::_child_c<2>)
,BuildActions(proto::_child_c<3>),BuildActions(proto::_child_c<4>) >()
>,
proto::when<
proto::function,BuildActions,BuildActions,BuildActions,BuildActions,BuildActions >,
get_fct
,BuildActions(proto::_child_c<1>),BuildActions(proto::_child_c<2>)
,BuildActions(proto::_child_c<3>),BuildActions(proto::_child_c<4>)
,BuildActions(proto::_child_c<5>) >()
>
#ifdef BOOST_MSVC
,proto::when<
proto::function,BuildActions,BuildActions,BuildActions,BuildActions,BuildActions,BuildActions >,
get_fct
,BuildActions(proto::_child_c<1>),BuildActions(proto::_child_c<2>)
,BuildActions(proto::_child_c<3>),BuildActions(proto::_child_c<4>)
,BuildActions(proto::_child_c<5>),BuildActions(proto::_child_c<6>) >()
>
#endif
>
>
{};
template<>
struct BuildActionsCases::case_
: proto::or_<
proto::when<
proto::terminal,
get_action_name()
>,
proto::when<
proto::terminal,
get_state_name()
>,
proto::when<
proto::terminal,
proto::_
>,
proto::when<
proto::terminal,
proto::_
>,
proto::when<
proto::terminal,
get_fct()
>,
proto::when<
proto::terminal,
proto::_value
>
>
{};
struct BuildActions
: proto::switch_
{};
// attributes building
#define BOOST_MSM_EUML_DECLARE_ATTRIBUTE(attr_type,attr_name) \
struct attr_name ## _ \
: proto::extends< proto::terminal< ::boost::msm::front::action_tag>::type, attr_name ## _, boost::msm::sm_domain> \
{typedef attr_name ## _ action_name; \
typedef ::boost::fusion::pair attribute_type; \
attr_name ## _ (){} \
}; \
attr_name ## _ const attr_name = attr_name ## _();
struct make_attributes_tag
{
typedef int attribute_tag;
};
template
struct get_attribute_type
{
typedef typename T::attribute_type type;
};
template
struct transform_to_fusion_pair
{
typedef typename ::boost::mpl::fold<
Seq,::boost::mpl::vector<>,
::boost::mpl::push_back< ::boost::mpl::placeholders::_1,
get_attribute_type< ::boost::mpl::placeholders::_2> >
>::type type;
};
template
struct attribute
{
BOOST_PROTO_BASIC_EXTENDS(
proto::terminal::type
, attribute
, boost::msm::sm_domain
)
typedef ::boost::fusion::pair attribute_type;
};
attribute<> const attributes_ = {{{}}};
attribute<> const no_attributes_ = {{{}}};
struct BuildAttributesHelper
: proto::make<
::boost::mpl::pop_front<
proto::fold_tree<
proto::_
, ::boost::fusion::vector<>()
, ::boost::mpl::push_back,
proto::_value,
get_attribute_type >
>()
>
>
>
{};
struct BuildAttributes
: proto::make<
::boost::mpl::if_<
has_attribute_tag< ::boost::mpl::deref< ::boost::mpl::prior< ::boost::mpl::end< BuildAttributesHelper > > > >,
::boost::fusion::result_of::as_map< ::boost::mpl::pop_back< BuildAttributesHelper > >,
::boost::fusion::result_of::as_map< BuildAttributesHelper > >
>
{};
// helper to build a mpl::vector from a << list
struct BuildMplVectorHelper
: proto::make<
::boost::mpl::pop_front<
proto::fold_tree<
proto::_
, ::boost::mpl::vector0<>()
, ::boost::mpl::push_back()
>
>
>
{};
// flags building
struct BuildFlags
: proto::make<
::boost::mpl::remove_if<
BuildMplVectorHelper,
::boost::mpl::not_< ::boost::is_same, flag_tag > >
>
>
{};
struct control_configure_tag {};
// configuration building
struct make_configure_tag
{
typedef int control_configure_tag;
};
template
struct configure
{
typedef not_euml_tag euml_tag_type;
BOOST_PROTO_BASIC_EXTENDS(
proto::terminal::type
, configure
, boost::msm::sm_domain
)
};
configure<> const configure_ = {{{}}};
configure<> const no_configure_ = {{{}}};
struct BuildConfigure
: proto::make<
::boost::mpl::remove_if<
BuildMplVectorHelper,
::boost::mpl::not_< ::boost::is_same, config_tag > >
>
>
{};
struct BuildDeferred
: proto::make<
::boost::mpl::remove_if<
BuildMplVectorHelper,
::boost::mpl::not_< ::boost::is_same, event_tag > >
>
>
{};
template
struct define_init
{
typedef int defer_create_tag;
BOOST_PROTO_BASIC_EXTENDS(
proto::terminal::type
, define_init
, boost::msm::sm_domain
)
};
define_init<> const init_ = {{{}}};
struct BuildInit
: proto::make<
::boost::mpl::pop_front<
proto::fold_tree<
proto::_
, ::boost::mpl::vector0<>()
, ::boost::mpl::push_back()
>
>
>
{};
template
inline
func_state<
StateNameTag,
typename ::boost::mpl::eval_if<
typename proto::matches::type,
boost::result_of,
make_invalid_type>::type,
typename ::boost::mpl::eval_if<
typename proto::matches::type,
boost::result_of,
make_invalid_type>::type,
typename boost::result_of::type,
typename boost::result_of::type,
typename boost::result_of::type,
BASE
>
build_state(Expr1 const& ,Expr2 const& , Attr const&, Configure const&, BASE )
{
typedef typename boost::result_of::type entry_action;
typedef typename boost::result_of::type exit_action;
typedef typename boost::result_of::type attributes_type;
typedef typename boost::result_of::type flags_type;
typedef typename boost::result_of::type deferred_type;
return func_state();
}
template
inline
func_state<
StateNameTag,
typename ::boost::mpl::eval_if<
typename proto::matches::type,
boost::result_of,
make_invalid_type>::type,
typename ::boost::mpl::eval_if<
typename proto::matches::type,
boost::result_of,
make_invalid_type>::type,
typename boost::result_of::type,
typename boost::result_of::type,
typename boost::result_of::type
>
build_state(Expr1 const& ,Expr2 const& ,Attr const&, Configure const&)
{
typedef typename boost::result_of::type entry_action;
typedef typename boost::result_of::type exit_action;
typedef typename boost::result_of::type attributes_type;
typedef typename boost::result_of::type flags_type;
typedef typename boost::result_of::type deferred_type;
return func_state();
}
template
inline
func_state<
StateNameTag,
typename ::boost::mpl::eval_if<
typename proto::matches::type,
boost::result_of,
make_invalid_type>::type,
typename ::boost::mpl::eval_if<
typename proto::matches::type,
boost::result_of,
make_invalid_type>::type,
typename boost::result_of::type
>
build_state(Expr1 const& ,Expr2 const& ,Attr const&)
{
typedef typename boost::result_of::type entry_action;
typedef typename boost::result_of::type exit_action;
typedef typename boost::result_of::type attributes_type;
return func_state();
}
template
inline
func_state<
StateNameTag,
typename ::boost::mpl::eval_if<
typename proto::matches::type,
boost::result_of,
make_invalid_type>::type,
typename ::boost::mpl::eval_if<
typename proto::matches::type,
boost::result_of,
make_invalid_type>::type
>
build_state(Expr1 const& ,Expr2 const& )
{
typedef typename boost::result_of::type entry_action;
typedef typename boost::result_of::type exit_action;
return func_state();
}
template
inline
func_state<
StateNameTag,
typename ::boost::mpl::eval_if<
typename proto::matches::type,
boost::result_of,
make_invalid_type>::type,
NoAction
>
build_state(Expr1 const& )
{
typedef typename boost::result_of::type entry_action;
return func_state();
}
template
inline
func_state<
StateNameTag,
NoAction,
NoAction
>
build_state()
{
return func_state();
}
// provides the typedefs and interface. Concrete states derive from it.
template,
class Flags = ::boost::mpl::vector0<>,
class Defer = ::boost::mpl::vector0<>,
class Configuration = ::boost::mpl::vector0<>,
class NoTransitionFunctor = NoAction,
class OnExceptionFunctor = NoAction,
class BASE = ::boost::msm::front::default_base_state>
struct func_state_machine : public ::boost::msm::front::detail::state_base,
euml_state_intern >
{
func_state_machine(){}
// grammar testing
BOOST_MPL_ASSERT_NOT(( boost::is_same ));
BOOST_MPL_ASSERT_NOT(( boost::is_same ));
BOOST_MPL_ASSERT_NOT(( boost::is_same ));
BOOST_MPL_ASSERT_NOT(( boost::is_same ));
BOOST_MPL_ASSERT_NOT(( boost::is_same ));
// flags
typedef StateNameTag state_name_tag;
typedef Flags flag_list;
typedef ::boost::mpl::vector0<> internal_flag_list;
// deferred events
typedef Defer deferred_events;
// customization (message queue, exceptions)
typedef Configuration configuration;
typedef BASE BaseAllStates;
typedef STT transition_table;
// the initial state of the player SM. Must be defined
typedef Init initial_state;
template
void on_entry(Event const& evt,FSM& fsm)
{
EntryFunctor()(evt,fsm,*this);
}
template
void on_exit(Event const& evt,FSM& fsm)
{
ExitFunctor()(evt,fsm,*this);
}
protected:
// Default no-transition handler. Can be replaced in the Derived SM class.
template
void no_transition(Event const& evt,FSM& fsm,int state)
{
NoTransitionFunctor()(evt,fsm,state);
}
// default exception handler. Can be replaced in the Derived SM class.
template
void exception_caught (Event const& evt,FSM& fsm,std::exception& e)
{
OnExceptionFunctor()(evt,fsm,e);
}
};
template
inline
func_state_machine<
StateNameTag,
STT,
typename boost::result_of::type
>
build_sm(STT ,Init)
{
typedef typename boost::result_of::type init_type;
return func_state_machine();
}
template
inline
func_state_machine<
StateNameTag,
STT,
typename boost::result_of::type,
typename ::boost::mpl::eval_if<
typename proto::matches::type,
boost::result_of,
make_invalid_type>::type
>
build_sm(STT ,Init , Expr1 const&)
{
typedef typename boost::result_of::type entry_action;
typedef typename boost::result_of::type init_type;
return func_state_machine();
}
template
inline
func_state_machine<
StateNameTag,
STT,
typename boost::result_of::type,
typename ::boost::mpl::eval_if<
typename proto::matches::type,
boost::result_of,
make_invalid_type>::type,
typename ::boost::mpl::eval_if<
typename proto::matches::type,
boost::result_of,
make_invalid_type>::type
>
build_sm(STT ,Init , Expr1 const& ,Expr2 const& )
{
typedef typename boost::result_of::type init_type;
typedef typename boost::result_of::type entry_action;
typedef typename boost::result_of::type exit_action;
return func_state_machine();
}
template
inline
func_state_machine<
StateNameTag,
STT,
typename boost::result_of::type,
typename ::boost::mpl::eval_if<
typename proto::matches::type,
boost::result_of,
make_invalid_type>::type,
typename ::boost::mpl::eval_if<
typename proto::matches