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
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
15 \brief VectorParser inline template implementation */
17 #include "VectorParser.ih"
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::VectorParser<ElementParser,Sizer>
27 template <class ElementParser, class AuxPolicy>
28 prefix_ senf::VectorParser<ElementParser,AuxPolicy>::VectorParser(data_iterator i, state_type s)
29 : PacketParserBase(i,s), AuxPolicy()
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)
38 template <class ElementParser, class AuxPolicy>
39 prefix_ senf::PacketInterpreterBase::size_type
40 senf::VectorParser<ElementParser,AuxPolicy>::bytes()
43 return size()*ElementParser::fixed_bytes + AuxPolicy::aux_bytes;
46 // Container interface
48 template <class ElementParser, class AuxPolicy>
49 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::container_type
50 senf::VectorParser<ElementParser,AuxPolicy>::container()
53 return container_type(*this);
56 template <class ElementParser, class AuxPolicy>
57 prefix_ senf::PacketInterpreterBase::size_type
58 senf::VectorParser<ElementParser,AuxPolicy>::size()
61 return AuxPolicy::aux(i(),state());
64 template <class ElementParser, class AuxPolicy>
65 prefix_ bool senf::VectorParser<ElementParser,AuxPolicy>::empty()
71 template <class ElementParser, class AuxPolicy>
72 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::iterator
73 senf::VectorParser<ElementParser,AuxPolicy>::begin()
76 return iterator(AuxPolicy::adjust(i(),state()),state());
79 template <class ElementParser, class AuxPolicy>
80 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::iterator
81 senf::VectorParser<ElementParser,AuxPolicy>::end()
84 return boost::next(begin(),size());
87 template <class ElementParser, class AuxPolicy>
88 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::value_type
89 senf::VectorParser<ElementParser,AuxPolicy>::operator[](difference_type i)
95 template <class ElementParser, class AuxPolicy>
96 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::value_type
97 senf::VectorParser<ElementParser,AuxPolicy>::front()
103 template <class ElementParser, class AuxPolicy>
104 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::value_type
105 senf::VectorParser<ElementParser,AuxPolicy>::back()
108 return begin()[size()-1];
113 template <class ElementParser, class AuxPolicy>
114 template <class InputIterator>
115 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::assign(InputIterator first, InputIterator last)
117 container_type c (*this);
119 while (first != last)
120 c.push_back( *first++);
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)
128 container_type c (*this);
129 c.push_back(value,n);
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)
137 container_type c (*this);
138 return c.push_back_space(n);
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)
146 container_type c (*this);
147 c.push_front(value,n);
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)
155 container_type c (*this);
156 return c.push_front_space(n);
159 template <class ElementParser, class AuxPolicy>
160 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::resize(size_type n)
163 container_type c (*this);
167 template <class ElementParser, class AuxPolicy>
168 template <class Value>
169 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::resize(size_type n, Value value)
172 container_type c (*this);
176 //-/////////////////////////////////////////////////////////////////////////////////////////////////
177 // senf::VectorParser_wrapper<Parser,SizeParser,Container>
179 // structors and default members
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()))
193 template <class ElementParser, class AuxPolicy>
194 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::size_type
195 senf::VectorParser_Container<ElementParser,AuxPolicy>::size()
198 return AuxPolicy::WrapperPolicy::aux(i(),state());
201 template <class ElementParser, class AuxPolicy>
202 prefix_ bool senf::VectorParser_Container<ElementParser,AuxPolicy>::empty()
208 template <class ElementParser, class AuxPolicy>
209 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::iterator
210 senf::VectorParser_Container<ElementParser,AuxPolicy>::begin()
213 return iterator( AuxPolicy::WrapperPolicy::adjust(i(),state()),state());
216 template <class ElementParser, class AuxPolicy>
217 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::iterator
218 senf::VectorParser_Container<ElementParser,AuxPolicy>::end()
221 return boost::next(begin(),size());
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)
232 template <class ElementParser, class AuxPolicy>
233 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::value_type
234 senf::VectorParser_Container<ElementParser,AuxPolicy>::front()
240 template <class ElementParser, class AuxPolicy>
241 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::value_type
242 senf::VectorParser_Container<ElementParser,AuxPolicy>::back()
245 return begin()[size()-1];
250 template <class ElementParser, class AuxPolicy>
251 template <class Value>
252 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::insert(iterator pos,
258 template <class ElementParser, class AuxPolicy>
259 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::erase(iterator pos, size_type n)
262 data().erase(pos.raw(),boost::next(pos.raw(),n*ElementParser::fixed_bytes));
265 template <class ElementParser, class AuxPolicy>
266 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::erase(iterator f, iterator l)
268 erase(f,std::distance(f,l));
271 template <class ElementParser, class AuxPolicy>
272 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::clear()
274 erase(begin(),end());
277 template <class ElementParser, class AuxPolicy>
278 template <class Value>
279 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::push_back(Value const & value,
282 insert(end(),n,value);
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)
289 return *shift(end(),n);
292 template <class ElementParser, class AuxPolicy>
293 template <class Value>
294 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::push_front(Value const & value,
297 insert(begin(),n,value);
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)
304 return *shift(begin(),n);
309 template <class ElementParser, class AuxPolicy>
310 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::parser_type
311 senf::VectorParser_Container<ElementParser,AuxPolicy>::parser()
314 return parser_type(i(),state());
317 template <class ElementParser, class AuxPolicy>
318 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::data_iterator
319 senf::VectorParser_Container<ElementParser,AuxPolicy>::i()
322 return boost::next(data().begin(),i_);
325 template <class ElementParser, class AuxPolicy>
326 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::state_type
327 senf::VectorParser_Container<ElementParser,AuxPolicy>::state()
333 template <class ElementParser, class AuxPolicy>
334 prefix_ senf::PacketData &
335 senf::VectorParser_Container<ElementParser,AuxPolicy>::data()
341 template <class ElementParser, class AuxPolicy>
342 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::size_type
343 senf::VectorParser_Container<ElementParser,AuxPolicy>::bytes()
346 return size()*ElementParser::fixed_bytes + AuxPolicy::aux_bytes;
351 template <class ElementParser, class AuxPolicy>
352 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::setSize(size_type value)
354 AuxPolicy::WrapperPolicy::aux(value, i(),state());
357 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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