PageRenderTime 45ms CodeModel.GetById 31ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://pythonocc.googlecode.com/
C++ Header | 155 lines | 121 code | 25 blank | 9 comment | 1 complexity | 675084a8a146ed646c5a8eff5e8fe83e 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_VALUE_HPP
  8#define PHOENIX_CORE_VALUE_HPP
  9
 10#include <boost/spirit/home/phoenix/core/actor.hpp>
 11#include <boost/spirit/home/phoenix/core/as_actor.hpp>
 12#include <boost/static_assert.hpp>
 13
 14#include <boost/type_traits/is_reference.hpp>
 15#include <boost/type_traits/remove_reference.hpp>
 16#include <boost/type_traits/is_pointer.hpp>
 17#include <boost/type_traits/add_const.hpp>
 18#include <boost/type_traits/add_reference.hpp>
 19#include <boost/type_traits/remove_pointer.hpp>
 20#include <boost/type_traits/is_function.hpp>
 21
 22#include <boost/mpl/bool.hpp>
 23#include <boost/mpl/eval_if.hpp>
 24#include <boost/mpl/identity.hpp>
 25
 26namespace boost { namespace phoenix
 27{
 28    namespace meta
 29    {
 30        template<typename T>
 31        struct const_ref
 32            : add_reference<typename add_const<T>::type>
 33        {};
 34
 35        template<typename T>
 36        struct argument_type
 37            : mpl::eval_if<
 38            is_function<typename remove_pointer<T>::type>,
 39            mpl::identity<T>,
 40            const_ref<T> >
 41        {
 42            typedef T type;
 43        };
 44    }
 45
 46    template <typename T>
 47    struct value 
 48    {
 49        BOOST_STATIC_ASSERT(
 50            mpl::not_<is_reference<T> >::value != 0);
 51
 52        typedef mpl::false_ no_nullary;
 53
 54        template <typename Env>
 55        struct result
 56        {
 57            typedef T type;
 58        };
 59
 60        value(T const& arg)
 61            : val(arg) {}
 62
 63        template <typename Env>
 64        T const&
 65        eval(Env const&) const
 66        {
 67            return val;
 68        }
 69
 70        T val;
 71    };
 72
 73    template <typename Actor>
 74    struct actor_value 
 75    {
 76        typedef typename Actor::no_nullary no_nullary;
 77
 78        template <typename Env>
 79        struct result
 80        {
 81            typedef typename 
 82                remove_reference<
 83                    typename eval_result<Actor, Env>::type
 84                >::type
 85            type;
 86        };
 87
 88        actor_value(Actor const& actor)
 89            : actor(actor) {}
 90
 91        template <typename Env>
 92        typename result<Env>::type
 93        eval(Env const& env) const
 94        {
 95            return actor.eval(env);
 96        }
 97
 98        Actor actor;
 99    };
100
101    template <typename T>
102    inline typename as_actor<T>::type
103    val(T const& v)
104    {
105        return as_actor<T>::convert(v);
106    }
107
108    template <typename Derived>
109    inline actor<actor_value<Derived> >
110    val(actor<Derived> const& actor)
111    {
112        return actor_value<Derived>(actor);
113    }
114
115    template <typename T>
116    struct as_actor_base
117    {
118        typedef value<T> type;
119
120        static value<T>
121        convert(typename meta::argument_type<T>::type x)
122        {
123            return value<T>(x);
124        }
125    };
126
127    // Sometimes it is necessary to auto-convert references to 
128    // a value<T>. This happens when we are re-currying. This
129    // cannot happen through the standard public actor interfaces.
130    template <typename T>
131    struct as_actor_base<T&>
132    {
133        typedef value<T> type;
134
135        static value<T>
136        convert(T& x)
137        {
138            return value<T>(x);
139        }
140    };
141
142    template <typename T, int N>
143    struct as_actor_base<T[N]>
144    {
145        typedef value<T const*> type;
146
147        static value<T const*>
148        convert(T const x[N])
149        {
150            return value<T const*>(x);
151        }
152    };
153}}
154
155#endif