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