4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief ListParser non-inline template implementation */
31 #include "ListParser.ih"
34 #include <senf/Utils/senfassert.hh>
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40 // senf::ListParser<ElementParser,ListPolicy>
42 template <class ListPolicy>
43 prefix_ void senf::ListParser<ListPolicy>::init()
46 ListPolicy::init(i(),state());
48 typename container::iterator i (c.begin());
49 typename container::iterator const e (c.end());
54 template <class ListPolicy>
55 prefix_ typename senf::ListParser<ListPolicy>::value_type
56 senf::ListParser<ListPolicy>::back()
59 SENF_ASSERT( ! empty(), "back() called on empty list" );
61 typename container::iterator i (c.begin()), j;
62 typename container::iterator const e (c.end());
63 for (j=i; i!=e; j=i, ++i) ;
67 //-/////////////////////////////////////////////////////////////////////////////////////////////////
68 // senf::ListParser_Container<ListPolicy>
70 template <class ListPolicy>
71 prefix_ typename senf::ListParser_Container<ListPolicy>::value_type
72 senf::ListParser_Container<ListPolicy>::back()
75 SENF_ASSERT( ! empty(), "back() called on empty list" );
76 iterator i (begin()), j;
77 iterator const e (end());
78 for (j=i; i!=e; j=i, ++i) ;
82 template <class ListPolicy>
83 prefix_ typename senf::ListParser_Container<ListPolicy>::value_type
84 senf::ListParser_Container<ListPolicy>::shift(iterator pos, size_type n)
86 ListPolicy::update(*this);
87 safe_data_iterator sp (data(),pos.raw());
89 data().insert(sp,senf::init_bytes<value_type>::value,0);
90 value_type(sp,state()).init();
91 ListPolicy::insert(*this,sp);
93 return value_type(sp,state());
96 template <class ListPolicy>
97 template <class Value>
98 prefix_ void senf::ListParser_Container<ListPolicy>::insert(iterator pos,
102 ListPolicy::update(*this);
103 safe_data_iterator sp (data(),pos.raw());
105 data().insert(sp,senf::init_bytes<value_type>::value,0);
106 value_type(sp,state()).init();
107 value_type(sp,state()) << t;
108 ListPolicy::insert(*this,sp);
113 template <class ListPolicy>
114 template <class ForwardIterator>
115 prefix_ void senf::ListParser_Container<ListPolicy>::
116 insert(iterator pos, ForwardIterator f, ForwardIterator l,
117 typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type *)
119 ListPolicy::update(*this);
120 safe_data_iterator sp (data(),pos.raw());
122 data().insert(sp,senf::init_bytes<value_type>::value,0);
123 value_type(sp,state()).init();
124 value_type(sp,state()) << *f;
125 ListPolicy::insert(*this,sp);
126 sp += senf::bytes(value_type(sp,state()));
130 template <class ListPolicy>
131 template <class ForwardIterator>
132 prefix_ void senf::ListParser_Container<ListPolicy>::
133 insert(iterator pos, ForwardIterator f, ForwardIterator l)
137 template <class ListPolicy>
138 prefix_ void senf::ListParser_Container<ListPolicy>::erase(iterator pos,
141 ListPolicy::update(*this);
142 safe_data_iterator sp (data(),pos.raw());
144 ListPolicy::erase(*this,sp);
145 data().erase(sp,boost::next(sp,senf::bytes(value_type(sp,state()))));
149 template <class ListPolicy>
150 prefix_ void senf::ListParser_Container<ListPolicy>::clear()
152 size_type sz (bytes());
153 if (sz > ListPolicy::init_bytes)
154 data().erase(boost::next(i(),ListPolicy::init_bytes),boost::next(i(),sz));
156 data().insert(boost::next(i(),sz), ListPolicy::init_bytes-sz, 0u);
157 std::fill(i(),boost::next(i(),ListPolicy::init_bytes), 0u);
158 ListPolicy::init(i(),state());
161 template <class ListPolicy>
162 prefix_ void senf::ListParser_Container<ListPolicy>::resize(size_type n)
164 size_type sz (size());
166 erase(boost::next(begin(),n),end());
168 push_back_space(n-sz);
171 template <class ListPolicy>
172 template <class Value>
173 prefix_ void senf::ListParser_Container<ListPolicy>::resize(size_type n,
176 size_type sz (size());
178 erase(boost::next(begin(),n),end());
180 push_back(value,n-sz);
183 //-/////////////////////////////////////////////////////////////////////////////////////////////////
190 // comment-column: 40
191 // c-file-style: "senf"
192 // indent-tabs-mode: nil
193 // ispell-local-dictionary: "american"
194 // compile-command: "scons -u test"