b92bff73c25fb989f92bd01f94ffe71eb3d82c94
[senf.git] / senf / Packets / AuxParser.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
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 AuxParser public header */
25
26 #ifndef HH_SENF_Packets_AuxParser_
27 #define HH_SENF_Packets_AuxParser_ 1
28
29 #ifndef HH_SENF_Packets_Packets_
30 #error "Don't include 'AuxParser.hh' directly, include 'Packets.hh'"
31 #endif
32
33 // Custom includes
34 #include "PacketParser.hh"
35 #include "SafeIterator.hh"
36
37 //#include "AuxParser.mpp"
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39
40 namespace senf {
41 namespace detail {
42
43     /** \brief Internal: Prefix aux-parser policy
44
45         Place auxiliary field directly before a container/collection.
46      */
47     template <class P>
48     struct PrefixAuxParserPolicy
49     {
50         typedef PrefixAuxParserPolicy WrapperPolicy;
51         typedef PrefixAuxParserPolicy ParserPolicy;
52
53         static PacketParserBase::size_type const aux_bytes = P::fixed_bytes;
54
55         typename P::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
56         void aux(typename P::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
57         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
58     };
59
60     /** \brief Internal: Fixed distance aux-parser policy
61
62         Place auxiliary field a fixed distance before the container/collection
63      */
64     template <class P, unsigned Dist>
65     struct FixedAuxParserPolicy
66     {
67         typedef FixedAuxParserPolicy WrapperPolicy;
68         typedef FixedAuxParserPolicy ParserPolicy;
69
70         static PacketParserBase::size_type const aux_bytes = 0;
71
72         typename P::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
73         void aux(typename P::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
74         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
75     };
76
77     template <class P> struct DynamicWrapperAuxParserPolicy;
78
79     /** \brief Internal: Dynamic aux-parser policy
80
81         Place auxiliary field at a variable distance before the container/collection
82      */
83     template <class P>
84     struct DynamicAuxParserPolicy
85     {
86         typedef DynamicWrapperAuxParserPolicy<P> WrapperPolicy;
87         typedef DynamicAuxParserPolicy<P> ParserPolicy;
88
89         static PacketParserBase::size_type const aux_bytes = 0;
90
91         DynamicAuxParserPolicy(P p);
92         DynamicAuxParserPolicy(WrapperPolicy const & other);
93
94         typename P::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
95         void aux(typename P::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
96         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
97
98         mutable P p_;
99     };
100
101     /** \brief Internal: Dynamic aux-parser policy (container wrapper)
102
103         Place auxiliary field at a variable distance before the container/collection. This is the
104         wrapper policy used by DynamicAuxParserPolicy
105      */
106     template <class P>
107     struct DynamicWrapperAuxParserPolicy
108     {
109         typedef DynamicWrapperAuxParserPolicy<P> WrapperPolicy;
110         typedef DynamicAuxParserPolicy<P> ParserPolicy;
111
112         static PacketParserBase::size_type const aux_bytes = 0;
113
114         DynamicWrapperAuxParserPolicy(ParserPolicy const & other);
115
116         typename P::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
117         void aux(typename P::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
118         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
119
120         mutable SafePacketParserWrapper<P> p_;
121     };
122
123     /** \brief Internal: Apply transformation to arbitrary aux-parser policy
124
125         Transform must satisfy the interface
126         \code
127         struct Transform
128         {
129             typedef unspecified value_type;
130             static value_type get(unspecified v);
131             static unspecified set(value_type v);
132         };
133         \endcode
134      */
135     template <class Policy, class Transform>
136     struct TransformAuxParserPolicy
137         : public Policy
138     {
139         typedef TransformAuxParserPolicy<typename Policy::WrapperPolicy, Transform> WrapperPolicy;
140         typedef TransformAuxParserPolicy<typename Policy::ParserPolicy, Transform> ParserPolicy;
141
142         static PacketParserBase::size_type const aux_bytes = Policy::aux_bytes;
143
144         TransformAuxParserPolicy();
145         template <class Arg> TransformAuxParserPolicy(Arg const & arg);
146
147         typename Transform::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
148         void aux(typename Transform::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
149     };
150
151     struct PacketSizeAuxParserPolicy
152     {
153         typedef PacketSizeAuxParserPolicy WrapperPolicy;
154         typedef PacketSizeAuxParserPolicy ParserPolicy;
155
156         static PacketParserBase::size_type const aux_bytes = 0;
157
158         PacketParserBase::size_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
159         void aux(unsigned v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
160         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
161     };
162 }}
163
164 //-/////////////////////////////////////////////////////////////////////////////////////////////////
165 #endif
166 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_AuxParser_i_)
167 #define HH_SENF_Packets_AuxParser_i_
168 #include "AuxParser.cci"
169 //#include "AuxParser.ct"
170 #include "AuxParser.cti"
171 #endif
172
173 \f
174 // Local Variables:
175 // mode: c++
176 // fill-column: 100
177 // comment-column: 40
178 // c-file-style: "senf"
179 // indent-tabs-mode: nil
180 // ispell-local-dictionary: "american"
181 // compile-command: "scons -u test"
182 // End: