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(fields) \
69 size_type offset_0_() const { return 0; } \
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(fields) \
86 static const size_type offset_0_ = 0; \
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 type name () const { \
97 return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () ); \
99 size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) () const { \
100 return BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () + senf::bytes( name () ); \
103 # define SENF_PACKET_PARSER_I_FIXED_Field(n,name,type) \
104 type name () const { \
105 return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) ); \
107 static const size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) = \
108 BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) + type::fixed_bytes;
110 # define SENF_PACKET_PARSER_I_OverlayField(n,name,type) \
111 type name () const { \
112 return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () ); \
114 size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) () const { \
115 return BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) (); \
118 # define SENF_PACKET_PARSER_I_FIXED_OverlayField(n,name,type) \
119 type name () const { \
120 return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) ); \
122 static const size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) = \
123 BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_));
125 # ///////////////////////////////mpp.e///////////////////////////////////////
129 # // Local Variables:
131 # // fill-column: 100
132 # // c-file-style: "senf"
133 # // indent-tabs-mode: nil
134 # // ispell-local-dictionary: "american"
135 # // compile-command: "scons -u test"