Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69829 - in branches/msm: . v2_30 v2_30/boost v2_30/boost/msm v2_30/boost/msm/lpp v2_30/libs v2_30/libs/msm v2_30/libs/msm/example
From: christophe.j.henry_at_[hidden]
Date: 2011-03-10 16:54:02


Author: chenry
Date: 2011-03-10 16:54:00 EST (Thu, 10 Mar 2011)
New Revision: 69829
URL: http://svn.boost.org/trac/boost/changeset/69829

Log:
added branch for msm.lpp (in process)
Added:
   branches/msm/
   branches/msm/v2_30/
   branches/msm/v2_30/boost/
   branches/msm/v2_30/boost/msm/
   branches/msm/v2_30/boost/msm/lpp/
   branches/msm/v2_30/boost/msm/lpp/basic_grammar.hpp (contents, props changed)
   branches/msm/v2_30/boost/msm/lpp/common_types.hpp (contents, props changed)
   branches/msm/v2_30/boost/msm/lpp/function.hpp (contents, props changed)
   branches/msm/v2_30/boost/msm/lpp/lpp.hpp (contents, props changed)
   branches/msm/v2_30/boost/msm/lpp/operator.hpp (contents, props changed)
   branches/msm/v2_30/libs/
   branches/msm/v2_30/libs/msm/
   branches/msm/v2_30/libs/msm/example/

Added: branches/msm/v2_30/boost/msm/lpp/basic_grammar.hpp
==============================================================================
--- (empty file)
+++ branches/msm/v2_30/boost/msm/lpp/basic_grammar.hpp 2011-03-10 16:54:00 EST (Thu, 10 Mar 2011)
@@ -0,0 +1,356 @@
+// Copyright 2011 Christophe Henry
+// henry UNDERSCORE christophe AT hotmail DOT com
+// 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_LPP_BASIC_GRAMMAR_H
+#define BOOST_MSM_LPP_BASIC_GRAMMAR_H
+
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/min_max.hpp>
+#include <boost/mpl/eval_if.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/next_prior.hpp>
+#include <boost/mpl/deref.hpp>
+#include <boost/mpl/for_each.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/proto/core.hpp>
+#include <boost/proto/context.hpp>
+#include <boost/proto/transform.hpp>
+#include <boost/fusion/container/list/cons.hpp>
+#include <boost/typeof/typeof.hpp>
+#include <boost/utility/result_of.hpp>
+
+
+namespace boost { namespace msm { namespace lpp
+{
+struct action_tag {};
+
+template <class T,class Arg1=void,class Arg2=void,class Arg3=void,class Arg4=void>
+struct get_fct
+{
+ typedef typename T::template In<Arg1,Arg2,Arg3,Arg4>::type type;
+};
+
+// wrapper for mpl::for_each as showed in the C++ Template Metaprogramming ch. 9
+template <class T>
+struct wrap{};
+
+template <class Sequence>
+struct LambdaSequence_
+{
+ typedef Sequence sequence;
+ typedef typename ::boost::mpl::deref< typename ::boost::mpl::prior< typename ::boost::mpl::end<Sequence>::type >::type>::type last;
+
+ template<class Sig> struct result;
+ template<class This,class B, class A0>
+ struct result<This(B& block,A0& a0)>
+ {
+ static B& block;
+ static A0& a0;
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,last()(block,a0) )
+ typedef typename nested::type type;
+ };
+ template<class This,class B, class A0, class A1>
+ struct result<This(B& block,A0& a0,A1& a1)>
+ {
+ static B& block;
+ static A0& a0;
+ static A1& a1;
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,last()(block,a0,a1) )
+ typedef typename nested::type type;
+ };
+
+ template <typename B,class A0,class A1=void>
+ struct Call
+ {
+ Call(B& block,A0& a0,A1& a1): block_(block),a0_(a0),a1_(a1){}
+ template <class FCT>
+ void operator()(wrap<FCT> const& )
+ {
+ FCT()(block_,a0_,a1_);
+ }
+ private:
+ B& block_;
+ A0& a0_;
+ A1& a1_;
+ };
+ template <typename B,class A0>
+ struct Call<B,A0,void>
+ {
+ Call(B& block,A0& a0): block_(block),a0_(a0){}
+ template <class FCT>
+ void operator()(wrap<FCT> const& )
+ {
+ FCT()(block_,a0_);
+ }
+ private:
+ B& block_;
+ A0& a0_;
+ };
+
+ template<typename B,typename A0>
+ typename boost::result_of<LambdaSequence_(B&,A0&)>::type
+ operator ()(B& block, A0 & a0) const
+ {
+ mpl::for_each< typename ::boost::mpl::pop_back<Sequence>::type,
+ wrap< ::boost::mpl::placeholders::_1> >
+ (Call<B,A0>(block,a0));
+ return last()(block,a0);
+ }
+ template<typename B,typename A0,typename A1>
+ typename boost::result_of<LambdaSequence_(B&,A0&,A1&)>::type
+ operator ()(B& block, A0 & a0, A1 & a1) const
+ {
+ mpl::for_each< typename ::boost::mpl::pop_back<Sequence>::type,
+ wrap< ::boost::mpl::placeholders::_1> >
+ (Call<B,A0,A1>(block,a0,a1));
+ return last()(block,a0,a1);
+ }
+};
+
+struct if_then_tag
+{
+};
+template <class T>
+struct get_condition
+{
+ typedef typename T::condition type;
+};
+template <class T>
+struct get_ifclause
+{
+ typedef typename T::ifclause type;
+};
+struct ignored {};
+template <class Condition,class IfClause=void>
+struct if_then_
+{
+ typedef Condition condition;
+ typedef IfClause ifclause;
+
+ template<class Sig> struct result;
+ template<class This,class B, class A0>
+ struct result<This(B& block,A0& a0)>
+ {
+ typedef ignored type;
+ };
+ template<class This,class B, class A0, class A1>
+ struct result<This(B& block,A0& a0,A1& a1)>
+ {
+ typedef ignored type;
+ };
+ template<typename B,typename A0>
+ typename boost::result_of<if_then_(B&,A0&)>::type
+ operator()(B& block, A0 & a0)const
+ {
+ if (Condition()(block,a0))
+ {
+ IfClause()(block,a0);
+ }
+ return ignored();
+ }
+ template<typename B,typename A0,typename A1>
+ typename boost::result_of<if_then_(B&,A0&,A1&)>::type
+ operator()(B& block, A0 & a0, A0 & a1)const
+ {
+ if (Condition()(block,a0,a1))
+ {
+ IfClause()(block,a0,a1);
+ }
+ return ignored();
+ }
+};
+
+struct if_then_helper : proto::extends< proto::terminal<if_then_tag>::type, if_then_helper >
+{
+ template <class Arg1,class Arg2,class Arg3,class Arg4>
+ struct In {typedef if_then_<Arg1,Arg2> type;};
+};
+if_then_helper const if_;
+
+
+template <class Condition,class IfClause,class ElseClause>
+struct if_then_else
+{
+ template<class Sig> struct result;
+ template<class This,class B, class A0>
+ struct result<This(B& block,A0& a0)>
+ {
+ static B& block;
+ static A0& a0;
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,IfClause()(block,a0))
+ typedef typename nested::type type;
+ };
+ template<class This,class B, class A0, class A1>
+ struct result<This(B& block,A0& a0,A1& a1)>
+ {
+ static B& block;
+ static A0& a0;
+ static A1& a1;
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,IfClause()(block,a0,a1))
+ typedef typename nested::type type;
+ };
+ template<typename B,typename A0>
+ typename boost::result_of<if_then_else(B&,A0&)>::type
+ operator()(B& block, A0 & a0)const
+ {
+ if (Condition()(block,a0))
+ {
+ return IfClause()(block,a0);
+ }
+ else
+ {
+ return ElseClause()(block,a0);
+ }
+ }
+ template<typename B,typename A0,typename A1>
+ typename boost::result_of<if_then_else(B&,A0&,A1&)>::type
+ operator()(B& block, A0 & a0, A0 & a1)const
+ {
+ if (Condition()(block,a0,a1))
+ {
+ return IfClause()(block,a0,a1);
+ }
+ else
+ {
+ return ElseClause()(block,a0,a1);
+ }
+ }
+};
+
+
+struct BuildLambda;
+
+struct BuildLambdaSequence
+ : proto::or_<
+ proto::when< proto::comma< BuildLambdaSequence, BuildLambdaSequence >,
+ proto::fold_tree<
+ proto::_
+ , ::boost::mpl::vector0<>()
+ , ::boost::mpl::push_back<proto::_state, BuildLambda(proto::_) >()
+ >
+
+ >,
+ proto::when< BuildLambda,
+ ::boost::mpl::vector1<BuildLambda>()
+ >
+ >
+{};
+
+
+struct BuildLambdaCases
+{
+ // The primary template matches nothing:
+ template<typename Tag>
+ struct case_
+ : proto::not_<proto::_>
+ {};
+};
+
+template<>
+struct BuildLambdaCases::case_<proto::tag::terminal>
+ : proto::or_<
+ proto::when<
+ proto::terminal< proto::_ >,
+ proto::_child
+ >
+ >
+{};
+
+template<>
+struct BuildLambdaCases::case_<proto::tag::function>
+ : proto::or_<
+ proto::when<
+ proto::function<proto::terminal<proto::_> >,
+ get_fct< proto::_child_c<0> >()
+ >,
+ proto::when<
+ proto::function<proto::terminal<proto::_>,BuildLambda >,
+ get_fct<proto::_child_c<0>,BuildLambda(proto::_child_c<1>) >()
+ >,
+ proto::when<
+ proto::function<proto::terminal<proto::_>,BuildLambda,BuildLambda >,
+ get_fct<proto::_child_c<0>,BuildLambda(proto::_child_c<1>),BuildLambda(proto::_child_c<2>) >()
+ >,
+ proto::when<
+ proto::function<proto::terminal<proto::_>,BuildLambda,BuildLambda,BuildLambda >,
+ get_fct<proto::_child_c<0>,BuildLambda(proto::_child_c<1>),BuildLambda(proto::_child_c<2>),
+ BuildLambda(proto::_child_c<3>) >()
+ >,
+ proto::when<
+ proto::function<proto::terminal<proto::_>,BuildLambda,BuildLambda,BuildLambda,BuildLambda >,
+ get_fct<proto::_child_c<0>,BuildLambda(proto::_child_c<1>),BuildLambda(proto::_child_c<2>),
+ BuildLambda(proto::_child_c<3>),BuildLambda(proto::_child_c<4>) >()
+ >
+ >
+{};
+
+struct IfThenCondition:
+ proto::when<
+ proto::function<proto::terminal<if_then_tag>,BuildLambdaSequence >,
+ if_then_< LambdaSequence_<BuildLambdaSequence(proto::_child_c<1>)>() >()
+
+ >
+{};
+struct IfThenGrammar:
+ proto::when<
+ proto::subscript< IfThenCondition , BuildLambdaSequence >,
+ if_then_< get_condition<IfThenCondition(proto::_child_c<0>)>(),
+ LambdaSequence_<BuildLambdaSequence(proto::_child_c<1>)>() >()
+ >
+{};
+struct IfThenElseGrammar:
+ proto::when<
+ proto::subscript< IfThenGrammar , BuildLambdaSequence >,
+ if_then_else< get_condition<IfThenGrammar(proto::_child_c<0>)>,
+ get_ifclause<IfThenGrammar(proto::_child_c<0>)>,
+ LambdaSequence_<BuildLambdaSequence(proto::_child_c<1>)>() >()
+ >
+{};
+template<>
+struct BuildLambdaCases::case_<proto::tag::subscript>
+ : proto::or_<
+ IfThenGrammar,
+ IfThenElseGrammar
+ >
+{};
+
+struct BuildLambda
+ : proto::switch_<BuildLambdaCases>
+{};
+
+struct params_tag{};
+// Eric Niebler's FoldToList
+struct FoldToList
+ : proto::or_<
+ // Don't add the params_ terminal to the list
+ proto::when<
+ proto::terminal< params_tag >
+ , proto::_state
+ >
+ // Put all other terminals at the head of the
+ // list that we're building in the "state" parameter
+ , proto::when<
+ proto::terminal< proto::_>
+ , boost::fusion::cons<proto::_value, proto::_state>(
+ proto::_value, proto::_state
+ )
+ >
+ // For left-shift operations, first fold the right
+ // child to a list using the current state. Use
+ // the result as the state parameter when folding
+ // the left child to a list.
+ , proto::when<
+ proto::shift_left<FoldToList, FoldToList>
+ , FoldToList(
+ proto::_left
+ , proto::call<FoldToList(proto::_right, proto::_state)>
+ )
+ >
+ >
+{};
+
+
+} } }// boost::msm::lpp
+#endif //BOOST_MSM_LPP_BASIC_GRAMMAR_H
+

Added: branches/msm/v2_30/boost/msm/lpp/common_types.hpp
==============================================================================
--- (empty file)
+++ branches/msm/v2_30/boost/msm/lpp/common_types.hpp 2011-03-10 16:54:00 EST (Thu, 10 Mar 2011)
@@ -0,0 +1,319 @@
+// Copyright 2011 Christophe Henry
+// henry UNDERSCORE christophe AT hotmail DOT com
+// 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_LPP_COMMON_TYPES_H
+#define BOOST_MSM_LPP_COMMON_TYPES_H
+
+
+#include <boost/fusion/container/vector.hpp>
+#include <boost/fusion/include/as_vector.hpp>
+
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/type_traits/add_reference.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/typeof/typeof.hpp>
+#include <boost/msm/lpp/basic_grammar.hpp>
+
+
+namespace boost { namespace msm { namespace lpp
+{
+
+struct lambda_tag{};
+
+template <class T>
+struct get_nested_type
+{
+ typedef typename ::boost::add_reference<typename T::type>::type type;
+};
+
+template<typename B,int position>
+struct lambda_parameter_result
+{
+ typedef typename ::boost::remove_reference<
+ typename boost::fusion::result_of::at_c<typename B::params,position>::type
+ >::type contained_type;
+
+ typedef typename boost::mpl::eval_if<
+ typename ::boost::is_reference_wrapper< contained_type >::type,
+ get_nested_type< contained_type >,
+ boost::fusion::result_of::at_c<typename B::params,position>
+ >::type type;
+};
+
+template<int I>
+struct lambda_parameter;
+
+template<>
+struct lambda_parameter<0>
+{
+ template<class Sig> struct result;
+ template<class This,class B, class A0>
+ struct result<This(B& block,A0& a0)>
+ {
+ static B& block;
+ static A0& a0;
+ typedef typename lambda_parameter_result<B,0>::type type;
+ };
+ template<class This,class B, class A0, class A1>
+ struct result<This(B& block,A0& a0,A1& a1)>
+ {
+ static B& block;
+ static A0& a0;
+ static A1& a1;
+ typedef typename lambda_parameter_result<B,0>::type type;
+ };
+
+ template<typename B,typename A0>
+ typename ::boost::enable_if<
+ typename ::boost::is_reference_wrapper< typename lambda_parameter_result<B,0>::contained_type >::type,
+ typename boost::result_of<lambda_parameter<0>(B&,A0&)>::type
+ >::type
+ operator ()(B& block, A0&) const
+ {
+ return boost::fusion::at_c<0>(block.lambda_params).get();
+ }
+
+ template<typename B,typename A0>
+ typename ::boost::disable_if<
+ typename ::boost::is_reference_wrapper< typename lambda_parameter_result<B,0>::contained_type >::type,
+ typename boost::result_of<lambda_parameter<0>(B&,A0&)>::type
+ >::type
+ operator ()(B& block, A0&) const
+ {
+ return boost::fusion::at_c<0>(block.lambda_params);
+ }
+ template<typename B,typename A0,typename A1>
+ typename ::boost::enable_if<
+ typename ::boost::is_reference_wrapper< typename lambda_parameter_result<B,0>::contained_type >::type,
+ typename boost::result_of<lambda_parameter<0>(B&,A0&,A1&)>::type
+ >::type
+ operator ()(B& block, A0&, A1&) const
+ {
+ return boost::fusion::at_c<0>(block.lambda_params).get();
+ }
+
+ template<typename B,typename A0,typename A1>
+ typename ::boost::disable_if<
+ typename ::boost::is_reference_wrapper< typename lambda_parameter_result<B,0>::contained_type >::type,
+ typename boost::result_of<lambda_parameter<0>(B&,A0&,A1&)>::type
+ >::type
+ operator ()(B& block, A0&, A1&) const
+ {
+ return boost::fusion::at_c<0>(block.lambda_params);
+ }
+};
+proto::terminal<lambda_parameter< 0 > >::type const _p1={{}};
+
+template<int I>
+struct placeholder;
+
+template<>
+struct placeholder<0>
+{
+ template<class Sig> struct result;
+ template<class This,class B, class A0>
+ struct result<This(B& block,A0& a0)>
+ {
+ static A0& a0;
+ typedef A0& type;
+ };
+ template<class This,class B, class A0, class A1>
+ struct result<This(B& block,A0& a0,A1& a1)>
+ {
+ static A0& a0;
+ typedef A0& type;
+ };
+ template<typename B,typename A0>
+ typename boost::result_of<placeholder<0>(B&,A0&)>::type
+ operator ()(B&, A0 &a0) const
+ {
+ return a0;
+ }
+ template<typename B,typename A0,typename A1>
+ typename boost::result_of<placeholder<0>(B&,A0&,A1&)>::type
+ operator ()(B&, A0 &a0, A1 &) const
+ {
+ return a0;
+ }
+};
+template<>
+struct placeholder<1>
+{
+ template<class Sig> struct result;
+ template<class This,class B, class A0, class A1>
+ struct result<This(B& block,A0& a0,A1& a1)>
+ {
+ static A0& a0;
+ static A1& a1;
+ typedef A1& type;
+ };
+
+ template<typename B,typename A0>
+ typename boost::result_of<placeholder<1>(B&,A0&)>::type
+ operator ()(B&,A0 &a0) const
+ {
+ //TODO error
+ }
+
+ template<typename B,typename A0, typename A1>
+ typename boost::result_of<placeholder<1>(B&,A0&,A1&)>::type
+ operator ()(B&,A0 &a0, A1 &a1) const
+ {
+ return a1;
+ }
+};
+
+
+// Define some lambda placeholders
+proto::terminal<placeholder< 0 > >::type const _1={{}};
+proto::terminal<placeholder< 1 > >::type const _2={{}};
+proto::terminal<params_tag>::type const _params={{}};
+
+
+
+template <class Seq = void, class Params = ::boost::fusion::vector0<> >
+struct Block
+{
+ typedef Seq sequence;
+ typedef Params params;
+
+ Block(){}
+ template <typename WithParams>
+ Block(WithParams const& p):lambda_params(p)
+ {
+ lambda_params = boost::fusion::as_vector(p);
+ }
+
+ template<class Sig> struct result;
+ template<class This, class A0>
+ struct result<This(A0& a0)>
+ {
+ static Block<Seq,Params>& block;
+ static A0& a0;
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,Seq()(block,a0) )
+ typedef typename nested::type type;
+ };
+ template<class This, class A0, class A1>
+ struct result<This(A0& a0,A1& a1)>
+ {
+ static Block<Seq,Params>& block;
+ static A0& a0;
+ static A1& a1;
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,Seq()(block,a0,a1) )
+ typedef typename nested::type type;
+ };
+ template<typename A0>
+ typename boost::result_of<Block(A0&)>::type
+ operator()(A0 &a0)
+ {
+ return Seq()(*this,a0);
+ }
+ template<typename A0,typename A1>
+ typename boost::result_of<Block(A0&,A1&)>::type
+ operator()(A0 &a0,A1 &a1)
+ {
+ return Seq()(*this,a0,a1);
+ }
+ //attribute
+ params lambda_params;
+};
+
+
+struct BuildParams
+ : proto::or_<
+ proto::when<
+ proto::subscript< proto::terminal<lambda_tag> , FoldToList >,
+ FoldToList(proto::_child_c<1>, boost::fusion::nil())
+ >
+ >
+{};
+
+struct Lambda:
+ proto::when<
+ BuildLambdaSequence, LambdaSequence_<BuildLambdaSequence(proto::_child_c<1>) >()
+ >
+{};
+#define BOOST_MSM_LPP_LAMBDA_EXPR(expr) BOOST_TYPEOF( Lambda()(expr) )
+
+
+
+struct BuildLambdaWithParams
+ : proto::or_<
+ proto::when<
+ proto::subscript< proto::terminal<lambda_tag> ,BuildLambdaSequence>,
+ Block<LambdaSequence_<BuildLambdaSequence(proto::_child_c<1>) > >()
+ >,
+ proto::when<
+ proto::subscript< BuildParams , BuildLambdaSequence >,
+ Block<
+ LambdaSequence_<BuildLambdaSequence(proto::_child_c<1>)>,
+ boost::fusion::result_of::as_vector<BuildParams(proto::_child_c<0>)> >
+ ( (BuildParams(proto::_value) ) )
+ >
+ >
+{};
+
+template<typename Expr>
+struct lambda_expr;
+
+struct lambda_dom
+ : proto::domain<proto::pod_generator<lambda_expr>, BuildLambdaWithParams>
+{};
+
+template<typename Expr>
+struct lambda_expr
+{
+ BOOST_PROTO_BASIC_EXTENDS(Expr, lambda_expr<Expr>, lambda_dom)
+ BOOST_PROTO_EXTENDS_SUBSCRIPT()
+ template<class Sig> struct result;
+ template<class This,class B, class A0>
+ struct result<This(B& block,A0& a0)>
+ {
+ static A0& a0;
+ typedef A0& type;
+ };
+ template<typename A0>
+ typename ::boost::result_of<
+ typename ::boost::result_of<BuildLambdaWithParams(Expr,A0&)>::type (A0&)
+ >::type
+ operator()(A0 &a0)const
+ {
+ BOOST_MPL_ASSERT((proto::matches<Expr, BuildLambdaWithParams>));
+ return BuildLambdaWithParams()(*this)(a0);
+ }
+ template<typename A0>
+ typename ::boost::result_of<
+ typename ::boost::result_of<BuildLambdaWithParams(Expr,A0&)>::type (A0&)
+ >::type
+ operator()(A0 const &a0)const
+ {
+ BOOST_MPL_ASSERT((proto::matches<Expr, BuildLambdaWithParams>));
+ return BuildLambdaWithParams()(*this)(a0);
+ }
+
+ template<typename A0,typename A1>
+ typename ::boost::result_of<
+ typename ::boost::result_of<BuildLambdaWithParams(Expr,A0&,A1&)>::type (A0&,A1&)
+ >::type
+ operator()(A0 &a0,A1 &a1)const
+ {
+ BOOST_MPL_ASSERT((proto::matches<Expr, BuildLambdaWithParams>));
+ return BuildLambdaWithParams()(*this)(a0,a1);
+ }
+ template<typename A0,typename A1>
+ typename ::boost::result_of<
+ typename ::boost::result_of<BuildLambdaWithParams(Expr,A0&,A1&)>::type (A0&,A1&)
+ >::type
+ operator()(A0 const &a0,A1 const &a1)const
+ {
+ BOOST_MPL_ASSERT((proto::matches<Expr, BuildLambdaWithParams>));
+ return BuildLambdaWithParams()(*this)(a0,a1);
+ }
+};
+
+lambda_expr<proto::terminal<lambda_tag>::type> const lambda = {{{}}};
+
+} } }// boost::msm::lpp
+#endif //BOOST_MSM_LPP_COMMON_TYPES_H
+

Added: branches/msm/v2_30/boost/msm/lpp/function.hpp
==============================================================================
--- (empty file)
+++ branches/msm/v2_30/boost/msm/lpp/function.hpp 2011-03-10 16:54:00 EST (Thu, 10 Mar 2011)
@@ -0,0 +1,96 @@
+// Copyright 2011 Christophe Henry
+// henry UNDERSCORE christophe AT hotmail DOT com
+// 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_LPP_FUNCTION_H
+#define BOOST_MSM_LPP_FUNCTION_H
+
+#include <boost/preprocessor/tuple/elem.hpp>
+#include <boost/preprocessor/punctuation/comma_if.hpp>
+#include <boost/preprocessor/repetition/enum.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
+
+
+namespace boost { namespace msm { namespace lpp
+{
+
+// user-defined functions
+//todo variadic macro for number of arguments
+#define BOOST_MSM_LPP_FUNCTION(funcname,userfunc) \
+template <class Param1=void , class Param2=void , class Param3=void , class Param4=void> \
+struct funcname ## impl : proto::extends< proto::terminal< boost::msm::lpp::action_tag>::type, \
+ funcname ## impl<Param1,Param2,Param3,Param4> >{}; \
+template < > struct funcname ## impl< void,void,void,void> \
+ : proto::extends< proto::terminal<boost::msm::lpp::action_tag>::type, funcname ## impl<void,void,void,void> > \
+{ \
+ template<class Sig> struct result; \
+ template<class This,class B, class A0> \
+ struct result<This(B& block,A0& a0)> \
+ { \
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,userfunc()) \
+ typedef typename nested::type type; \
+ }; \
+ template<class This,class B, class A0, class A1> \
+ struct result<This(B& block,A0& a0,A1& a1)> \
+ { \
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,userfunc()) \
+ typedef typename nested::type type; \
+ }; \
+ template<typename B,typename A0> \
+ typename boost::result_of<funcname ## impl(B&,A0&)>::type \
+ operator()(B& block, A0 &)const \
+ { \
+ return userfunc(); \
+ } \
+ template<typename B,typename A0,typename A1> \
+ typename boost::result_of<funcname ## impl(B&,A0&,A1&)>::type \
+ operator()(B& block, A0 &, A1 &)const \
+ { \
+ return userfunc(); \
+ } \
+}; \
+template < class Param1 > struct funcname ## impl< Param1, void,void,void> \
+ : proto::extends< proto::terminal<boost::msm::lpp::action_tag>::type, funcname ## impl<Param1, void,void,void> > \
+{ \
+ template<class Sig> struct result; \
+ template<class This,class B, class A0> \
+ struct result<This(B& block,A0& a0)> \
+ { \
+ static B& block; \
+ static A0& a0; \
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,userfunc(Param1()(block,a0))) \
+ typedef typename nested::type type; \
+ }; \
+ template<class This,class B, class A0, class A1> \
+ struct result<This(B& block,A0& a0,A1& a1)> \
+ { \
+ static B& block; \
+ static A0& a0; \
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,userfunc(Param1()(block,a0))) \
+ typedef typename nested::type type; \
+ }; \
+ template<typename B,typename A0> \
+ typename boost::result_of<funcname ## impl(B&,A0&)>::type \
+ operator()(B& block, A0 & a0)const \
+ { \
+ return userfunc(Param1()(block,a0)); \
+ } \
+ template<typename B,typename A0,typename A1> \
+ typename boost::result_of<funcname ## impl(B&,A0&,A1&)>::type \
+ operator()(B& block, A0 & a0, A1 & a1)const \
+ { \
+ return userfunc(Param1()(block,a0,a1)); \
+ } \
+}; \
+struct funcname ## helper : proto::extends< proto::terminal< boost::msm::lpp::action_tag >::type,funcname ## helper> \
+{ \
+ funcname ## helper(){} \
+ template <class Arg1,class Arg2,class Arg3,class Arg4> \
+ struct In {typedef funcname ## impl<Arg1,Arg2,Arg3,Arg4> type;}; \
+}; \
+funcname ## helper const funcname;
+
+} } }// boost::msm::lpp
+#endif //BOOST_MSM_LPP_OPERATOR_H
+

Added: branches/msm/v2_30/boost/msm/lpp/lpp.hpp
==============================================================================
--- (empty file)
+++ branches/msm/v2_30/boost/msm/lpp/lpp.hpp 2011-03-10 16:54:00 EST (Thu, 10 Mar 2011)
@@ -0,0 +1,17 @@
+// Copyright 2011 Christophe Henry
+// henry UNDERSCORE christophe AT hotmail DOT com
+// 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_LPP_LPP_H
+#define BOOST_MSM_LPP_LPP_H
+
+//include everything (at cost of longer compile)
+
+#include <boost/msm/lpp/basic_grammar.hpp>
+#include <boost/msm/lpp/operator.hpp>
+#include <boost/msm/lpp/common_types.hpp>
+#include <boost/msm/lpp/function.hpp>
+
+
+#endif //BOOST_MSM_LPP_LPP_H
+

Added: branches/msm/v2_30/boost/msm/lpp/operator.hpp
==============================================================================
--- (empty file)
+++ branches/msm/v2_30/boost/msm/lpp/operator.hpp 2011-03-10 16:54:00 EST (Thu, 10 Mar 2011)
@@ -0,0 +1,180 @@
+// Copyright 2011 Christophe Henry
+// henry UNDERSCORE christophe AT hotmail DOT com
+// 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_LPP_OPERATOR_H
+#define BOOST_MSM_LPP_OPERATOR_H
+
+#include <boost/preprocessor/tuple/elem.hpp>
+#include <boost/preprocessor/punctuation/comma_if.hpp>
+#include <boost/preprocessor/repetition/enum.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
+
+#include <boost/msm/lpp/basic_grammar.hpp>
+
+namespace boost { namespace msm { namespace lpp
+{
+
+#define BOOST_MSM_LPP_ARGS_HELPER(z, n, unused) ARG ## n & t ## n
+#define BOOST_MSM_LPP_ARGS_HELPER2(z, n, unused) static ARG ## n & t ## n;
+#define BOOST_MSM_LPP_ARGS_HELPER3(z, n, unused) t ## n
+#define BOOST_MSM_LPP_ARGS_HELPER4(z, n, unused) ARG ## n &
+
+#define BOOST_MSM_LPP_BINARY_OPERATOR_EXECUTE(z, n, data) \
+ template <class This,class B BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class ARG)> \
+ struct result<This(B& block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER, ~ ) )> \
+ { \
+ static B& block; \
+ BOOST_PP_REPEAT(n, BOOST_MSM_LPP_ARGS_HELPER2, ~) \
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,T1()(block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER3, ~ )) BOOST_PP_TUPLE_ELEM(2, 1, data) T2()(block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER3, ~ ))) \
+ typedef typename nested::type type; \
+ }; \
+ template<typename B BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class ARG)> \
+ typename boost::result_of<BOOST_PP_TUPLE_ELEM(2, 0, data)(B& BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER4, ~ ) )>::type \
+ operator()(B& block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER, ~ ) )const \
+ { \
+ return T1()(block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER3, ~ ) ) BOOST_PP_TUPLE_ELEM(2, 1, data) T2()(block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER3, ~ )); \
+ }
+
+
+#define BOOST_MSM_LPP_BINARY_OPERATOR(functor,op) \
+template <class T1,class T2> \
+struct functor ## _ : proto::extends<typename proto::terminal<action_tag>::type, functor ## _<T1,T2> > \
+{ \
+ template<class Sig> struct result; \
+ BOOST_PP_REPEAT(5, BOOST_MSM_LPP_BINARY_OPERATOR_EXECUTE, (functor ## _ ,op) ) \
+}; \
+template<> struct BuildLambdaCases::case_<proto::tag::functor> \
+ : proto::when< \
+ proto::functor<BuildLambda,BuildLambda >, \
+ functor ## _<BuildLambda(proto::_left),BuildLambda(proto::_right)>() \
+ >{};
+
+// binary operators
+BOOST_MSM_LPP_BINARY_OPERATOR(shift_left,<<)
+BOOST_MSM_LPP_BINARY_OPERATOR(shift_right,>>)
+BOOST_MSM_LPP_BINARY_OPERATOR(multiplies,*)
+BOOST_MSM_LPP_BINARY_OPERATOR(divides,/)
+BOOST_MSM_LPP_BINARY_OPERATOR(modulus,%)
+BOOST_MSM_LPP_BINARY_OPERATOR(plus,+)
+BOOST_MSM_LPP_BINARY_OPERATOR(minus,-)
+BOOST_MSM_LPP_BINARY_OPERATOR(less,<)
+BOOST_MSM_LPP_BINARY_OPERATOR(greater,>)
+BOOST_MSM_LPP_BINARY_OPERATOR(less_equal,<=)
+BOOST_MSM_LPP_BINARY_OPERATOR(greater_equal,>=)
+BOOST_MSM_LPP_BINARY_OPERATOR(equal_to,==)
+BOOST_MSM_LPP_BINARY_OPERATOR(not_equal_to,!=)
+BOOST_MSM_LPP_BINARY_OPERATOR(logical_or,||)
+BOOST_MSM_LPP_BINARY_OPERATOR(logical_and,&&)
+BOOST_MSM_LPP_BINARY_OPERATOR(bitwise_and,&)
+BOOST_MSM_LPP_BINARY_OPERATOR(bitwise_or,|)
+BOOST_MSM_LPP_BINARY_OPERATOR(bitwise_xor,^)
+// not comma, used as ;
+BOOST_MSM_LPP_BINARY_OPERATOR(mem_ptr,->*)
+BOOST_MSM_LPP_BINARY_OPERATOR(assign,=)
+BOOST_MSM_LPP_BINARY_OPERATOR(shift_left_assign,>>=)
+BOOST_MSM_LPP_BINARY_OPERATOR(shift_right_assign,<<=)
+BOOST_MSM_LPP_BINARY_OPERATOR(multiplies_assign,*=)
+BOOST_MSM_LPP_BINARY_OPERATOR(divides_assign,/=)
+BOOST_MSM_LPP_BINARY_OPERATOR(modulus_assign,%=)
+BOOST_MSM_LPP_BINARY_OPERATOR(plus_assign,+=)
+BOOST_MSM_LPP_BINARY_OPERATOR(minus_assign,-=)
+BOOST_MSM_LPP_BINARY_OPERATOR(bitwise_and_assign,&=)
+BOOST_MSM_LPP_BINARY_OPERATOR(bitwise_or_assign,|=)
+BOOST_MSM_LPP_BINARY_OPERATOR(bitwise_xor_assign,^=)
+
+
+
+#undef BOOST_MSM_LPP_BINARY_OPERATOR_EXECUTE
+#undef BOOST_MSM_LPP_BINARY_OPERATOR
+
+#define BOOST_MSM_LPP_PRE_UNARY_OPERATOR_EXECUTE(z, n, data) \
+ template <class This,class B BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class ARG)> \
+ struct result<This(B& block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER, ~ ) )> \
+ { \
+ static B& block; \
+ BOOST_PP_REPEAT(n, BOOST_MSM_LPP_ARGS_HELPER2, ~) \
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,BOOST_PP_TUPLE_ELEM(2, 1, data)T1()(block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER3, ~ )) ) \
+ typedef typename nested::type type; \
+ }; \
+ template<typename B BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class ARG)> \
+ typename boost::result_of<BOOST_PP_TUPLE_ELEM(2, 0, data)(B& BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER4, ~ ) )>::type \
+ operator()(B& block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER, ~ ) )const \
+ { \
+ return BOOST_PP_TUPLE_ELEM(2, 1, data)T1()(block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER3, ~ ) ); \
+ }
+
+#define BOOST_MSM_LPP_PRE_UNARY_OPERATOR(functor,op) \
+template <class T1> \
+struct functor ## _ : proto::extends<typename proto::terminal<action_tag>::type, functor ## _ <T1> > \
+{ \
+ template<class Sig> struct result; \
+ BOOST_PP_REPEAT(5, BOOST_MSM_LPP_PRE_UNARY_OPERATOR_EXECUTE, (functor ## _ ,op) ) \
+}; \
+template<> struct BuildLambdaCases::case_<proto::tag::functor> \
+ : proto::when< \
+ proto::functor <BuildLambda >, \
+ functor ## _< BuildLambda(proto::_child)>() \
+ >{};
+
+// unary prefix operators
+BOOST_MSM_LPP_PRE_UNARY_OPERATOR(unary_plus,+)
+BOOST_MSM_LPP_PRE_UNARY_OPERATOR(negate,-)
+BOOST_MSM_LPP_PRE_UNARY_OPERATOR(dereference,*)
+BOOST_MSM_LPP_PRE_UNARY_OPERATOR(complement,~)
+BOOST_MSM_LPP_PRE_UNARY_OPERATOR(address_of,&)
+BOOST_MSM_LPP_PRE_UNARY_OPERATOR(logical_not,!)
+BOOST_MSM_LPP_PRE_UNARY_OPERATOR(pre_inc,++)
+BOOST_MSM_LPP_PRE_UNARY_OPERATOR(pre_dec,--)
+
+
+
+#undef BOOST_MSM_LPP_PRE_UNARY_OPERATOR_EXECUTE
+#undef BOOST_MSM_LPP_PRE_UNARY_OPERATOR
+
+
+#define BOOST_MSM_LPP_POST_UNARY_OPERATOR_EXECUTE(z, n, data) \
+ template <class This,class B BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class ARG)> \
+ struct result<This(B& block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER, ~ ) )> \
+ { \
+ static B& block; \
+ BOOST_PP_REPEAT(n, BOOST_MSM_LPP_ARGS_HELPER2, ~) \
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,T1()(block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER3, ~ ))BOOST_PP_TUPLE_ELEM(2, 1, data) ) \
+ typedef typename nested::type type; \
+ }; \
+ template<typename B BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class ARG)> \
+ typename boost::result_of<BOOST_PP_TUPLE_ELEM(2, 0, data)(B& BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER4, ~ ) )>::type \
+ operator()(B& block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER, ~ ) )const \
+ { \
+ return T1()(block BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, BOOST_MSM_LPP_ARGS_HELPER3, ~ ) )BOOST_PP_TUPLE_ELEM(2, 1, data); \
+ }
+
+#define BOOST_MSM_LPP_POST_UNARY_OPERATOR(functor,op) \
+template <class T1> \
+struct functor ## _ : proto::extends<typename proto::terminal<action_tag>::type, functor ## _<T1> > \
+{ \
+ template<class Sig> struct result; \
+ BOOST_PP_REPEAT(5, BOOST_MSM_LPP_POST_UNARY_OPERATOR_EXECUTE, (functor ## _ ,op) ) \
+}; \
+template<> struct BuildLambdaCases::case_<proto::tag::functor> \
+ : proto::when< \
+ proto::functor <BuildLambda >, \
+ functor ## _< BuildLambda(proto::_child)>() \
+ >{};
+
+// unary postfix operators
+BOOST_MSM_LPP_POST_UNARY_OPERATOR(post_inc,++)
+BOOST_MSM_LPP_POST_UNARY_OPERATOR(post_dec,--)
+
+#undef BOOST_MSM_LPP_POST_UNARY_OPERATOR_EXECUTE
+#undef BOOST_MSM_LPP_POST_UNARY_OPERATOR
+
+#undef BOOST_MSM_LPP_ARGS_HELPER
+#undef BOOST_MSM_LPP_ARGS_HELPER2
+#undef BOOST_MSM_LPP_ARGS_HELPER3
+#undef BOOST_MSM_LPP_ARGS_HELPER4
+
+} } }// boost::msm::lpp
+#endif //BOOST_MSM_LPP_OPERATOR_H
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk