switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / AuxParser.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief AuxParser public header */
30
31 #ifndef HH_SENF_Packets_AuxParser_
32 #define HH_SENF_Packets_AuxParser_ 1
33
34 #ifndef HH_SENF_Packets_Packets_
35 #error "Don't include 'AuxParser.hh' directly, include 'Packets.hh'"
36 #endif
37
38 // Custom includes
39 #include "PacketParser.hh"
40 #include "SafeIterator.hh"
41
42 //#include "AuxParser.mpp"
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44
45 namespace senf {
46 namespace detail {
47
48     /** \brief Internal: Prefix aux-parser policy
49
50         Place auxiliary field directly before a container/collection.
51      */
52     template <class P>
53     struct PrefixAuxParserPolicy
54     {
55         typedef PrefixAuxParserPolicy WrapperPolicy;
56         typedef PrefixAuxParserPolicy ParserPolicy;
57
58         static PacketParserBase::size_type const aux_bytes = P::fixed_bytes;
59
60         typename P::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
61         void aux(typename P::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
62         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
63     };
64
65     /** \brief Internal: Fixed distance aux-parser policy
66
67         Place auxiliary field a fixed distance before the container/collection
68      */
69     template <class P, unsigned Dist>
70     struct FixedAuxParserPolicy
71     {
72         typedef FixedAuxParserPolicy WrapperPolicy;
73         typedef FixedAuxParserPolicy ParserPolicy;
74
75         static PacketParserBase::size_type const aux_bytes = 0;
76
77         typename P::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
78         void aux(typename P::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
79         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
80     };
81
82     template <class P> struct DynamicWrapperAuxParserPolicy;
83
84     /** \brief Internal: Dynamic aux-parser policy
85
86         Place auxiliary field at a variable distance before the container/collection
87      */
88     template <class P>
89     struct DynamicAuxParserPolicy
90     {
91         typedef DynamicWrapperAuxParserPolicy<P> WrapperPolicy;
92         typedef DynamicAuxParserPolicy<P> ParserPolicy;
93
94         static PacketParserBase::size_type const aux_bytes = 0;
95
96         DynamicAuxParserPolicy(P p);
97         DynamicAuxParserPolicy(WrapperPolicy const & other);
98
99         typename P::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
100         void aux(typename P::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
101         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
102
103         mutable P p_;
104     };
105
106     /** \brief Internal: Dynamic aux-parser policy (container wrapper)
107
108         Place auxiliary field at a variable distance before the container/collection. This is the
109         wrapper policy used by DynamicAuxParserPolicy
110      */
111     template <class P>
112     struct DynamicWrapperAuxParserPolicy
113     {
114         typedef DynamicWrapperAuxParserPolicy<P> WrapperPolicy;
115         typedef DynamicAuxParserPolicy<P> ParserPolicy;
116
117         static PacketParserBase::size_type const aux_bytes = 0;
118
119         DynamicWrapperAuxParserPolicy(ParserPolicy const & other);
120
121         typename P::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
122         void aux(typename P::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
123         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
124
125         mutable SafePacketParserWrapper<P> p_;
126     };
127
128     /** \brief Internal: Apply transformation to arbitrary aux-parser policy
129
130         Transform must satisfy the interface
131         \code
132         struct Transform
133         {
134             typedef unspecified value_type;
135             static value_type get(unspecified v);
136             static unspecified set(value_type v);
137         };
138         \endcode
139      */
140     template <class Policy, class Transform>
141     struct TransformAuxParserPolicy
142         : public Policy
143     {
144         typedef TransformAuxParserPolicy<typename Policy::WrapperPolicy, Transform> WrapperPolicy;
145         typedef TransformAuxParserPolicy<typename Policy::ParserPolicy, Transform> ParserPolicy;
146
147         static PacketParserBase::size_type const aux_bytes = Policy::aux_bytes;
148
149         TransformAuxParserPolicy();
150         template <class Arg> TransformAuxParserPolicy(Arg const & arg);
151
152         typename Transform::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
153         void aux(typename Transform::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
154     };
155
156     struct PacketSizeAuxParserPolicy
157     {
158         typedef PacketSizeAuxParserPolicy WrapperPolicy;
159         typedef PacketSizeAuxParserPolicy ParserPolicy;
160
161         static PacketParserBase::size_type const aux_bytes = 0;
162
163         PacketParserBase::size_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
164         void aux(unsigned v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
165         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
166     };
167 }}
168
169 //-/////////////////////////////////////////////////////////////////////////////////////////////////
170 #endif
171 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_AuxParser_i_)
172 #define HH_SENF_Packets_AuxParser_i_
173 #include "AuxParser.cci"
174 //#include "AuxParser.ct"
175 #include "AuxParser.cti"
176 #endif
177
178 \f
179 // Local Variables:
180 // mode: c++
181 // fill-column: 100
182 // comment-column: 40
183 // c-file-style: "senf"
184 // indent-tabs-mode: nil
185 // ispell-local-dictionary: "american"
186 // compile-command: "scons -u test"
187 // End: