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 PacketParser Boost.Preprocesser definitions */
24 # if !defined(MPP_PacketParser_)
25 # define MPP_PacketParser_ 1
28 # include <boost/preprocessor/seq/for_each_i.hpp>
29 # include <boost/preprocessor/seq/for_each.hpp>
30 # include <boost/preprocessor/seq/size.hpp>
31 # include <boost/preprocessor/cat.hpp>
32 # include <boost/preprocessor/inc.hpp>
33 # include <boost/preprocessor/tuple/elem.hpp>
34 # include <boost/preprocessor/facilities/expand.hpp>
36 # ///////////////////////////////mpp.p///////////////////////////////////////
38 # define SENF_PACKET_PARSER_I_UNWRAP(n,elt) (n,SENF_PACKET_PARSER_I_UNWRAP_1 elt)
39 # define SENF_PACKET_PARSER_I_UNWRAP_1(x) x,SENF_PACKET_PARSER_I_UNWRAP_2
40 # define SENF_PACKET_PARSER_I_UNWRAP_2(x,y) x,y
42 # define SENF_PACKET_PARSER_I_GET_NAME(elt) SENF_PACKET_PARSER_I_GET_NAME_1 elt
43 # define SENF_PACKET_PARSER_I_GET_NAME_1(x) SENF_PACKET_PARSER_I_GET_NAME_2
44 # define SENF_PACKET_PARSER_I_GET_NAME_2(name,type) name
46 # define SENF_PACKET_PARSER_I_GET_TYPE(elt) SENF_PACKET_PARSER_I_GET_TYPE_1 elt
47 # define SENF_PACKET_PARSER_I_GET_TYPE_1(x) SENF_PACKET_PARSER_I_GET_TYPE_2
48 # define SENF_PACKET_PARSER_I_GET_TYPE_2(name,type) type
50 # define SENF_PACKET_PARSER_I_DEFINE_INIT_C(_0,_1,elt) \
51 SENF_PACKET_PARSER_I_GET_NAME(elt) ().init();
53 # define SENF_PACKET_PARSER_I_DEFINE_INIT(fields) \
54 void defaultInit() const { \
55 BOOST_PP_SEQ_FOR_EACH( SENF_PACKET_PARSER_I_DEFINE_INIT_C, _, fields) \
58 # define SENF_PACKET_PARSER_I_FIELD_DISPATCH(n,t,name,type) \
59 SENF_PACKET_PARSER_I_ ## t(n,name,type)
61 # define SENF_PACKET_PARSER_I_FIELD_C(_0,_1,n,elt) \
63 SENF_PACKET_PARSER_I_FIELD_DISPATCH SENF_PACKET_PARSER_I_UNWRAP(n,elt))
65 # define SENF_PACKET_PARSER_I_INITSIZE_C(_0,_1,n,elt) \
66 BOOST_PP_IF(n,+,) senf::init_bytes< SENF_PACKET_PARSER_I_GET_TYPE(elt) >::value
68 # define SENF_PACKET_PARSER_I_DEFINE_FIELDS(offset,fields) \
69 size_type offset_0_() const { return offset; } \
70 BOOST_PP_SEQ_FOR_EACH_I(SENF_PACKET_PARSER_I_FIELD_C, _, fields) \
71 size_type bytes() const { \
72 return BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_SEQ_SIZE(fields),_)) (); \
74 SENF_PACKET_PARSER_I_DEFINE_INIT(fields) \
75 static const size_type init_bytes = \
76 BOOST_PP_SEQ_FOR_EACH_I(SENF_PACKET_PARSER_I_INITSIZE_C, _, fields) ;
78 # define SENF_PACKET_PARSER_I_FIXED_FIELD_DISPATCH(n,t,name,type) \
79 SENF_PACKET_PARSER_I_FIXED_ ## t(n,name,type)
81 # define SENF_PACKET_PARSER_I_FIXED_FIELD_C(_0,_1,n,elt) \
83 SENF_PACKET_PARSER_I_FIXED_FIELD_DISPATCH SENF_PACKET_PARSER_I_UNWRAP(n,elt))
85 # define SENF_PACKET_PARSER_I_DEFINE_FIXED_FIELDS(offset,fields) \
86 static const size_type offset_0_ = offset; \
87 BOOST_PP_SEQ_FOR_EACH_I(SENF_PACKET_PARSER_I_FIXED_FIELD_C, _, fields) \
88 static const size_type fixed_bytes = \
89 BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_SEQ_SIZE(fields),_)); \
90 SENF_PACKET_PARSER_I_DEFINE_INIT(fields)
92 # ///////////////////////////////////////////////////////////////////////////
93 # // Definition of the field types
95 # define SENF_PACKET_PARSER_I_Field(n,name,type) \
96 typedef type BOOST_PP_CAT(name,_t) ; \
97 type name () const { \
98 return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () ); \
100 size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) () const { \
101 return BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () + senf::bytes( name () ); \
103 size_type BOOST_PP_CAT(name, _offset) () const { \
104 return BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) () ; \
107 # define SENF_PACKET_PARSER_I_FIXED_Field(n,name,type) \
108 typedef type BOOST_PP_CAT(name,_t) ; \
109 type name () const { \
110 return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) ); \
112 static const size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) = \
113 BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) + type::fixed_bytes; \
114 static const size_type BOOST_PP_CAT(name,_offset) = \
115 BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_));
117 # define SENF_PACKET_PARSER_I_OverlayField(n,name,type) \
118 typedef type BOOST_PP_CAT(name,_t) ; \
119 type name () const { \
120 return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () ); \
122 size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) () const { \
123 return BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) (); \
125 size_type BOOST_PP_CAT(name, _offset) () const { \
126 return BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) () ; \
129 # define SENF_PACKET_PARSER_I_FIXED_OverlayField(n,name,type) \
130 typedef type BOOST_PP_CAT(name,_t) ; \
131 type name () const { \
132 return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) ); \
134 static const size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) = \
135 BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)); \
136 static const size_type BOOST_PP_CAT(name,_offset) = \
137 BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_));
139 # ///////////////////////////////mpp.e///////////////////////////////////////
143 # // Local Variables:
145 # // fill-column: 100
146 # // c-file-style: "senf"
147 # // indent-tabs-mode: nil
148 # // ispell-local-dictionary: "american"
149 # // compile-command: "scons -u test"