ArrayParser.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 ArrayParser inline template implementation */
16 
17 #include "ArrayParser.ih"
18 
19 // Custom includes
20 #include <senf/Utils/senfassert.hh>
21 
22 #define prefix_ inline
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 // senf::ArrayParser<elements,ElementParser>
27 
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)
31 {}
32 
33 // Container interface
34 
35 template <unsigned elements, class ElementParser>
36 prefix_ typename senf::ArrayParser<elements,ElementParser>::size_type
37 senf::ArrayParser<elements,ElementParser>::size()
38 {
39  return elements;
40 }
41 
42 template <unsigned elements, class ElementParser>
43 prefix_ typename senf::ArrayParser<elements,ElementParser>::iterator
44 senf::ArrayParser<elements,ElementParser>::begin()
45  const
46 {
47  return iterator(i(),state());
48 }
49 
50 template <unsigned elements, class ElementParser>
51 prefix_ typename senf::ArrayParser<elements,ElementParser>::iterator
52 senf::ArrayParser<elements,ElementParser>::end()
53  const
54 {
55  return iterator(boost::next(i(),fixed_bytes),state());
56 }
57 
58 template <unsigned elements, class ElementParser>
59 prefix_ typename senf::ArrayParser<elements,ElementParser>::value_type
60 senf::ArrayParser<elements,ElementParser>::operator[](difference_type i)
61  const
62 {
63  // Access out of range element
64  SENF_ASSERT( i>=0 && i < difference_type(elements), "Access to out-of-range array element" );
65  return begin()[i];
66 }
67 
68 //-/////////////////////////////////////////////////////////////////////////////////////////////////
69 // senf::detail::ArrayParser_iterator<ElementParser>
70 
71 template <class ElementParser>
72 prefix_ senf::detail::ArrayParser_iterator<ElementParser>::ArrayParser_iterator()
73  : i_()
74 {}
75 
76 template <class ElementParser>
77 prefix_ senf::detail::ArrayParser_iterator<ElementParser>::
78 ArrayParser_iterator(PacketParserBase::data_iterator const & i, PacketParserBase::state_type s)
79  : i_(i), s_(s)
80 {}
81 
82 template <class ElementParser>
83 prefix_ ElementParser
84 senf::detail::ArrayParser_iterator<ElementParser>::operator[](int i)
85  const
86 {
87  return (*this+i).dereference();
88 }
89 
90 template <class ElementParser>
91 prefix_ senf::PacketParserBase::data_iterator
92 senf::detail::ArrayParser_iterator<ElementParser>::raw()
93  const
94 {
95  return i_;
96 }
97 
98 // iterator_facade interface
99 
100 template <class ElementParser>
101 prefix_ ElementParser
102 senf::detail::ArrayParser_iterator<ElementParser>::dereference()
103  const
104 {
105  return ElementParser(i_,s_);
106 }
107 
108 template <class ElementParser>
109 prefix_ bool
110 senf::detail::ArrayParser_iterator<ElementParser>::
111 equal(ArrayParser_iterator const & other)
112  const
113 {
114  return i_==other.i_;
115 }
116 
117 template <class ElementParser>
118 prefix_ int senf::detail::ArrayParser_iterator<ElementParser>::
119 distance_to(ArrayParser_iterator const & other)
120  const
121 {
122  return (other.i_-i_)/ElementParser::fixed_bytes;
123 }
124 
125 template <class ElementParser>
126 prefix_ void senf::detail::ArrayParser_iterator<ElementParser>::increment()
127 {
128  i_ += ElementParser::fixed_bytes;
129 }
130 
131 template <class ElementParser>
132 prefix_ void senf::detail::ArrayParser_iterator<ElementParser>::decrement()
133 {
134  i_ -= ElementParser::fixed_bytes;
135 }
136 
137 template <class ElementParser>
138 prefix_ void senf::detail::ArrayParser_iterator<ElementParser>::advance(int n)
139 {
140  i_ += n*ElementParser::fixed_bytes;
141 }
142 
143 //-/////////////////////////////////////////////////////////////////////////////////////////////////
144 #undef prefix_
145 
146 
147 // Local Variables:
148 // mode: c++
149 // fill-column: 100
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
155 // End: