PageRenderTime 43ms CodeModel.GetById 36ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/spirit/home/phoenix/core/argument.hpp

http://hadesmem.googlecode.com/
C++ Header | 99 lines | 78 code | 11 blank | 10 comment | 0 complexity | 08028452fca9d56f13c28a68afcabf91 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    typedef actor<argument<n> >                                               \
26        BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(n)), _type);              \
27    actor<argument<n> > const                                                 \
28        BOOST_PP_CAT(arg, BOOST_PP_INC(n)) = argument<n>();                   \
29    typedef actor<argument<n> >                                               \
30        BOOST_PP_CAT(BOOST_PP_CAT(_, BOOST_PP_INC(n)), _type);                \
31    actor<argument<n> > const                                                 \
32        BOOST_PP_CAT(_, BOOST_PP_INC(n)) = argument<n>();
33
34namespace boost { namespace phoenix
35{
36    namespace detail
37    {
38        template <typename Arg>
39        struct error_argument_not_found {};
40        inline void test_invalid_argument(int) {}
41    }
42
43    template <int N>
44    struct argument
45    {
46        typedef mpl::true_ no_nullary;
47
48        template <typename Env>
49        struct result
50        {
51            typedef typename
52                fusion::result_of::at<typename Env::tie_type, mpl::int_<N> >::type
53            type;
54        };
55
56        template <typename Env>
57        typename result<Env>::type
58        eval(Env const& env) const
59        {
60            typedef typename
61                mpl::if_<
62                    mpl::less<mpl::int_<N>, mpl::size<typename Env::args_type> >
63                  , int
64                  , detail::error_argument_not_found<argument<N> >
65                >::type
66            check_out_of_bounds;
67
68            detail::test_invalid_argument(check_out_of_bounds());
69            return fusion::at_c<N>(env.args());
70        }
71    };
72
73    namespace arg_names
74    {
75    //  Phoenix style names
76        typedef actor<argument<0> > arg1_type;
77        actor<argument<0> > const arg1 = argument<0>();
78        typedef actor<argument<1> > arg2_type;
79        actor<argument<1> > const arg2 = argument<1>();
80        typedef actor<argument<2> > arg3_type;
81        actor<argument<2> > const arg3 = argument<2>();
82
83    //  BLL style names
84        typedef actor<argument<0> > _1_type;
85        actor<argument<0> > const _1 = argument<0>();
86        typedef actor<argument<1> > _2_type;
87        actor<argument<1> > const _2 = argument<1>();
88        typedef actor<argument<2> > _3_type;
89        actor<argument<2> > const _3 = argument<2>();
90
91    //  Bring in the rest or the Phoenix style arguments (arg4 .. argN+1)
92    //  and BLL style arguments (_4 .. _N+1), using PP
93        BOOST_PP_REPEAT_FROM_TO(
94            3, PHOENIX_ARG_LIMIT, PHOENIX_DECLARE_ARG, _)
95    }
96}}
97
98#undef PHOENIX_DECLARE_ARG
99#endif