source: NonGTP/Boost/boost/spirit/meta/impl/parser_traits.ipp @ 857

Revision 857, 6.8 KB checked in by igarcia, 18 years ago (diff)
Line 
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/core/composite/operators.hpp>
15
16///////////////////////////////////////////////////////////////////////////////
17namespace boost { namespace spirit {
18
19namespace impl
20{
21
22#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
23
24    ///////////////////////////////////////////////////////////////////////////
25    //
26    //  from spirit 1.1 (copyright (c) 2001 Bruce Florman)
27    //  various workarounds to support compile time decisions without partial
28    //  template specialization whether a given type is an instance of a
29    //  concrete parser type.
30    //
31    ///////////////////////////////////////////////////////////////////////////
32
33    ///////////////////////////////////////////////////////////////////////////
34    template <typename T>
35    struct parser_type_traits
36    {
37    //  Determine at compile time (without partial specialization)
38    //  whether a given type is an instance of the alternative<A,B>
39
40        static T t();
41
42        typedef struct { char dummy[1]; }   size1_t;
43        typedef struct { char dummy[2]; }   size2_t;
44        typedef struct { char dummy[3]; }   size3_t;
45        typedef struct { char dummy[4]; }   size4_t;
46        typedef struct { char dummy[5]; }   size5_t;
47        typedef struct { char dummy[6]; }   size6_t;
48        typedef struct { char dummy[7]; }   size7_t;
49        typedef struct { char dummy[8]; }   size8_t;
50        typedef struct { char dummy[9]; }   size9_t;
51        typedef struct { char dummy[10]; }  size10_t;
52
53    // the following functions need no implementation
54        template <typename A, typename B>
55        static size1_t test_(alternative<A, B> const&);
56        template <typename A, typename B>
57        static size2_t test_(sequence<A, B> const&);
58        template <typename A, typename B>
59        static size3_t test_(sequential_or<A, B> const&);
60        template <typename A, typename B>
61        static size4_t test_(intersection<A, B> const&);
62        template <typename A, typename B>
63        static size5_t test_(difference<A, B> const&);
64        template <typename A, typename B>
65        static size6_t test_(exclusive_or<A, B> const&);
66        template <typename S>
67        static size7_t test_(optional<S> const&);
68        template <typename S>
69        static size8_t test_(kleene_star<S> const&);
70        template <typename S>
71        static size9_t test_(positive<S> const&);
72
73        static size10_t test_(...);
74
75        BOOST_STATIC_CONSTANT(bool,
76            is_alternative = (sizeof(size1_t) == sizeof(test_(t()))) );
77        BOOST_STATIC_CONSTANT(bool,
78            is_sequence = (sizeof(size2_t) == sizeof(test_(t()))) );
79        BOOST_STATIC_CONSTANT(bool,
80            is_sequential_or = (sizeof(size3_t) == sizeof(test_(t()))) );
81        BOOST_STATIC_CONSTANT(bool,
82            is_intersection = (sizeof(size4_t) == sizeof(test_(t()))) );
83        BOOST_STATIC_CONSTANT(bool,
84            is_difference = (sizeof(size5_t) == sizeof(test_(t()))) );
85        BOOST_STATIC_CONSTANT(bool,
86            is_exclusive_or = (sizeof(size6_t) == sizeof(test_(t()))) );
87        BOOST_STATIC_CONSTANT(bool,
88            is_optional = (sizeof(size7_t) == sizeof(test_(t()))) );
89        BOOST_STATIC_CONSTANT(bool,
90            is_kleene_star = (sizeof(size8_t) == sizeof(test_(t()))) );
91        BOOST_STATIC_CONSTANT(bool,
92            is_positive = (sizeof(size9_t) == sizeof(test_(t()))) );
93    };
94
95#else
96
97    ///////////////////////////////////////////////////////////////////////////
98    struct parser_type_traits_base {
99
100        BOOST_STATIC_CONSTANT(bool, is_alternative = false);
101        BOOST_STATIC_CONSTANT(bool, is_sequence = false);
102        BOOST_STATIC_CONSTANT(bool, is_sequential_or = false);
103        BOOST_STATIC_CONSTANT(bool, is_intersection = false);
104        BOOST_STATIC_CONSTANT(bool, is_difference = false);
105        BOOST_STATIC_CONSTANT(bool, is_exclusive_or = false);
106        BOOST_STATIC_CONSTANT(bool, is_optional = false);
107        BOOST_STATIC_CONSTANT(bool, is_kleene_star = false);
108        BOOST_STATIC_CONSTANT(bool, is_positive = false);
109    };
110
111    template <typename ParserT>
112    struct parser_type_traits : public parser_type_traits_base {
113
114    //  no definition here, fallback for all not explicitly mentioned parser
115    //  types
116    };
117
118    template <typename A, typename B>
119    struct parser_type_traits<alternative<A, B> >
120    :   public parser_type_traits_base {
121
122        BOOST_STATIC_CONSTANT(bool, is_alternative = true);
123    };
124
125    template <typename A, typename B>
126    struct parser_type_traits<sequence<A, B> >
127    :   public parser_type_traits_base {
128
129        BOOST_STATIC_CONSTANT(bool, is_sequence = true);
130    };
131
132    template <typename A, typename B>
133    struct parser_type_traits<sequential_or<A, B> >
134    :   public parser_type_traits_base {
135
136        BOOST_STATIC_CONSTANT(bool, is_sequential_or = true);
137    };
138
139    template <typename A, typename B>
140    struct parser_type_traits<intersection<A, B> >
141    :   public parser_type_traits_base {
142
143        BOOST_STATIC_CONSTANT(bool, is_intersection = true);
144    };
145
146    template <typename A, typename B>
147    struct parser_type_traits<difference<A, B> >
148    :   public parser_type_traits_base {
149
150        BOOST_STATIC_CONSTANT(bool, is_difference = true);
151    };
152
153    template <typename A, typename B>
154    struct parser_type_traits<exclusive_or<A, B> >
155    :   public parser_type_traits_base {
156
157        BOOST_STATIC_CONSTANT(bool, is_exclusive_or = true);
158    };
159
160    template <typename S>
161    struct parser_type_traits<optional<S> >
162    :   public parser_type_traits_base {
163
164        BOOST_STATIC_CONSTANT(bool, is_optional = true);
165    };
166
167    template <typename S>
168    struct parser_type_traits<kleene_star<S> >
169    :   public parser_type_traits_base {
170
171        BOOST_STATIC_CONSTANT(bool, is_kleene_star = true);
172    };
173
174    template <typename S>
175    struct parser_type_traits<positive<S> >
176    :   public parser_type_traits_base {
177
178        BOOST_STATIC_CONSTANT(bool, is_positive = true);
179    };
180
181#endif // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
182}   // namespace impl
183
184///////////////////////////////////////////////////////////////////////////////
185}} // namespace boost::spirit
186
187#endif // !defined(BOOST_SPIRIT_PARSER_TRAITS_IPP)
Note: See TracBrowser for help on using the repository browser.