Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ListParser.ct

Go to the documentation of this file.
00001 // $Id: ListParser.ct 1772 2011-03-10 12:45:21Z tho $
00002 //
00003 // Copyright (C) 2007
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #include "ListParser.ih"
00027 
00028 // Custom includes
00029 #include <senf/Utils/senfassert.hh>
00030 
00031 #define prefix_
00032 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00033 
00034 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00035 // senf::ListParser<ElementParser,ListPolicy>
00036 
00037 template <class ListPolicy>
00038 prefix_ void senf::ListParser<ListPolicy>::init()
00039     const
00040 {
00041     ListPolicy::init(i(),state());
00042     container c (*this);
00043     typename container::iterator i (c.begin());
00044     typename container::iterator const e (c.end());
00045     for (; i!=e; ++i)
00046         i->init();
00047 }
00048 
00049 template <class ListPolicy>
00050 prefix_ typename senf::ListParser<ListPolicy>::value_type
00051 senf::ListParser<ListPolicy>::back()
00052     const
00053 {
00054     SENF_ASSERT( ! empty(), "back() called on empty list" );
00055     container c(*this);
00056     typename container::iterator i (c.begin()), j;
00057     typename container::iterator const e (c.end());
00058     for (j=i; i!=e; j=i, ++i) ;
00059     return *j;
00060 }
00061 
00062 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00063 // senf::ListParser_Container<ListPolicy>
00064 
00065 template <class ListPolicy>
00066 prefix_ typename senf::ListParser_Container<ListPolicy>::value_type
00067 senf::ListParser_Container<ListPolicy>::back()
00068     const
00069 {
00070     SENF_ASSERT( ! empty(), "back() called on empty list" );
00071     iterator i (begin()), j;
00072     iterator const e (end());
00073     for (j=i; i!=e; j=i, ++i) ;
00074     return *j;
00075 }
00076 
00077 template <class ListPolicy>
00078 prefix_ typename senf::ListParser_Container<ListPolicy>::value_type
00079 senf::ListParser_Container<ListPolicy>::shift(iterator pos, size_type n)
00080 {
00081     ListPolicy::update(*this);
00082     safe_data_iterator sp (data(),pos.raw());
00083     for (; n>0; --n) {
00084         data().insert(sp,senf::init_bytes<value_type>::value,0);
00085         value_type(sp,state()).init();
00086         ListPolicy::insert(*this,sp);
00087     }
00088     return value_type(sp,state());
00089 }
00090 
00091 template <class ListPolicy>
00092 template <class Value>
00093 prefix_ void senf::ListParser_Container<ListPolicy>::insert(iterator pos,
00094                                                             size_type n,
00095                                                             Value const & t)
00096 {
00097     ListPolicy::update(*this);
00098     safe_data_iterator sp (data(),pos.raw());
00099     for (; n>0; --n) {
00100         data().insert(sp,senf::init_bytes<value_type>::value,0);
00101         value_type(sp,state()).init();
00102         value_type(sp,state()) << t;
00103         ListPolicy::insert(*this,sp);
00104     }
00105 }
00106 
00107 #ifndef DOXYGEN
00108 template <class ListPolicy>
00109 template <class ForwardIterator>
00110 prefix_ void senf::ListParser_Container<ListPolicy>::
00111 insert(iterator pos, ForwardIterator f, ForwardIterator l,
00112        typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type *)
00113 {
00114     ListPolicy::update(*this);
00115     safe_data_iterator sp (data(),pos.raw());
00116     for (; f!=l; ++f) {
00117         data().insert(sp,senf::init_bytes<value_type>::value,0);
00118         value_type(sp,state()).init();
00119         value_type(sp,state()) << *f;
00120         ListPolicy::insert(*this,sp);
00121         sp += senf::bytes(value_type(sp,state()));
00122     }
00123 }
00124 #else
00125 template <class ListPolicy>
00126 template <class ForwardIterator>
00127 prefix_ void senf::ListParser_Container<ListPolicy>::
00128 insert(iterator pos, ForwardIterator f, ForwardIterator l)
00129 {}
00130 #endif
00131 
00132 template <class ListPolicy>
00133 prefix_ void senf::ListParser_Container<ListPolicy>::erase(iterator pos,
00134                                                            size_type n)
00135 {
00136     ListPolicy::update(*this);
00137     safe_data_iterator sp (data(),pos.raw());
00138     for (; n>0; --n) {
00139         ListPolicy::erase(*this,sp);
00140         data().erase(sp,boost::next(sp,senf::bytes(value_type(sp,state()))));
00141     }
00142 }
00143 
00144 template <class ListPolicy>
00145 prefix_ void senf::ListParser_Container<ListPolicy>::clear()
00146 {
00147     size_type sz (bytes());
00148     if (sz > ListPolicy::init_bytes)
00149         data().erase(boost::next(i(),ListPolicy::init_bytes),boost::next(i(),sz));
00150     else
00151         data().insert(boost::next(i(),sz), ListPolicy::init_bytes-sz, 0u);
00152     std::fill(i(),boost::next(i(),ListPolicy::init_bytes), 0u);
00153     ListPolicy::init(i(),state());
00154 }
00155 
00156 template <class ListPolicy>
00157 prefix_ void senf::ListParser_Container<ListPolicy>::resize(size_type n)
00158 {
00159     size_type sz (size());
00160     if (sz>n)
00161         erase(boost::next(begin(),n),end());
00162     else
00163         push_back_space(n-sz);
00164 }
00165 
00166 template <class ListPolicy>
00167 template <class Value>
00168 prefix_ void senf::ListParser_Container<ListPolicy>::resize(size_type n,
00169                                                             Value value)
00170 {
00171     size_type sz (size());
00172     if (sz>n)
00173         erase(boost::next(begin(),n),end());
00174     else
00175         push_back(value,n-sz);
00176 }
00177 
00178 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00179 #undef prefix_
00180 
00181 
00182 // Local Variables:
00183 // mode: c++
00184 // fill-column: 100
00185 // comment-column: 40
00186 // c-file-style: "senf"
00187 // indent-tabs-mode: nil
00188 // ispell-local-dictionary: "american"
00189 // compile-command: "scons -u test"
00190 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research