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 ListParser inline template implementation */
17 #include "ListParser.ih"
20 #include <senf/Utils/senfassert.hh>
22 #define prefix_ inline
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 // senf::ListParser<ListPolicy>
28 template <class ListPolicy>
29 prefix_ senf::ListParser<ListPolicy>::ListParser(data_iterator i, state_type s)
30 : PacketParserBase(i,s), ListPolicy()
33 template <class ListPolicy>
34 prefix_ senf::ListParser<ListPolicy>::ListParser(ListPolicy policy,
35 data_iterator i, state_type s)
36 : PacketParserBase(i,s), ListPolicy(policy)
39 template <class ListPolicy>
40 prefix_ senf::PacketParserBase::size_type
41 senf::ListParser<ListPolicy>::bytes()
44 return ListPolicy::bytes(i(),state());
47 template <class ListPolicy, class OutputIterator>
48 prefix_ void senf::copy(ListParser_Container<ListPolicy> container, OutputIterator result)
50 for (typename ListParser_Container<ListPolicy>::iterator i (container.begin()); i != container.end(); ++i) {
55 //-/////////////////////////////////////////////////////////////////////////////////////////////////
56 // Container interface
58 template <class ListPolicy>
59 prefix_ typename senf::ListParser<ListPolicy>::container_type
60 senf::ListParser<ListPolicy>::container()
63 return container_type(*this);
66 template <class ListPolicy>
67 prefix_ senf::PacketParserBase::size_type
68 senf::ListParser<ListPolicy>::size()
71 return ListPolicy::size(i(),state());
74 template <class ListPolicy>
75 prefix_ bool senf::ListParser<ListPolicy>::empty()
78 container_type c (*this);
82 template <class ListPolicy>
83 template <class InputIterator>
84 prefix_ void senf::ListParser<ListPolicy>::assign(InputIterator first, InputIterator last)
86 container_type c (*this);
89 c.push_back( *first++);
92 template <class ListPolicy>
93 template <class Range>
94 prefix_ void senf::ListParser<ListPolicy>::assign(Range const & range)
96 assign(boost::begin(range), boost::end(range));
99 template <class ListPolicy>
100 prefix_ typename senf::ListParser<ListPolicy>::value_type
101 senf::ListParser<ListPolicy>::front()
104 SENF_ASSERT( ! empty(), "front() called on empty list" );
105 container_type c (*this);
109 template <class ListPolicy>
110 template <class Value>
111 prefix_ void senf::ListParser<ListPolicy>::push_back(Value const & value, size_type n)
114 container_type c (*this);
115 c.push_back(value,n);
118 template <class ListPolicy>
119 prefix_ typename senf::ListParser<ListPolicy>::value_type
120 senf::ListParser<ListPolicy>::push_back_space(size_type n)
123 container_type c (*this);
124 return c.push_back_space(n);
127 template <class ListPolicy>
128 template <class Value>
129 prefix_ void senf::ListParser<ListPolicy>::push_front(Value const & value, size_type n)
132 container_type c (*this);
133 c.push_front(value,n);
136 template <class ListPolicy>
137 prefix_ typename senf::ListParser<ListPolicy>::value_type
138 senf::ListParser<ListPolicy>::push_front_space(size_type n)
141 container_type c (*this);
142 return c.push_front_space(n);
145 template <class ListPolicy>
146 prefix_ void senf::ListParser<ListPolicy>::resize(size_type n)
149 container_type c (*this);
153 template <class ListPolicy>
154 template <class Value>
155 prefix_ void senf::ListParser<ListPolicy>::resize(size_type n, Value value)
158 container_type c (*this);
162 template <class ListPolicy>
163 prefix_ typename senf::ListParser<ListPolicy> &
164 senf::ListParser<ListPolicy>::get(ListPolicy & p)
166 return static_cast<ListParser &>(p);
169 template <class ListPolicy>
170 prefix_ typename senf::ListParser<ListPolicy> const &
171 senf::ListParser<ListPolicy>::get(ListPolicy const & p)
173 return static_cast<ListParser const &>(p);
176 //-/////////////////////////////////////////////////////////////////////////////////////////////////
177 // senf::detail::ListParser_Iterator<ElementParser,IteratorPolicy>
179 template <class Container>
180 prefix_ senf::detail::ListParser_Iterator<Container>::ListParser_Iterator()
183 template <class Container>
184 prefix_ senf::detail::ListParser_Iterator<Container>::ListParser_Iterator(Container const & c)
188 template <class Container>
189 prefix_ senf::PacketParserBase::data_iterator
190 senf::detail::ListParser_Iterator<Container>::raw()
193 return c_->Container::policy::raw(*c_, *this);
196 template <class Container>
197 prefix_ senf::PacketParserBase::data_iterator
198 senf::detail::ListParser_Iterator<Container>::i()
204 template <class Container>
205 prefix_ typename senf::detail::ListParser_Iterator<Container> &
206 senf::detail::ListParser_Iterator<Container>::get(typename Container::policy::iterator_data & d)
208 return static_cast<ListParser_Iterator &>(d);
211 template <class Container>
212 prefix_ typename senf::detail::ListParser_Iterator<Container> const &
213 senf::detail::ListParser_Iterator<Container>::
214 get(typename Container::policy::iterator_data const & d)
216 return static_cast<ListParser_Iterator const &>(d);
219 template <class Container>
220 prefix_ typename senf::detail::ListParser_Iterator<Container>::value_type
221 senf::detail::ListParser_Iterator<Container>::dereference()
224 return value_type(i_,c_->state());
227 template <class Container>
229 senf::detail::ListParser_Iterator<Container>::equal(ListParser_Iterator const & other)
232 return i_ == other.i_;
235 template <class Container>
236 prefix_ void senf::detail::ListParser_Iterator<Container>::increment()
238 i_ = c_->Container::policy::next(*c_, *this);
241 //-/////////////////////////////////////////////////////////////////////////////////////////////////
242 // senf::ListParser_Container<ListPolicy>
244 // Structors and default members
246 template <class ListPolicy>
247 prefix_ senf::ListParser_Container<ListPolicy>::
248 ListParser_Container(parser_type const & list)
249 : ListPolicy(static_cast<typename parser_type::policy const &>(list)),
250 state_(list.state()), i_(std::distance(data().begin(),list.i()))
252 ListPolicy::construct(*this);
255 template <class ListPolicy>
256 prefix_ senf::ListParser_Container<ListPolicy>::~ListParser_Container()
258 ListPolicy::update(*this);
259 ListPolicy::destruct(*this);
264 template <class ListPolicy>
265 prefix_ typename senf::ListParser_Container<ListPolicy>::size_type
266 senf::ListParser_Container<ListPolicy>::size()
269 ListPolicy::update(*this);
270 return ListPolicy::size(i(),state());
273 template <class ListPolicy>
274 prefix_ bool senf::ListParser_Container<ListPolicy>::empty()
277 ListPolicy::update(*this);
278 return begin() == end();
281 template <class ListPolicy>
282 prefix_ typename senf::ListParser_Container<ListPolicy>::iterator
283 senf::ListParser_Container<ListPolicy>::begin()
286 ListPolicy::update(*this);
288 i.i_ = ListPolicy::setBegin(*this, i);
292 template <class ListPolicy>
293 prefix_ typename senf::ListParser_Container<ListPolicy>::iterator
294 senf::ListParser_Container<ListPolicy>::end()
297 ListPolicy::update(*this);
299 i.i_ = ListPolicy::setEnd(*this, i);
303 template <class ListPolicy>
304 prefix_ typename senf::ListParser_Container<ListPolicy>::value_type
305 senf::ListParser_Container<ListPolicy>::front()
308 SENF_ASSERT( ! empty(), "front() called on empty list" );
314 template <class ListPolicy>
315 template <class Value>
316 prefix_ void senf::ListParser_Container<ListPolicy>::insert(iterator pos,
322 template <class ListPolicy>
323 prefix_ void senf::ListParser_Container<ListPolicy>::erase(iterator f, iterator l)
325 erase(f,std::distance(f,l));
328 template <class ListPolicy>
329 template <class Value>
330 prefix_ void senf::ListParser_Container<ListPolicy>::push_back(Value const & value,
333 insert(end(),n,value);
336 template <class ListPolicy>
337 prefix_ typename senf::ListParser_Container<ListPolicy>::value_type
338 senf::ListParser_Container<ListPolicy>::push_back_space(size_type n)
340 return shift(end(),n);
343 template <class ListPolicy>
344 template <class Value>
345 prefix_ void senf::ListParser_Container<ListPolicy>::push_front(Value const & value,
348 insert(begin(),n,value);
351 template <class ListPolicy>
352 prefix_ typename senf::ListParser_Container<ListPolicy>::value_type
353 senf::ListParser_Container<ListPolicy>::push_front_space(size_type n)
355 return shift(begin(),n);
360 template <class ListPolicy>
361 prefix_ typename senf::ListParser_Container<ListPolicy>::parser_type
362 senf::ListParser_Container<ListPolicy>::parser()
365 ListPolicy::update(*this);
366 return parser_type(i(),state());
369 template <class ListPolicy>
370 prefix_ typename senf::ListParser_Container<ListPolicy>::data_iterator
371 senf::ListParser_Container<ListPolicy>::i()
374 return boost::next(data().begin(),i_);
377 template <class ListPolicy>
378 prefix_ typename senf::ListParser_Container<ListPolicy>::state_type
379 senf::ListParser_Container<ListPolicy>::state()
385 template <class ListPolicy>
386 prefix_ senf::PacketData & senf::ListParser_Container<ListPolicy>::data()
392 template <class ListPolicy>
393 prefix_ typename senf::ListParser_Container<ListPolicy>::size_type
394 senf::ListParser_Container<ListPolicy>::bytes()
397 ListPolicy::update(*this);
398 return ListPolicy::bytes(i(),state());
401 template <class ListPolicy>
402 prefix_ void senf::ListParser_Container<ListPolicy>::init()
408 //-/////////////////////////////////////////////////////////////////////////////////////////////////
415 // comment-column: 40
416 // c-file-style: "senf"
417 // indent-tabs-mode: nil
418 // ispell-local-dictionary: "american"
419 // compile-command: "scons -u test"