2 // Fraunhofer Institute for Open Communication Systems (FOKUS)
3 // Competence Center NETwork research (NET), St. Augustin, GERMANY
4 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
23 /** \brief Example of a variant policy. ONLY FOR EXPOSITION
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:
28 struct ExampleVariantPolicy
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;
36 static size_type const init_bytes = 0;
37 size_type bytes (data_iterator i, state_type s) const;
39 data_iterator begin(data_iterator i, state_type s) const;
41 unsigned variant (data_iterator i, state_type s) const;
42 void variant (unsigned v, data_iterator i, state_type s);
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.
51 \see senf::Parse_Variant
53 struct ExampleVariantPolicy
55 typedef PacketParserBase::data_iterator data_iterator;
56 typedef PacketParserBase::state_type state_type;
57 typedef PacketParserBase::size_type size_type;
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. */
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
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
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. */
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.
85 This member must not process the sub-parser data (like
86 initializing the sub-parser or changing the data
97 // c-file-style: "senf"
98 // indent-tabs-mode: nil
99 // ispell-local-dictionary: "american"
100 // compile-command: "scons -u test"