os/ossrv/ossrv_pub/boost_apis/boost/spirit/phoenix/primitives.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/spirit/phoenix/primitives.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,248 @@
     1.4 +/*=============================================================================
     1.5 +    Phoenix V1.2.1
     1.6 +    Copyright (c) 2001-2002 Joel de Guzman
     1.7 +
     1.8 +    Use, modification and distribution is subject to the Boost Software
     1.9 +    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    1.10 +    http://www.boost.org/LICENSE_1_0.txt)
    1.11 +==============================================================================*/
    1.12 +#ifndef PHOENIX_PRIMITIVES_HPP
    1.13 +#define PHOENIX_PRIMITIVES_HPP
    1.14 +
    1.15 +///////////////////////////////////////////////////////////////////////////////
    1.16 +#include <boost/spirit/phoenix/actor.hpp>
    1.17 +
    1.18 +///////////////////////////////////////////////////////////////////////////////
    1.19 +namespace phoenix {
    1.20 +
    1.21 +///////////////////////////////////////////////////////////////////////////////
    1.22 +//
    1.23 +//  argument class
    1.24 +//
    1.25 +//      Lazy arguments
    1.26 +//
    1.27 +//      An actor base class that extracts and returns the Nth argument
    1.28 +//      from the argument list passed in the 'args' tuple in the eval
    1.29 +//      member function (see actor.hpp). There are some predefined
    1.30 +//      argument constants that can be used as actors (arg1..argN).
    1.31 +//
    1.32 +//      The argument actor is a place-holder for the actual arguments
    1.33 +//      passed by the client. For example, wherever arg1 is seen placed
    1.34 +//      in a lazy function (see functions.hpp) or lazy operator (see
    1.35 +//      operators.hpp), this will be replaced by the actual first
    1.36 +//      argument in the actual function evaluation. Argument actors are
    1.37 +//      essentially lazy arguments. A lazy argument is a full actor in
    1.38 +//      its own right and can be evaluated through the actor's operator().
    1.39 +//
    1.40 +//      Example:
    1.41 +//
    1.42 +//          char        c = 'A';
    1.43 +//          int         i = 123;
    1.44 +//          const char* s = "Hello World";
    1.45 +//
    1.46 +//          cout << arg1(c) << ' ';
    1.47 +//          cout << arg1(i, s) << ' ';
    1.48 +//          cout << arg2(i, s) << ' ';
    1.49 +//
    1.50 +//       will print out "A 123 Hello World"
    1.51 +//
    1.52 +///////////////////////////////////////////////////////////////////////////////
    1.53 +template <int N>
    1.54 +struct argument {
    1.55 +
    1.56 +    template <typename TupleT>
    1.57 +    struct result { typedef typename tuple_element<N, TupleT>::type type; };
    1.58 +
    1.59 +    template <typename TupleT>
    1.60 +    typename tuple_element<N, TupleT>::type
    1.61 +    eval(TupleT const& args) const
    1.62 +    {
    1.63 +        return args[tuple_index<N>()];
    1.64 +    }
    1.65 +};
    1.66 +
    1.67 +//////////////////////////////////
    1.68 +actor<argument<0> > const arg1 = argument<0>();
    1.69 +actor<argument<1> > const arg2 = argument<1>();
    1.70 +actor<argument<2> > const arg3 = argument<2>();
    1.71 +
    1.72 +#if PHOENIX_LIMIT > 3
    1.73 +actor<argument<3> > const arg4 = argument<3>();
    1.74 +actor<argument<4> > const arg5 = argument<4>();
    1.75 +actor<argument<5> > const arg6 = argument<5>();
    1.76 +
    1.77 +#if PHOENIX_LIMIT > 6
    1.78 +actor<argument<6> > const arg7 = argument<6>();
    1.79 +actor<argument<7> > const arg8 = argument<7>();
    1.80 +actor<argument<8> > const arg9 = argument<8>();
    1.81 +
    1.82 +#if PHOENIX_LIMIT > 9
    1.83 +actor<argument<9> > const arg10 = argument<9>();
    1.84 +actor<argument<10> > const arg11 = argument<10>();
    1.85 +actor<argument<11> > const arg12 = argument<11>();
    1.86 +
    1.87 +#if PHOENIX_LIMIT > 12
    1.88 +actor<argument<12> > const arg13 = argument<12>();
    1.89 +actor<argument<13> > const arg14 = argument<13>();
    1.90 +actor<argument<14> > const arg15 = argument<14>();
    1.91 +
    1.92 +#endif
    1.93 +#endif
    1.94 +#endif
    1.95 +#endif
    1.96 +///////////////////////////////////////////////////////////////////////////////
    1.97 +//
    1.98 +//  value class
    1.99 +//
   1.100 +//      Lazy values
   1.101 +//
   1.102 +//      A bound actual parameter is kept in a value class for deferred
   1.103 +//      access later when needed. A value object is immutable. Value
   1.104 +//      objects are typically created through the val(x) free function
   1.105 +//      which returns a value<T> with T deduced from the type of x. x is
   1.106 +//      held in the value<T> object by value.
   1.107 +//
   1.108 +//      Lazy values are actors. As such, lazy values can be evaluated
   1.109 +//      through the actor's operator(). Such invocation gives the value's
   1.110 +//      identity. Example:
   1.111 +//
   1.112 +//          cout << val(3)() << val("Hello World")();
   1.113 +//
   1.114 +//      prints out "3 Hello World"
   1.115 +//
   1.116 +///////////////////////////////////////////////////////////////////////////////
   1.117 +template <typename T>
   1.118 +struct value {
   1.119 +
   1.120 +    typedef typename boost::remove_reference<T>::type plain_t;
   1.121 +
   1.122 +    template <typename TupleT>
   1.123 +    struct result { typedef plain_t const type; };
   1.124 +
   1.125 +    value(plain_t val_)
   1.126 +    :   val(val_) {}
   1.127 +
   1.128 +    template <typename TupleT>
   1.129 +    plain_t const
   1.130 +    eval(TupleT const& /*args*/) const
   1.131 +    {
   1.132 +        return val;
   1.133 +    }
   1.134 +
   1.135 +    plain_t val;
   1.136 +};
   1.137 +
   1.138 +//////////////////////////////////
   1.139 +template <typename T>
   1.140 +inline actor<value<T> > const
   1.141 +val(T v)
   1.142 +{
   1.143 +    return value<T>(v);
   1.144 +}
   1.145 +
   1.146 +//////////////////////////////////
   1.147 +template <typename BaseT>
   1.148 +void
   1.149 +val(actor<BaseT> const& v);     //  This is undefined and not allowed.
   1.150 +
   1.151 +///////////////////////////////////////////////////////////////////////////
   1.152 +//
   1.153 +//  Arbitrary types T are typically converted to a actor<value<T> >
   1.154 +//  (see as_actor<T> in actor.hpp). A specialization is also provided
   1.155 +//  for arrays. T[N] arrays are converted to actor<value<T const*> >.
   1.156 +//
   1.157 +///////////////////////////////////////////////////////////////////////////
   1.158 +template <typename T>
   1.159 +struct as_actor {
   1.160 +
   1.161 +    typedef actor<value<T> > type;
   1.162 +    static type convert(T const& x)
   1.163 +    { return value<T>(x); }
   1.164 +};
   1.165 +
   1.166 +//////////////////////////////////
   1.167 +template <typename T, int N>
   1.168 +struct as_actor<T[N]> {
   1.169 +
   1.170 +    typedef actor<value<T const*> > type;
   1.171 +    static type convert(T const x[N])
   1.172 +    { return value<T const*>(x); }
   1.173 +};
   1.174 +
   1.175 +///////////////////////////////////////////////////////////////////////////////
   1.176 +//
   1.177 +//  variable class
   1.178 +//
   1.179 +//      Lazy variables
   1.180 +//
   1.181 +//      A bound actual parameter may also be held by non-const reference
   1.182 +//      in a variable class for deferred access later when needed. A
   1.183 +//      variable object is mutable, i.e. its referenced variable can be
   1.184 +//      modified. Variable objects are typically created through the
   1.185 +//      var(x) free function which returns a variable<T> with T deduced
   1.186 +//      from the type of x. x is held in the value<T> object by
   1.187 +//      reference.
   1.188 +//
   1.189 +//      Lazy variables are actors. As such, lazy variables can be
   1.190 +//      evaluated through the actor's operator(). Such invocation gives
   1.191 +//      the variables's identity. Example:
   1.192 +//
   1.193 +//          int i = 3;
   1.194 +//          char const* s = "Hello World";
   1.195 +//          cout << var(i)() << var(s)();
   1.196 +//
   1.197 +//      prints out "3 Hello World"
   1.198 +//
   1.199 +//      Another free function const_(x) may also be used. const_(x) creates
   1.200 +//      a variable<T const&> object using a constant reference.
   1.201 +//
   1.202 +///////////////////////////////////////////////////////////////////////////////
   1.203 +template <typename T>
   1.204 +struct variable {
   1.205 +
   1.206 +    template <typename TupleT>
   1.207 +    struct result { typedef T& type; };
   1.208 +
   1.209 +    variable(T& var_)
   1.210 +    :   var(var_) {}
   1.211 +
   1.212 +    template <typename TupleT>
   1.213 +    T&
   1.214 +    eval(TupleT const& /*args*/) const
   1.215 +    {
   1.216 +        return var;
   1.217 +    }
   1.218 +
   1.219 +    T& var;
   1.220 +};
   1.221 +
   1.222 +//////////////////////////////////
   1.223 +template <typename T>
   1.224 +inline actor<variable<T> > const
   1.225 +var(T& v)
   1.226 +{
   1.227 +    return variable<T>(v);
   1.228 +}
   1.229 +
   1.230 +//////////////////////////////////
   1.231 +template <typename T>
   1.232 +inline actor<variable<T const> > const
   1.233 +const_(T const& v)
   1.234 +{
   1.235 +    return variable<T const>(v);
   1.236 +}
   1.237 +
   1.238 +//////////////////////////////////
   1.239 +template <typename BaseT>
   1.240 +void
   1.241 +var(actor<BaseT> const& v);     //  This is undefined and not allowed.
   1.242 +
   1.243 +//////////////////////////////////
   1.244 +template <typename BaseT>
   1.245 +void
   1.246 +const_(actor<BaseT> const& v);  //  This is undefined and not allowed.
   1.247 +
   1.248 +///////////////////////////////////////////////////////////////////////////////
   1.249 +}   //  namespace phoenix
   1.250 +
   1.251 +#endif