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 ListBParser inline template implementation */
26 #include "ListBParser.ih"
30 #define prefix_ inline
31 //-/////////////////////////////////////////////////////////////////////////////////////////////////
33 //-/////////////////////////////////////////////////////////////////////////////////////////////////
34 // senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>
36 template <class ElementParser, class AuxPolicy>
37 prefix_ senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::ListBParser_Policy()
40 template <class ElementParser, class AuxPolicy>
43 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::ListBParser_Policy(Arg const & arg)
47 template <class ElementParser, class AuxPolicy>
48 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size_type
49 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::bytes(data_iterator i, state_type s)
52 return AuxPolicy::aux(i,s) + AuxPolicy::aux_bytes;
55 template <class ElementParser, class AuxPolicy>
56 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size_type
57 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size(data_iterator i, state_type s)
60 parser_type p (*this, i, s);
62 return std::distance(c.begin(),c.end());
65 template <class ElementParser, class AuxPolicy>
66 prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::init(data_iterator i,
70 AuxPolicy::aux(0,i,s);
73 //-/////////////////////////////////////////////////////////////////////////////////////////////////
74 // senf::detail::ListBParser_Policy<ElementParser,BytesParser>
76 template <class ElementParser, class AuxPolicy>
77 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size_type
78 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::bytes(data_iterator i,
82 return AuxPolicy::WrapperPolicy::aux(i,s) + AuxPolicy::aux_bytes;
85 template <class ElementParser, class AuxPolicy>
86 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size_type
87 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size(data_iterator i,
94 template <class ElementParser, class AuxPolicy>
95 prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
96 init(data_iterator i, state_type s)
99 container_size_ = s->size();
100 AuxPolicy::WrapperPolicy::aux(0,i,s);
103 template <class ElementParser, class AuxPolicy>
105 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
106 construct(container_type & c)
110 template <class ElementParser, class AuxPolicy>
112 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
113 destruct(container_type & c)
117 template <class ElementParser, class AuxPolicy>
118 prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
119 erase(container_type & c, data_iterator p)
121 size_type b (senf::bytes(ElementParser(p,c.state())));
122 AuxPolicy::WrapperPolicy::aux(
123 AuxPolicy::WrapperPolicy::aux(c.i(), c.state())-b, c.i(), c.state());
125 // The container will be reduced by b bytes directly after this call
126 container_size_ = c.data().size()-b;
129 template <class ElementParser, class AuxPolicy>
131 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
132 insert(container_type & c, data_iterator p)
134 size_type b (senf::bytes(ElementParser(p,c.state())));
135 AuxPolicy::WrapperPolicy::aux(
136 AuxPolicy::WrapperPolicy::aux(c.i(), c.state())+b, c.i(), c.state());
138 container_size_ = c.data().size();
141 template <class ElementParser, class AuxPolicy>
143 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
144 update(container_type const & c)
147 if (container_size_ == c.data().size())
150 data_iterator i (AuxPolicy::WrapperPolicy::adjust(c.i(), c.state()));
152 for (size_type n (n_); n; --n, std::advance(j,senf::bytes(ElementParser(j,c.state())))) ;
153 aux( std::distance(i,j), c.i(), c.state() );
155 aux ( aux(c.i(),c.state()) + c.data().size() - container_size_, c.i(), c.state() );
157 container_size_ = c.data().size();
160 template <class ElementParser, class AuxPolicy>
161 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
162 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
163 setBegin(container_type const & c, iterator_data & d)
166 return AuxPolicy::WrapperPolicy::adjust(c.i(), c.state());
169 template <class ElementParser, class AuxPolicy>
170 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
171 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
172 setEnd(container_type const & c, iterator_data & d)
175 return boost::next(AuxPolicy::WrapperPolicy::adjust(c.i(), c.state()),aux(c.i(),c.state()));
178 template <class ElementParser, class AuxPolicy>
180 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
181 setFromPosition(container_type const & c, iterator_data & d, data_iterator p)
185 template <class ElementParser, class AuxPolicy>
186 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
187 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
188 next(container_type const & c, iterator_data & d)
191 return boost::next( container_type::iterator::get(d).i(),
192 senf::bytes(ElementParser( container_type::iterator::get(d).i(),
196 template <class ElementParser, class AuxPolicy>
197 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
198 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
199 raw(container_type const & c, iterator_data const & d)
202 return container_type::iterator::get(d).i();
205 //-/////////////////////////////////////////////////////////////////////////////////////////////////
212 // comment-column: 40
213 // c-file-style: "senf"
214 // indent-tabs-mode: nil
215 // ispell-local-dictionary: "american"
216 // compile-command: "scons -u test"