1 # // Copyright (C) 2007
2 # // Fraunhofer Institute for Open Communication Systems (FOKUS)
3 # // Competence Center NETwork research (NET), St. Augustin, GERMANY
4 # // Stefan Bund <g0dil@berlios.de>
6 # // This program is free software; you can redistribute it and/or modify
7 # // it under the terms of the GNU General Public License as published by
8 # // the Free Software Foundation; either version 2 of the License, or
9 # // (at your option) any later version.
11 # // This program is distributed in the hope that it will be useful,
12 # // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # // GNU General Public License for more details.
16 # // You should have received a copy of the GNU General Public License
17 # // along with this program; if not, write to the
18 # // Free Software Foundation, Inc.,
19 # // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 # \brief ParseHelpers internal header */
24 # if !defined(IH_ParseHelpers_)
25 # define IH_ParseHelpers_ 1
28 # include <boost/preprocessor/cat.hpp>
29 # include <boost/preprocessor/if.hpp>
30 # include <boost/preprocessor/expand.hpp>
31 # include <boost/preprocessor/facilities/is_empty.hpp>
32 # include <boost/preprocessor/punctuation/comma.hpp>
33 # include "../Utils/mpl.hh"
35 # ////////////////////////////////ih.p///////////////////////////////////////
37 # ///////////////////////////////////////////////////////////////////////////
38 # // SENF_PARSER_INITIALIZE
40 # define SENF_PARSER_INITIALIZE BOOST_PP_CAT( SENF_PARSER_INITIALIZE_ , SENF_PARSER_TYPE )
42 # define SENF_PARSER_INITIALIZE_fix() \
44 SENF_MPL_SLOT_DEF_ZERO(index); \
45 SENF_MPL_SLOT_DEF_ZERO(offset); \
46 SENF_MPL_SLOT_DEF_ZERO(bit); \
47 SENF_MPL_SLOT_DEF_ZERO(bitfield_size); \
48 void init_chain(senf::mpl::rv<0>*) const {} \
51 # define SENF_PARSER_INITIALIZE_var() \
53 SENF_MPL_SLOT_DEF_ZERO(index); \
54 SENF_MPL_SLOT_DEF_ZERO(init_bytes); \
55 SENF_MPL_SLOT_DEF_ZERO(bit); \
56 SENF_MPL_SLOT_DEF_ZERO(bitfield_size); \
57 SENF_MPL_SLOT_DEF_ZERO(group); \
58 void init_chain(senf::mpl::rv<0>*) const {} \
59 size_type field_offset_(senf::mpl::rv<0>*) const { return 0; } \
62 # ///////////////////////////////////////////////////////////////////////////
63 # // SENF_PARSER_INHERIT_*
65 # define SENF_PARSER_INHERIT_var(name) \
66 typedef name parser_base_type; \
68 SENF_MPL_SLOT_SET(index, 1); \
69 SENF_MPL_SLOT_SET(init_bytes, senf::init_bytes<name>::value); \
70 size_type field_offset_(senf::mpl::rv<1>*) const { \
71 return senf::bytes( *static_cast<name const*>(this) ); \
73 void init_chain(senf::mpl::rv<1>*) const { \
78 # define SENF_PARSER_INHERIT_fix(name) \
79 typedef name parser_base_type; \
81 SENF_MPL_SLOT_SET(offset, name::fixed_bytes); \
82 SENF_MPL_SLOT_SET(index, 1); \
83 void init_chain(senf::mpl::rv<1>*) const { \
88 # ///////////////////////////////////////////////////////////////////////////
89 # // SENF_PARSER_FIELD*
90 # // SENF_PARSER_P_FIELD_*
92 # define SENF_PARSER_FIELD_var(name, type) SENF_PARSER_FIELD_I(name, type, var, rw, public)
93 # define SENF_PARSER_FIELD_RO_var(name, type) SENF_PARSER_FIELD_I(name, type, var, ro, public)
94 # define SENF_PARSER_FIELD_fix(name, type) SENF_PARSER_FIELD_I(name, type, fix, rw, public)
95 # define SENF_PARSER_FIELD_RO_fix(name, type) SENF_PARSER_FIELD_I(name, type, fix, ro, public)
97 # define SENF_PARSER_P_FIELD_var(name, type) SENF_PARSER_FIELD_I(name, type, var, rw, protected)
98 # define SENF_PARSER_P_FIELD_fix(name, type) SENF_PARSER_FIELD_I(name, type, fix, rw, protected)
100 # define SENF_PARSER_FIELD_I(name, type, ofstype, rwtype, access) \
102 SENF_PARSER_FIELD_SETUP_I(name, type, ofstype, rwtype, access) \
103 BOOST_PP_CAT(SENF_PARSER_I_FIELD_VAL_, rwtype) (name, type, access) \
106 # define SENF_PARSER_FIELD_SETUP_I(name, type, ofstype, rwtype, access) \
107 SENF_PARSER_I_BITFIELD_RESET() \
108 SENF_PARSER_I_FIELD_INTRO(name, type, access) \
109 BOOST_PP_CAT(SENF_PARSER_I_FIELD_INIT_, rwtype) (name, type, access) \
110 BOOST_PP_CAT(SENF_PARSER_I_FIELD_OFS_, ofstype) (name, type, access) \
111 BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) ( \
113 BOOST_PP_CAT(SENF_PARSER_I_SIZE_, ofstype) (name, type), \
114 BOOST_PP_CAT(SENF_PARSER_I_INITBYTES_, ofstype) (name, type), \
115 BOOST_PP_CAT(SENF_PARSER_I_ISVAR_, ofstype) (name, type), \
118 # ////////////////////////////////////////
119 # // SENF_PARSER_I_FIELD_INTRO
121 # define SENF_PARSER_I_FIELD_INTRO(name, type, access) \
122 typedef type BOOST_PP_CAT(name, _t); \
123 static size_type const BOOST_PP_CAT(name,_index) = SENF_MPL_SLOT_GET(index)+1; \
125 SENF_MPL_SLOT_SET(index, BOOST_PP_CAT(name,_index)); \
128 # ////////////////////////////////////////
129 # // SENF_PARSER_I_FIELD_INIT_*
131 # define SENF_PARSER_I_FIELD_INIT_rw(name, type, access) \
133 void init_chain(senf::mpl::rv<BOOST_PP_CAT(name,_index)>*) const { \
134 init_chain(static_cast<senf::mpl::rv<BOOST_PP_CAT(name,_index)-1>*>(0)); \
139 # define SENF_PARSER_I_FIELD_INIT_ro(name, type, access) \
141 void init_chain(senf::mpl::rv<BOOST_PP_CAT(name,_index)>*) const { \
142 init_chain(static_cast<senf::mpl::rv<BOOST_PP_CAT(name,_index)-1>*>(0)); \
146 # ////////////////////////////////////////
147 # // SENF_PARSER_I_FIELD_OFS_*
149 # define SENF_PARSER_I_FIELD_OFS_var(name, type, access) \
151 size_type BOOST_PP_CAT(name,_offset)() const { \
152 return field_offset_(static_cast<senf::mpl::rv<BOOST_PP_CAT(name,_index)-1>*>(0)); \
154 static size_type const BOOST_PP_CAT(name, _init_bytes) = \
155 SENF_MPL_SLOT_GET(init_bytes); \
158 # define SENF_PARSER_I_FIELD_OFS_fix(name, type, access) \
160 static size_type const BOOST_PP_CAT(name, _offset) = \
161 SENF_MPL_SLOT_GET(offset); \
164 # ////////////////////////////////////////
165 # // SENF_PARSER_I_ADVANCE_OFS_*
167 # define SENF_PARSER_I_SIZE_var(name, type) senf::bytes(BOOST_PP_CAT(name, _)())
168 # define SENF_PARSER_I_INITBYTES_var(name, type) senf::init_bytes<type>::value
170 # define SENF_PARSER_I_SIZE_fix(name, type) type::fixed_bytes
171 # define SENF_PARSER_I_INITBYTES_fix(name, type) void
173 # define SENF_PARSER_I_ISVAR_fix(name, type) 0
174 # define SENF_PARSER_I_ISVAR_var(name, type) (senf::is_fixed<type>::value?0:1)
176 # define SENF_PARSER_I_ADVANCE_OFS_var(name, type, size, isize, isvar, access) \
177 size_type BOOST_PP_CAT(name, _next_offset)() const { \
178 return BOOST_PP_CAT(name,_offset)() + size; \
180 static size_type const BOOST_PP_CAT(name, _next_init_bytes) = \
181 BOOST_PP_CAT(name, _init_bytes) + isize; \
183 size_type field_offset_(senf::mpl::rv<BOOST_PP_CAT(name,_index)>*) const { \
184 return BOOST_PP_CAT(name, _next_offset)(); \
186 SENF_MPL_SLOT_SET(init_bytes, BOOST_PP_CAT(name,_next_init_bytes)); \
188 static size_type const BOOST_PP_CAT(name, _group) = SENF_MPL_SLOT_GET(group) + isvar; \
190 SENF_MPL_SLOT_SET(group, BOOST_PP_CAT(name, _group)); \
193 # define SENF_PARSER_I_ADVANCE_OFS_fix(name, type, size, isize, isvar, access) \
194 static size_type const BOOST_PP_CAT(name, _next_offset) = \
195 BOOST_PP_CAT(name, _offset) + size; \
197 SENF_MPL_SLOT_SET(offset, BOOST_PP_CAT(name, _next_offset)); \
200 # ////////////////////////////////////////
201 # // SENF_PARSER_I_FIELD_VAL_*
203 # define SENF_PARSER_I_FIELD_VAL_rw(name, type, access) \
205 BOOST_PP_CAT(name, _t) BOOST_PP_CAT(name, _)() const { \
206 return parse<type>( SENF_PARSER_OFFSET(name) ); \
209 BOOST_PP_CAT(name, _t) name() const { \
210 return BOOST_PP_CAT(name,_)(); \
213 # define SENF_PARSER_I_FIELD_VAL_ro(name, type, access) \
215 BOOST_PP_CAT(name, _t) BOOST_PP_CAT(name, _)() const { \
216 return parse<type>( SENF_PARSER_OFFSET(name) ); \
219 BOOST_PP_CAT(name, _t)::value_type name() const { \
220 return BOOST_PP_CAT(name,_)(); \
223 # ///////////////////////////////////////////////////////////////////////////
224 # // SENF_PARSER_CUSTOM_FIELD_*
226 # define SENF_PARSER_CUSTOM_FIELD_var(name, type, size, isize) \
227 SENF_PARSER_CUSTOM_FIELD_I(name, type, size, isize, var)
228 # define SENF_PARSER_CUSTOM_FIELD_fix(name, type, size) \
229 SENF_PARSER_CUSTOM_FIELD_I(name, type, size, size, fix)
231 # define SENF_PARSER_CUSTOM_FIELD_I(name, type, size, isize, ofstype) \
232 SENF_PARSER_I_BITFIELD_RESET() \
233 SENF_PARSER_I_FIELD_INTRO(name, type, public) \
234 SENF_PARSER_I_FIELD_INIT_ro(name, type, public) \
235 BOOST_PP_CAT(SENF_PARSER_I_FIELD_OFS_, ofstype) (name, type, public) \
236 BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) (name, type, size, isize, 1, public) \
237 BOOST_PP_CAT(name, _t) name() const
239 # ///////////////////////////////////////////////////////////////////////////
240 # // SENF_PARSER_BITFIELD_*
241 # // SENF_PARSER_P_BITFIELD_*
243 # define SENF_PARSER_BITFIELD_var(name, bits, type) \
244 SENF_PARSER_BITFIELD_I(name, bits, type, var, rw, public)
245 # define SENF_PARSER_BITFIELD_RO_var(name, bits, type) \
246 SENF_PARSER_BITFIELD_I(name, bits, type, var, ro, public)
247 # define SENF_PARSER_BITFIELD_fix(name, bits, type) \
248 SENF_PARSER_BITFIELD_I(name, bits, type, fix, rw, public)
249 # define SENF_PARSER_BITFIELD_RO_fix(name, bits, type) \
250 SENF_PARSER_BITFIELD_I(name, bits, type, fix, ro, public)
252 # define SENF_PARSER_P_BITFIELD_var(name, bits, type) \
253 SENF_PARSER_BITFIELD_I(name, bits, type, var, rw, protected)
254 # define SENF_PARSER_P_BITFIELD_fix(name, bits, type) \
255 SENF_PARSER_BITFIELD_I(name, bits, type, fix, rw, protected)
257 # ////////////////////////////////////////
258 # // SENF_PARSER_BITFIELD_I
260 # define SENF_PARSER_BITFIELD_TYPE_signed(start, bits) senf::IntFieldParser<start, start+bits>
261 # define SENF_PARSER_BITFIELD_TYPE_unsigned(start, bits) senf::UIntFieldParser<start, start+bits>
262 # define SENF_PARSER_BITFIELD_TYPE_bool(start, bits) senf::FlagParser<start>
264 # define SENF_PARSER_BITFIELD_I(name, bits, type, ofstype, rwtype, access) \
266 static size_type const BOOST_PP_CAT(name, _bit) = SENF_MPL_SLOT_GET(bit); \
268 SENF_MPL_SLOT_SET(bit, BOOST_PP_CAT(name, _bit) + bits); \
269 typedef BOOST_PP_CAT(SENF_PARSER_BITFIELD_TYPE_, type)( BOOST_PP_CAT(name, _bit), bits ) \
270 BOOST_PP_CAT(name,_bit_t ); \
272 SENF_PARSER_BITFIELD_II( name, bits, BOOST_PP_CAT(name, _bit_t), ofstype, rwtype, access) \
275 # define SENF_PARSER_BITFIELD_II(name, bits, type, ofstype, rwtype, access) \
276 SENF_PARSER_I_FIELD_INTRO(name, type, access) \
277 SENF_PARSER_I_FIELD_INIT_ro(name, type, access) \
278 BOOST_PP_CAT(SENF_PARSER_I_BITFIELD_OFS_, ofstype) (name, type, access) \
279 BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) ( \
281 BOOST_PP_CAT(name, _t)::fixed_bytes, BOOST_PP_CAT(name, _t)::fixed_bytes, \
285 SENF_MPL_SLOT_SET(bitfield_size, BOOST_PP_CAT(name, _t)::fixed_bytes); \
287 BOOST_PP_CAT(SENF_PARSER_I_FIELD_VAL_, rwtype) (name, type, access) \
290 # ////////////////////////////////////////
291 # // SENF_PARSER_I_BITFIELD_OFS_*
293 # define SENF_PARSER_I_BITFIELD_OFS_var(name, type, access) \
294 size_type BOOST_PP_CAT(name,_offset)() const { \
295 return field_offset_(static_cast<senf::mpl::rv<BOOST_PP_CAT(name,_index)-1>*>(0)) \
296 - SENF_MPL_SLOT_GET(bitfield_size); \
298 static size_type const BOOST_PP_CAT(name, _init_bytes) = \
299 SENF_MPL_SLOT_GET(init_bytes) - SENF_MPL_SLOT_GET(bitfield_size);
301 # define SENF_PARSER_I_BITFIELD_OFS_fix(name, type, access) \
302 static size_type const BOOST_PP_CAT(name, _offset) = \
303 SENF_MPL_SLOT_GET(offset) - SENF_MPL_SLOT_GET(bitfield_size);
305 # ////////////////////////////////////////
306 # // SENF_PARSER_I_BITFIELD_RESET
308 # define SENF_PARSER_I_BITFIELD_RESET() \
309 SENF_MPL_SLOT_SET(bit, 0); \
310 SENF_MPL_SLOT_SET(bitfield_size, 0);
312 # ///////////////////////////////////////////////////////////////////////////
313 # // SENF_PARSER_SKIP_*
315 # define SENF_PARSER_SKIP_var(bytes, ibytes) \
316 SENF_PARSER_I_SKIP( BOOST_PP_CAT(senf_anon_, __LINE__), bytes, ibytes, var)
318 # define SENF_PARSER_SKIP_fix(bytes) \
319 SENF_PARSER_I_SKIP( BOOST_PP_CAT(senf_anon_, __LINE__), bytes, bytes, fix)
321 # define SENF_PARSER_I_SKIP(name, bytes, ibytes, ofstype) \
323 SENF_PARSER_I_BITFIELD_RESET() \
324 SENF_PARSER_I_FIELD_INTRO(name, void, private) \
325 SENF_PARSER_I_FIELD_INIT_ro(name, void, private) \
326 BOOST_PP_CAT(SENF_PARSER_I_FIELD_OFS_, ofstype) (name, type, access) \
327 BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) (name, void, bytes, ibytes, 1, \
331 # ///////////////////////////////////////////////////////////////////////////
332 # // SENF_PARSER_SKIP_BITS_*
334 # define SENF_PARSER_SKIP_BITS_var(bits) SENF_PARSER_I_SKIP_BITS(bits, var)
335 # define SENF_PARSER_SKIP_BITS_fix(bits) SENF_PARSER_I_SKIP_BITS(bits, fix)
337 # define SENF_PARSER_I_SKIP_BITS(bits, ofstype) \
339 SENF_MPL_SLOT_SET(bit, SENF_MPL_SLOT_GET(bit) + bits); \
342 # ///////////////////////////////////////////////////////////////////////////
343 # // SENF_PARSER_GOTO_*
345 # define SENF_PARSER_GOTO_var(name) \
346 SENF_PARSER_I_GOTO( BOOST_PP_CAT(senf_anon_, __LINE__), \
347 BOOST_PP_CAT(name, _offset)(), \
348 BOOST_PP_CAT(name, _init_bytes), \
351 # define SENF_PARSER_GOTO_fix(name) \
352 SENF_PARSER_I_GOTO( BOOST_PP_CAT(senf_anon_, __LINE__), \
353 BOOST_PP_CAT(name, _offset), \
354 BOOST_PP_CAT(name, _offset), \
357 # define SENF_PARSER_GOTO_OFFSET_var(offset, isize) \
358 SENF_PARSER_I_GOTO( BOOST_PP_CAT(senf_anon_, __LINE__), offset, isize, var )
360 # define SENF_PARSER_GOTO_OFFSET_fix(offset) \
361 SENF_PARSER_I_GOTO( BOOST_PP_CAT(senf_anon_, __LINE__), offset, offset, fix )
363 # define SENF_PARSER_I_GOTO(name, offset, initsize, ofstype) \
365 SENF_PARSER_I_BITFIELD_RESET() \
366 SENF_PARSER_I_FIELD_INTRO(name, void, private) \
367 SENF_PARSER_I_FIELD_INIT_ro(name, void, private) \
368 BOOST_PP_CAT( SENF_PARSER_I_GOTO_SET_OFS_, ofstype ) (name, offset, initsize) \
371 # define SENF_PARSER_I_GOTO_SET_OFS_var(name, offs, initsize) \
372 size_type field_offset_(senf::mpl::rv<BOOST_PP_CAT(name,_index)>*) const { \
375 SENF_MPL_SLOT_SET(init_bytes, initsize);
377 # define SENF_PARSER_I_GOTO_SET_OFS_fix(name, offs, initsize) \
378 SENF_MPL_SLOT_SET(offset, offs);
380 # ///////////////////////////////////////////////////////////////////////////
381 # // SENF_PARSER_LABEL_*
383 # define SENF_PARSER_LABEL_var(name) SENF_PARSER_I_LABEL( name, var, public )
384 # define SENF_PARSER_LABEL_fix(name) SENF_PARSER_I_LABEL( name, fix, public )
386 # define SENF_PARSER_I_LABEL(name, ofstype, access) \
388 SENF_PARSER_I_BITFIELD_RESET() \
389 SENF_PARSER_I_FIELD_INTRO(name, void, access) \
390 SENF_PARSER_I_FIELD_INIT_ro(name, void, access) \
391 BOOST_PP_CAT(SENF_PARSER_I_FIELD_OFS_, ofstype) (name, type, access) \
392 BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) (name, void, 0, 0, 0, access) \
395 # ///////////////////////////////////////////////////////////////////////////
396 # // SENF_PARSER_OFFSET_*
398 # define SENF_PARSER_OFFSET_fix(name) BOOST_PP_CAT(name, _offset)
399 # define SENF_PARSER_OFFSET_var(name) BOOST_PP_CAT(name, _offset)()
401 # ///////////////////////////////////////////////////////////////////////////
402 # // SENF_PARSER_FIXED_OFFSET_*
404 # define SENF_PARSER_FIXED_OFFSET_fix(name) BOOST_PP_CAT(name, _offset)
405 # define SENF_PARSER_FIXED_OFFSET_var(name) BOOST_PP_CAT(name, _init_bytes)
407 # ///////////////////////////////////////////////////////////////////////////
408 # // SENF_PARSER_CURRENT_FIXED_OFFSET_*
410 # define SENF_PARSER_CURRENT_FIXED_OFFSET_fix() SENF_MPL_SLOT_GET(offset)
411 # define SENF_PARSER_CURRENT_FIXED_OFFSET_var() SENF_MPL_SLOT_GET(init_bytes)
413 # ///////////////////////////////////////////////////////////////////////////
414 # // SENF_PARSER_FINALIZE_*
416 # define SENF_PARSER_FINALIZE_var(name) \
417 SENF_PARSER_FINALIZE_GENERIC(name) \
418 size_type bytes() const { \
419 return field_offset_(static_cast<senf::mpl::rv<SENF_MPL_SLOT_GET(index)>*>(0)); \
421 static size_type const init_bytes = SENF_MPL_SLOT_GET(init_bytes)
423 # define SENF_PARSER_FINALIZE_fix(name) \
424 SENF_PARSER_FINALIZE_GENERIC(name) \
425 static size_type const fixed_bytes = SENF_MPL_SLOT_GET(offset);
427 # define SENF_PARSER_FINALIZE_GENERIC(name) \
428 void defaultInit() const { \
429 init_chain(static_cast<senf::mpl::rv<SENF_MPL_SLOT_GET(index)>*>(0)); \
431 name(data_iterator i, state_type s) : parser_base_type(i,s) {} \
433 template <class T> void init(T) const { defaultInit(); } \
435 void init() const { init(0); }
437 # ///////////////////////////////////////////////////////////////////////////
438 # // SENF_PARSER_REQUIRE_VAR
440 # define SENF_PARSER_REQUIRE_VAR(description) \
441 BOOST_PP_CAT(SENF_PARSER_REQUIRE_VAR_, SENF_PARSER_TYPE)(description)
443 # define SENF_PARSER_REQUIRE_VAR_var(description)
445 # define SENF_PARSER_REQUIRE_VAR_fix(description) \
446 typedef BOOST_PP_CAT( PARSER_ERROR__, \
447 BOOST_PP_CAT(description, _not_allowed_in_fixed_parser) ) \
448 BOOST_PP_CAT(errsym_, __LINE__);
450 # ///////////////////////////////////////////////////////////////////////////
451 # // SENF_PARSER_COLLECTION_I
455 namespace senf { namespace detail { namespace auxtag {
456 struct none {}; } } }
457 namespace senf { namespace detail { namespace auxtag {
458 struct bytes {}; } } }
459 namespace senf { namespace detail { namespace auxtag {
460 template <class Transform, class Tag>
461 struct transform {}; } } }
462 namespace senf { namespace detail { namespace auxtag {
463 struct packetSize {}; } } }
467 # // Each tag is implemented by defining the following macros. If the Tag is <name>(<args>):
468 # // SENF_PARSER_COLLECTION_TAG_GOBBLE__<name>(<args>)
469 # // gobble the tag, that is expand to nothing
470 # // SENF_PARSER_COLLECTION_TAG__<name>(<args>)
471 # // return an intermediate tag. This tag will be used with the next macro to get the aux tag
472 # // this indirection is needed since the tag may include templates with more than one
473 # // argument which cannot be passed through macros ... Ugh ...
474 # // SENF_PARSER_COLLECTION_TAG_EXPAND__<tag>(<tag args>)
475 # // expand to the real tag type
476 # // SENF_PARSER_COLLECTION_TAG_GETAUX__<name>(<args>)
477 # // return the real aux field. More specifically, this is the aux argument to the aux expand
479 # // SENF_PARSER_COLLECTION_TAG_AUXTYPE__<name>(<args>)
480 # // return an identifier selecting the aux type macro to use. If the expansion of this macro
481 # // is <auxtag>, the macro will be called SENF_PARSER_COLLECTION_TAG_AUXDEF__<auxtag>
482 # // SENF_PARSER_COLLECTION_TAG_AUXDEF__<auxtag>(<name>,<auxarg>)
483 # // this command must declare the typedef <fieldname>_aux_type to the base aux policy
485 # define SENF_PARSER_COLLECTION_TAG_GOBBLE__bytes(x)
486 # define SENF_PARSER_COLLECTION_TAG__bytes(x) bytes()
487 # define SENF_PARSER_COLLECTION_TAG_EXPAND__bytes() senf::detail::auxtag::bytes
488 # define SENF_PARSER_COLLECTION_TAG_GETAUX__bytes(x) x
489 # define SENF_PARSER_COLLECTION_TAG_AUXTYPE__bytes(x) auxField
491 # define SENF_PARSER_COLLECTION_TAG_GOBBLE__transform(x,y)
492 # define SENF_PARSER_COLLECTION_TAG__transform(x,y) \
493 transform(x, SENF_PARSER_COLLECTION_TAG_RECURS1(y))
494 # define SENF_PARSER_COLLECTION_TAG_EXPAND__transform(x,y) \
495 senf::detail::auxtag::transform< \
497 SENF_CAT_RECURS1(SENF_PARSER_COLLECTION_TAG_EXPAND__, y)>
498 # define SENF_PARSER_COLLECTION_TAG_GETAUX__transform(x,y) \
499 SENF_PARSER_COLLECTION_TAG_GETAUX_RECURS1(y)
500 # define SENF_PARSER_COLLECTION_TAG_AUXTYPE__transform(x,y) \
501 SENF_PARSER_COLLECTION_TAG_AUXTYPE_RECURS1(y)
503 # define SENF_PARSER_COLLECTION_TAG_GOBBLE__packetSize()
504 # define SENF_PARSER_COLLECTION_TAG__packetSize() packetSize()
505 # define SENF_PARSER_COLLECTION_TAG_EXPAND__packetSize() senf::detail::auxtag::bytes
506 # define SENF_PARSER_COLLECTION_TAG_GETAUX__packetSize() _
507 # define SENF_PARSER_COLLECTION_TAG_AUXTYPE__packetSize() packetSize
509 # // No recursive call so we need some more of theese ... ARGH !!!
510 # define SENF_CAT_RECURS1(a, b) SENF_CAT_RECURS1_I(a,b)
511 # define SENF_CAT_RECURS1_I(a, b) a ## b
512 # define SENF_CAT_RECURS2(a, b) SENF_CAT_RECURS2_I(a,b)
513 # define SENF_CAT_RECURS2_I(a, b) a ## b
514 # define SENF_CAT_RECURS3(a, b) SENF_CAT_RECURS3_I(a,b)
515 # define SENF_CAT_RECURS3_I(a, b) a ## b
517 # define SENF_PARSER_COLLECTION_TAG_EXPAND__none() senf::detail::auxtag::none
519 # define SENF_PARSER_COLLECTION_TAG_RECURS1(aux) \
521 SENF_PARSER_COLLECTION_HAS_KEYWORD(aux), \
522 BOOST_PP_CAT(SENF_PARSER_COLLECTION_TAG__, aux), \
525 # define SENF_PARSER_COLLECTION_TAG_GETAUX_RECURS1(aux) \
527 SENF_PARSER_COLLECTION_HAS_KEYWORD(aux), \
528 BOOST_PP_CAT(SENF_PARSER_COLLECTION_TAG_GETAUX__, aux), \
531 # define SENF_PARSER_COLLECTION_TAG_AUXTYPE_RECURS1(aux) \
533 SENF_PARSER_COLLECTION_HAS_KEYWORD(aux), \
534 BOOST_PP_CAT(SENF_PARSER_COLLECTION_TAG_AUXTYPE__, aux), \
537 # define SENF_PARSER_COLLECTION_HAS_KEYWORD(x) \
538 BOOST_PP_IS_EMPTY( SENF_CAT_RECURS1(SENF_PARSER_COLLECTION_TAG_GOBBLE__, x) )
540 # define SENF_PARSER_COLLECTION_GETAUX(aux) \
541 BOOST_PP_IF( SENF_PARSER_COLLECTION_HAS_KEYWORD(aux), \
542 SENF_CAT_RECURS2(SENF_PARSER_COLLECTION_TAG_GETAUX__, aux), \
545 # define SENF_PARSER_COLLECTION_I(access, name, aux, traits) \
547 SENF_PARSER_COLLECTION_II \
549 SENF_PARSER_COLLECTION_HAS_KEYWORD(aux), \
552 SENF_CAT_RECURS2(SENF_PARSER_COLLECTION_TAG_AUXTYPE__, aux), \
553 SENF_CAT_RECURS2(SENF_PARSER_COLLECTION_TAG_GETAUX__, aux), \
554 SENF_CAT_RECURS2(SENF_PARSER_COLLECTION_TAG__, aux), \
563 # define SENF_PARSER_COLLECTION_II(access, name, auxtype, aux, tag, traits) \
565 BOOST_PP_CAT(SENF_PARSER_COLLECTION_TAG_AUXDEF__, auxtype)(name, aux) \
566 typedef traits::parser< \
567 BOOST_PP_CAT(name,_aux_policy), \
568 BOOST_PP_CAT(SENF_PARSER_COLLECTION_TAG_EXPAND__, tag) \
569 >::type BOOST_PP_CAT(name, _collection_t); \
571 SENF_PARSER_FIELD_SETUP_I( name, \
572 BOOST_PP_CAT(name, _collection_t), \
576 BOOST_PP_CAT(SENF_PARSER_COLLECTION_TAG_VAL__, auxtype)(name, aux, access) \
579 # define SENF_PARSER_COLLECTION_TAG_AUXDEF__auxField(name, aux) \
580 BOOST_PP_CAT(SENF_PARSER_COLLECTION_AUXTYPE_, SENF_PARSER_TYPE)(name, aux) \
581 typedef BOOST_PP_CAT(SENF_PARSER_COLLECTION_AUX_I_, SENF_PARSER_TYPE)(name, aux) \
582 BOOST_PP_CAT(name,_aux_policy);
584 # define SENF_PARSER_COLLECTION_AUXTYPE_var(name, aux) \
585 static bool const BOOST_PP_CAT(name, _aux_fixed) = \
586 (SENF_MPL_SLOT_GET(group) - BOOST_PP_CAT(aux, _group) == 0);
588 # define SENF_PARSER_COLLECTION_AUXTYPE_fix(name, aux)
592 namespace senf { namespace detail {
593 template <class Parser> struct DynamicAuxParserPolicy;
594 template <class Parser, unsigned offset> struct FixedAuxParserPolicy;
595 template <class Parser, unsigned fixedOffset, bool fixedDelta>
596 struct ParserAuxPolicySelect
597 { typedef senf::detail::DynamicAuxParserPolicy<Parser> type; };
598 template <class Parser, unsigned fixedOffset>
599 struct ParserAuxPolicySelect<Parser, fixedOffset, true>
600 { typedef senf::detail::FixedAuxParserPolicy<Parser, fixedOffset> type; };
605 # define SENF_PARSER_COLLECTION_AUX_I_var(name, aux) \
606 senf::detail::ParserAuxPolicySelect< BOOST_PP_CAT(aux, _t), \
607 SENF_PARSER_CURRENT_FIXED_OFFSET() \
608 - SENF_PARSER_FIXED_OFFSET(aux), \
609 BOOST_PP_CAT(name, _aux_fixed) >::type
611 # define SENF_PARSER_COLLECTION_AUX_I_fix(name, aux) \
612 senf::detail::FixedAuxParserPolicy< BOOST_PP_CAT(aux, _t), \
613 SENF_PARSER_CURRENT_FIXED_OFFSET() \
614 - SENF_PARSER_FIXED_OFFSET(aux) >
616 # define SENF_PARSER_COLLECTION_TAG_AUXDEF__packetSize(name, aux) \
617 typedef senf::detail::PacketSizeAuxParserPolicy BOOST_PP_CAT(name, _aux_policy);
619 # define SENF_PARSER_COLLECTION_TAG_VAL__auxField(name, aux, access) \
620 BOOST_PP_CAT(SENF_PARSER_COLLECTION_VAL_, SENF_PARSER_TYPE)(name, aux, access)
622 # define SENF_PARSER_COLLECTION_VAL_var(name,aux,access) \
624 template <class T> T BOOST_PP_CAT(name, _dispatch)(boost::true_type) const \
625 { return parse<T>( SENF_PARSER_OFFSET(name) ); } \
626 template <class T> T BOOST_PP_CAT(name, _dispatch)(boost::false_type) const \
627 { return parse<T>( BOOST_PP_CAT(aux,_)(), SENF_PARSER_OFFSET(name) ); } \
628 BOOST_PP_CAT(name, _t) BOOST_PP_CAT(name, _)() const \
629 { return BOOST_PP_CAT(name, _dispatch) <BOOST_PP_CAT(name, _t)>( \
630 boost::integral_constant<bool, BOOST_PP_CAT(name, _aux_fixed)>()); } \
632 BOOST_PP_CAT(name, _t) name() const \
633 { return BOOST_PP_CAT(name, _)(); }
635 # define SENF_PARSER_COLLECTION_VAL_fix(name,aux,access) \
637 BOOST_PP_CAT(name, _t) BOOST_PP_CAT(name, _)() const \
638 { return parse<BOOST_PP_CAT(name, _t)>( SENF_PARSER_OFFSET(name) ); } \
640 BOOST_PP_CAT(name, _t) name() const \
641 { return BOOST_PP_CAT(name, _)(); }
643 # define SENF_PARSER_COLLECTION_TAG_VAL__packetSize(name, aux, access) \
645 BOOST_PP_CAT(name, _t) BOOST_PP_CAT(name, _)() const \
646 { return parse<BOOST_PP_CAT(name, _t)>( SENF_PARSER_OFFSET(name) ); } \
648 BOOST_PP_CAT(name, _t) name() const \
649 { return BOOST_PP_CAT(name, _)(); }
651 # ////////////////////////////////ih.e///////////////////////////////////////
655 # // Local Variables:
657 # // fill-column: 100
658 # // c-file-style: "senf"
659 # // indent-tabs-mode: nil
660 # // ispell-local-dictionary: "american"
661 # // compile-command: "scons -u test"