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 // Philipp Batroff <pug@berlios.de>
29 \brief ListOptionTypeParser inline template implementation */
31 #include "ListOptionTypeParser.ih"
35 #define prefix_ inline
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 // senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>
41 template <class ElementParser, class AuxPolicy>
43 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::
44 ListOptionTypeParser_Policy()
47 template <class ElementParser, class AuxPolicy>
50 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::
51 ListOptionTypeParser_Policy(Arg const & arg)
55 template <class ElementParser, class AuxPolicy>
56 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::size_type
57 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::bytes(data_iterator i,
61 return ((AuxPolicy::aux(i, s) * 8 + 6) + AuxPolicy::aux_bytes);
64 template <class ElementParser, class AuxPolicy>
65 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::size_type
66 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::size(data_iterator i,
70 parser_type p(*this, i, s);
72 return std::distance(c.begin(), c.end());
75 template <class ElementParser, class AuxPolicy>
77 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::init(data_iterator i,
83 for (unsigned int n = 2;n < 6; ++n)
85 AuxPolicy::aux(0, i, s);
88 //-/////////////////////////////////////////////////////////////////////////////////////////////////
89 // senf::detail::ListOptionTypeParser_Policy<ElementParser,BytesParser>
92 template <class ElementParser, class AuxPolicy>
94 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
95 container_policy(parser_policy const & p)
100 template <class ElementParser, class AuxPolicy>
102 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
107 template <class ElementParser, class AuxPolicy>
109 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
110 construct(container_type & c)
112 safe_data_iterator i (c.data(), c.i()) ;
113 realAux_ = (AuxPolicy::aux(i, c.state()) * 8) + 6;
114 safe_data_iterator e = i + realAux_;
115 for (n_ = 0; i != e;) {
120 elByte = senf::bytes(ElementParser(i, c.state()));
121 if (((i + elByte) == e) && (i[0] == 0u || i[0] == 1u)) { //check weather last element is padding or not
122 realAux_ -= std::distance(i, e);
123 c.data().erase(i, e); //delete padding
124 e = i; //set end iterator
127 std::advance(i, elByte);
130 container_size_ = c.data().size(); //set actual size without padding
134 template <class ElementParser, class AuxPolicy>
136 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
137 destruct(container_type & c)
139 //data_iterator i (AuxPolicy::adjust(parser_type::get(p).i(), parser_type::get(p).state()));
140 safe_data_iterator i (c.data(), c.i()) ;
141 safe_data_iterator e = i + realAux_;
142 unsigned int padBytes = 0;
143 if (realAux_ == 0) //if list is empty, 6 padding bytes required!
146 padBytes = ( (realAux_+2) % 8);
148 padBytes = 8 - padBytes;
151 c.data().insert(e, padBytes, 0u);
157 container_size_ += padBytes;
158 realAux_ += padBytes;
161 AuxPolicy::aux(( (realAux_ + 2)/ 8 - 1), i, c.state());
165 template <class ElementParser, class AuxPolicy>
166 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
167 ElementParser,AuxPolicy>::container_policy::size_type
168 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
169 bytes(data_iterator i, state_type s)
176 template <class ElementParser, class AuxPolicy>
177 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
178 ElementParser,AuxPolicy>::container_policy::size_type
179 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
180 size(data_iterator i, state_type s)
187 template <class ElementParser, class AuxPolicy>
189 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
190 init(data_iterator i, state_type s)
194 container_size_ = s->size();
195 AuxPolicy::aux(0, i, s);
199 template <class ElementParser, class AuxPolicy>
201 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
202 erase(container_type & c, data_iterator p)
204 size_type b(senf::bytes(ElementParser(p, c.state())));
207 container_size_ = c.data().size() - b;
211 template <class ElementParser, class AuxPolicy>
213 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
214 insert(container_type & c, data_iterator p)
216 size_type b(senf::bytes(ElementParser(p, c.state())));
219 container_size_ = c.data().size();
223 template <class ElementParser, class AuxPolicy>
225 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
226 update(container_type const & c)
229 if (container_size_ == c.data().size())
231 data_iterator i(AuxPolicy::adjust(c.i(), c.state()));
233 for (size_type n(n_); n; --n, std::advance(j, senf::bytes(ElementParser(j,c.state())))) { ; }
234 realAux_ = std::distance(i, j);
235 container_size_ = c.data().size();
239 template <class ElementParser, class AuxPolicy>
240 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
241 ElementParser,AuxPolicy>::container_policy::data_iterator
242 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
243 setBegin(container_type const & c, iterator_data & d)
250 template <class ElementParser, class AuxPolicy>
251 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
252 ElementParser,AuxPolicy>::container_policy::data_iterator
253 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
254 setEnd(container_type const & c, iterator_data & d)
257 return boost::next(c.i(),realAux_);
261 template <class ElementParser, class AuxPolicy>
263 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
264 setFromPosition(container_type const & c, iterator_data & d, data_iterator p)
269 template <class ElementParser, class AuxPolicy>
270 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
271 ElementParser,AuxPolicy>::container_policy::data_iterator
272 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
273 next(container_type const & c, iterator_data & d)
276 return boost::next(container_type::iterator::get(d).i(), senf::bytes(ElementParser(container_type::iterator::get(d).i(), c.state())));
280 template <class ElementParser, class AuxPolicy>
281 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
282 ElementParser,AuxPolicy>::container_policy::data_iterator
283 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
284 raw(container_type const & c, iterator_data const & d)
287 return container_type::iterator::get(d).i();
290 //-/////////////////////////////////////////////////////////////////////////////////////////////////
297 // comment-column: 40
298 // c-file-style: "senf"
299 // indent-tabs-mode: nil
300 // ispell-local-dictionary: "american"
301 // compile-command: "scons -u test"