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 ListBParser inline template implementation */
17 #include "ListBParser.ih"
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>
27 template <class ElementParser, class AuxPolicy>
28 prefix_ senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::ListBParser_Policy()
31 template <class ElementParser, class AuxPolicy>
34 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::ListBParser_Policy(Arg const & arg)
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)
43 return AuxPolicy::aux(i,s) + AuxPolicy::aux_bytes;
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)
51 parser_type p (*this, i, s);
53 return std::distance(c.begin(),c.end());
56 template <class ElementParser, class AuxPolicy>
57 prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::init(data_iterator i,
61 AuxPolicy::aux(0,i,s);
64 //-/////////////////////////////////////////////////////////////////////////////////////////////////
65 // senf::detail::ListBParser_Policy<ElementParser,BytesParser>
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,
73 return AuxPolicy::WrapperPolicy::aux(i,s) + AuxPolicy::aux_bytes;
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,
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)
90 container_size_ = s->size();
91 AuxPolicy::WrapperPolicy::aux(0,i,s);
94 template <class ElementParser, class AuxPolicy>
96 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
97 construct(container_type & c)
101 template <class ElementParser, class AuxPolicy>
103 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
104 destruct(container_type & c)
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)
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());
116 // The container will be reduced by b bytes directly after this call
117 container_size_ = c.data().size()-b;
120 template <class ElementParser, class AuxPolicy>
122 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
123 insert(container_type & c, data_iterator p)
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());
129 container_size_ = c.data().size();
132 template <class ElementParser, class AuxPolicy>
134 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
135 update(container_type const & c)
138 if (container_size_ == c.data().size())
141 data_iterator i (AuxPolicy::WrapperPolicy::adjust(c.i(), c.state()));
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() );
146 AuxPolicy::WrapperPolicy::aux( aux(c.i(),c.state()) + c.data().size() - container_size_, c.i(), c.state() );
148 container_size_ = c.data().size();
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)
157 return AuxPolicy::WrapperPolicy::adjust(c.i(), c.state());
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)
166 return boost::next(AuxPolicy::WrapperPolicy::adjust(c.i(), c.state()),AuxPolicy::WrapperPolicy::aux(c.i(),c.state()));
169 template <class ElementParser, class AuxPolicy>
171 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
172 setFromPosition(container_type const & c, iterator_data & d, data_iterator p)
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)
182 return boost::next( container_type::iterator::get(d).i(),
183 senf::bytes(ElementParser( container_type::iterator::get(d).i(),
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)
193 return container_type::iterator::get(d).i();
196 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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"