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>
37 prefix_ senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::ListOptionTypeParser_Policy() {
40 template<class ElementParser, class AuxPolicy>
42 prefix_ senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::ListOptionTypeParser_Policy(Arg const & arg) :AuxPolicy(arg) {
45 template<class ElementParser, class AuxPolicy>
46 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::size_type
47 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::bytes(data_iterator i, state_type s) const {
48 return AuxPolicy::aux(i, s) + AuxPolicy::aux_bytes;
51 template<class ElementParser, class AuxPolicy>
52 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::size_type
53 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::size(data_iterator i, state_type s) const {
54 parser_type p(*this, i, s);
56 return std::distance(c.begin(), c.end());
59 template<class ElementParser, class AuxPolicy>
61 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::init(data_iterator i, state_type s) const {
62 AuxPolicy::aux(0, i, s);
65 ///////////////////////////////////////////////////////////////////////////
66 // senf::detail::ListOptionTypeParser_Policy<ElementParser,BytesParser>
69 template<class ElementParser, class AuxPolicy>
70 prefix_ senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::container_policy(parser_policy const & p) :
75 template<class ElementParser, class AuxPolicy>
76 prefix_ senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::~container_policy()
80 template<class ElementParser, class AuxPolicy>
82 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::construct(container_type & c) {
83 data_iterator i = c.i();
84 realAux_ = (AuxPolicy::aux(i, c.state()) * 8) + 6;
85 data_iterator e = i + realAux_;
86 for (n_ = 0; i != e; ++n_) {
87 unsigned int elByte = senf::bytes(ElementParser(i, c.state()));
88 if (((i + elByte) == e) && (i[0] == 0u || i[0] == 1u)) { //check wether last element is padding or not
89 realAux_ -= std::distance(i, e);
90 c.data().erase(i, e); //delete padding
91 e = i; //set end iterator
93 std::advance(i, elByte);
95 // container_size_ = std::distance(i,e);
96 container_size_ = c.data().size(); //set actual size without padding
100 template<class ElementParser, class AuxPolicy>
102 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::destruct(container_type & c) {
103 // data_iterator i (AuxPolicy::adjust(parser_type::get(p).i(), parser_type::get(p).state()));
104 data_iterator i = c.i();
105 data_iterator const e = i + realAux_;
106 unsigned int padBytes = (realAux_ % 8);
107 c.data().insert(e, padBytes, 0u);
114 container_size_ += padBytes;
117 AuxPolicy::aux((realAux_ / 8 - 1), i, c.state());
121 template<class ElementParser, class AuxPolicy>
122 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::size_type
123 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::bytes(data_iterator i,state_type s) const {
124 return (realAux_ + 2);
128 template<class ElementParser, class AuxPolicy>
129 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::size_type
130 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::size(data_iterator i,state_type s) const {
135 template<class ElementParser, class AuxPolicy>
137 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::init(data_iterator i, state_type s) {
139 container_size_ = s->size();
140 AuxPolicy::aux(0, i, s);
144 template<class ElementParser, class AuxPolicy>
146 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::erase(container_type & c, data_iterator p) {
147 size_type b(senf::bytes(ElementParser(p, c.state()))); //length of parser
149 // AuxPolicy::aux( c.i(), c.state()) -b,
154 // The container will be reduced by b bytes directly after this call
155 container_size_ = c.data().size() - b;
159 template<class ElementParser, class AuxPolicy>
161 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::insert(container_type & c, data_iterator p) {
162 size_type b(senf::bytes(ElementParser(p, c.state())));
163 // AuxPolicy::aux( AuxPolicy::aux(c.i(), c.state())+b, c.i(), c.state());
166 container_size_ = c.data().size();
170 template<class ElementParser, class AuxPolicy>
172 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::update(container_type const & c) const {
173 if (container_size_ == c.data().size())
175 data_iterator i(AuxPolicy::adjust(c.i(), c.state()));
177 for (size_type n(n_); n; --n, std::advance(j, senf::bytes(ElementParser(j,c.state()))));
178 realAux_ = std::distance(i, j);
179 // aux( std::distance(i,j), c.i(), c.state() );
180 container_size_ = c.data().size();
184 template<class ElementParser, class AuxPolicy>
185 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
186 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::setBegin(container_type const & c, iterator_data & d) const {
188 // return AuxPolicy::adjust(c.i(), c.state());
192 template<class ElementParser, class AuxPolicy>
193 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
194 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::setEnd(container_type const & c, iterator_data & d) const { //wtf??
195 return boost::next(AuxPolicy::adjust(c.i(), c.state()), aux(c.i(),c.state()));
199 template<class ElementParser, class AuxPolicy>
201 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::setFromPosition(container_type const & c, iterator_data & d, data_iterator p) const {
205 template<class ElementParser, class AuxPolicy>
206 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
207 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::next(container_type const & c, iterator_data & d) const {
208 return boost::next(container_type::iterator::get(d).i(), senf::bytes(ElementParser(container_type::iterator::get(d).i(), c.state())));
212 template<class ElementParser, class AuxPolicy>
213 prefix_ typename senf::detail::ListOptionTypeParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
214 senf::detail::ListOptionTypeParser_Policy<ElementParser, AuxPolicy>::container_policy::raw(container_type const & c, iterator_data const & d) const {
215 return container_type::iterator::get(d).i();
218 ///////////////////////////////cti.e///////////////////////////////////////
225 // comment-column: 40
226 // c-file-style: "senf"
227 // indent-tabs-mode: nil
228 // ispell-local-dictionary: "american"
229 // compile-command: "scons -u test"