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 non-inline template implementation */
17 #include "ListParser.ih"
20 #include <senf/Utils/senfassert.hh>
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 // senf::ListParser<ElementParser,ListPolicy>
28 template <class ListPolicy>
29 prefix_ void senf::ListParser<ListPolicy>::init()
32 ListPolicy::init(i(),state());
33 container_type c (*this);
34 typename container_type::iterator i (c.begin());
35 typename container_type::iterator const e (c.end());
40 template <class ListPolicy>
41 prefix_ typename senf::ListParser<ListPolicy>::value_type
42 senf::ListParser<ListPolicy>::back()
45 SENF_ASSERT( ! empty(), "back() called on empty list" );
46 container_type c (*this);
47 typename container_type::iterator i (c.begin()), j;
48 typename container_type::iterator const e (c.end());
49 for (j=i; i!=e; j=i, ++i) ;
53 //-/////////////////////////////////////////////////////////////////////////////////////////////////
54 // senf::ListParser_Container<ListPolicy>
56 template <class ListPolicy>
57 prefix_ typename senf::ListParser_Container<ListPolicy>::value_type
58 senf::ListParser_Container<ListPolicy>::back()
61 SENF_ASSERT( ! empty(), "back() called on empty list" );
62 iterator i (begin()), j;
63 iterator const e (end());
64 for (j=i; i!=e; j=i, ++i) ;
68 template <class ListPolicy>
69 prefix_ typename senf::ListParser_Container<ListPolicy>::value_type
70 senf::ListParser_Container<ListPolicy>::shift(iterator pos, size_type n)
72 ListPolicy::update(*this);
73 safe_data_iterator sp (data(),pos.raw());
75 data().insert(sp,senf::init_bytes<value_type>::value,0);
76 value_type(sp,state()).init();
77 ListPolicy::insert(*this,sp);
79 return value_type(sp,state());
82 template <class ListPolicy>
83 template <class Value>
84 prefix_ void senf::ListParser_Container<ListPolicy>::insert(iterator pos,
88 ListPolicy::update(*this);
89 safe_data_iterator sp (data(),pos.raw());
91 data().insert(sp,senf::init_bytes<value_type>::value,0);
92 value_type(sp,state()).init();
93 value_type(sp,state()) << t;
94 ListPolicy::insert(*this,sp);
99 template <class ListPolicy>
100 template <class ForwardIterator>
101 prefix_ void senf::ListParser_Container<ListPolicy>::
102 insert(iterator pos, ForwardIterator f, ForwardIterator l,
103 typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type *)
105 ListPolicy::update(*this);
106 safe_data_iterator sp (data(),pos.raw());
108 data().insert(sp,senf::init_bytes<value_type>::value,0);
109 value_type(sp,state()).init();
110 value_type(sp,state()) << *f;
111 ListPolicy::insert(*this,sp);
112 sp += senf::bytes(value_type(sp,state()));
116 template <class ListPolicy>
117 template <class ForwardIterator>
118 prefix_ void senf::ListParser_Container<ListPolicy>::
119 insert(iterator pos, ForwardIterator f, ForwardIterator l)
123 template <class ListPolicy>
124 prefix_ void senf::ListParser_Container<ListPolicy>::erase(iterator pos,
127 ListPolicy::update(*this);
128 safe_data_iterator sp (data(),pos.raw());
130 ListPolicy::erase(*this,sp);
131 data().erase(sp,boost::next(sp,senf::bytes(value_type(sp,state()))));
135 template <class ListPolicy>
136 prefix_ void senf::ListParser_Container<ListPolicy>::clear()
138 size_type sz (bytes());
139 if (sz > ListPolicy::init_bytes)
140 data().erase(boost::next(i(),ListPolicy::init_bytes),boost::next(i(),sz));
142 data().insert(boost::next(i(),sz), ListPolicy::init_bytes-sz, 0u);
143 std::fill(i(),boost::next(i(),ListPolicy::init_bytes), 0u);
144 ListPolicy::init(i(),state());
147 template <class ListPolicy>
148 prefix_ void senf::ListParser_Container<ListPolicy>::resize(size_type n)
150 size_type sz (size());
152 erase(boost::next(begin(),n),end());
154 push_back_space(n-sz);
157 template <class ListPolicy>
158 template <class Value>
159 prefix_ void senf::ListParser_Container<ListPolicy>::resize(size_type n,
162 size_type sz (size());
164 erase(boost::next(begin(),n),end());
166 push_back(value,n-sz);
169 //-/////////////////////////////////////////////////////////////////////////////////////////////////
176 // comment-column: 40
177 // c-file-style: "senf"
178 // indent-tabs-mode: nil
179 // ispell-local-dictionary: "american"
180 // compile-command: "scons -u test"