PageRenderTime 38ms CodeModel.GetById 27ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://hadesmem.googlecode.com/
C++ Header | 194 lines | 142 code | 35 blank | 17 comment | 0 complexity | 07283f775706a2fae679604a9dd33261 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_ACTOR_HPP
  8#define PHOENIX_CORE_ACTOR_HPP
  9
 10#include <boost/spirit/home/phoenix/core/limits.hpp>
 11
 12#if !defined(BOOST_RESULT_OF_NUM_ARGS)
 13# define BOOST_RESULT_OF_NUM_ARGS PHOENIX_ACTOR_LIMIT
 14#elif (BOOST_RESULT_OF_NUM_ARGS < PHOENIX_ACTOR_LIMIT)
 15# error "BOOST_RESULT_OF_NUM_ARGS < PHOENIX_ACTOR_LIMIT"
 16#endif
 17
 18#include <boost/spirit/home/phoenix/core/basic_environment.hpp>
 19#include <boost/mpl/min.hpp>
 20#include <boost/mpl/identity.hpp>
 21#include <boost/type_traits/add_const.hpp>
 22#include <boost/type_traits/remove_reference.hpp>
 23#include <boost/utility/result_of.hpp>
 24
 25namespace boost { namespace phoenix
 26{
 27    // phoenix::void_ is the same as fusion::void_
 28    typedef fusion::void_ void_;
 29
 30    namespace detail
 31    {
 32        //  Forward declarations. These will come in when we get to the
 33        //  operator module, yet, the actor's assignment operator and index
 34        //  operator are required to be members.
 35
 36        template <typename T0, typename T1>
 37        struct make_assign_composite;
 38
 39        template <typename T0, typename T1>
 40        struct make_index_composite;
 41
 42        template <typename BaseT0, typename BaseT1>
 43        struct comma_result;
 44
 45        // error no arguments supplied
 46        struct error_expecting_arguments
 47        {
 48            template <typename T>
 49            error_expecting_arguments(T const&) {}
 50        };
 51    }
 52
 53    template <typename Eval, typename Env>
 54    struct eval_result
 55    {
 56        typedef typename Eval::template result<Env>::type type;
 57    };
 58
 59#if defined(BOOST_MSVC)
 60# pragma warning(push)
 61# pragma warning(disable: 4522) // multiple assignment operators specified warning
 62#endif
 63
 64    template <typename Eval>
 65    struct actor : Eval
 66    {
 67        typedef actor<Eval> self_type;
 68        typedef Eval eval_type;
 69
 70        template <class Sig> struct result {};
 71
 72        actor()
 73            : Eval() {}
 74
 75        actor(Eval const& base)
 76            : Eval(base) {}
 77
 78        template <typename T0>
 79        explicit actor(T0 const& _0)
 80            : Eval(_0) {}
 81
 82        template <typename T0, typename T1>
 83        actor(T0 const& _0, T1 const& _1)
 84            : Eval(_0, _1) {}
 85
 86        typedef typename
 87            mpl::eval_if<
 88                typename Eval::no_nullary // avoid calling eval_result when this is true
 89              , mpl::identity<detail::error_expecting_arguments>
 90              , eval_result<eval_type, basic_environment<> >
 91            >::type
 92        nullary_result;
 93
 94        actor& operator=(actor const& rhs)
 95        {
 96            Eval::operator=(rhs);
 97            return *this;
 98        }
 99
100        actor& operator=(actor& rhs)
101        {
102            Eval::operator=(rhs);
103            return *this;
104        }
105
106        nullary_result
107        operator()() const
108        {
109            return eval_type::eval(basic_environment<>());
110        }
111
112        template <class F, class A0>
113        struct result<F(A0)>
114          : eval_result<
115                eval_type
116              , basic_environment<
117                    typename remove_reference<A0>::type
118                >
119            >
120        {};
121
122        template <typename T0>
123        typename result<actor(T0&)>::type
124        operator()(T0& _0) const
125        {
126            return eval_type::eval(basic_environment<T0>(_0));
127        }
128
129        template <class F, class A0, class A1>
130        struct result<F(A0,A1)>
131          : eval_result<
132                eval_type
133              , basic_environment<
134                    typename remove_reference<A0>::type
135                  , typename remove_reference<A1>::type
136                >
137            >
138        {};
139
140        template <typename T0, typename T1>
141        typename result<actor(T0&,T1&)>::type
142        operator()(T0& _0, T1& _1) const
143        {
144            return eval_type::eval(basic_environment<T0, T1>(_0, _1));
145        }
146
147        template <typename T1>
148        typename detail::make_assign_composite<self_type, T1>::type
149        operator=(T1 const& a1) const;
150
151        template <typename T1>
152        typename detail::make_index_composite<self_type, T1>::type
153        operator[](T1 const& a1) const;
154
155        //  Bring in the rest of the constructors and function call operators
156        #include <boost/spirit/home/phoenix/core/detail/actor.hpp>
157    };
158
159#if defined(BOOST_MSVC)
160# pragma warning(pop)
161#endif
162
163    //  Forward declaration: The intent to overload the comma must be
164    //  stated early on to avoid the subtle problem that arises when
165    //  the header file where the comma operator overload is defined,
166    //  is not included by the client and the client attempts to use
167    //  the comma anyway.
168
169    namespace detail
170    {
171        template <typename BaseT0, typename BaseT1>
172        struct comma_result;
173    }
174
175    template <typename BaseT0, typename BaseT1>
176    typename detail::comma_result<BaseT0, BaseT1>::type
177    operator,(actor<BaseT0> const& a0, actor<BaseT1> const& a1);
178}}
179
180namespace boost
181{
182    template <typename Eval>
183    struct result_of<phoenix::actor<Eval>()>
184    {
185        typedef typename phoenix::actor<Eval>::nullary_result type;
186    };
187
188    template <typename Eval>
189    struct result_of<phoenix::actor<Eval> const()>
190        : result_of<phoenix::actor<Eval>()>
191    {};
192}
193
194#endif