// $Id$ // // Copyright (C) 2009 // Fraunhofer Institute for Open Communication Systems (FOKUS) // // The contents of this file are subject to the Fraunhofer FOKUS Public License // Version 1.0 (the "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // http://senf.berlios.de/license.html // // The Fraunhofer FOKUS Public License Version 1.0 is based on, // but modifies the Mozilla Public License Version 1.1. // See the full license text for the amendments. // // Software distributed under the License is distributed on an "AS IS" basis, // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License // for the specific language governing rights and limitations under the License. // // The Original Code is Fraunhofer FOKUS code. // // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. // (registered association), Hansastraße 27 c, 80686 Munich, Germany. // All Rights Reserved. // // Contributor(s): // Philipp Batroff /** \file \brief ListOptionTypeParser inline template implementation */ #include "ListOptionTypeParser.ih" // Custom includes #define prefix_ inline //-///////////////////////////////////////////////////////////////////////////////////////////////// //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::detail::ListOptionTypeParser_Policy template prefix_ senf::detail::ListOptionTypeParser_Policy:: ListOptionTypeParser_Policy() {} template template prefix_ senf::detail::ListOptionTypeParser_Policy:: ListOptionTypeParser_Policy(Arg const & arg) : AuxPolicy(arg) {} template prefix_ typename senf::detail::ListOptionTypeParser_Policy::size_type senf::detail::ListOptionTypeParser_Policy::bytes(data_iterator i, state_type s) const { return ((AuxPolicy::aux(i, s) * 8 + 6) + AuxPolicy::aux_bytes); } template prefix_ typename senf::detail::ListOptionTypeParser_Policy::size_type senf::detail::ListOptionTypeParser_Policy::size(data_iterator i, state_type s) const { parser_type p(*this, i, s); container_type c(p); return std::distance(c.begin(), c.end()); } template prefix_ void senf::detail::ListOptionTypeParser_Policy::init(data_iterator i, state_type s) const { i[0] = 1u; i[1] = 4u; for (unsigned int n = 2;n < 6; ++n) i[n] = 0u; AuxPolicy::aux(0, i, s); } //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::detail::ListOptionTypeParser_Policy //constructor template prefix_ senf::detail::ListOptionTypeParser_Policy::container_policy:: container_policy(parser_policy const & p) : AuxPolicy(p) {} //destructor template prefix_ senf::detail::ListOptionTypeParser_Policy::container_policy:: ~container_policy() {} //construct method template prefix_ void senf::detail::ListOptionTypeParser_Policy::container_policy:: construct(container_type & c) { safe_data_iterator i (c.data(), c.i()) ; realAux_ = (AuxPolicy::aux(i, c.state()) * 8) + 6; safe_data_iterator e = i + realAux_; for (n_ = 0; i != e;) { size_type elByte; if (i[0] == 0u) elByte = 1; else elByte = senf::bytes(ElementParser(i, c.state())); if (((i + elByte) == e) && (i[0] == 0u || i[0] == 1u)) { //check weather last element is padding or not realAux_ -= std::distance(i, e); c.data().erase(i, e); //delete padding e = i; //set end iterator } else { ++n_; std::advance(i, elByte); } } container_size_ = c.data().size(); //set actual size without padding } //destruct method template prefix_ void senf::detail::ListOptionTypeParser_Policy::container_policy:: destruct(container_type & c) { //data_iterator i (AuxPolicy::adjust(parser_type::get(p).i(), parser_type::get(p).state())); safe_data_iterator i (c.data(), c.i()) ; safe_data_iterator e = i + realAux_; unsigned int padBytes = 0; if (realAux_ == 0) //if list is empty, 6 padding bytes required! padBytes = 6; else { padBytes = ( (realAux_+2) % 8); if (padBytes != 0) padBytes = 8 - padBytes; } if (padBytes > 0) { c.data().insert(e, padBytes, 0u); if (padBytes > 1) { e[0] = 1u; e[1] = padBytes - 2; } else e[0] = 0; container_size_ += padBytes; realAux_ += padBytes; ++n_; } AuxPolicy::aux(( (realAux_ + 2)/ 8 - 1), i, c.state()); } //bytes() template prefix_ typename senf::detail::ListOptionTypeParser_Policy< ElementParser,AuxPolicy>::container_policy::size_type senf::detail::ListOptionTypeParser_Policy::container_policy:: bytes(data_iterator i, state_type s) const { return (realAux_ ); } //size() template prefix_ typename senf::detail::ListOptionTypeParser_Policy< ElementParser,AuxPolicy>::container_policy::size_type senf::detail::ListOptionTypeParser_Policy::container_policy:: size(data_iterator i, state_type s) const { return n_; } //init() template prefix_ void senf::detail::ListOptionTypeParser_Policy::container_policy:: init(data_iterator i, state_type s) { realAux_ = 0; n_ = 0; container_size_ = s->size(); AuxPolicy::aux(0, i, s); } //erase() template prefix_ void senf::detail::ListOptionTypeParser_Policy::container_policy:: erase(container_type & c, data_iterator p) { size_type b(senf::bytes(ElementParser(p, c.state()))); realAux_ -= b; --n_; container_size_ = c.data().size() - b; } //insert() template prefix_ void senf::detail::ListOptionTypeParser_Policy::container_policy:: insert(container_type & c, data_iterator p) { size_type b(senf::bytes(ElementParser(p, c.state()))); realAux_ += b; ++n_; container_size_ = c.data().size(); } //update() template prefix_ void senf::detail::ListOptionTypeParser_Policy::container_policy:: update(container_type const & c) const { if (container_size_ == c.data().size()) return; data_iterator i(AuxPolicy::adjust(c.i(), c.state())); data_iterator j(i); for (size_type n(n_); n; --n, std::advance(j, senf::bytes(ElementParser(j,c.state())))) { ; } realAux_ = std::distance(i, j); container_size_ = c.data().size(); } //setbegin() template prefix_ typename senf::detail::ListOptionTypeParser_Policy< ElementParser,AuxPolicy>::container_policy::data_iterator senf::detail::ListOptionTypeParser_Policy::container_policy:: setBegin(container_type const & c, iterator_data & d) const { return c.i(); } //setEnd() template prefix_ typename senf::detail::ListOptionTypeParser_Policy< ElementParser,AuxPolicy>::container_policy::data_iterator senf::detail::ListOptionTypeParser_Policy::container_policy:: setEnd(container_type const & c, iterator_data & d) const { return boost::next(c.i(),realAux_); } //setFromPosition() template prefix_ void senf::detail::ListOptionTypeParser_Policy::container_policy:: setFromPosition(container_type const & c, iterator_data & d, data_iterator p) const {} //next() template prefix_ typename senf::detail::ListOptionTypeParser_Policy< ElementParser,AuxPolicy>::container_policy::data_iterator senf::detail::ListOptionTypeParser_Policy::container_policy:: next(container_type const & c, iterator_data & d) const { return boost::next(container_type::iterator::get(d).i(), senf::bytes(ElementParser(container_type::iterator::get(d).i(), c.state()))); } //raw() template prefix_ typename senf::detail::ListOptionTypeParser_Policy< ElementParser,AuxPolicy>::container_policy::data_iterator senf::detail::ListOptionTypeParser_Policy::container_policy:: raw(container_type const & c, iterator_data const & d) const { return container_type::iterator::get(d).i(); } //-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_ // Local Variables: // mode: c++ // fill-column: 100 // comment-column: 40 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" // End: