c7de8b916db384e8be88128dc02256f2a59b3550
[senf.git] / Packets / VariantParser.dox
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 namespace senf {
24
25     /** \brief Example of a variant policy. ONLY FOR EXPOSITION
26
27         This class shows the interace which must be impemented by a variant policy. It is \e not a
28         variant policy, it is only a declaration of the interface:
29         \code
30         struct ExampleVariantPolicy
31         {
32             // optional typedefs used tosimplify all other declarations
33             typedef PacketParserBase::data_iterator data_iterator;
34             typedef PacketParserBase::state_type state_type;
35             typedef PacketParserBase::size_type size_type;
36
37             // mandatory members
38             static size_type const init_bytes = 0;
39             size_type bytes  (data_iterator i, state_type s) const;
40
41             data_iterator begin(data_iterator i, state_type s) const;
42
43             unsigned variant (data_iterator i, state_type s) const;
44             void variant     (unsigned v, data_iterator i, state_type s);
45         };
46         \endcode
47
48         The \a VariantPolicy may define additional data members if needed. It must be either default
49         constructible or copy constructible. If a \a VariantPolicy is not default constructible, an
50         additional \a VariantPolicy argument needs to be passed to the senf::Parse_Variant
51         constructor which is used to copy-initialize the embeded policy.
52
53         \see senf::Parse_Variant
54      */
55     struct ExampleVariantPolicy
56     {
57         typedef PacketParserBase::data_iterator data_iterator;
58         typedef PacketParserBase::state_type state_type;
59         typedef PacketParserBase::size_type size_type;
60
61         static size_type const init_bytes = 0; ///< Additional initial size
62                                         /**< This value is added to the size of the first variant
63                                              sub-parser to calculate the \c init_bytes value. */
64
65         size_type bytes  (data_iterator i, state_type s) const;
66                                         ///< Additional parser size
67                                         /**< The return value is added to the size of the current
68                                              variant. */
69
70         data_iterator begin(data_iterator i, state_type s) const;
71                                         ///< Advance \a i to beginning of variant data
72                                         /**< This member must return the beginning of the variant's
73                                              data (the place, where the sub-parsers reside in the
74                                              packet). */
75
76         unsigned variant (data_iterator i, state_type s) const;
77                                         ///< Get current variant index
78                                         /**< \returns current variant sub-parser, interpreted as
79                                              index into the 0-indexed list of sub-parsers. */
80
81         void variant     (unsigned v, data_iterator i, state_type s);
82                                         ///< Set current variant index
83                                         /**< Must set the current variant to \a v which is the index
84                                              into the 0-index list of sub-parsers of the currently
85                                              active variant sub-parser.
86
87                                              This member must not process the sub-parser data (like
88                                              initializing the sub-parser or changing the data
89                                              container size). */
90     };
91
92 }
93
94 \f
95 // Local Variables:
96 // mode: c++
97 // fill-column: 100
98 // comment-column: 40
99 // c-file-style: "senf"
100 // indent-tabs-mode: nil
101 // ispell-local-dictionary: "american"
102 // compile-command: "scons -u test"
103 // mode: flyspell
104 // mode: auto-fill
105 // End: