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 ArrayParser inline template implementation */
17 #include "ArrayParser.ih"
20 #include <senf/Utils/senfassert.hh>
22 #define prefix_ inline
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 // senf::ArrayParser<elements,ElementParser>
28 template <unsigned elements, class ElementParser>
29 prefix_ senf::ArrayParser<elements,ElementParser>::ArrayParser(data_iterator i, state_type s)
30 : PacketParserBase(i,s,fixed_bytes)
33 // Container interface
35 template <unsigned elements, class ElementParser>
36 prefix_ typename senf::ArrayParser<elements,ElementParser>::size_type
37 senf::ArrayParser<elements,ElementParser>::size()
42 template <unsigned elements, class ElementParser>
43 prefix_ typename senf::ArrayParser<elements,ElementParser>::iterator
44 senf::ArrayParser<elements,ElementParser>::begin()
47 return iterator(i(),state());
50 template <unsigned elements, class ElementParser>
51 prefix_ typename senf::ArrayParser<elements,ElementParser>::iterator
52 senf::ArrayParser<elements,ElementParser>::end()
55 return iterator(boost::next(i(),fixed_bytes),state());
58 template <unsigned elements, class ElementParser>
59 prefix_ typename senf::ArrayParser<elements,ElementParser>::value_type
60 senf::ArrayParser<elements,ElementParser>::operator[](difference_type i)
63 // Access out of range element
64 SENF_ASSERT( i>=0 && i < difference_type(elements), "Access to out-of-range array element" );
68 //-/////////////////////////////////////////////////////////////////////////////////////////////////
69 // senf::detail::ArrayParser_iterator<ElementParser>
71 template <class ElementParser>
72 prefix_ senf::detail::ArrayParser_iterator<ElementParser>::ArrayParser_iterator()
76 template <class ElementParser>
77 prefix_ senf::detail::ArrayParser_iterator<ElementParser>::
78 ArrayParser_iterator(PacketParserBase::data_iterator const & i, PacketParserBase::state_type s)
82 template <class ElementParser>
84 senf::detail::ArrayParser_iterator<ElementParser>::operator[](int i)
87 return (*this+i).dereference();
90 template <class ElementParser>
91 prefix_ senf::PacketParserBase::data_iterator
92 senf::detail::ArrayParser_iterator<ElementParser>::raw()
98 // iterator_facade interface
100 template <class ElementParser>
101 prefix_ ElementParser
102 senf::detail::ArrayParser_iterator<ElementParser>::dereference()
105 return ElementParser(i_,s_);
108 template <class ElementParser>
110 senf::detail::ArrayParser_iterator<ElementParser>::
111 equal(ArrayParser_iterator const & other)
117 template <class ElementParser>
118 prefix_ int senf::detail::ArrayParser_iterator<ElementParser>::
119 distance_to(ArrayParser_iterator const & other)
122 return (other.i_-i_)/ElementParser::fixed_bytes;
125 template <class ElementParser>
126 prefix_ void senf::detail::ArrayParser_iterator<ElementParser>::increment()
128 i_ += ElementParser::fixed_bytes;
131 template <class ElementParser>
132 prefix_ void senf::detail::ArrayParser_iterator<ElementParser>::decrement()
134 i_ -= ElementParser::fixed_bytes;
137 template <class ElementParser>
138 prefix_ void senf::detail::ArrayParser_iterator<ElementParser>::advance(int n)
140 i_ += n*ElementParser::fixed_bytes;
143 //-/////////////////////////////////////////////////////////////////////////////////////////////////
150 // c-file-style: "senf"
151 // indent-tabs-mode: nil
152 // ispell-local-dictionary: "american"
153 // compile-command: "scons -u test"
154 // comment-column: 40