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

VectorParser.cti

Go to the documentation of this file.
00001 // $Id: VectorParser.cti 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2006
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 "VectorParser.ih"
00027 
00028 // Custom includes
00029 
00030 #define prefix_ inline
00031 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00032 
00033 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00034 // senf::VectorParser<ElementParser,Sizer>
00035 
00036 template <class ElementParser, class AuxPolicy>
00037 prefix_ senf::VectorParser<ElementParser,AuxPolicy>::VectorParser(data_iterator i, state_type s)
00038     : PacketParserBase(i,s), AuxPolicy()
00039 {}
00040 
00041 template <class ElementParser, class AuxPolicy>
00042 prefix_ senf::VectorParser<ElementParser,AuxPolicy>::VectorParser(AuxPolicy policy,
00043                                                                   data_iterator i, state_type s)
00044     : PacketParserBase(i,s), AuxPolicy(policy)
00045 {}
00046 
00047 template <class ElementParser, class AuxPolicy>
00048 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::size_type
00049 senf::VectorParser<ElementParser,AuxPolicy>::bytes()
00050     const
00051 {
00052     return size()*ElementParser::fixed_bytes + AuxPolicy::aux_bytes;
00053 }
00054 
00055 // Container interface
00056 
00057 template <class ElementParser, class AuxPolicy>
00058 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::size_type
00059 senf::VectorParser<ElementParser,AuxPolicy>::size()
00060     const
00061 {
00062     return aux(i(),state());
00063 }
00064 
00065 template <class ElementParser, class AuxPolicy>
00066 prefix_ bool senf::VectorParser<ElementParser,AuxPolicy>::empty()
00067     const
00068 {
00069     return size()==0;
00070 }
00071 
00072 template <class ElementParser, class AuxPolicy>
00073 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::iterator
00074 senf::VectorParser<ElementParser,AuxPolicy>::begin()
00075     const
00076 {
00077     return iterator(adjust(i(),state()),state());
00078 }
00079 
00080 template <class ElementParser, class AuxPolicy>
00081 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::iterator
00082 senf::VectorParser<ElementParser,AuxPolicy>::end()
00083     const
00084 {
00085     return boost::next(begin(),size());
00086 }
00087 
00088 template <class ElementParser, class AuxPolicy>
00089 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::value_type
00090 senf::VectorParser<ElementParser,AuxPolicy>::operator[](difference_type i)
00091     const
00092 {
00093     return begin()[i];
00094 }
00095 
00096 template <class ElementParser, class AuxPolicy>
00097 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::value_type
00098 senf::VectorParser<ElementParser,AuxPolicy>::front()
00099     const
00100 {
00101     return begin()[0];
00102 }
00103 
00104 template <class ElementParser, class AuxPolicy>
00105 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::value_type
00106 senf::VectorParser<ElementParser,AuxPolicy>::back()
00107     const
00108 {
00109     return begin()[size()-1];
00110 }
00111 
00112 // Mutators
00113 
00114 template <class ElementParser, class AuxPolicy>
00115 template <class Value>
00116 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::push_back(Value const & value, size_type n)
00117     const
00118 {
00119     container c (*this);
00120     c.push_back(value,n);
00121 }
00122 
00123 template <class ElementParser, class AuxPolicy>
00124 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::value_type
00125 senf::VectorParser<ElementParser,AuxPolicy>::push_back_space(size_type n)
00126     const
00127 {
00128     container c (*this);
00129     return c.push_back_space(n);
00130 }
00131 
00132 template <class ElementParser, class AuxPolicy>
00133 template <class Value>
00134 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::push_front(Value const & value, size_type n)
00135     const
00136 {
00137     container c (*this);
00138     c.push_front(value,n);
00139 }
00140 
00141 template <class ElementParser, class AuxPolicy>
00142 prefix_ typename senf::VectorParser<ElementParser,AuxPolicy>::value_type
00143 senf::VectorParser<ElementParser,AuxPolicy>::push_front_space(size_type n)
00144     const
00145 {
00146     container c (*this);
00147     return c.push_front_space(n);
00148 }
00149 
00150 template <class ElementParser, class AuxPolicy>
00151 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::resize(size_type n)
00152     const
00153 {
00154     container c (*this);
00155     c.resize(n);
00156 }
00157 
00158 template <class ElementParser, class AuxPolicy>
00159 template <class Value>
00160 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::resize(size_type n, Value value)
00161     const
00162 {
00163     container c (*this);
00164     c.resize(n,value);
00165 }
00166 
00167 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00168 // senf::VectorParser_wrapper<Parser,SizeParser,Container>
00169 
00170 // structors and default members
00171 
00172 // hm ... be careful here ! the data() member is called in an incompletely intitialized
00173 // instance. However, data() only depends on state_ which is initialized before the call. YOU MUST
00174 // NOT CHANGE THE ORDERING OF THE DATA MEMBERS
00175 template <class ElementParser, class AuxPolicy>
00176 prefix_ senf::VectorParser_Container<ElementParser,AuxPolicy>::
00177 VectorParser_Container(parser_type const & vector)
00178     : AuxPolicy::WrapperPolicy(static_cast<AuxPolicy const &>(vector)), state_ (vector.state()),
00179       i_ (std::distance(data().begin(),vector.i()))
00180 {}
00181 
00182 // accessors
00183 
00184 template <class ElementParser, class AuxPolicy>
00185 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::size_type
00186 senf::VectorParser_Container<ElementParser,AuxPolicy>::size()
00187     const
00188 {
00189     return aux(i(),state());
00190 }
00191 
00192 template <class ElementParser, class AuxPolicy>
00193 prefix_ bool senf::VectorParser_Container<ElementParser,AuxPolicy>::empty()
00194     const
00195 {
00196     return size() == 0;
00197 }
00198 
00199 template <class ElementParser, class AuxPolicy>
00200 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::iterator
00201 senf::VectorParser_Container<ElementParser,AuxPolicy>::begin()
00202     const
00203 {
00204     return iterator(adjust(i(),state()),state());
00205 }
00206 
00207 template <class ElementParser, class AuxPolicy>
00208 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::iterator
00209 senf::VectorParser_Container<ElementParser,AuxPolicy>::end()
00210     const
00211 {
00212     return boost::next(begin(),size());
00213 }
00214 
00215 template <class ElementParser, class AuxPolicy>
00216 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::value_type
00217 senf::VectorParser_Container<ElementParser,AuxPolicy>::operator[](difference_type i)
00218     const
00219 {
00220     return begin()[i];
00221 }
00222 
00223 template <class ElementParser, class AuxPolicy>
00224 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::value_type
00225 senf::VectorParser_Container<ElementParser,AuxPolicy>::front()
00226     const
00227 {
00228     return begin()[0];
00229 }
00230 
00231 template <class ElementParser, class AuxPolicy>
00232 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::value_type
00233 senf::VectorParser_Container<ElementParser,AuxPolicy>::back()
00234     const
00235 {
00236     return begin()[size()-1];
00237 }
00238 
00239 // Mutators
00240 
00241 template <class ElementParser, class AuxPolicy>
00242 template <class Value>
00243 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::insert(iterator pos,
00244                                                                        Value const & t)
00245 {
00246     *shift(pos) << t;
00247 }
00248 
00249 template <class ElementParser, class AuxPolicy>
00250 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::erase(iterator pos, size_type n)
00251 {
00252     setSize(size()-n);
00253     data().erase(pos.raw(),boost::next(pos.raw(),n*ElementParser::fixed_bytes));
00254 }
00255 
00256 template <class ElementParser, class AuxPolicy>
00257 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::erase(iterator f, iterator l)
00258 {
00259     erase(f,std::distance(f,l));
00260 }
00261 
00262 template <class ElementParser, class AuxPolicy>
00263 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::clear()
00264 {
00265     erase(begin(),end());
00266 }
00267 
00268 template <class ElementParser, class AuxPolicy>
00269 template <class Value>
00270 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::push_back(Value const & value,
00271                                                                               size_type n)
00272 {
00273     insert(end(),n,value);
00274 }
00275 
00276 template <class ElementParser, class AuxPolicy>
00277 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::value_type
00278 senf::VectorParser_Container<ElementParser,AuxPolicy>::push_back_space(size_type n)
00279 {
00280     return *shift(end(),n);
00281 }
00282 
00283 template <class ElementParser, class AuxPolicy>
00284 template <class Value>
00285 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::push_front(Value const & value,
00286                                                                                size_type n)
00287 {
00288     insert(begin(),n,value);
00289 }
00290 
00291 template <class ElementParser, class AuxPolicy>
00292 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::value_type
00293 senf::VectorParser_Container<ElementParser,AuxPolicy>::push_front_space(size_type n)
00294 {
00295     return *shift(begin(),n);
00296 }
00297 
00298 // Parser interface
00299 
00300 template <class ElementParser, class AuxPolicy>
00301 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::parser_type
00302 senf::VectorParser_Container<ElementParser,AuxPolicy>::parser()
00303     const
00304 {
00305     return parser_type(i(),state());
00306 }
00307 
00308 template <class ElementParser, class AuxPolicy>
00309 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::data_iterator
00310 senf::VectorParser_Container<ElementParser,AuxPolicy>::i()
00311     const
00312 {
00313     return boost::next(data().begin(),i_);
00314 }
00315 
00316 template <class ElementParser, class AuxPolicy>
00317 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::state_type
00318 senf::VectorParser_Container<ElementParser,AuxPolicy>::state()
00319     const
00320 {
00321     return state_;
00322 }
00323 
00324 template <class ElementParser, class AuxPolicy>
00325 prefix_ senf::PacketData &
00326 senf::VectorParser_Container<ElementParser,AuxPolicy>::data()
00327     const
00328 {
00329     return *state_;
00330 }
00331 
00332 template <class ElementParser, class AuxPolicy>
00333 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::size_type
00334 senf::VectorParser_Container<ElementParser,AuxPolicy>::bytes()
00335     const
00336 {
00337     return size()*ElementParser::fixed_bytes + AuxPolicy::aux_bytes;
00338 }
00339 
00340 // private members
00341 
00342 template <class ElementParser, class AuxPolicy>
00343 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::setSize(size_type value)
00344 {
00345     aux(value, i(),state());
00346 }
00347 
00348 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00349 #undef prefix_
00350 
00351 
00352 // Local Variables:
00353 // mode: c++
00354 // fill-column: 100
00355 // c-file-style: "senf"
00356 // indent-tabs-mode: nil
00357 // ispell-local-dictionary: "american"
00358 // compile-command: "scons -u test"
00359 // comment-column: 40
00360 // End:

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