PageRenderTime 37ms CodeModel.GetById 30ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/boost/spirit/home/phoenix/core/argument.hpp

http://pythonocc.googlecode.com/
C++ Header | 89 lines | 68 code | 11 blank | 10 comment | 0 complexity | dbbbdedf578db8cc54174270a4f86b25 MD5 | raw file
 1/*=============================================================================
 2    Copyright (c) 2001-2007 Joel de Guzman
 3
 4    Distributed under the Boost Software License, Version 1.0. (See accompanying 
 5    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 6==============================================================================*/
 7#ifndef PHOENIX_CORE_ARGUMENT_HPP
 8#define PHOENIX_CORE_ARGUMENT_HPP
 9
10#include <boost/preprocessor/repetition/repeat_from_to.hpp>
11#include <boost/preprocessor/inc.hpp>
12#include <boost/spirit/home/phoenix/core/actor.hpp>
13#include <boost/fusion/include/at.hpp>
14#include <boost/mpl/if.hpp>
15#include <boost/mpl/eval_if.hpp>
16#include <boost/mpl/identity.hpp>
17#include <boost/mpl/less.hpp>
18#include <boost/mpl/bool.hpp>
19#include <boost/mpl/int.hpp>
20#include <boost/mpl/at.hpp>
21#include <boost/mpl/size.hpp>
22#include <boost/type_traits/add_reference.hpp>
23
24#define PHOENIX_DECLARE_ARG(z, n, data)                                         \
25    actor<argument<n> > const                                                   \
26        BOOST_PP_CAT(arg, BOOST_PP_INC(n)) = argument<n>();                     \
27    actor<argument<n> > const                                                   \
28        BOOST_PP_CAT(_, BOOST_PP_INC(n)) = argument<n>();
29
30namespace boost { namespace phoenix
31{
32    namespace detail
33    {
34        template <typename Arg>
35        struct error_argument_not_found {};
36        inline void test_invalid_argument(int) {}
37    }
38
39    template <int N>
40    struct argument
41    {
42        typedef mpl::true_ no_nullary;
43
44        template <typename Env>
45        struct result
46        {
47            typedef typename
48                fusion::result_of::at<typename Env::tie_type, mpl::int_<N> >::type
49            type;
50        };
51
52        template <typename Env>
53        typename result<Env>::type
54        eval(Env const& env) const
55        {
56            typedef typename
57                mpl::if_<
58                    mpl::less<mpl::int_<N>, mpl::size<typename Env::args_type> >
59                  , int
60                  , detail::error_argument_not_found<argument<N> >
61                >::type
62            check_out_of_bounds;
63
64            detail::test_invalid_argument(check_out_of_bounds());
65            return fusion::at_c<N>(env.args());
66        }
67    };
68
69    namespace arg_names
70    {
71    //  Phoenix style names
72        actor<argument<0> > const arg1 = argument<0>();
73        actor<argument<1> > const arg2 = argument<1>();
74        actor<argument<2> > const arg3 = argument<2>();
75
76    //  BLL style names
77        actor<argument<0> > const _1 = argument<0>();
78        actor<argument<1> > const _2 = argument<1>();
79        actor<argument<2> > const _3 = argument<2>();
80
81    //  Bring in the rest or the Phoenix style arguments (arg4 .. argN+1)
82    //  and BLL style arguments (_4 .. _N+1), using PP
83        BOOST_PP_REPEAT_FROM_TO(
84            3, PHOENIX_ARG_LIMIT, PHOENIX_DECLARE_ARG, _)
85    }
86}}
87
88#undef PHOENIX_DECLARE_ARG
89#endif