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

Go to the documentation of this file.
00001 // $Id: ListParser.hh 1756 2011-01-06 10:10:07Z 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 #ifndef HH_SENF_Packets_ListParser_
00027 #define HH_SENF_Packets_ListParser_ 1
00028 
00029 // Custom includes
00030 #include <boost/utility.hpp>
00031 #include "PacketParser.hh"
00032 
00033 //#include "ListParser.mpp"
00034 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00035 
00036 namespace senf {
00037 
00038     namespace detail { template <class Container> class ListParser_Iterator; }
00039 
00040     template <class ListPolicy>
00041     class ListParser_Container;
00042 
00073     template <class ListPolicy>
00074     class ListParser
00075         : public PacketParserBase,
00076           private ListPolicy
00077     {
00078     public:
00079         typedef ListPolicy policy;
00080 
00081         ListParser(data_iterator i, state_type s);
00082         ListParser(ListPolicy policy, data_iterator i, state_type s);
00084 
00087         size_type bytes() const;
00088         void init() const;
00089 
00090         static const size_type init_bytes = ListPolicy::init_bytes;
00091 
00092         //-////////////////////////////////////////////////////////////////////////
00093         // Container interface
00094 
00095         typedef typename ListPolicy::element_type value_type;
00096         typedef typename ListPolicy::container_type container;
00097 
00098         size_type size() const;
00099         bool empty() const;
00100 
00101         value_type front() const;
00102         value_type back() const;
00103 
00104         template <class Value> void push_back        (Value const & value, size_type n=1) const;
00105         value_type                  push_back_space  (size_type n=1) const;
00106         template <class Value> void push_front       (Value const & value, size_type n=1) const;
00107         value_type                  push_front_space (size_type n=1) const;
00108                                void resize           (size_type n) const;
00109         template <class Value> void resize           (size_type n, Value value) const;
00110 
00111         static ListParser & get(ListPolicy & p);
00112         static ListParser const & get(ListPolicy const & p);
00113 
00114     private:
00115         template <class Policy> friend class ListParser_Container;
00116     };
00117 
00136     template <class ListPolicy>
00137     class ListParser_Container
00138         : private ListPolicy
00139     {
00140     public:
00141         //-////////////////////////////////////////////////////////////////////////
00142         // Types
00143 
00144         typedef ListPolicy policy;
00145         typedef typename ListPolicy::parser_type parser_type;
00146         typedef PacketParserBase::data_iterator data_iterator;
00147         typedef PacketParserBase::size_type size_type;
00148         typedef PacketParserBase::difference_type difference_type;
00149         typedef typename ListPolicy::element_type value_type;
00150         typedef detail::ListParser_Iterator<ListParser_Container> iterator;
00151         typedef iterator const_iterator;
00152         typedef PacketParserBase::state_type state_type;
00153 
00154         //-////////////////////////////////////////////////////////////////////////
00156         //\{
00157 
00158         // no default constructor
00159         // default copy
00160         // default destructor
00161         // conversion constructors
00162 
00163         ListParser_Container(parser_type const & list);
00164         ~ListParser_Container();
00165 
00166         //\}
00167         //-////////////////////////////////////////////////////////////////////////
00168 
00170         //\{
00171 
00172         size_type size() const;
00173         bool empty() const;
00174 
00175         iterator begin() const;
00176         iterator end() const;
00177 
00178         value_type front() const;
00179         value_type back() const;
00180 
00181         //\}
00183         //\{
00184 
00185         // All these operations can be quite inefficient depending on the list type
00186         value_type shift(iterator pos, size_type n=1);
00187         template <class Value>
00188         void insert(iterator pos, Value const & t);
00189         template <class Value>
00190         void insert(iterator pos, size_type n, Value const & t);
00191         template <class ForwardIterator>
00192 #       ifndef DOXYGEN
00193         void insert(iterator pos, ForwardIterator f, ForwardIterator l,
00194                     typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type * = 0);
00195 #       else
00196         void insert(iterator pos, ForwardIterator f, ForwardIterator l);
00197 #       endif
00198 
00199         void erase(iterator pos, size_type n=1);
00200         void erase(iterator f, iterator l);
00201         void clear();
00202 
00203         template <class Value> void push_back        (Value const & value, size_type n=1);
00204         value_type                  push_back_space  (size_type n=1);
00205         template <class Value> void push_front       (Value const & value, size_type n=1);
00206         value_type                  push_front_space (size_type n=1);
00207         void                        resize           (size_type n);
00208         template <class Value> void resize           (size_type n, Value value);
00209 
00210         //\}
00211 
00213         //\{
00214 
00215         parser_type parser() const;
00216         data_iterator i() const;
00217         state_type state() const;
00218         PacketData & data() const;
00219 
00220         size_type bytes() const;
00221         void init() const;
00222 
00223         //\}
00224 
00225     private:
00226         friend class detail::ListParser_Iterator<ListParser_Container>;
00227 
00228         state_type state_;
00229         size_type i_;
00230     };
00231 
00308 #   define SENF_PARSER_LIST(name, size, elt_type) \
00309         SENF_PARSER_LIST_I(public, name, size, elt_type)
00310 
00318 #   define SENF_PARSER_PRIVATE_LIST(name, size, elt_type) \
00319         SENF_PARSER_LIST_I(protected, name, size, elt_type)
00320 
00321 }
00322 
00323 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00324 #endif
00325 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_ListParser_i_)
00326 #define HH_SENF_Packets_ListParser_i_
00327 //#include "ListParser.cci"
00328 #include "ListParser.ct"
00329 #include "ListParser.cti"
00330 #endif
00331 
00332 
00333 // Local Variables:
00334 // mode: c++
00335 // fill-column: 100
00336 // c-file-style: "senf"
00337 // indent-tabs-mode: nil
00338 // ispell-local-dictionary: "american"
00339 // compile-command: "scons -u test"
00340 // comment-column: 40
00341 // End:

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