43feb378760f2a5e99b52671b4916f760c2a7cb0
[senf.git] / Packets / VectorParser.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 vector sizer. ONLY FOR EXPOSITION
26
27         This class shows the interface which must be implemented by a vector sizer policy. It is not
28         a vector sizer, it is only a declaration of the interface:
29         \code
30         struct ExampleVectorPolicy
31         {
32             // optional typedefs used to simplify all other declarations
33             typedef PacketParserBase::size_type size_type;
34             typedef PacketParserBase::data_iterator iterator;
35             typedef PacketParserBase::state_type state_type;
36
37             // mandatory members
38             static const size_type init_bytes = 0;
39             size_type  size  (iterator i, state_type s) const;
40             void       size  (iterator i, state_type s, size_type v) const;
41             iterator   begin (iterator i, state_type s) const;
42             size_type  bytes (iterator i, state_type s) const;
43             void       init  (iterator i, state_type s) const;
44         };
45         \endcode
46
47         A sizer may if needed define additional data members.
48      */
49     struct ExampleVectorPolicy
50     {
51         typedef PacketParserBase::size_type size_type;
52         typedef PacketParserBase::data_iterator iterator;
53         typedef PacketParserBase::state_type state_type;
54
55         static const size_type init_bytes = 0; ///< Size of a new vector of this size
56                                         /**< Initial size which needs to be allocated to this type
57                                              of list */
58
59         size_type  size  (iterator i, state_type s) const; ///< Get current vector size
60                                         /**< Return the current number of elements in the 
61                                              vector. */
62         void       size  (iterator i, state_type s, size_type v) const; ///< Change vector size
63                                         /**< Set the size of the vector to \a v. */
64         iterator   begin (iterator i, state_type s) const; 
65                                         ///< Return data_iterator to first element
66                                         /**< The returned data_iterator must point to the beginning
67                                              of the first vector element. The last iterator can than
68                                              automatically be calculated from the fixed element size
69                                              and the number of vector elements. */
70         size_type  bytes (iterator i, state_type s) const; ///< Bytes taken by the vector size
71                                         /**< Return the additional size which needs to be added to
72                                              the size of the vector data (calculated form \c size()
73                                              * <em>ElementType::fixed_bytes</em>) to get the size of
74                                              the complete vector. This may be zero if the size is
75                                              not considered part of the vector. */
76         void       init  (iterator i, state_type s) const; ///< Initialize new vector
77                                         /** Called to initialize a new vector after allocating
78                                             init_bytes number of bytes for the vector. */
79     };
80
81 }
82
83 \f
84 // Local Variables:
85 // mode: c++
86 // fill-column: 100
87 // comment-column: 40
88 // c-file-style: "senf"
89 // indent-tabs-mode: nil
90 // ispell-local-dictionary: "american"
91 // compile-command: "scons -u test"
92 // mode: flyspell
93 // mode: auto-fill
94 // End: