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