7de7ea8bb36a5a96beb2281e7af7ed68d7766c05
[senf.git] / Packets / ListBParser.hh
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief ListBParser public header */
25
26 #ifndef HH_ListBParser_
27 #define HH_ListBParser_ 1
28
29 // Custom includes
30 #include "ListParser.hh"
31
32 //#include "ListBParser.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace senf {
36     
37     namespace detail { template <class ElementParser, class BytesParser>
38                        class ListBParser_Policy; }
39
40     /** \brief List parser with size-field in bytes
41
42         This list parser will parse a list which size is given by a preceding field containing the
43         length of the list in bytes. This struct is just a template typedef:
44         \code
45         typedef senf::VectorNParser< Parser_UInt32, Parser_UInt16 >::parser MyVectorParser;
46         typedef senf::ListBParser< MyVectorParser, UInt16Parser >::parser MyListParser;
47         \endcode
48         This first defines a Vector of 32 bit unsigned integers with 16 bit length counter. Then it
49         defines a list of such vectors with a 16 bit bytes field.
50
51         \warning There are some caveats when working with this kind of list
52         \li You may <b>only change the size of a contained element from a container wrapper</b>.
53         \li While you hold a container wrapper, <b>only access the packet through this wrapper</b>
54             or a nested wrapper either for reading or writing.
55
56         If lists are nested, you need to allocate a container wrapper for each level and may only
57         access the packet through the lowest-level active container wrapper.
58
59         \implementation These restrictions are necessary to ensure correct recalculation of the
60             <tt>bytes</tt> field. For more info, see the comments in \ref ListBParser.ih
61
62         \see ListParser
63         \ingroup parsecollection
64      */
65     template <class ElementParser, class BytesParser>
66     struct ListBParser {
67         typedef ListParser< detail::ListBParser_Policy<ElementParser,BytesParser> > parser;
68     };
69
70     /** \brief Define ListBParser field
71
72         This macro is a special helper to define a senf::ListBParser type field, a list of elements
73         of type \a elt_type (a parser type) directly preceded by a numeric size field of type \a
74         size_type (another parser type) giving the total number of bytes of the list (not the
75         element count).
76
77         \param[in] name field name
78         \param[in] elt_type list element type
79         \param[in] size_type size type
80         \hideinitializer
81         \ingroup packetparsermacros
82      */
83 #    define SENF_PARSER_LIST_B(name, elt_type, size_type)                                         \
84         typedef senf::ListBParser<elt_type, size_type>::parser BOOST_PP_CAT(name, _list_t);       \
85         SENF_PARSER_FIELD( name, BOOST_PP_CAT(name, _list_t) )
86
87 }
88
89 ///////////////////////////////hh.e////////////////////////////////////////
90 #endif
91 #if !defined(HH_Packets__decls_) && !defined(HH_ListBParser_i_)
92 #define HH_ListBParser_i_
93 //#include "ListBParser.cci"
94 //#include "ListBParser.ct"
95 #include "ListBParser.cti"
96 #endif
97
98 \f
99 // Local Variables:
100 // mode: c++
101 // fill-column: 100
102 // comment-column: 40
103 // c-file-style: "senf"
104 // indent-tabs-mode: nil
105 // ispell-local-dictionary: "american"
106 // compile-command: "scons -u test"
107 // End: