Link statically against boost_unit_test_framework library
[senf.git] / Packets / ParseListB.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
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 ParseListB public header */
23
24 #ifndef HH_ParseListB_
25 #define HH_ParseListB_ 1
26
27 // Custom includes
28 #include "ParseList.hh"
29
30 //#include "ParseListB.mpp"
31 ///////////////////////////////hh.p////////////////////////////////////////
32
33 namespace senf {
34     
35     namespace detail { template <class ElementParser, class BytesParser>
36                        class Parse_ListB_Policy; }
37
38     /** \brief List parser with size-field in bytes
39
40         This list parser will parse a list which size is given by a preceding field containing the
41         length of the list in bytes. This struct is just a template typedef:
42         \code
43         typedef senf::Parse_VectorN< Parser_UInt32, Parser_UInt16 >::parser Parse_MyVector;
44         typedef senf::Parse_ListB< Parse_MyVector, Parse_UInt16 >::parser Parse_MyList;
45         \endcode
46         This first defines a Vector of 32 bit unsigned integers with 16 bit length counter. Then it
47         defines a list of such vectors with a 16 bit bytes field.
48
49         \warning There are some caveats when working with this kind of list
50         \li You may <b>only change the size of a contained element from a container wrapper</b>.
51         \li While you hold a container wrapper, <b>only access the packet through this wrapper</b>
52             or a nested wrapper either for reading or writing.
53
54         If lists are nested, you need to allocate a container wrapper for each level and may only
55         access the packet through the lowest-level active container wrapper.
56
57         \implementation These restrictions are necessary to ensure correct recalculation of the
58             <tt>bytes</tt> field. For more info, see the comments in \ref ParseListB.ih
59
60         \see Parse_List
61         \ingroup parsecollection
62      */
63     template <class ElementParser, class BytesParser>
64     struct Parse_ListB {
65         typedef Parse_List< detail::Parse_ListB_Policy<ElementParser,BytesParser> > parser;
66     };
67
68     /** \brief Define Parse_ListB field
69
70         This macro is a special helper to define a senf::Parse_ListB type field, a list of elements
71         of type \a elt_type (a parser type) directly preceded by a numeric size field of type \a
72         size_type (another parser type) giving the total number of bytes of the list (not the
73         element count).
74
75         \param[in] name field name
76         \param[in] elt_type list element type
77         \param[in] size_type size type
78         \hideinitializer
79         \ingroup packetparsermacros
80      */
81 #    define SENF_PARSER_LIST_B(name, elt_type, size_type)                                         \
82         typedef senf::Parse_ListB<elt_type, size_type>::parser BOOST_PP_CAT(name, _list_t);       \
83         SENF_PARSER_FIELD( name, BOOST_PP_CAT(name, _list_t) )
84
85 }
86
87 ///////////////////////////////hh.e////////////////////////////////////////
88 #endif
89 #if !defined(HH_Packets__decls_) && !defined(HH_ParseListB_i_)
90 #define HH_ParseListB_i_
91 //#include "ParseListB.cci"
92 //#include "ParseListB.ct"
93 #include "ParseListB.cti"
94 #endif
95
96 \f
97 // Local Variables:
98 // mode: c++
99 // fill-column: 100
100 // comment-column: 40
101 // c-file-style: "senf"
102 // indent-tabs-mode: nil
103 // ispell-local-dictionary: "american"
104 // compile-command: "scons -u test"
105 // End: