📄 new.hpp
字号:
/*=============================================================================
Phoenix V1.2.1
Copyright (c) 2001-2003 Joel de Guzman
Copyright (c) 2001-2003 Hartmut Kaiser
Copyright (c) 2003 Vaclav Vesely
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#ifndef PHOENIX_NEW_HPP
#define PHOENIX_NEW_HPP
///////////////////////////////////////////////////////////////////////////////
#include <boost/spirit/phoenix/actor.hpp>
#include <boost/spirit/phoenix/composite.hpp>
#include <boost/static_assert.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace phoenix {
///////////////////////////////////////////////////////////////////////////////
//
// Phoenix predefined maximum new_ limit. This limit defines the maximum
// number of parameters supported for calles to the set of new_ template
// functions (lazy object construction, see below). This number defaults to 3.
// The actual maximum is rounded up in multiples of 3. Thus, if this value
// is 4, the actual limit is 6. The ultimate maximum limit in this
// implementation is 15.
// PHOENIX_CONSTRUCT_LIMIT should NOT be greater than PHOENIX_LIMIT!
#if !defined(PHOENIX_CONSTRUCT_LIMIT)
#define PHOENIX_CONSTRUCT_LIMIT PHOENIX_LIMIT
#endif
// ensure PHOENIX_CONSTRUCT_LIMIT <= PHOENIX_LIMIT
BOOST_STATIC_ASSERT(PHOENIX_CONSTRUCT_LIMIT <= PHOENIX_LIMIT);
// ensure PHOENIX_CONSTRUCT_LIMIT <= 15
BOOST_STATIC_ASSERT(PHOENIX_CONSTRUCT_LIMIT <= 15);
///////////////////////////////////////////////////////////////////////////////
//
// new_
//
// Lazy object construction
//
// The set of new_<> template classes and functions provide a way
// of lazily constructing certain object from a arbitrary set of
// actors during parsing.
// The new_ templates are (syntactically) used very much like
// the well known C++ casts:
//
// A *a = new_<A>(...arbitrary list of actors...);
//
// where the given parameters are submitted as parameters to the
// contructor of the object of type A. (This certainly implies, that
// type A has a constructor with a fitting set of parameter types
// defined.)
//
// The maximum number of needed parameters is controlled through the
// preprocessor constant PHOENIX_CONSTRUCT_LIMIT. Note though, that this
// limit should not be greater than PHOENIX_LIMIT.
//
///////////////////////////////////////////////////////////////////////////////
template <typename T>
struct new_l_0
{
typedef T* result_type;
T* operator()() const
{
return new T();
}
};
template <typename T>
struct new_l {
template <
typename A
, typename B
, typename C
#if PHOENIX_CONSTRUCT_LIMIT > 3
, typename D
, typename E
, typename F
#if PHOENIX_CONSTRUCT_LIMIT > 6
, typename G
, typename H
, typename I
#if PHOENIX_CONSTRUCT_LIMIT > 9
, typename J
, typename K
, typename L
#if PHOENIX_CONSTRUCT_LIMIT > 12
, typename M
, typename N
, typename O
#endif
#endif
#endif
#endif
>
struct result { typedef T* type; };
T* operator()() const {
return new T();
}
template <typename A>
T* operator()(A const& a) const {
return new T(a);
}
template <typename A, typename B>
T* operator()(A const& a, B const& b) const {
return new T(a, b);
}
template <typename A, typename B, typename C>
T* operator()(A const& a, B const& b, C const& c) const {
return new T(a, b, c);
}
#if PHOENIX_CONSTRUCT_LIMIT > 3
template <
typename A, typename B, typename C, typename D
>
T* operator()(
A const& a, B const& b, C const& c, D const& d) const
{
return new T(a, b, c, d);
}
template <
typename A, typename B, typename C, typename D, typename E
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e) const
{
return new T(a, b, c, d, e);
}
template <
typename A, typename B, typename C, typename D, typename E,
typename F
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e,
F const& f) const
{
return new T(a, b, c, d, e, f);
}
#if PHOENIX_CONSTRUCT_LIMIT > 6
template <
typename A, typename B, typename C, typename D, typename E,
typename F, typename G
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e,
F const& f, G const& g) const
{
return new T(a, b, c, d, e, f, g);
}
template <
typename A, typename B, typename C, typename D, typename E,
typename F, typename G, typename H
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e,
F const& f, G const& g, H const& h) const
{
return new T(a, b, c, d, e, f, g, h);
}
template <
typename A, typename B, typename C, typename D, typename E,
typename F, typename G, typename H, typename I
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e,
F const& f, G const& g, H const& h, I const& i) const
{
return new T(a, b, c, d, e, f, g, h, i);
}
#if PHOENIX_CONSTRUCT_LIMIT > 9
template <
typename A, typename B, typename C, typename D, typename E,
typename F, typename G, typename H, typename I, typename J
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e,
F const& f, G const& g, H const& h, I const& i, J const& j) const
{
return new T(a, b, c, d, e, f, g, h, i, j);
}
template <
typename A, typename B, typename C, typename D, typename E,
typename F, typename G, typename H, typename I, typename J,
typename K
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e,
F const& f, G const& g, H const& h, I const& i, J const& j,
K const& k) const
{
return new T(a, b, c, d, e, f, g, h, i, j, k);
}
template <
typename A, typename B, typename C, typename D, typename E,
typename F, typename G, typename H, typename I, typename J,
typename K, typename L
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e,
F const& f, G const& g, H const& h, I const& i, J const& j,
K const& k, L const& l) const
{
return new T(a, b, c, d, e, f, g, h, i, j, k, l);
}
#if PHOENIX_CONSTRUCT_LIMIT > 12
template <
typename A, typename B, typename C, typename D, typename E,
typename F, typename G, typename H, typename I, typename J,
typename K, typename L, typename M
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e,
F const& f, G const& g, H const& h, I const& i, J const& j,
K const& k, L const& l, M const& m) const
{
return new T(a, b, c, d, e, f, g, h, i, j, k, l, m);
}
template <
typename A, typename B, typename C, typename D, typename E,
typename F, typename G, typename H, typename I, typename J,
typename K, typename L, typename M, typename N
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e,
F const& f, G const& g, H const& h, I const& i, J const& j,
K const& k, L const& l, M const& m, N const& n) const
{
return new T(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
}
template <
typename A, typename B, typename C, typename D, typename E,
typename F, typename G, typename H, typename I, typename J,
typename K, typename L, typename M, typename N, typename O
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e,
F const& f, G const& g, H const& h, I const& i, J const& j,
K const& k, L const& l, M const& m, N const& n, O const& o) const
{
return new T(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
}
#endif
#endif
#endif
#endif
};
template <typename T>
struct new_1 {
template <
typename A
>
struct result { typedef T* type; };
template <typename A>
T* operator()(A const& a) const {
return new T(a);
}
};
template <typename T>
struct new_2 {
template <
typename A
, typename B
>
struct result { typedef T* type; };
template <typename A, typename B>
T* operator()(A const& a, B const& b) const {
return new T(a, b);
}
};
template <typename T>
struct new_3 {
template <
typename A
, typename B
, typename C
>
struct result { typedef T* type; };
template <typename A, typename B, typename C>
T* operator()(A const& a, B const& b, C const& c) const {
return new T(a, b, c);
}
};
#if PHOENIX_CONSTRUCT_LIMIT > 3
template <typename T>
struct new_4 {
template <
typename A
, typename B
, typename C
, typename D
>
struct result { typedef T* type; };
template <
typename A, typename B, typename C, typename D
>
T* operator()(
A const& a, B const& b, C const& c, D const& d) const
{
return new T(a, b, c, d);
}
};
template <typename T>
struct new_5 {
template <
typename A
, typename B
, typename C
, typename D
, typename E
>
struct result { typedef T* type; };
template <
typename A, typename B, typename C, typename D, typename E
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e) const
{
return new T(a, b, c, d, e);
}
};
template <typename T>
struct new_6 {
template <
typename A
, typename B
, typename C
, typename D
, typename E
, typename F
>
struct result { typedef T* type; };
template <
typename A, typename B, typename C, typename D, typename E,
typename F
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e,
F const& f) const
{
return new T(a, b, c, d, e, f);
}
};
#endif
#if PHOENIX_CONSTRUCT_LIMIT > 6
template <typename T>
struct new_7 {
template <
typename A
, typename B
, typename C
, typename D
, typename E
, typename F
, typename G
>
struct result { typedef T* type; };
template <
typename A, typename B, typename C, typename D, typename E,
typename F, typename G
>
T* operator()(
A const& a, B const& b, C const& c, D const& d, E const& e,
F const& f, G const& g) const
{
return new T(a, b, c, d, e, f, g);
}
};
template <typename T>
struct new_8 {
template <
typename A
, typename B
, typename C
, typename D
, typename E
, typename F
, typename G
, typename H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -