ListBParser.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 ListBParser inline template implementation */
16 
17 #include "ListBParser.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>
26 
27 template <class ElementParser, class AuxPolicy>
28 prefix_ senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::ListBParser_Policy()
29 {}
30 
31 template <class ElementParser, class AuxPolicy>
32 template <class Arg>
33 prefix_
34 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::ListBParser_Policy(Arg const & arg)
35  : AuxPolicy (arg)
36 {}
37 
38 template <class ElementParser, class AuxPolicy>
39 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size_type
40 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::bytes(data_iterator i, state_type s)
41  const
42 {
43  return AuxPolicy::aux(i,s) + AuxPolicy::aux_bytes;
44 }
45 
46 template <class ElementParser, class AuxPolicy>
47 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size_type
48 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size(data_iterator i, state_type s)
49  const
50 {
51  parser_type p (*this, i, s);
52  container_type c (p);
53  return std::distance(c.begin(),c.end());
54 }
55 
56 template <class ElementParser, class AuxPolicy>
57 prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::init(data_iterator i,
58  state_type s)
59  const
60 {
61  AuxPolicy::aux(0,i,s);
62 }
63 
64 //-/////////////////////////////////////////////////////////////////////////////////////////////////
65 // senf::detail::ListBParser_Policy<ElementParser,BytesParser>
66 
67 template <class ElementParser, class AuxPolicy>
68 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size_type
69 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::bytes(data_iterator i,
70  state_type s)
71  const
72 {
73  return AuxPolicy::WrapperPolicy::aux(i,s) + AuxPolicy::aux_bytes;
74 }
75 
76 template <class ElementParser, class AuxPolicy>
77 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size_type
78 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size(data_iterator i,
79  state_type s)
80  const
81 {
82  return n_;
83 }
84 
85 template <class ElementParser, class AuxPolicy>
86 prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
87 init(data_iterator i, state_type s)
88 {
89  n_ = 0;
90  container_size_ = s->size();
91  AuxPolicy::WrapperPolicy::aux(0,i,s);
92 }
93 
94 template <class ElementParser, class AuxPolicy>
95 prefix_ void
96 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
97 construct(container_type & c)
98  const
99 {}
100 
101 template <class ElementParser, class AuxPolicy>
102 prefix_ void
103 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
104 destruct(container_type & c)
105  const
106 {}
107 
108 template <class ElementParser, class AuxPolicy>
109 prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
110 erase(container_type & c, data_iterator p)
111 {
112  size_type b (senf::bytes(ElementParser(p,c.state())));
113  AuxPolicy::WrapperPolicy::aux(
114  AuxPolicy::WrapperPolicy::aux(c.i(), c.state())-b, c.i(), c.state());
115  --n_;
116  // The container will be reduced by b bytes directly after this call
117  container_size_ = c.data().size()-b;
118 }
119 
120 template <class ElementParser, class AuxPolicy>
121 prefix_ void
122 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
123 insert(container_type & c, data_iterator p)
124 {
125  size_type b (senf::bytes(ElementParser(p,c.state())));
126  AuxPolicy::WrapperPolicy::aux(
127  AuxPolicy::WrapperPolicy::aux(c.i(), c.state())+b, c.i(), c.state());
128  ++n_;
129  container_size_ = c.data().size();
130 }
131 
132 template <class ElementParser, class AuxPolicy>
133 prefix_ void
134 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
135 update(container_type const & c)
136  const
137 {
138  if (container_size_ == c.data().size())
139  return;
140 #if 1
141  data_iterator i (AuxPolicy::WrapperPolicy::adjust(c.i(), c.state()));
142  data_iterator j (i);
143  for (size_type n (n_); n; --n, std::advance(j,senf::bytes(ElementParser(j,c.state())))) ;
144  AuxPolicy::WrapperPolicy::aux( std::distance(i,j), c.i(), c.state() );
145 #else
146  AuxPolicy::WrapperPolicy::aux( aux(c.i(),c.state()) + c.data().size() - container_size_, c.i(), c.state() );
147 #endif
148  container_size_ = c.data().size();
149 }
150 
151 template <class ElementParser, class AuxPolicy>
152 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
153 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
154 setBegin(container_type const & c, iterator_data & d)
155  const
156 {
157  return AuxPolicy::WrapperPolicy::adjust(c.i(), c.state());
158 }
159 
160 template <class ElementParser, class AuxPolicy>
161 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
162 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
163 setEnd(container_type const & c, iterator_data & d)
164  const
165 {
166  return boost::next(AuxPolicy::WrapperPolicy::adjust(c.i(), c.state()),AuxPolicy::WrapperPolicy::aux(c.i(),c.state()));
167 }
168 
169 template <class ElementParser, class AuxPolicy>
170 prefix_ void
171 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
172 setFromPosition(container_type const & c, iterator_data & d, data_iterator p)
173  const
174 {}
175 
176 template <class ElementParser, class AuxPolicy>
177 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
178 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
179 next(container_type const & c, iterator_data & d)
180  const
181 {
182  return boost::next( container_type::iterator::get(d).i(),
183  senf::bytes(ElementParser( container_type::iterator::get(d).i(),
184  c.state() )) );
185 }
186 
187 template <class ElementParser, class AuxPolicy>
188 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
189 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
190 raw(container_type const & c, iterator_data const & d)
191  const
192 {
193  return container_type::iterator::get(d).i();
194 }
195 
196 //-/////////////////////////////////////////////////////////////////////////////////////////////////
197 #undef prefix_
198 
199 
200 // Local Variables:
201 // mode: c++
202 // fill-column: 100
203 // comment-column: 40
204 // c-file-style: "senf"
205 // indent-tabs-mode: nil
206 // ispell-local-dictionary: "american"
207 // compile-command: "scons -u test"
208 // End: