PageRenderTime 83ms CodeModel.GetById 77ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/boost/spirit/home/classic/meta/impl/parser_traits.ipp

http://hadesmem.googlecode.com/
C++ Header | 191 lines | 125 code | 39 blank | 27 comment | 9 complexity | 7971c054f0b113e94bc3d4e47642d754 MD5 | raw file
  1/*=============================================================================
  2    Copyright (c) 2002-2003 Joel de Guzman
  3    Copyright (c) 2002-2003 Hartmut Kaiser
  4    Copyright (c) 2003 Martin Wille
  5    http://spirit.sourceforge.net/
  6
  7    Use, modification and distribution is subject to the Boost Software
  8    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9    http://www.boost.org/LICENSE_1_0.txt)
 10=============================================================================*/
 11#if !defined(BOOST_SPIRIT_PARSER_TRAITS_IPP)
 12#define BOOST_SPIRIT_PARSER_TRAITS_IPP
 13
 14#include <boost/spirit/home/classic/core/composite/operators.hpp>
 15
 16///////////////////////////////////////////////////////////////////////////////
 17namespace boost { namespace spirit {
 18
 19BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
 20
 21namespace impl
 22{
 23
 24#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
 25
 26    ///////////////////////////////////////////////////////////////////////////
 27    //
 28    //  from spirit 1.1 (copyright (c) 2001 Bruce Florman)
 29    //  various workarounds to support compile time decisions without partial
 30    //  template specialization whether a given type is an instance of a
 31    //  concrete parser type.
 32    //
 33    ///////////////////////////////////////////////////////////////////////////
 34
 35    ///////////////////////////////////////////////////////////////////////////
 36    template <typename T>
 37    struct parser_type_traits
 38    {
 39    //  Determine at compile time (without partial specialization)
 40    //  whether a given type is an instance of the alternative<A,B>
 41
 42        static T t();
 43
 44        typedef struct { char dummy[1]; }   size1_t;
 45        typedef struct { char dummy[2]; }   size2_t;
 46        typedef struct { char dummy[3]; }   size3_t;
 47        typedef struct { char dummy[4]; }   size4_t;
 48        typedef struct { char dummy[5]; }   size5_t;
 49        typedef struct { char dummy[6]; }   size6_t;
 50        typedef struct { char dummy[7]; }   size7_t;
 51        typedef struct { char dummy[8]; }   size8_t;
 52        typedef struct { char dummy[9]; }   size9_t;
 53        typedef struct { char dummy[10]; }  size10_t;
 54
 55    // the following functions need no implementation
 56        template <typename A, typename B>
 57        static size1_t test_(alternative<A, B> const&);
 58        template <typename A, typename B>
 59        static size2_t test_(sequence<A, B> const&);
 60        template <typename A, typename B>
 61        static size3_t test_(sequential_or<A, B> const&);
 62        template <typename A, typename B>
 63        static size4_t test_(intersection<A, B> const&);
 64        template <typename A, typename B>
 65        static size5_t test_(difference<A, B> const&);
 66        template <typename A, typename B>
 67        static size6_t test_(exclusive_or<A, B> const&);
 68        template <typename S>
 69        static size7_t test_(optional<S> const&);
 70        template <typename S>
 71        static size8_t test_(kleene_star<S> const&);
 72        template <typename S>
 73        static size9_t test_(positive<S> const&);
 74
 75        static size10_t test_(...);
 76
 77        BOOST_STATIC_CONSTANT(bool,
 78            is_alternative = (sizeof(size1_t) == sizeof(test_(t()))) );
 79        BOOST_STATIC_CONSTANT(bool,
 80            is_sequence = (sizeof(size2_t) == sizeof(test_(t()))) );
 81        BOOST_STATIC_CONSTANT(bool,
 82            is_sequential_or = (sizeof(size3_t) == sizeof(test_(t()))) );
 83        BOOST_STATIC_CONSTANT(bool,
 84            is_intersection = (sizeof(size4_t) == sizeof(test_(t()))) );
 85        BOOST_STATIC_CONSTANT(bool,
 86            is_difference = (sizeof(size5_t) == sizeof(test_(t()))) );
 87        BOOST_STATIC_CONSTANT(bool,
 88            is_exclusive_or = (sizeof(size6_t) == sizeof(test_(t()))) );
 89        BOOST_STATIC_CONSTANT(bool,
 90            is_optional = (sizeof(size7_t) == sizeof(test_(t()))) );
 91        BOOST_STATIC_CONSTANT(bool,
 92            is_kleene_star = (sizeof(size8_t) == sizeof(test_(t()))) );
 93        BOOST_STATIC_CONSTANT(bool,
 94            is_positive = (sizeof(size9_t) == sizeof(test_(t()))) );
 95    };
 96
 97#else
 98
 99    ///////////////////////////////////////////////////////////////////////////
100    struct parser_type_traits_base {
101
102        BOOST_STATIC_CONSTANT(bool, is_alternative = false);
103        BOOST_STATIC_CONSTANT(bool, is_sequence = false);
104        BOOST_STATIC_CONSTANT(bool, is_sequential_or = false);
105        BOOST_STATIC_CONSTANT(bool, is_intersection = false);
106        BOOST_STATIC_CONSTANT(bool, is_difference = false);
107        BOOST_STATIC_CONSTANT(bool, is_exclusive_or = false);
108        BOOST_STATIC_CONSTANT(bool, is_optional = false);
109        BOOST_STATIC_CONSTANT(bool, is_kleene_star = false);
110        BOOST_STATIC_CONSTANT(bool, is_positive = false);
111    };
112
113    template <typename ParserT>
114    struct parser_type_traits : public parser_type_traits_base {
115
116    //  no definition here, fallback for all not explicitly mentioned parser
117    //  types
118    };
119
120    template <typename A, typename B>
121    struct parser_type_traits<alternative<A, B> >
122    :   public parser_type_traits_base {
123
124        BOOST_STATIC_CONSTANT(bool, is_alternative = true);
125    };
126
127    template <typename A, typename B>
128    struct parser_type_traits<sequence<A, B> >
129    :   public parser_type_traits_base {
130
131        BOOST_STATIC_CONSTANT(bool, is_sequence = true);
132    };
133
134    template <typename A, typename B>
135    struct parser_type_traits<sequential_or<A, B> >
136    :   public parser_type_traits_base {
137
138        BOOST_STATIC_CONSTANT(bool, is_sequential_or = true);
139    };
140
141    template <typename A, typename B>
142    struct parser_type_traits<intersection<A, B> >
143    :   public parser_type_traits_base {
144
145        BOOST_STATIC_CONSTANT(bool, is_intersection = true);
146    };
147
148    template <typename A, typename B>
149    struct parser_type_traits<difference<A, B> >
150    :   public parser_type_traits_base {
151
152        BOOST_STATIC_CONSTANT(bool, is_difference = true);
153    };
154
155    template <typename A, typename B>
156    struct parser_type_traits<exclusive_or<A, B> >
157    :   public parser_type_traits_base {
158
159        BOOST_STATIC_CONSTANT(bool, is_exclusive_or = true);
160    };
161
162    template <typename S>
163    struct parser_type_traits<optional<S> >
164    :   public parser_type_traits_base {
165
166        BOOST_STATIC_CONSTANT(bool, is_optional = true);
167    };
168
169    template <typename S>
170    struct parser_type_traits<kleene_star<S> >
171    :   public parser_type_traits_base {
172
173        BOOST_STATIC_CONSTANT(bool, is_kleene_star = true);
174    };
175
176    template <typename S>
177    struct parser_type_traits<positive<S> >
178    :   public parser_type_traits_base {
179
180        BOOST_STATIC_CONSTANT(bool, is_positive = true);
181    };
182
183#endif // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
184}   // namespace impl
185
186///////////////////////////////////////////////////////////////////////////////
187BOOST_SPIRIT_CLASSIC_NAMESPACE_END
188
189}} // namespace boost::spirit
190
191#endif // !defined(BOOST_SPIRIT_PARSER_TRAITS_IPP)