1 // $Id: ListOptionTypeParser.cti 869 2008-06-09 13:57:27Z pug $
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Philipp.Batroff@fokus.fraunhofer.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 ListOptionTypeParser inline template implementation */
26 #include "ListOptionTypeParser.ih"
30 #define prefix_ inline
31 ///////////////////////////////cti.p///////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>
36 template <class ElementParser, class AuxPolicy>
38 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::
39 ListOptionTypeParser_Policy()
42 template <class ElementParser, class AuxPolicy>
45 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::
46 ListOptionTypeParser_Policy(Arg const & arg)
50 template <class ElementParser, class AuxPolicy>
51 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::size_type
52 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::bytes(data_iterator i,
56 return ((AuxPolicy::aux(i, s) * 8 + 6) + AuxPolicy::aux_bytes);
59 template <class ElementParser, class AuxPolicy>
60 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::size_type
61 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::size(data_iterator i,
65 parser_type p(*this, i, s);
67 return std::distance(c.begin(), c.end());
70 template <class ElementParser, class AuxPolicy>
72 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::init(data_iterator i,
78 for (unsigned int n = 2;n < 6; ++n)
80 AuxPolicy::aux(0, i, s);
83 ///////////////////////////////////////////////////////////////////////////
84 // senf::detail::ListOptionTypeParser_Policy<ElementParser,BytesParser>
87 template <class ElementParser, class AuxPolicy>
89 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
90 container_policy(parser_policy const & p)
95 template <class ElementParser, class AuxPolicy>
97 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
102 template <class ElementParser, class AuxPolicy>
104 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
105 construct(container_type & c)
107 safe_data_iterator i (c.data(), c.i()) ;
108 realAux_ = (AuxPolicy::aux(i, c.state()) * 8) + 6;
109 safe_data_iterator e = i + realAux_;
110 for (n_ = 0; i != e;) {
111 unsigned int elByte = senf::bytes(ElementParser(i, c.state()));
112 if (((i + elByte) == e) && (i[0] == 0u || i[0] == 1u)) { //check weather last element is padding or not
113 realAux_ -= std::distance(i, e);
114 c.data().erase(i, e); //delete padding
115 e = i; //set end iterator
118 std::advance(i, elByte);
121 container_size_ = c.data().size(); //set actual size without padding
125 template <class ElementParser, class AuxPolicy>
127 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
128 destruct(container_type & c)
130 // data_iterator i (AuxPolicy::adjust(parser_type::get(p).i(), parser_type::get(p).state()));
131 safe_data_iterator i (c.data(), c.i()) ;
132 safe_data_iterator e = i + realAux_;
133 unsigned int padBytes = 0;
134 if (realAux_ == 0) //if list is empty, 6 padding bytes required!
137 padBytes = ( (realAux_+2) % 8);
139 padBytes = 8 - padBytes;
142 c.data().insert(e, padBytes, 0u);
148 container_size_ += padBytes;
149 realAux_ += padBytes;
152 AuxPolicy::aux(( (realAux_ + 2)/ 8 - 1), i, c.state());
156 template <class ElementParser, class AuxPolicy>
157 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
158 ElementParser,AuxPolicy>::container_policy::size_type
159 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
160 bytes(data_iterator i, state_type s)
167 template <class ElementParser, class AuxPolicy>
168 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
169 ElementParser,AuxPolicy>::container_policy::size_type
170 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
171 size(data_iterator i, state_type s)
178 template <class ElementParser, class AuxPolicy>
180 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
181 init(data_iterator i, state_type s)
185 container_size_ = s->size();
186 AuxPolicy::aux(0, i, s);
190 template <class ElementParser, class AuxPolicy>
192 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
193 erase(container_type & c, data_iterator p)
195 size_type b(senf::bytes(ElementParser(p, c.state())));
198 container_size_ = c.data().size() - b;
202 template <class ElementParser, class AuxPolicy>
204 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
205 insert(container_type & c, data_iterator p)
207 size_type b(senf::bytes(ElementParser(p, c.state())));
210 container_size_ = c.data().size();
214 template <class ElementParser, class AuxPolicy>
216 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
217 update(container_type const & c)
220 if (container_size_ == c.data().size())
222 data_iterator i(AuxPolicy::adjust(c.i(), c.state()));
224 for (size_type n(n_); n; --n, std::advance(j, senf::bytes(ElementParser(j,c.state()))));
225 realAux_ = std::distance(i, j);
226 container_size_ = c.data().size();
230 template <class ElementParser, class AuxPolicy>
231 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
232 ElementParser,AuxPolicy>::container_policy::data_iterator
233 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
234 setBegin(container_type const & c, iterator_data & d)
241 template <class ElementParser, class AuxPolicy>
242 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
243 ElementParser,AuxPolicy>::container_policy::data_iterator
244 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
245 setEnd(container_type const & c, iterator_data & d)
248 return boost::next(c.i(),realAux_);
252 template <class ElementParser, class AuxPolicy>
254 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
255 setFromPosition(container_type const & c, iterator_data & d, data_iterator p)
260 template <class ElementParser, class AuxPolicy>
261 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
262 ElementParser,AuxPolicy>::container_policy::data_iterator
263 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
264 next(container_type const & c, iterator_data & d)
267 return boost::next(container_type::iterator::get(d).i(), senf::bytes(ElementParser(container_type::iterator::get(d).i(), c.state())));
271 template <class ElementParser, class AuxPolicy>
272 prefix_ typename senf::detail::ListOptionTypeParser_Policy<
273 ElementParser,AuxPolicy>::container_policy::data_iterator
274 senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::
275 raw(container_type const & c, iterator_data const & d)
278 return container_type::iterator::get(d).i();
281 ///////////////////////////////cti.e///////////////////////////////////////
288 // comment-column: 40
289 // c-file-style: "senf"
290 // indent-tabs-mode: nil
291 // ispell-local-dictionary: "american"
292 // compile-command: "scons -u test"