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.hh

Go to the documentation of this file.
00001 // $Id: VectorParser.hh 1756 2011-01-06 10:10:07Z tho $
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 #ifndef HH_SENF_Packets_VectorParser_
00027 #define HH_SENF_Packets_VectorParser_ 1
00028 
00029 // Custom includes
00030 #include <boost/type_traits.hpp>
00031 #include "PacketParser.hh"
00032 #include "ArrayParser.hh" // for ArrayParser_iterator
00033 #include "AuxParser.hh" // for the AuxPolicies
00034 
00035 //#include "VectorParser.mpp"
00036 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00037 
00038 namespace senf {
00039 
00040     template <class ElementParser, class AuxPolicy> class VectorParser_Container;
00041 
00066     template <class ElementParser, class AuxPolicy>
00067     struct VectorParser
00068         : public PacketParserBase,
00069           private AuxPolicy
00070     {
00071         VectorParser(data_iterator i, state_type s);
00072         VectorParser(AuxPolicy policy, data_iterator i, state_type s);
00074 
00077         size_type bytes() const;
00078         void init() const;
00079 
00080         static const size_type init_bytes = AuxPolicy::aux_bytes;
00081 
00082         //-////////////////////////////////////////////////////////////////////////
00083         // Container interface
00084 
00085         typedef ElementParser value_type;
00086         typedef detail::ArrayParser_iterator<value_type> iterator;
00087         typedef iterator const_iterator;
00088         typedef VectorParser_Container<ElementParser,AuxPolicy> container;
00089 
00090         size_type size() const;
00091         bool empty() const;
00092 
00093         iterator begin() const;
00094         iterator end() const;
00095 
00096         value_type operator[](difference_type i) const;
00097         value_type front() const;
00098         value_type back() const;
00099 
00100         // Mutators
00101 
00102         // The mutators provided here are those which don't take an iterator argument.
00103         // If you need to pass an iterator it is much simpler and cleaner to use the
00104         // 'container' wrapper
00105 
00106         template <class Value> void push_back        (Value const & value, size_type n=1) const;
00107         value_type                  push_back_space  (size_type n=1) const;
00108         template <class Value> void push_front       (Value const & value, size_type n=1) const;
00109         value_type                  push_front_space (size_type n=1) const;
00110         void                        resize           (size_type n) const;
00111         template <class Value> void resize           (size_type n, Value value) const;
00112 
00113      private:
00114 
00115         friend class VectorParser_Container<ElementParser,AuxPolicy>;
00116     };
00117 
00136     template <class ElementParser, class AuxPolicy>
00137     class VectorParser_Container
00138         : private AuxPolicy::WrapperPolicy
00139     {
00140     public:
00141         //-////////////////////////////////////////////////////////////////////////
00142         // Types
00143 
00144         typedef VectorParser<ElementParser,AuxPolicy> parser_type;
00145         typedef PacketParserBase::data_iterator data_iterator;
00146         typedef PacketParserBase::size_type size_type;
00147         typedef PacketParserBase::difference_type difference_type;
00148         typedef ElementParser value_type;
00149         typedef detail::ArrayParser_iterator<value_type> iterator;
00150         typedef iterator const_iterator;
00151         typedef PacketParserBase::state_type state_type;
00152 
00153         //-////////////////////////////////////////////////////////////////////////
00155         //\{
00156 
00157         // no default constructor
00158         // default copy
00159         // default destructor
00160         // conversion constructors
00161 
00162         VectorParser_Container(parser_type const & vector);
00163 
00164         //\}
00165         //-////////////////////////////////////////////////////////////////////////
00166 
00168         //\{
00169 
00170         size_type size() const;
00171         bool empty() const;
00172 
00173         iterator begin() const;
00174         iterator end() const;
00175 
00176         value_type operator[](difference_type i) const;
00177         value_type front() const;
00178         value_type back() const;
00179 
00180         //\}
00182         //\{
00183 
00184         iterator shift(iterator pos, size_type n=1);
00185         template <class Value>
00186         void insert(iterator pos, Value const & t);
00187         template <class Value>
00188         void insert(iterator pos, size_type n, Value const & t);
00189 #       ifndef DOXYGEN
00190         template <class ForwardIterator>
00191         void insert(iterator pos, ForwardIterator f, ForwardIterator l,
00192                     typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type * = 0);
00193 #       else
00194         template <class ForwardIterator>
00195         void insert(iterator pos, ForwardIterator f, ForwardIterator l);
00196 #       endif
00197 
00198         void erase(iterator pos, size_type n=1);
00199         void erase(iterator f, iterator l);
00200         void clear();
00201 
00202         template <class Value> void push_back        (Value const & value, size_type n=1);
00203         value_type                  push_back_space  (size_type n=1);
00204         template <class Value> void push_front       (Value const & value, size_type n=1);
00205         value_type                  push_front_space (size_type n=1);
00206         void                        resize           (size_type n);
00207         template <class Value> void resize           (size_type n, Value value);
00208 
00209         //\}
00210 
00212         //\{
00213 
00214         parser_type parser() const;
00215         data_iterator i() const;
00216         state_type state() const;
00217         PacketData & data() const;
00218 
00219         size_type bytes() const;
00220         void init() const;
00221 
00222         //\}
00223 
00224     protected:
00225 
00226     private:
00227         void setSize(size_type value);
00228 
00229         state_type state_;
00230         size_type i_;
00231     };
00232 
00293 #   define SENF_PARSER_VECTOR(name, size, elt_type) \
00294         SENF_PARSER_VECTOR_I(public, name, size, elt_type)
00295 
00303 #   define SENF_PARSER_PRIVATE_VECTOR(name, size, elt_type) \
00304         SENF_PARSER_VECTOR_I(protected, name, size, elt_type)
00305 }
00306 
00307 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00308 #endif
00309 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_VectorParser_i_)
00310 #define HH_SENF_Packets_VectorParser_i_
00311 //#include "VectorParser.cci"
00312 #include "VectorParser.ct"
00313 #include "VectorParser.cti"
00314 #endif
00315 
00316 
00317 // Local Variables:
00318 // mode: c++
00319 // fill-column: 100
00320 // c-file-style: "senf"
00321 // indent-tabs-mode: nil
00322 // ispell-local-dictionary: "american"
00323 // compile-command: "scons -u test"
00324 // comment-column: 40
00325 // End:

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