switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / AuxParser.cti
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 inline template implementation */
30
31 //#include "AuxParser.ih"
32
33 // Custom includes
34
35 #define prefix_ inline
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 // senf::detail::PrefixAuxParserPolicy<P>
40
41 template <class P>
42 prefix_ typename P::value_type
43 senf::detail::PrefixAuxParserPolicy<P>::aux(PacketParserBase::data_iterator i,
44                                             PacketParserBase::state_type s)
45     const
46 {
47     return P(i, s).value();
48 }
49
50 template <class P>
51 prefix_ void senf::detail::PrefixAuxParserPolicy<P>::aux(typename P::value_type const & v,
52                                                          PacketParserBase::data_iterator i,
53                                                          PacketParserBase::state_type s)
54     const
55 {
56     P(i, s).value(v);
57 }
58
59 template <class P>
60 prefix_ senf::PacketParserBase::data_iterator
61 senf::detail::PrefixAuxParserPolicy<P>::adjust(PacketParserBase::data_iterator i,
62                                                PacketParserBase::state_type s)
63     const
64 {
65     return i+P::fixed_bytes;
66 }
67
68 //-/////////////////////////////////////////////////////////////////////////////////////////////////
69 // senf::detail::FixedAuxParserPolicy<P>
70
71 template <class P, unsigned Dist>
72 prefix_ typename P::value_type
73 senf::detail::FixedAuxParserPolicy<P,Dist>::aux(PacketParserBase::data_iterator i,
74                                                 PacketParserBase::state_type s)
75     const
76 {
77     return P(i-Dist, s).value();
78 }
79
80 template <class P, unsigned Dist>
81 prefix_ void senf::detail::FixedAuxParserPolicy<P,Dist>::aux(typename P::value_type const & v,
82                                                              PacketParserBase::data_iterator i,
83                                                              PacketParserBase::state_type s)
84     const
85 {
86     P(i-Dist, s).value(v);
87 }
88
89 template <class P, unsigned Dist>
90 prefix_ senf::PacketParserBase::data_iterator
91 senf::detail::FixedAuxParserPolicy<P,Dist>::adjust(PacketParserBase::data_iterator i,
92                                                    PacketParserBase::state_type s)
93     const
94 {
95     return i;
96 }
97
98 //-/////////////////////////////////////////////////////////////////////////////////////////////////
99 // senf::detail::DynamicAuxParserPolicy<P>
100
101 template <class P>
102 prefix_ senf::detail::DynamicAuxParserPolicy<P>::DynamicAuxParserPolicy(P p)
103     : p_ (p)
104 {}
105
106 template <class P>
107 prefix_
108 senf::detail::DynamicAuxParserPolicy<P>::DynamicAuxParserPolicy(WrapperPolicy const & other)
109     : p_ (* other.p_)
110 {}
111
112 template <class P>
113 prefix_ typename P::value_type
114 senf::detail::DynamicAuxParserPolicy<P>::aux(PacketParserBase::data_iterator i,
115                                              PacketParserBase::state_type s)
116     const
117 {
118     return p_.value();
119 }
120
121 template <class P>
122 prefix_ void senf::detail::DynamicAuxParserPolicy<P>::aux(typename P::value_type const & v,
123                                                           PacketParserBase::data_iterator i,
124                                                           PacketParserBase::state_type s)
125     const
126 {
127     p_.value(v);
128 }
129
130 template <class P>
131 prefix_ senf::PacketParserBase::data_iterator
132 senf::detail::DynamicAuxParserPolicy<P>::adjust(PacketParserBase::data_iterator i,
133                                                 PacketParserBase::state_type s)
134     const
135 {
136     return i;
137 }
138
139 //-/////////////////////////////////////////////////////////////////////////////////////////////////
140 // senf::detail::DynamicWrapperAuxParserPolicy<P>
141
142 template <class P>
143 prefix_ senf::detail::DynamicWrapperAuxParserPolicy<P>::
144 DynamicWrapperAuxParserPolicy(ParserPolicy const & other)
145     : p_ (other.p_)
146 {}
147
148 template <class P>
149 prefix_ typename P::value_type
150 senf::detail::DynamicWrapperAuxParserPolicy<P>::aux(PacketParserBase::data_iterator i,
151                                                     PacketParserBase::state_type s)
152     const
153 {
154     return p_->value();
155 }
156
157 template <class P>
158 prefix_ void
159 senf::detail::DynamicWrapperAuxParserPolicy<P>::aux(typename P::value_type const & v,
160                                                     PacketParserBase::data_iterator i,
161                                                     PacketParserBase::state_type s)
162     const
163 {
164     p_->value(v);
165 }
166
167 template <class P>
168 prefix_ senf::PacketParserBase::data_iterator
169 senf::detail::DynamicWrapperAuxParserPolicy<P>::adjust(PacketParserBase::data_iterator i,
170                                                        PacketParserBase::state_type s)
171     const
172 {
173     return i;
174 }
175
176 //-/////////////////////////////////////////////////////////////////////////////////////////////////
177 // senf::detail::TransformAuxParserPolicy<Policy,Transform>
178
179 template <class Policy, class Transform>
180 prefix_ senf::detail::TransformAuxParserPolicy<Policy,Transform>::TransformAuxParserPolicy()
181 {}
182
183 template <class Policy, class Transform>
184 template <class Arg>
185 prefix_ senf::detail::TransformAuxParserPolicy<Policy,Transform>::
186 TransformAuxParserPolicy(Arg const & arg)
187     : Policy(arg)
188 {}
189
190 template <class Policy, class Transform>
191 prefix_ typename Transform::value_type
192 senf::detail::TransformAuxParserPolicy<Policy,Transform>::aux(PacketParserBase::data_iterator i,
193                                                               PacketParserBase::state_type s)
194     const
195 {
196     return Transform::get(Policy::aux(i,s));
197 }
198
199 template <class Policy, class Transform>
200 prefix_ void senf::detail::TransformAuxParserPolicy<Policy,Transform>::
201 aux(typename Transform::value_type const & v, PacketParserBase::data_iterator i,
202     PacketParserBase::state_type s)
203     const
204 {
205     Policy::aux(Transform::set(v), i, s);
206 }
207
208 //-/////////////////////////////////////////////////////////////////////////////////////////////////
209 #undef prefix_
210
211 \f
212 // Local Variables:
213 // mode: c++
214 // fill-column: 100
215 // comment-column: 40
216 // c-file-style: "senf"
217 // indent-tabs-mode: nil
218 // ispell-local-dictionary: "american"
219 // compile-command: "scons -u test"
220 // End: