08cf568d66066332722c046e938874df4781fbbc
[senf.git] / Packets / ListNParser.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
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 ListNParser public header */
25
26 #ifndef HH_ListNParser_
27 #define HH_ListNParser_ 1
28
29 // Custom includes
30 #include "ListParser.hh"
31 #include "AuxParser.hh"
32
33 //#include "ListNParser.mpp"
34 #include "ListNParser.ih"
35 ///////////////////////////////hh.p////////////////////////////////////////
36
37 namespace senf {
38
39     /** \brief List parser with size-field giving number of list elements
40
41         This parser will parse a list which size is giving by a preceding field containing the
42         number of list elements. This struct is just a 'template typedef':
43         \code
44         senf::VectorNParser< Parser_UInt32, Parser_UInt16 >::parser MyVectorParser;
45         senf::ListNParser< MyVectorParser, UInt16Parser >::parser MyListParser;
46         \endcode
47         This first defines a Vector of 32 bit unsigned integers with 16 bit length counter. Then it
48         defines a list of such vectors with a 16 bit size field.
49
50         \see ListParser
51         \ingroup parsecollection
52      */
53     template <class ElementParser, class SizeParser>
54     struct ListNParser {
55         typedef ListParser< detail::ListNParser_Policy<
56             ElementParser,
57             detail::PrefixAuxParserPolicy<SizeParser> > > parser;
58     };
59
60     /** \brief Define ListNParser field
61
62         This macro is a special helper to define a senf::ListNParser type field, a list of elements
63         of type \a elt_type (a parser type) directly preceded by a numeric size field of type \a
64         size_type (another parser type).
65
66         \param[in] name field name
67         \param[in] elt_type list element type
68         \param[in] size_type size type
69         \hideinitializer
70         \ingroup packetparsermacros
71      */
72 #    define SENF_PARSER_LIST_N(name, elt_type, size_type)                                         \
73         typedef senf::ListNParser<elt_type, size_type>::parser BOOST_PP_CAT(name, _list_t);       \
74         SENF_PARSER_FIELD( name, BOOST_PP_CAT(name, _list_t) )
75 }
76
77 ///////////////////////////////hh.e////////////////////////////////////////
78 #endif
79 #if !defined(HH_Packets__decls_) && !defined(HH_ListNParser_i_)
80 #define HH_ListNParser_i_
81 //#include "ListNParser.cci"
82 #include "ListNParser.ct"
83 #include "ListNParser.cti"
84 #endif
85
86 \f
87 // Local Variables:
88 // mode: c++
89 // fill-column: 100
90 // comment-column: 40
91 // c-file-style: "senf"
92 // indent-tabs-mode: nil
93 // ispell-local-dictionary: "american"
94 // compile-command: "scons -u test"
95 // End: