Add missing install files
[senf.git] / senf / Packets / ListOptionTypeParser.cti
1 // $Id: ListOptionTypeParser.cti 869 2008-06-09 13:57:27Z pug $
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Philipp.Batroff@fokus.fraunhofer.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 ListOptionTypeParser inline template implementation */
25
26 #include "ListOptionTypeParser.ih"
27
28 // Custom includes
29
30 #define prefix_ inline
31 ///////////////////////////////cti.p///////////////////////////////////////
32
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>
35
36 template <class ElementParser, class AuxPolicy>
37 prefix_
38 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::
39 ListOptionTypeParser_Policy()
40 {}
41
42 template <class ElementParser, class AuxPolicy>
43 template <class Arg>
44 prefix_
45 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::
46 ListOptionTypeParser_Policy(Arg const & arg)
47     : AuxPolicy(arg) 
48 {}
49
50 template <class ElementParser, class AuxPolicy>
51 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::size_type
52 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::bytes(data_iterator i,
53                                                                           state_type s)
54     const
55 {
56     return AuxPolicy::aux(i, s) + AuxPolicy::aux_bytes;
57 }
58
59 template <class ElementParser, class AuxPolicy>
60 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::size_type
61 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::size(data_iterator i,
62                                                                          state_type s)
63     const
64 {
65     parser_type p(*this, i, s);
66     container_type c(p);
67     return std::distance(c.begin(), c.end());
68 }
69
70 template <class ElementParser, class AuxPolicy>
71 prefix_ void
72 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::init(data_iterator i,
73                                                                          state_type s)
74     const
75 {
76     AuxPolicy::aux(0, i, s);
77 }
78
79 ///////////////////////////////////////////////////////////////////////////
80 // senf::detail::ListOptionTypeParser_Policy<ElementParser,BytesParser>
81
82 //constructor
83 template <class ElementParser, class AuxPolicy>
84 prefix_
85 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
86 container_policy(parser_policy const & p)
87     : AuxPolicy(p) 
88 {}
89
90 //destructor
91 template <class ElementParser, class AuxPolicy>
92 prefix_
93 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
94 ~container_policy()
95 {}
96
97 //construct method
98 template <class ElementParser, class AuxPolicy>
99 prefix_ void
100 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
101 construct(container_type & c)
102 {
103     data_iterator i = c.i();
104     realAux_ = (AuxPolicy::aux(i, c.state()) * 8) + 6;
105     data_iterator e = i + realAux_;
106     for (n_ = 0; i != e; ++n_) {
107         unsigned int elByte = senf::bytes(ElementParser(i, c.state()));
108         if (((i + elByte) == e) && (i[0] == 0u || i[0] == 1u)) { //check wether last element is padding or not
109             realAux_ -= std::distance(i, e);
110             c.data().erase(i, e); //delete padding
111             e = i; //set end iterator
112         } else
113             std::advance(i, elByte);
114     }
115     //    container_size_ = std::distance(i,e);
116     container_size_ = c.data().size(); //set actual size without padding
117 }
118
119 //destruct method
120 template <class ElementParser, class AuxPolicy>
121 prefix_ void
122 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
123 destruct(container_type & c)
124 {
125     //  data_iterator i (AuxPolicy::adjust(parser_type::get(p).i(), parser_type::get(p).state()));
126     data_iterator i = c.i();
127     data_iterator const e = i + realAux_;
128     unsigned int padBytes = (realAux_ % 8);
129     c.data().insert(e, padBytes, 0u);
130     if (padBytes > 0) {
131         if (padBytes > 1) {
132             e[0] = 1;
133             e[1] = padBytes - 2;
134         } else
135             e[0] = 0;
136         container_size_ += padBytes;
137         ++n_;
138     }
139     AuxPolicy::aux((realAux_ / 8 - 1), i, c.state());
140 }
141
142 //bytes()
143 template <class ElementParser, class AuxPolicy>
144 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
145     ElementParser,AuxPolicy>::container_policy::size_type
146 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
147 bytes(data_iterator i, state_type s)
148     const
149 {
150     return (realAux_ + 2);
151 }
152
153 //size()
154 template <class ElementParser, class AuxPolicy>
155 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
156     ElementParser,AuxPolicy>::container_policy::size_type
157 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
158 size(data_iterator i, state_type s)
159     const
160 {
161     return n_;
162 }
163
164 //init()
165 template <class ElementParser, class AuxPolicy>
166 prefix_ void
167 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
168 init(data_iterator i, state_type s)
169 {
170     n_ = 0;
171     container_size_ = s->size();
172     AuxPolicy::aux(0, i, s);
173 }
174
175 //erase()
176 template <class ElementParser, class AuxPolicy>
177 prefix_ void
178 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
179 erase(container_type & c, data_iterator p)
180 {
181     size_type b(senf::bytes(ElementParser(p, c.state()))); //length of parser
182     //    AuxPolicy::aux(
183     //                  AuxPolicy::aux( c.i(), c.state()) -b,
184     //                  c.i(),
185     //                  c.state());
186     realAux_ -= b;
187     --n_;
188     // The container will be reduced by b bytes directly after this call
189     container_size_ = c.data().size() - b;
190 }
191
192 //insert()
193 template <class ElementParser, class AuxPolicy>
194 prefix_ void
195 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
196 insert(container_type & c, data_iterator p)
197 {
198     size_type b(senf::bytes(ElementParser(p, c.state())));
199     //    AuxPolicy::aux( AuxPolicy::aux(c.i(), c.state())+b, c.i(), c.state());
200     realAux_ += b;
201     ++n_;
202     container_size_ = c.data().size();
203 }
204
205 //update()
206 template <class ElementParser, class AuxPolicy>
207 prefix_ void
208 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
209 update(container_type const & c)
210     const
211 {
212     if (container_size_ == c.data().size())
213         return;
214     data_iterator i(AuxPolicy::adjust(c.i(), c.state()));
215     data_iterator j(i);
216     for (size_type n(n_); n; --n, std::advance(j, senf::bytes(ElementParser(j,c.state()))));
217     realAux_ = std::distance(i, j);
218     //    aux( std::distance(i,j), c.i(), c.state() );
219     container_size_ = c.data().size();
220 }
221
222 //setbegin()
223 template <class ElementParser, class AuxPolicy>
224 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
225     ElementParser,AuxPolicy>::container_policy::data_iterator
226 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
227 setBegin(container_type const & c, iterator_data & d)
228     const
229 {
230     return c.i();
231     //    return AuxPolicy::adjust(c.i(), c.state());
232 }
233
234 //setEnd()
235 template <class ElementParser, class AuxPolicy>
236 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
237     ElementParser,AuxPolicy>::container_policy::data_iterator
238 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
239 setEnd(container_type const & c, iterator_data & d)
240     const
241 { //wtf??
242     return boost::next(AuxPolicy::adjust(c.i(), c.state()), aux(c.i(),c.state()));
243 }
244
245 //setFromPosition()
246 template <class ElementParser, class AuxPolicy>
247 prefix_ void
248 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
249 setFromPosition(container_type const & c, iterator_data & d, data_iterator p)
250     const
251 {}
252
253 //next()
254 template <class ElementParser, class AuxPolicy>
255 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
256     ElementParser,AuxPolicy>::container_policy::data_iterator
257 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
258 next(container_type const & c, iterator_data & d)
259     const
260 {
261     return boost::next(container_type::iterator::get(d).i(), senf::bytes(ElementParser(container_type::iterator::get(d).i(), c.state())));
262 }
263
264 //raw()
265 template <class ElementParser, class AuxPolicy>
266 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
267     ElementParser,AuxPolicy>::container_policy::data_iterator
268 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
269 raw(container_type const & c, iterator_data const & d)
270     const
271 {
272     return container_type::iterator::get(d).i();
273 }
274
275 ///////////////////////////////cti.e///////////////////////////////////////
276 #undef prefix_
277
278 \f
279 // Local Variables:
280 // mode: c++
281 // fill-column: 100
282 // comment-column: 40
283 // c-file-style: "senf"
284 // indent-tabs-mode: nil
285 // ispell-local-dictionary: "american"
286 // compile-command: "scons -u test"
287 // End: