VectorParser.cti
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief VectorParser inline template implementation */
16 
17 #include "VectorParser.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::VectorParser<ElementParser,Sizer>
26 
27 template <class ElementParser, class AuxPolicy>
28 prefix_ senf::VectorParser<ElementParser,AuxPolicy>::VectorParser(data_iterator i, state_type s)
29  : PacketParserBase(i,s), AuxPolicy()
30 {}
31 
32 template <class ElementParser, class AuxPolicy>
33 prefix_ senf::VectorParser<ElementParser,AuxPolicy>::VectorParser(AuxPolicy policy,
34  data_iterator i, state_type s)
35  : PacketParserBase(i,s), AuxPolicy(policy)
36 {}
37 
38 template <class ElementParser, class AuxPolicy>
39 prefix_ senf::PacketInterpreterBase::size_type
40 senf::VectorParser<ElementParser,AuxPolicy>::bytes()
41  const
42 {
43  return size()*ElementParser::fixed_bytes + AuxPolicy::aux_bytes;
44 }
45 
46 // Container interface
47 
48 template <class ElementParser, class AuxPolicy>
49 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::container_type
50 senf::VectorParser<ElementParser,AuxPolicy>::container()
51  const
52 {
53  return container_type(*this);
54 }
55 
56 template <class ElementParser, class AuxPolicy>
57 prefix_ senf::PacketInterpreterBase::size_type
58 senf::VectorParser<ElementParser,AuxPolicy>::size()
59  const
60 {
61  return AuxPolicy::aux(i(),state());
62 }
63 
64 template <class ElementParser, class AuxPolicy>
65 prefix_ bool senf::VectorParser<ElementParser,AuxPolicy>::empty()
66  const
67 {
68  return size()==0;
69 }
70 
71 template <class ElementParser, class AuxPolicy>
72 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::iterator
73 senf::VectorParser<ElementParser,AuxPolicy>::begin()
74  const
75 {
76  return iterator(AuxPolicy::adjust(i(),state()),state());
77 }
78 
79 template <class ElementParser, class AuxPolicy>
80 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::iterator
81 senf::VectorParser<ElementParser,AuxPolicy>::end()
82  const
83 {
84  return boost::next(begin(),size());
85 }
86 
87 template <class ElementParser, class AuxPolicy>
88 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::value_type
89 senf::VectorParser<ElementParser,AuxPolicy>::operator[](difference_type i)
90  const
91 {
92  return begin()[i];
93 }
94 
95 template <class ElementParser, class AuxPolicy>
96 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::value_type
97 senf::VectorParser<ElementParser,AuxPolicy>::front()
98  const
99 {
100  return begin()[0];
101 }
102 
103 template <class ElementParser, class AuxPolicy>
104 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::value_type
105 senf::VectorParser<ElementParser,AuxPolicy>::back()
106  const
107 {
108  return begin()[size()-1];
109 }
110 
111 // Mutators
112 
113 template <class ElementParser, class AuxPolicy>
114 template <class InputIterator>
115 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::assign(InputIterator first, InputIterator last)
116 {
117  container_type c (*this);
118  c.clear();
119  while (first != last)
120  c.push_back( *first++);
121 }
122 
123 template <class ElementParser, class AuxPolicy>
124 template <class Value>
125 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::push_back(Value const & value, size_type n)
126  const
127 {
128  container_type c (*this);
129  c.push_back(value,n);
130 }
131 
132 template <class ElementParser, class AuxPolicy>
133 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::value_type
134 senf::VectorParser<ElementParser,AuxPolicy>::push_back_space(size_type n)
135  const
136 {
137  container_type c (*this);
138  return c.push_back_space(n);
139 }
140 
141 template <class ElementParser, class AuxPolicy>
142 template <class Value>
143 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::push_front(Value const & value, size_type n)
144  const
145 {
146  container_type c (*this);
147  c.push_front(value,n);
148 }
149 
150 template <class ElementParser, class AuxPolicy>
151 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::value_type
152 senf::VectorParser<ElementParser,AuxPolicy>::push_front_space(size_type n)
153  const
154 {
155  container_type c (*this);
156  return c.push_front_space(n);
157 }
158 
159 template <class ElementParser, class AuxPolicy>
160 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::resize(size_type n)
161  const
162 {
163  container_type c (*this);
164  c.resize(n);
165 }
166 
167 template <class ElementParser, class AuxPolicy>
168 template <class Value>
169 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::resize(size_type n, Value value)
170  const
171 {
172  container_type c (*this);
173  c.resize(n,value);
174 }
175 
176 //-/////////////////////////////////////////////////////////////////////////////////////////////////
177 // senf::VectorParser_wrapper<Parser,SizeParser,Container>
178 
179 // structors and default members
180 
181 // hm ... be careful here ! the data() member is called in an incompletely intitialized
182 // instance. However, data() only depends on state_ which is initialized before the call. YOU MUST
183 // NOT CHANGE THE ORDERING OF THE DATA MEMBERS
184 template <class ElementParser, class AuxPolicy>
185 prefix_ senf::VectorParser_Container<ElementParser,AuxPolicy>::
186 VectorParser_Container(parser_type const & vector)
187  : AuxPolicy::WrapperPolicy(static_cast<AuxPolicy const &>(vector)), state_ (vector.state()),
188  i_ (std::distance(data().begin(),vector.i()))
189 {}
190 
191 // accessors
192 
193 template <class ElementParser, class AuxPolicy>
194 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::size_type
195 senf::VectorParser_Container<ElementParser,AuxPolicy>::size()
196  const
197 {
198  return AuxPolicy::WrapperPolicy::aux(i(),state());
199 }
200 
201 template <class ElementParser, class AuxPolicy>
202 prefix_ bool senf::VectorParser_Container<ElementParser,AuxPolicy>::empty()
203  const
204 {
205  return size() == 0;
206 }
207 
208 template <class ElementParser, class AuxPolicy>
209 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::iterator
210 senf::VectorParser_Container<ElementParser,AuxPolicy>::begin()
211  const
212 {
213  return iterator( AuxPolicy::WrapperPolicy::adjust(i(),state()),state());
214 }
215 
216 template <class ElementParser, class AuxPolicy>
217 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::iterator
218 senf::VectorParser_Container<ElementParser,AuxPolicy>::end()
219  const
220 {
221  return boost::next(begin(),size());
222 }
223 
224 template <class ElementParser, class AuxPolicy>
225 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::value_type
226 senf::VectorParser_Container<ElementParser,AuxPolicy>::operator[](difference_type i)
227  const
228 {
229  return begin()[i];
230 }
231 
232 template <class ElementParser, class AuxPolicy>
233 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::value_type
234 senf::VectorParser_Container<ElementParser,AuxPolicy>::front()
235  const
236 {
237  return begin()[0];
238 }
239 
240 template <class ElementParser, class AuxPolicy>
241 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::value_type
242 senf::VectorParser_Container<ElementParser,AuxPolicy>::back()
243  const
244 {
245  return begin()[size()-1];
246 }
247 
248 // Mutators
249 
250 template <class ElementParser, class AuxPolicy>
251 template <class Value>
252 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::insert(iterator pos,
253  Value const & t)
254 {
255  *shift(pos) << t;
256 }
257 
258 template <class ElementParser, class AuxPolicy>
259 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::erase(iterator pos, size_type n)
260 {
261  setSize(size()-n);
262  data().erase(pos.raw(),boost::next(pos.raw(),n*ElementParser::fixed_bytes));
263 }
264 
265 template <class ElementParser, class AuxPolicy>
266 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::erase(iterator f, iterator l)
267 {
268  erase(f,std::distance(f,l));
269 }
270 
271 template <class ElementParser, class AuxPolicy>
272 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::clear()
273 {
274  erase(begin(),end());
275 }
276 
277 template <class ElementParser, class AuxPolicy>
278 template <class Value>
279 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::push_back(Value const & value,
280  size_type n)
281 {
282  insert(end(),n,value);
283 }
284 
285 template <class ElementParser, class AuxPolicy>
286 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::value_type
287 senf::VectorParser_Container<ElementParser,AuxPolicy>::push_back_space(size_type n)
288 {
289  return *shift(end(),n);
290 }
291 
292 template <class ElementParser, class AuxPolicy>
293 template <class Value>
294 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::push_front(Value const & value,
295  size_type n)
296 {
297  insert(begin(),n,value);
298 }
299 
300 template <class ElementParser, class AuxPolicy>
301 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::value_type
302 senf::VectorParser_Container<ElementParser,AuxPolicy>::push_front_space(size_type n)
303 {
304  return *shift(begin(),n);
305 }
306 
307 // Parser interface
308 
309 template <class ElementParser, class AuxPolicy>
310 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::parser_type
311 senf::VectorParser_Container<ElementParser,AuxPolicy>::parser()
312  const
313 {
314  return parser_type(i(),state());
315 }
316 
317 template <class ElementParser, class AuxPolicy>
318 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::data_iterator
319 senf::VectorParser_Container<ElementParser,AuxPolicy>::i()
320  const
321 {
322  return boost::next(data().begin(),i_);
323 }
324 
325 template <class ElementParser, class AuxPolicy>
326 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::state_type
327 senf::VectorParser_Container<ElementParser,AuxPolicy>::state()
328  const
329 {
330  return state_;
331 }
332 
333 template <class ElementParser, class AuxPolicy>
334 prefix_ senf::PacketData &
335 senf::VectorParser_Container<ElementParser,AuxPolicy>::data()
336  const
337 {
338  return *state_;
339 }
340 
341 template <class ElementParser, class AuxPolicy>
342 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::size_type
343 senf::VectorParser_Container<ElementParser,AuxPolicy>::bytes()
344  const
345 {
346  return size()*ElementParser::fixed_bytes + AuxPolicy::aux_bytes;
347 }
348 
349 // private members
350 
351 template <class ElementParser, class AuxPolicy>
352 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::setSize(size_type value)
353 {
354  AuxPolicy::WrapperPolicy::aux(value, i(),state());
355 }
356 
357 //-/////////////////////////////////////////////////////////////////////////////////////////////////
358 #undef prefix_
359 
360 
361 // Local Variables:
362 // mode: c++
363 // fill-column: 100
364 // c-file-style: "senf"
365 // indent-tabs-mode: nil
366 // ispell-local-dictionary: "american"
367 // compile-command: "scons -u test"
368 // comment-column: 40
369 // End: