NEW FILE HEADER / COPYRIGHT FORMAT
[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
32 //#include "ListNParser.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace senf {
36
37     namespace detail { template <class ElementParser, class SizeParser>
38                        class ListNParser_Policy; }
39
40     /** \brief List parser with size-field giving number of list elements
41
42         This parser will parse a list which size is giving by a preceding field containing the
43         number of list elements. This struct is just a 'template typedef':
44         \code
45         senf::VectorNParser< Parser_UInt32, Parser_UInt16 >::parser MyVectorParser;
46         senf::ListNParser< 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 size field.
50
51         \see ListParser
52         \ingroup parsecollection
53      */
54     template <class ElementParser, class SizeParser>
55     struct ListNParser {
56         typedef ListParser< detail::ListNParser_Policy<ElementParser,SizeParser> > parser;
57     };
58
59     /** \brief Define ListNParser field
60
61         This macro is a special helper to define a senf::ListNParser type field, a list of elements
62         of type \a elt_type (a parser type) directly preceded by a numeric size field of type \a
63         size_type (another parser type).
64
65         \param[in] name field name
66         \param[in] elt_type list element type
67         \param[in] size_type size type
68         \hideinitializer
69         \ingroup packetparsermacros
70      */
71 #    define SENF_PARSER_LIST_N(name, elt_type, size_type)                                         \
72         typedef senf::ListNParser<elt_type, size_type>::parser BOOST_PP_CAT(name, _list_t);       \
73         SENF_PARSER_FIELD( name, BOOST_PP_CAT(name, _list_t) )
74
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: