// $Id$ // // Copyright (C) 2007 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file \brief ListParser non-inline template implementation */ #include "ListParser.ih" // Custom includes #include #define prefix_ //-///////////////////////////////////////////////////////////////////////////////////////////////// //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::ListParser template prefix_ void senf::ListParser::init() const { ListPolicy::init(i(),state()); container c (*this); typename container::iterator i (c.begin()); typename container::iterator const e (c.end()); for(; i!=e; ++i) i->init(); } template prefix_ typename senf::ListParser::value_type senf::ListParser::back() const { SENF_ASSERT( ! empty(), "back() called on empty list" ); container c(*this); typename container::iterator i (c.begin()), j; typename container::iterator const e (c.end()); for (j=i; i!=e; j=i, ++i) ; return *j; } //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::ListParser_Container template prefix_ typename senf::ListParser_Container::value_type senf::ListParser_Container::back() const { SENF_ASSERT( ! empty(), "back() called on empty list" ); iterator i (begin()), j; iterator const e (end()); for (j=i; i!=e; j=i, ++i) ; return *j; } template prefix_ typename senf::ListParser_Container::value_type senf::ListParser_Container::shift(iterator pos, size_type n) { ListPolicy::update(*this); safe_data_iterator sp (data(),pos.raw()); for (; n>0; --n) { data().insert(sp,senf::init_bytes::value,0); value_type(sp,state()).init(); ListPolicy::insert(*this,sp); } return value_type(sp,state()); } template template prefix_ void senf::ListParser_Container::insert(iterator pos, size_type n, Value const & t) { ListPolicy::update(*this); safe_data_iterator sp (data(),pos.raw()); for (; n>0; --n) { data().insert(sp,senf::init_bytes::value,0); value_type(sp,state()).init(); value_type(sp,state()) << t; ListPolicy::insert(*this,sp); } } #ifndef DOXYGEN template template prefix_ void senf::ListParser_Container:: insert(iterator pos, ForwardIterator f, ForwardIterator l, typename boost::disable_if< boost::is_convertible >::type *) { ListPolicy::update(*this); safe_data_iterator sp (data(),pos.raw()); for (; f!=l; ++f) { data().insert(sp,senf::init_bytes::value,0); value_type(sp,state()).init(); value_type(sp,state()) << *f; ListPolicy::insert(*this,sp); sp += senf::bytes(value_type(sp,state())); } } #else template template prefix_ void senf::ListParser_Container:: insert(iterator pos, ForwardIterator f, ForwardIterator l) {} #endif template prefix_ void senf::ListParser_Container::erase(iterator pos, size_type n) { ListPolicy::update(*this); safe_data_iterator sp (data(),pos.raw()); for (; n>0; --n) { ListPolicy::erase(*this,sp); data().erase(sp,boost::next(sp,senf::bytes(value_type(sp,state())))); } } template prefix_ void senf::ListParser_Container::clear() { size_type sz (bytes()); if (sz > ListPolicy::init_bytes) data().erase(boost::next(i(),ListPolicy::init_bytes),boost::next(i(),sz)); else data().insert(boost::next(i(),sz), ListPolicy::init_bytes-sz, 0u); std::fill(i(),boost::next(i(),ListPolicy::init_bytes), 0u); ListPolicy::init(i(),state()); } template prefix_ void senf::ListParser_Container::resize(size_type n) { size_type sz (size()); if (sz>n) erase(boost::next(begin(),n),end()); else push_back_space(n-sz); } template template prefix_ void senf::ListParser_Container::resize(size_type n, Value value) { size_type sz (size()); if (sz>n) erase(boost::next(begin(),n),end()); else push_back(value,n-sz); } //-///////////////////////////////////////////////////////////////////////////////////////////////// #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: