1 # // Copyright (C) 2007
2 # // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 # // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
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/facilities/expand.hpp>
30 # include "../Utils/mpl.hh"
32 # ////////////////////////////////ih.p///////////////////////////////////////
34 # define SENF_PARSER_I_FIELD_INTRO(name, type) \
35 typedef type BOOST_PP_CAT(name, _t); \
36 static size_type const BOOST_PP_CAT(name,_index) = SENF_MPL_SLOT_GET(index)+1; \
38 SENF_MPL_SLOT_SET(index, BOOST_PP_CAT(name,_index)); \
41 # define SENF_PARSER_I_FIELD_INIT_rw(name, type) \
43 void init_chain(senf::mpl::rv<BOOST_PP_CAT(name,_index)>*) { \
44 init_chain(static_cast<senf::mpl::rv<BOOST_PP_CAT(name,_index)-1>*>(0)); \
49 # define SENF_PARSER_I_FIELD_INIT_ro(name, type) \
51 void init_chain(senf::mpl::rv<BOOST_PP_CAT(name,_index)>*) { \
52 init_chain(static_cast<senf::mpl::rv<BOOST_PP_CAT(name,_index)-1>*>(0)); \
56 # define SENF_PARSER_I_SIZE_var(name, type) senf::bytes(name())
57 # define SENF_PARSER_I_INITBYTES_var(name, type) senf::init_bytes<type>::value
59 # define SENF_PARSER_I_ADVANCE_OFS_var(name, type, size, isize) \
61 size_type BOOST_PP_CAT(name, _next_offset)() const { \
62 return BOOST_PP_CAT(name,_offset)() + size; \
64 size_type field_offset_(senf::mpl::rv<BOOST_PP_CAT(name,_index)>*) const { \
65 return BOOST_PP_CAT(name, _next_offset)(); \
67 SENF_MPL_SLOT_SET(init_bytes, SENF_MPL_SLOT_GET(init_bytes) + isize); \
70 # define SENF_PARSER_I_FIELD_OFS_var(name, type) \
71 size_type BOOST_PP_CAT(name,_offset)() const { \
72 return field_offset_(static_cast<senf::mpl::rv<BOOST_PP_CAT(name,_index)-1>*>(0)); \
75 # define SENF_PARSER_I_FIELD_OFS_AFTER_var(name, type, prev) \
76 size_type BOOST_PP_CAT(name,_offset)() const { \
77 return BOOST_PP_CAT(prev,_next_offset)(); \
80 # define SENF_PARSER_I_SIZE_fix(name, type) type::fixed_bytes
81 # define SENF_PARSER_I_INITBYTES_fix(name, type) void
83 # define SENF_PARSER_I_ADVANCE_OFS_fix(name, type, size, isize) \
85 static size_type const BOOST_PP_CAT(name, _next_offset) = \
86 BOOST_PP_CAT(name, _offset) + size; \
87 SENF_MPL_SLOT_SET(offset, BOOST_PP_CAT(name, _next_offset)); \
90 # define SENF_PARSER_I_FIELD_OFS_fix(name, type) \
91 static size_type const BOOST_PP_CAT(name, _offset) = SENF_MPL_SLOT_GET(offset);
93 # define SENF_PARSER_I_FIELD_OFS_AFTER_fix(name, type, prev) \
94 static size_type const BOOST_PP_CAT(name, _offset) = BOOST_PP_CAT(prev, _next_offset);
96 # define SENF_PARSER_I_MAYBECALL_var() ()
97 # define SENF_PARSER_I_MAYBECALL_fix()
99 # define SENF_PARSER_I_FIELD_VAL_rw(name,type,ofstype) \
100 BOOST_PP_CAT(name, _t) name() const { \
101 return parse<type>( \
102 BOOST_PP_CAT(name,_offset) BOOST_PP_CAT(SENF_PARSER_I_MAYBECALL_, ofstype)()); \
105 # define SENF_PARSER_I_FIELD_VAL_ro(name,type,ofstype) \
106 BOOST_PP_CAT(name, _t)::value_type name() const { \
107 return parse<type>( \
108 BOOST_PP_CAT(name,_offset) BOOST_PP_CAT(SENF_PARSER_I_MAYBECALL_, ofstype)() \
112 # define SENF_PARSER_FIELD_I(name, type, ofstype, rwtype) \
113 SENF_PARSER_I_BITFIELD_RESET() \
114 SENF_PARSER_I_FIELD_INTRO(name, type) \
115 BOOST_PP_CAT(SENF_PARSER_I_FIELD_INIT_, rwtype) (name, type) \
116 BOOST_PP_CAT(SENF_PARSER_I_FIELD_OFS_, ofstype) (name, type) \
117 BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) ( \
119 BOOST_PP_CAT(SENF_PARSER_I_SIZE_, ofstype) (name, type), \
120 BOOST_PP_CAT(SENF_PARSER_I_INITBYTES_, ofstype) (name, type) ) \
121 BOOST_PP_CAT(SENF_PARSER_I_FIELD_VAL_, rwtype) (name, type, ofstype)
123 # define SENF_PARSER_FIELD_I_AFTER(name, type, prev, ofstype, rwtype) \
124 SENF_PARSER_I_BITFIELD_RESET() \
125 SENF_PARSER_I_FIELD_INTRO(name, type) \
126 BOOST_PP_CAT(SENF_PARSER_I_FIELD_INIT_, rwtype) (name, type) \
127 BOOST_PP_CAT(SENF_PARSER_I_FIELD_OFS_AFTER_, ofstype) (name, type, prev); \
128 BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) ( \
130 BOOST_PP_CAT(SENF_PARSER_I_SIZE_, ofstype) (name, type), \
131 BOOST_PP_CAT(SENF_PARSER_I_INITBYTES_, ofstype) (name, type) ) \
132 BOOST_PP_CAT(SENF_PARSER_I_FIELD_VAL_, rwtype) (name, type, ofstype)
134 # define SENF_PARSER_CUSTOM_FIELD_I(name, type, size, isize, ofstype) \
135 SENF_PARSER_I_BITFIELD_RESET() \
136 SENF_PARSER_I_FIELD_INTRO(name, type) \
137 SENF_PARSER_I_FIELD_INIT_ro(name, type) \
138 BOOST_PP_CAT(SENF_PARSER_I_FIELD_OFS_, ofstype) (name, type) \
139 BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) (name, type, size, isize) \
140 BOOST_PP_CAT(name, _t) name() const
142 # define SENF_PARSER_CUSTOM_FIELD_I_AFTER(name, type, size, isize, prev, ofstype) \
143 SENF_PARSER_I_BITFIELD_RESET() \
144 SENF_PARSER_I_FIELD_INTRO(name, type) \
145 SENF_PARSER_I_FIELD_INIT_ro(name, type) \
146 BOOST_PP_CAT(SENF_PARSER_I_FIELD_OFS_AFTER, ofstype) (name, type, prev) \
147 BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) (name, type, size) \
148 BOOST_PP_CAT(name, _t) name() const
150 # define SENF_PARSER_I_BITFIELD_RESET() \
151 SENF_MPL_SLOT_SET(bit, 0); \
152 SENF_MPL_SLOT_SET(bitfield_size, 0);
154 # define SENF_PARSER_BITFIELD_I(name, bits, type, ofstype, rwtype) \
155 static size_type const BOOST_PP_CAT(name, _bit) = SENF_MPL_SLOT_GET(bit); \
157 SENF_MPL_SLOT_SET(bit, BOOST_PP_CAT(name, _bit) + bits); \
158 typedef BOOST_PP_CAT(SENF_PARSER_BITFIELD_TYPE_, type)( BOOST_PP_CAT(name, _bit), bits ) \
159 BOOST_PP_CAT(name,_bit_t ); \
161 SENF_PARSER_BITFIELD_II( name, bits, BOOST_PP_CAT(name, _bit_t), ofstype, rwtype)
163 # define SENF_PARSER_BITFIELD_TYPE_signed(start, bits) senf::Parse_IntField<start, start+bits>
164 # define SENF_PARSER_BITFIELD_TYPE_unsigned(start, bits) senf::Parse_UIntField<start, start+bits>
165 # define SENF_PARSER_BITFIELD_TYPE_bool(start, bits) senf::Parse_Flag<start>
167 # define SENF_PARSER_BITFIELD_II(name, bits, type, ofstype, rwtype) \
168 SENF_PARSER_I_FIELD_INTRO(name, type) \
169 SENF_PARSER_I_FIELD_INIT_ro(name, type) \
170 BOOST_PP_CAT(SENF_PARSER_I_BITFIELD_OFS_, ofstype) (name, type) \
171 BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) ( \
173 BOOST_PP_CAT(name, _t)::fixed_bytes, BOOST_PP_CAT(name, _t)::fixed_bytes ) \
175 SENF_MPL_SLOT_SET(bitfield_size, BOOST_PP_CAT(name, _t)::fixed_bytes); \
177 BOOST_PP_CAT(SENF_PARSER_I_FIELD_VAL_, rwtype) (name, type, ofstype)
179 # define SENF_PARSER_I_BITFIELD_OFS_var(name, type) \
180 size_type BOOST_PP_CAT(name,_offset)() const { \
181 return field_offset_(static_cast<senf::mpl::rv<BOOST_PP_CAT(name,_index)-1>*>(0)) \
182 - SENF_MPL_SLOT_GET(bitfield_size); \
185 # define SENF_PARSER_I_BITFIELD_OFS_fix(name, type) \
186 static size_type const BOOST_PP_CAT(name, _offset) = SENF_MPL_SLOT_GET(offset) \
187 - SENF_MPL_SLOT_GET(bitfield_size);
189 # define SENF_PARSER_INHERIT_I(name) \
191 SENF_MPL_SLOT_SET(index, 1); \
192 SENF_MPL_SLOT_SET(init_bytes, senf::init_bytes<name>::value); \
193 size_type field_offset_(senf::mpl::rv<1>*) const { \
194 return senf::bytes( *static_cast<name*>(this) ); \
196 void init_chain(senf::mpl::rv<inherit_index_>*) { \
201 # define SENF_PARSER_FIXED_INHERIT_I(name) \
203 SENF_MPL_SLOT_SET(offset, name::fixed_bytes); \
204 SENF_MPL_SLOT_SET(index, 1); \
205 void init_chain(senf::mpl::rv<1>*) { \
211 # ////////////////////////////////ih.e///////////////////////////////////////
215 # // Local Variables:
217 # // fill-column: 100
218 # // c-file-style: "senf"
219 # // indent-tabs-mode: nil
220 # // ispell-local-dictionary: "american"
221 # // compile-command: "scons -u test"