Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# // Copyright (C) 2007
# // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
# // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
# // Stefan Bund <g0dil@berlios.de>
# //
# // This program is free software; you can redistribute it and/or modify
# // it under the terms of the GNU General Public License as published by
# // the Free Software Foundation; either version 2 of the License, or
# // (at your option) any later version.
# //
# // This program is distributed in the hope that it will be useful,
# // but WITHOUT ANY WARRANTY; without even the implied warranty of
# // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# // GNU General Public License for more details.
# //
# // You should have received a copy of the GNU General Public License
# // along with this program; if not, write to the
# // Free Software Foundation, Inc.,
# // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# /** \file
# \brief PacketParser Boost.Preprocesser definitions */
#
# if !defined(MPP_PacketParser_)
# define MPP_PacketParser_ 1
#
# // Custom includes
# include <boost/preprocessor/seq/for_each_i.hpp>
# include <boost/preprocessor/seq/for_each.hpp>
# include <boost/preprocessor/seq/size.hpp>
# include <boost/preprocessor/cat.hpp>
# include <boost/preprocessor/inc.hpp>
# include <boost/preprocessor/tuple/elem.hpp>
# include <boost/preprocessor/facilities/expand.hpp>
#
# ///////////////////////////////mpp.p///////////////////////////////////////
#
# define SENF_PACKET_PARSER_I_UNWRAP(n,elt) (n,SENF_PACKET_PARSER_I_UNWRAP_1 elt)
# define SENF_PACKET_PARSER_I_UNWRAP_1(x) x,SENF_PACKET_PARSER_I_UNWRAP_2
# define SENF_PACKET_PARSER_I_UNWRAP_2(x,y) x,y
#
# define SENF_PACKET_PARSER_I_GET_NAME(elt) SENF_PACKET_PARSER_I_GET_NAME_1 elt
# define SENF_PACKET_PARSER_I_GET_NAME_1(x) SENF_PACKET_PARSER_I_GET_NAME_2
# define SENF_PACKET_PARSER_I_GET_NAME_2(name,type) name
#
# define SENF_PACKET_PARSER_I_GET_TYPE(elt) SENF_PACKET_PARSER_I_GET_TYPE_1 elt
# define SENF_PACKET_PARSER_I_GET_TYPE_1(x) SENF_PACKET_PARSER_I_GET_TYPE_2
# define SENF_PACKET_PARSER_I_GET_TYPE_2(name,type) type
#
# define SENF_PACKET_PARSER_I_DEFINE_INIT_C(_0,_1,elt) \
SENF_PACKET_PARSER_I_GET_NAME(elt) ().init();
#
# define SENF_PACKET_PARSER_I_DEFINE_INIT(fields) \
void defaultInit() const { \
BOOST_PP_SEQ_FOR_EACH( SENF_PACKET_PARSER_I_DEFINE_INIT_C, _, fields) \
# define SENF_PACKET_PARSER_I_FIELD_DISPATCH(n,t,name,type) \
SENF_PACKET_PARSER_I_ ## t(n,name,type)
#
# define SENF_PACKET_PARSER_I_FIELD_C(_0,_1,n,elt) \
BOOST_PP_EXPAND( \
SENF_PACKET_PARSER_I_FIELD_DISPATCH SENF_PACKET_PARSER_I_UNWRAP(n,elt))
#
# define SENF_PACKET_PARSER_I_INITSIZE_C(_0,_1,n,elt) \
BOOST_PP_IF(n,+,) senf::init_bytes< SENF_PACKET_PARSER_I_GET_TYPE(elt) >::value
#
# define SENF_PACKET_PARSER_I_DEFINE_FIELDS(offset,fields) \
size_type offset_0_() const { return offset; } \
BOOST_PP_SEQ_FOR_EACH_I(SENF_PACKET_PARSER_I_FIELD_C, _, fields) \
size_type bytes() const { \
return BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_SEQ_SIZE(fields),_)) (); \
} \
SENF_PACKET_PARSER_I_DEFINE_INIT(fields) \
static const size_type init_bytes = \
BOOST_PP_SEQ_FOR_EACH_I(SENF_PACKET_PARSER_I_INITSIZE_C, _, fields) ;
#
# define SENF_PACKET_PARSER_I_FIXED_FIELD_DISPATCH(n,t,name,type) \
SENF_PACKET_PARSER_I_FIXED_ ## t(n,name,type)
#
# define SENF_PACKET_PARSER_I_FIXED_FIELD_C(_0,_1,n,elt) \
BOOST_PP_EXPAND( \
SENF_PACKET_PARSER_I_FIXED_FIELD_DISPATCH SENF_PACKET_PARSER_I_UNWRAP(n,elt))
#
# define SENF_PACKET_PARSER_I_DEFINE_FIXED_FIELDS(offset,fields) \
static const size_type offset_0_ = offset; \
BOOST_PP_SEQ_FOR_EACH_I(SENF_PACKET_PARSER_I_FIXED_FIELD_C, _, fields) \
static const size_type fixed_bytes = \
BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_SEQ_SIZE(fields),_)); \
SENF_PACKET_PARSER_I_DEFINE_INIT(fields)
#
# ///////////////////////////////////////////////////////////////////////////
# // Definition of the field types
#
# define SENF_PACKET_PARSER_I_Field(n,name,type) \
typedef type BOOST_PP_CAT(name,_t) ; \
type name () const { \
return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () ); \
} \
size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) () const { \
return BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () + senf::bytes( name () ); \
} \
size_type BOOST_PP_CAT(name, _offset) () const { \
return BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) () ; \
# define SENF_PACKET_PARSER_I_FIXED_Field(n,name,type) \
typedef type BOOST_PP_CAT(name,_t) ; \
type name () const { \
return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) ); \
} \
static const size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) = \
BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) + type::fixed_bytes; \
static const size_type BOOST_PP_CAT(name,_offset) = \
BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_));
#
# define SENF_PACKET_PARSER_I_OverlayField(n,name,type) \
typedef type BOOST_PP_CAT(name,_t) ; \
type name () const { \
return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () ); \
} \
size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) () const { \
return BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) (); \
} \
size_type BOOST_PP_CAT(name, _offset) () const { \
return BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) () ; \
# define SENF_PACKET_PARSER_I_FIXED_OverlayField(n,name,type) \
typedef type BOOST_PP_CAT(name,_t) ; \
type name () const { \
return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) ); \
} \
static const size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) = \
BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)); \
static const size_type BOOST_PP_CAT(name,_offset) = \
BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_));
#
# ///////////////////////////////mpp.e///////////////////////////////////////
# endif
#
#
# // Local Variables:
# // mode: c++
# // fill-column: 100
# // c-file-style: "senf"
# // indent-tabs-mode: nil
# // ispell-local-dictionary: "american"
# // compile-command: "scons -u test"
# // End: