4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief ListParser non-inline template implementation */
26 #include "ListParser.ih"
29 #include <senf/Utils/senfassert.hh>
32 ///////////////////////////////ct.p////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////
35 // senf::ListParser<ElementParser,ListPolicy>
37 template <class ListPolicy>
38 prefix_ void senf::ListParser<ListPolicy>::init()
41 ListPolicy::init(i(),state());
43 typename container::iterator i (c.begin());
44 typename container::iterator const e (c.end());
49 template <class ListPolicy>
50 prefix_ typename senf::ListParser<ListPolicy>::value_type
51 senf::ListParser<ListPolicy>::back()
54 SENF_ASSERT( ! empty() );
56 typename container::iterator i (c.begin()), j;
57 typename container::iterator const e (c.end());
58 for (j=i; i!=e; j=i, ++i) ;
62 ///////////////////////////////////////////////////////////////////////////
63 // senf::ListParser_Container<ListPolicy>
65 template <class ListPolicy>
66 prefix_ typename senf::ListParser_Container<ListPolicy>::value_type
67 senf::ListParser_Container<ListPolicy>::back()
70 SENF_ASSERT( ! empty() );
71 iterator i (begin()), j;
72 iterator const e (end());
73 for (j=i; i!=e; j=i, ++i) ;
77 template <class ListPolicy>
78 prefix_ typename senf::ListParser_Container<ListPolicy>::value_type
79 senf::ListParser_Container<ListPolicy>::shift(iterator pos, size_type n)
81 ListPolicy::update(*this);
82 safe_data_iterator sp (data(),pos.raw());
84 data().insert(sp,senf::init_bytes<value_type>::value,0);
85 value_type(sp,state()).init();
86 ListPolicy::insert(*this,sp);
88 return value_type(sp,state());
91 template <class ListPolicy>
92 template <class Value>
93 prefix_ void senf::ListParser_Container<ListPolicy>::insert(iterator pos,
97 ListPolicy::update(*this);
98 safe_data_iterator sp (data(),pos.raw());
100 data().insert(sp,senf::init_bytes<value_type>::value,0);
101 value_type(sp,state()).init();
102 value_type(sp,state()) << t;
103 ListPolicy::insert(*this,sp);
108 template <class ListPolicy>
109 template <class ForwardIterator>
110 prefix_ void senf::ListParser_Container<ListPolicy>::
111 insert(iterator pos, ForwardIterator f, ForwardIterator l,
112 typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type *)
114 ListPolicy::update(*this);
115 safe_data_iterator sp (data(),pos.raw());
117 data().insert(sp,senf::init_bytes<value_type>::value,0);
118 value_type(sp,state()).init();
119 value_type(sp,state()) << *f;
120 ListPolicy::insert(*this,sp);
121 sp += senf::bytes(value_type(sp,state()));
125 template <class ListPolicy>
126 template <class ForwardIterator>
127 prefix_ void senf::ListParser_Container<ListPolicy>::
128 insert(iterator pos, ForwardIterator f, ForwardIterator l)
132 template <class ListPolicy>
133 prefix_ void senf::ListParser_Container<ListPolicy>::erase(iterator pos,
136 ListPolicy::update(*this);
137 safe_data_iterator sp (data(),pos.raw());
139 ListPolicy::erase(*this,sp);
140 data().erase(sp,boost::next(sp,senf::bytes(value_type(sp,state()))));
144 template <class ListPolicy>
145 prefix_ void senf::ListParser_Container<ListPolicy>::clear()
147 size_type sz (bytes());
148 if (sz > ListPolicy::init_bytes)
149 data().erase(boost::next(i(),ListPolicy::init_bytes),boost::next(i(),sz));
151 data().insert(boost::next(i(),sz), ListPolicy::init_bytes-sz, 0u);
152 std::fill(i(),boost::next(i(),ListPolicy::init_bytes), 0u);
153 ListPolicy::init(i(),state());
156 template <class ListPolicy>
157 prefix_ void senf::ListParser_Container<ListPolicy>::resize(size_type n)
159 size_type sz (size());
161 erase(boost::next(begin(),n),end());
163 push_back_space(n-sz);
166 template <class ListPolicy>
167 template <class Value>
168 prefix_ void senf::ListParser_Container<ListPolicy>::resize(size_type n,
171 size_type sz (size());
173 erase(boost::next(begin(),n),end());
175 push_back(value,n-sz);
178 ///////////////////////////////ct.e////////////////////////////////////////
185 // comment-column: 40
186 // c-file-style: "senf"
187 // indent-tabs-mode: nil
188 // ispell-local-dictionary: "american"
189 // compile-command: "scons -u test"