Fix SCons 1.2.0 build failure
[senf.git] / senf / Packets / ParseHelpers.ih
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>
5 # //
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.
10 # //
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.
15 # //
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.
20 #
21 # /** \file
22 #     \brief ParseHelpers internal header */
23 #
24 # if !defined(IH_ParseHelpers_)
25 # define IH_ParseHelpers_ 1
26 #
27 # // Custom includes
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"
34 #
35 # ////////////////////////////////ih.p///////////////////////////////////////
36 #
37 # ///////////////////////////////////////////////////////////////////////////
38 # // SENF_PARSER_INITIALIZE
39 #
40 # define SENF_PARSER_INITIALIZE  BOOST_PP_CAT( SENF_PARSER_INITIALIZE_ , SENF_PARSER_TYPE )
41 #
42 # define SENF_PARSER_INITIALIZE_fix()                                                             \
43     private:                                                                                      \
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 {}                                               \
49     public:
50 #
51 # define SENF_PARSER_INITIALIZE_var()                                                             \
52     private:                                                                                      \
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; }                            \
60     public:
61 #
62 # ///////////////////////////////////////////////////////////////////////////
63 # // SENF_PARSER_INHERIT_*
64 #
65 # define SENF_PARSER_INHERIT_var(name)                                                            \
66         typedef name parser_base_type;                                                            \
67     private:                                                                                      \
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) );                                \
72         }                                                                                         \
73         void init_chain(senf::mpl::rv<1>*) const {                                                \
74             name::init();                                                                         \
75         }                                                                                         \
76     public:
77 #
78 # define SENF_PARSER_INHERIT_fix(name)                                                            \
79         typedef name parser_base_type;                                                            \
80     private:                                                                                      \
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 {                                                \
84             name::init();                                                                         \
85         }                                                                                         \
86     public:
87 #
88 # ///////////////////////////////////////////////////////////////////////////
89 # // SENF_PARSER_FIELD*
90 # // SENF_PARSER_P_FIELD_*
91 #
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)
96 #
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)
99 #
100 # define SENF_PARSER_FIELD_I(name, type, ofstype, rwtype, access)                                 \
101     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)                       \
104     public:
105 #
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) (                                       \
112             name, type,                                                                           \
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),                             \
116             access )
117 #
118 # ////////////////////////////////////////
119 # // SENF_PARSER_I_FIELD_INTRO
120 #
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;            \
124     private:                                                                                      \
125         SENF_MPL_SLOT_SET(index, BOOST_PP_CAT(name,_index));                                      \
126     access:
127 #
128 # ////////////////////////////////////////
129 # // SENF_PARSER_I_FIELD_INIT_*
130 #
131 # define SENF_PARSER_I_FIELD_INIT_rw(name, type, access)                                          \
132     private:                                                                                      \
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));              \
135             name().init();                                                                        \
136         }                                                                                         \
137     access:
138 #
139 # define SENF_PARSER_I_FIELD_INIT_ro(name, type, access)                                          \
140     private:                                                                                      \
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));              \
143         }                                                                                         \
144     access:
145 #
146 # ////////////////////////////////////////
147 # // SENF_PARSER_I_FIELD_OFS_*
148 #
149 # define SENF_PARSER_I_FIELD_OFS_var(name, type, access)                                          \
150     protected:                                                                                    \
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));    \
153         }                                                                                         \
154         static size_type const BOOST_PP_CAT(name, _init_bytes) =                                  \
155             SENF_MPL_SLOT_GET(init_bytes);                                                        \
156     private:
157 #
158 # define SENF_PARSER_I_FIELD_OFS_fix(name, type, access)                                          \
159     protected:                                                                                    \
160         static size_type const BOOST_PP_CAT(name, _offset) =                                      \
161             SENF_MPL_SLOT_GET(offset);                                                            \
162     private:
163 #
164 # ////////////////////////////////////////
165 # // SENF_PARSER_I_ADVANCE_OFS_*
166 #
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
169 #
170 # define SENF_PARSER_I_SIZE_fix(name, type) type::fixed_bytes
171 # define SENF_PARSER_I_INITBYTES_fix(name, type) void
172 #
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)
175 #
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;                                           \
179         }                                                                                         \
180         static size_type const BOOST_PP_CAT(name, _next_init_bytes) =                             \
181             BOOST_PP_CAT(name, _init_bytes) + isize;                                              \
182     private:                                                                                      \
183         size_type field_offset_(senf::mpl::rv<BOOST_PP_CAT(name,_index)>*) const {                \
184             return BOOST_PP_CAT(name, _next_offset)();                                            \
185         }                                                                                         \
186         SENF_MPL_SLOT_SET(init_bytes, BOOST_PP_CAT(name,_next_init_bytes));                       \
187     protected:                                                                                    \
188         static size_type const BOOST_PP_CAT(name, _group) = SENF_MPL_SLOT_GET(group) + isvar;     \
189     private:                                                                                      \
190         SENF_MPL_SLOT_SET(group, BOOST_PP_CAT(name, _group));                                     \
191     access:
192 #
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;                                                   \
196     private:                                                                                      \
197         SENF_MPL_SLOT_SET(offset, BOOST_PP_CAT(name, _next_offset));                              \
198     access:
199 #
200 # ////////////////////////////////////////
201 # // SENF_PARSER_I_FIELD_VAL_*
202 #
203 # define SENF_PARSER_I_FIELD_VAL_rw(name, type, access)                                           \
204     protected:                                                                                    \
205         BOOST_PP_CAT(name, _t) BOOST_PP_CAT(name, _)() const {                                    \
206             return parse<type>( SENF_PARSER_OFFSET(name) );                                       \
207         }                                                                                         \
208     access:                                                                                       \
209         BOOST_PP_CAT(name, _t) name() const {                                                     \
210             return BOOST_PP_CAT(name,_)();                                                        \
211         }
212 #
213 # define SENF_PARSER_I_FIELD_VAL_ro(name, type, access)                                           \
214     protected:                                                                                    \
215         BOOST_PP_CAT(name, _t) BOOST_PP_CAT(name, _)() const {                                    \
216             return parse<type>( SENF_PARSER_OFFSET(name) );                                       \
217         }                                                                                         \
218     access:                                                                                       \
219         BOOST_PP_CAT(name, _t)::value_type name() const {                                         \
220             return BOOST_PP_CAT(name,_)();                                                        \
221         }
222 #
223 # ///////////////////////////////////////////////////////////////////////////
224 # // SENF_PARSER_CUSTOM_FIELD_*
225 #
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)
230 #
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
238 #
239 # ///////////////////////////////////////////////////////////////////////////
240 # // SENF_PARSER_BITFIELD_*
241 # // SENF_PARSER_P_BITFIELD_*
242 #
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)
251 #
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)
256 #
257 # ////////////////////////////////////////
258 # // SENF_PARSER_BITFIELD_I
259 #
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>
263 #
264 # define SENF_PARSER_BITFIELD_I(name, bits, type, ofstype, rwtype, access)                        \
265     access:                                                                                       \
266         static size_type const BOOST_PP_CAT(name, _bit) = SENF_MPL_SLOT_GET(bit);                 \
267     private:                                                                                      \
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 );                                                          \
271     access:                                                                                       \
272         SENF_PARSER_BITFIELD_II( name, bits, BOOST_PP_CAT(name, _bit_t), ofstype, rwtype, access) \
273     public:
274 #
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) (                                      \
280              name, type,                                                                          \
281              BOOST_PP_CAT(name, _t)::fixed_bytes, BOOST_PP_CAT(name, _t)::fixed_bytes,            \
282              0,                                                                                   \
283              access)                                                                              \
284     private:                                                                                      \
285          SENF_MPL_SLOT_SET(bitfield_size, BOOST_PP_CAT(name, _t)::fixed_bytes);                   \
286     access:                                                                                       \
287          BOOST_PP_CAT(SENF_PARSER_I_FIELD_VAL_, rwtype) (name, type, access)                      \
288     public:
289 #
290 # ////////////////////////////////////////
291 # // SENF_PARSER_I_BITFIELD_OFS_*
292 #
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);                                               \
297         }                                                                                         \
298         static size_type const BOOST_PP_CAT(name, _init_bytes) =                                  \
299             SENF_MPL_SLOT_GET(init_bytes) - SENF_MPL_SLOT_GET(bitfield_size);
300 #
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);
304 #
305 # ////////////////////////////////////////
306 # // SENF_PARSER_I_BITFIELD_RESET
307 #
308 # define SENF_PARSER_I_BITFIELD_RESET()                                                           \
309         SENF_MPL_SLOT_SET(bit, 0);                                                                \
310         SENF_MPL_SLOT_SET(bitfield_size, 0);
311 #
312 # ///////////////////////////////////////////////////////////////////////////
313 # // SENF_PARSER_SKIP_*
314 #
315 # define SENF_PARSER_SKIP_var(bytes, ibytes)                                                      \
316       SENF_PARSER_I_SKIP( BOOST_PP_CAT(senf_anon_, __LINE__), bytes, ibytes, var)
317 #
318 # define SENF_PARSER_SKIP_fix(bytes)                                                              \
319       SENF_PARSER_I_SKIP( BOOST_PP_CAT(senf_anon_, __LINE__), bytes, bytes, fix)
320 #
321 # define SENF_PARSER_I_SKIP(name, bytes, ibytes, ofstype)                                         \
322     private:                                                                                      \
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,        \
328                                                              private)                             \
329     public:
330 #
331 # ///////////////////////////////////////////////////////////////////////////
332 # // SENF_PARSER_SKIP_BITS_*
333 #
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)
336 #
337 # define SENF_PARSER_I_SKIP_BITS(bits, ofstype)                                                   \
338       private:                                                                                    \
339           SENF_MPL_SLOT_SET(bit, SENF_MPL_SLOT_GET(bit) + bits);                                  \
340       public:
341 #
342 # ///////////////////////////////////////////////////////////////////////////
343 # // SENF_PARSER_GOTO_*
344 #
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),                                        \
349                           var )
350 #
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),                                            \
355                           fix )
356 #
357 # define SENF_PARSER_GOTO_OFFSET_var(offset, isize)                                               \
358       SENF_PARSER_I_GOTO( BOOST_PP_CAT(senf_anon_, __LINE__), offset, isize, var )
359 #
360 # define SENF_PARSER_GOTO_OFFSET_fix(offset)                                                      \
361       SENF_PARSER_I_GOTO( BOOST_PP_CAT(senf_anon_, __LINE__), offset, offset, fix )
362 #
363 # define SENF_PARSER_I_GOTO(name, offset, initsize, ofstype)                                      \
364       private:                                                                                    \
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)           \
369       public:
370 #
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 {              \
373               return offs;                                                                        \
374           }                                                                                       \
375           SENF_MPL_SLOT_SET(init_bytes, initsize);
376 #
377 # define SENF_PARSER_I_GOTO_SET_OFS_fix(name, offs, initsize)                                     \
378           SENF_MPL_SLOT_SET(offset, offs);
379 #
380 # ///////////////////////////////////////////////////////////////////////////
381 # // SENF_PARSER_LABEL_*
382 #
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 )
385 #
386 # define SENF_PARSER_I_LABEL(name, ofstype, access)                                               \
387       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)         \
393       public:
394 #
395 # ///////////////////////////////////////////////////////////////////////////
396 # // SENF_PARSER_OFFSET_*
397 #
398 # define SENF_PARSER_OFFSET_fix(name) BOOST_PP_CAT(name, _offset)
399 # define SENF_PARSER_OFFSET_var(name) BOOST_PP_CAT(name, _offset)()
400 #
401 # ///////////////////////////////////////////////////////////////////////////
402 # // SENF_PARSER_FIXED_OFFSET_*
403 #
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)
406 #
407 # ///////////////////////////////////////////////////////////////////////////
408 # // SENF_PARSER_CURRENT_FIXED_OFFSET_*
409 #
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)
412 #
413 # ///////////////////////////////////////////////////////////////////////////
414 # // SENF_PARSER_FINALIZE_*
415 #
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));           \
420     }                                                                                             \
421     static size_type const init_bytes = SENF_MPL_SLOT_GET(init_bytes)
422 #
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);
426 #
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));                \
430          }                                                                                        \
431          name(data_iterator i, state_type s) : parser_base_type(i,s) {}                           \
432     private:                                                                                      \
433          template <class T> void init(T) const { defaultInit(); }                                 \
434     public:                                                                                       \
435          void init() const { init(0); }
436 #
437 # ///////////////////////////////////////////////////////////////////////////
438 # // SENF_PARSER_REQUIRE_VAR
439 #
440 # define SENF_PARSER_REQUIRE_VAR(description) \
441       BOOST_PP_CAT(SENF_PARSER_REQUIRE_VAR_, SENF_PARSER_TYPE)(description)
442 #
443 # define SENF_PARSER_REQUIRE_VAR_var(description)
444 #
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__);
449 #
450 # ///////////////////////////////////////////////////////////////////////////
451 # // SENF_PARSER_COLLECTION_I
452 #
453 # ifndef DOXYGEN
454 #
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 {}; } } }
464 #
465 # endif
466 #
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
478 # //       macro
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
484 #
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
490 #
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<                                                            \
496           x,                                                                                      \
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)
502 #
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
508 #
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
516 #
517 # define SENF_PARSER_COLLECTION_TAG_EXPAND__none() senf::detail::auxtag::none
518 #
519 # define SENF_PARSER_COLLECTION_TAG_RECURS1(aux)                                                  \
520       BOOST_PP_IF(                                                                                \
521           SENF_PARSER_COLLECTION_HAS_KEYWORD(aux),                                                \
522           BOOST_PP_CAT(SENF_PARSER_COLLECTION_TAG__, aux),                                        \
523           none() )
524 #
525 # define SENF_PARSER_COLLECTION_TAG_GETAUX_RECURS1(aux)                                           \
526       BOOST_PP_IF(                                                                                \
527           SENF_PARSER_COLLECTION_HAS_KEYWORD(aux),                                                \
528           BOOST_PP_CAT(SENF_PARSER_COLLECTION_TAG_GETAUX__, aux),                                 \
529           aux)
530 #
531 # define SENF_PARSER_COLLECTION_TAG_AUXTYPE_RECURS1(aux)                                          \
532       BOOST_PP_IF(                                                                                \
533           SENF_PARSER_COLLECTION_HAS_KEYWORD(aux),                                                \
534           BOOST_PP_CAT(SENF_PARSER_COLLECTION_TAG_AUXTYPE__, aux),                                \
535           auxField)
536 #
537 # define SENF_PARSER_COLLECTION_HAS_KEYWORD(x)                                                    \
538       BOOST_PP_IS_EMPTY( SENF_CAT_RECURS1(SENF_PARSER_COLLECTION_TAG_GOBBLE__, x) )
539 #
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),                    \
543                    aux )
544
545 # define SENF_PARSER_COLLECTION_I(access, name, aux, traits)                                      \
546       BOOST_PP_EXPAND(                                                                            \
547           SENF_PARSER_COLLECTION_II                                                               \
548               BOOST_PP_IF(                                                                        \
549                   SENF_PARSER_COLLECTION_HAS_KEYWORD(aux),                                        \
550                   ( access,                                                                       \
551                     name,                                                                         \
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),                          \
555                     traits ),                                                                     \
556                   ( access,                                                                       \
557                     name,                                                                         \
558                     auxField,                                                                     \
559                     aux,                                                                          \
560                     none(),                                                                       \
561                     traits ) ))
562 #
563 # define SENF_PARSER_COLLECTION_II(access, name, auxtype, aux, tag, traits)                       \
564       private:                                                                                    \
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);                                          \
570       access:                                                                                     \
571           SENF_PARSER_FIELD_SETUP_I( name,                                                        \
572                                      BOOST_PP_CAT(name, _collection_t),                           \
573                                      SENF_PARSER_TYPE,                                            \
574                                      rw,                                                          \
575                                      access )                                                     \
576           BOOST_PP_CAT(SENF_PARSER_COLLECTION_TAG_VAL__, auxtype)(name, aux, access)              \
577       public:
578 #
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);
583 #
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);
587 #
588 # define SENF_PARSER_COLLECTION_AUXTYPE_fix(name, aux)
589 #
590 # ifndef DOXYGEN
591 #
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; };
601   }};
602 #
603 # endif
604 #
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
610 #
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) >
615 #
616 # define SENF_PARSER_COLLECTION_TAG_AUXDEF__packetSize(name, aux)                                 \
617           typedef senf::detail::PacketSizeAuxParserPolicy BOOST_PP_CAT(name, _aux_policy);
618 #
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)
621 #
622 # define SENF_PARSER_COLLECTION_VAL_var(name,aux,access)                                          \
623       private:                                                                                    \
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)>()); }            \
631       access:                                                                                     \
632           BOOST_PP_CAT(name, _t) name() const                                                     \
633           { return BOOST_PP_CAT(name, _)(); }
634 #
635 # define SENF_PARSER_COLLECTION_VAL_fix(name,aux,access)                                          \
636       private:                                                                                    \
637           BOOST_PP_CAT(name, _t) BOOST_PP_CAT(name, _)() const                                    \
638           { return parse<BOOST_PP_CAT(name, _t)>( SENF_PARSER_OFFSET(name) ); }                   \
639       access:                                                                                     \
640           BOOST_PP_CAT(name, _t) name() const                                                     \
641           { return BOOST_PP_CAT(name, _)(); }
642 #
643 # define SENF_PARSER_COLLECTION_TAG_VAL__packetSize(name, aux, access)                            \
644       private:                                                                                    \
645           BOOST_PP_CAT(name, _t) BOOST_PP_CAT(name, _)() const                                    \
646           { return parse<BOOST_PP_CAT(name, _t)>( SENF_PARSER_OFFSET(name) ); }                   \
647       access:                                                                                     \
648           BOOST_PP_CAT(name, _t) name() const                                                     \
649           { return BOOST_PP_CAT(name, _)(); }
650 #
651 # ////////////////////////////////ih.e///////////////////////////////////////
652 # endif
653 #
654 #
655 # // Local Variables:
656 # // mode: c++
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"
662 # // End: