~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to boost/boost/spirit/core/meta/impl/fundamental.ipp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=============================================================================
 
2
    Spirit v1.6.1
 
3
    Copyright (c) 2002-2003 Hartmut Kaiser
 
4
    http://spirit.sourceforge.net/
 
5
 
 
6
    Permission to copy, use, modify, sell and distribute this software is
 
7
    granted provided this copyright notice appears in all copies. This
 
8
    software is provided "as is" without express or implied warranty, and
 
9
    with no claim as to its suitability for any purpose.
 
10
=============================================================================*/
 
11
#if !defined(BOOST_SPIRIT_FUNDAMENTAL_IPP)
 
12
#define BOOST_SPIRIT_FUNDAMENTAL_IPP
 
13
 
 
14
///////////////////////////////////////////////////////////////////////////////
 
15
namespace boost { namespace spirit {
 
16
 
 
17
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
 
18
    BOOST_SPIRIT_DEPENDENT_TEMPLATE_WRAPPER2(count_wrapper, count);
 
19
#endif // defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
 
20
 
 
21
namespace impl
 
22
{
 
23
    ///////////////////////////////////////////////////////////////////////////
 
24
    //
 
25
    //  Helper template for counting the number of nodes contained in a
 
26
    //  given parser type.
 
27
    //  All parser_category type parsers are counted as nodes.
 
28
    //
 
29
    ///////////////////////////////////////////////////////////////////////////
 
30
    template <typename CategoryT>
 
31
    struct nodes;
 
32
 
 
33
    template <>
 
34
    struct nodes<plain_parser_category> {
 
35
 
 
36
        template <typename ParserT, typename LeafCountT>
 
37
        struct count {
 
38
 
 
39
            // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
 
40
            enum { value = (LeafCountT::value + 1) };
 
41
        };
 
42
    };
 
43
 
 
44
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
 
45
 
 
46
    template <>
 
47
    struct nodes<unary_parser_category> {
 
48
 
 
49
        template <typename ParserT, typename LeafCountT>
 
50
        struct count {
 
51
 
 
52
            typedef typename ParserT::subject_t             subject_t;
 
53
            typedef typename subject_t::parser_category_t   subject_category_t;
 
54
 
 
55
            typedef nodes<subject_category_t> nodes_t;
 
56
            typedef typename count_wrapper<nodes_t>
 
57
                ::template result_<subject_t, LeafCountT>    count_t;
 
58
 
 
59
            BOOST_STATIC_CONSTANT(int, value = count_t::value + 1);
 
60
        };
 
61
    };
 
62
 
 
63
    template <>
 
64
    struct nodes<action_parser_category> {
 
65
 
 
66
        template <typename ParserT, typename LeafCountT>
 
67
        struct count {
 
68
 
 
69
            typedef typename ParserT::subject_t             subject_t;
 
70
            typedef typename subject_t::parser_category_t   subject_category_t;
 
71
 
 
72
            typedef nodes<subject_category_t> nodes_t;
 
73
            typedef typename count_wrapper<nodes_t>
 
74
                ::template result_<subject_t, LeafCountT>    count_t;
 
75
 
 
76
            BOOST_STATIC_CONSTANT(int, value = count_t::value + 1);
 
77
        };
 
78
    };
 
79
 
 
80
    template <>
 
81
    struct nodes<binary_parser_category> {
 
82
 
 
83
        template <typename ParserT, typename LeafCountT>
 
84
        struct count {
 
85
 
 
86
            typedef typename ParserT::left_t                left_t;
 
87
            typedef typename ParserT::right_t               right_t;
 
88
            typedef typename left_t::parser_category_t      left_category_t;
 
89
            typedef typename right_t::parser_category_t     right_category_t;
 
90
 
 
91
            typedef nodes<left_category_t> left_nodes_t;
 
92
            typedef typename count_wrapper<left_nodes_t>
 
93
                ::template result_<left_t, LeafCountT>       left_count_t;
 
94
 
 
95
            typedef nodes<right_category_t> right_nodes_t;
 
96
            typedef typename count_wrapper<right_nodes_t>
 
97
                ::template result_<right_t, LeafCountT>      right_count_t;
 
98
 
 
99
            BOOST_STATIC_CONSTANT(int,
 
100
                value = (left_count_t::value + right_count_t::value + 1));
 
101
        };
 
102
    };
 
103
 
 
104
#else
 
105
 
 
106
    template <>
 
107
    struct nodes<unary_parser_category> {
 
108
 
 
109
        template <typename ParserT, typename LeafCountT>
 
110
        struct count {
 
111
 
 
112
            typedef typename ParserT::subject_t             subject_t;
 
113
            typedef typename subject_t::parser_category_t   subject_category_t;
 
114
 
 
115
            // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
 
116
            enum { value = (nodes<subject_category_t>
 
117
                ::template count<subject_t, LeafCountT>::value + 1) };
 
118
        };
 
119
    };
 
120
 
 
121
    template <>
 
122
    struct nodes<action_parser_category> {
 
123
 
 
124
        template <typename ParserT, typename LeafCountT>
 
125
        struct count {
 
126
 
 
127
            typedef typename ParserT::subject_t             subject_t;
 
128
            typedef typename subject_t::parser_category_t   subject_category_t;
 
129
 
 
130
            // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
 
131
            enum { value = (nodes<subject_category_t>
 
132
                ::template count<subject_t, LeafCountT>::value + 1) };
 
133
        };
 
134
    };
 
135
 
 
136
    template <>
 
137
    struct nodes<binary_parser_category> {
 
138
 
 
139
        template <typename ParserT, typename LeafCountT>
 
140
        struct count {
 
141
 
 
142
            typedef typename ParserT::left_t                left_t;
 
143
            typedef typename ParserT::right_t               right_t;
 
144
            typedef typename left_t::parser_category_t      left_category_t;
 
145
            typedef typename right_t::parser_category_t     right_category_t;
 
146
 
 
147
            typedef count self_t;
 
148
 
 
149
            // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
 
150
            enum {
 
151
                leftcount = (nodes<left_category_t>
 
152
                    ::template count<left_t, LeafCountT>::value),
 
153
                rightcount = (nodes<right_category_t>
 
154
                    ::template count<right_t, LeafCountT>::value),
 
155
                value = ((self_t::leftcount) + (self_t::rightcount) + 1)
 
156
            };
 
157
        };
 
158
    };
 
159
 
 
160
#endif
 
161
 
 
162
    ///////////////////////////////////////////////////////////////////////////
 
163
    //
 
164
    //  Helper template for counting the number of leaf nodes contained in a
 
165
    //  given parser type.
 
166
    //  Only plain_parser_category type parsers are counted as leaf nodes.
 
167
    //
 
168
    ///////////////////////////////////////////////////////////////////////////
 
169
    template <typename CategoryT>
 
170
    struct leafs;
 
171
 
 
172
    template <>
 
173
    struct leafs<plain_parser_category> {
 
174
 
 
175
        template <typename ParserT, typename LeafCountT>
 
176
        struct count {
 
177
 
 
178
            // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
 
179
            enum { value = (LeafCountT::value + 1) };
 
180
        };
 
181
    };
 
182
 
 
183
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
 
184
 
 
185
    template <>
 
186
    struct leafs<unary_parser_category> {
 
187
 
 
188
        template <typename ParserT, typename LeafCountT>
 
189
        struct count {
 
190
 
 
191
            typedef typename ParserT::subject_t             subject_t;
 
192
            typedef typename subject_t::parser_category_t   subject_category_t;
 
193
 
 
194
            typedef leafs<subject_category_t> nodes_t;
 
195
            typedef typename count_wrapper<nodes_t>
 
196
                ::template result_<subject_t, LeafCountT>    count_t;
 
197
 
 
198
            BOOST_STATIC_CONSTANT(int, value = count_t::value);
 
199
        };
 
200
    };
 
201
 
 
202
    template <>
 
203
    struct leafs<action_parser_category> {
 
204
 
 
205
        template <typename ParserT, typename LeafCountT>
 
206
        struct count {
 
207
 
 
208
            typedef typename ParserT::subject_t             subject_t;
 
209
            typedef typename subject_t::parser_category_t   subject_category_t;
 
210
 
 
211
            typedef leafs<subject_category_t> nodes_t;
 
212
            typedef typename count_wrapper<nodes_t>
 
213
                ::template result_<subject_t, LeafCountT>    count_t;
 
214
 
 
215
            BOOST_STATIC_CONSTANT(int, value = count_t::value);
 
216
        };
 
217
    };
 
218
 
 
219
    template <>
 
220
    struct leafs<binary_parser_category> {
 
221
 
 
222
        template <typename ParserT, typename LeafCountT>
 
223
        struct count {
 
224
 
 
225
            typedef typename ParserT::left_t                left_t;
 
226
            typedef typename ParserT::right_t               right_t;
 
227
            typedef typename left_t::parser_category_t      left_category_t;
 
228
            typedef typename right_t::parser_category_t     right_category_t;
 
229
 
 
230
            typedef leafs<left_category_t> left_nodes_t;
 
231
            typedef typename count_wrapper<left_nodes_t>
 
232
                ::template result_<left_t, LeafCountT>       left_count_t;
 
233
 
 
234
            typedef leafs<right_category_t> right_nodes_t;
 
235
            typedef typename count_wrapper<right_nodes_t>
 
236
                ::template result_<right_t, LeafCountT>      right_count_t;
 
237
 
 
238
            BOOST_STATIC_CONSTANT(int,
 
239
                value = (left_count_t::value + right_count_t::value));
 
240
        };
 
241
    };
 
242
 
 
243
#else
 
244
 
 
245
    template <>
 
246
    struct leafs<unary_parser_category> {
 
247
 
 
248
        template <typename ParserT, typename LeafCountT>
 
249
        struct count {
 
250
 
 
251
            typedef typename ParserT::subject_t             subject_t;
 
252
            typedef typename subject_t::parser_category_t   subject_category_t;
 
253
 
 
254
            // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
 
255
            enum { value = (leafs<subject_category_t>
 
256
                ::template count<subject_t, LeafCountT>::value) };
 
257
        };
 
258
    };
 
259
 
 
260
    template <>
 
261
    struct leafs<action_parser_category> {
 
262
 
 
263
        template <typename ParserT, typename LeafCountT>
 
264
        struct count {
 
265
 
 
266
            typedef typename ParserT::subject_t             subject_t;
 
267
            typedef typename subject_t::parser_category_t   subject_category_t;
 
268
 
 
269
            // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
 
270
            enum { value = (leafs<subject_category_t>
 
271
                ::template count<subject_t, LeafCountT>::value) };
 
272
        };
 
273
    };
 
274
 
 
275
    template <>
 
276
    struct leafs<binary_parser_category> {
 
277
 
 
278
        template <typename ParserT, typename LeafCountT>
 
279
        struct count {
 
280
 
 
281
            typedef typename ParserT::left_t                left_t;
 
282
            typedef typename ParserT::right_t               right_t;
 
283
            typedef typename left_t::parser_category_t      left_category_t;
 
284
            typedef typename right_t::parser_category_t     right_category_t;
 
285
 
 
286
            typedef count self_t;
 
287
 
 
288
            // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
 
289
            enum {
 
290
                leftcount = (leafs<left_category_t>
 
291
                    ::template count<left_t, LeafCountT>::value),
 
292
                rightcount = (leafs<right_category_t>
 
293
                    ::template count<right_t, LeafCountT>::value),
 
294
                value = (self_t::leftcount + self_t::rightcount)
 
295
            };
 
296
        };
 
297
    };
 
298
 
 
299
#endif
 
300
 
 
301
}   // namespace impl
 
302
 
 
303
///////////////////////////////////////////////////////////////////////////////
 
304
}} // namespace boost::spirit
 
305
 
 
306
#endif // !defined(BOOST_SPIRIT_FUNDAMENTAL_IPP)