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

SafeIterator.hh

Go to the documentation of this file.
00001 // $Id: SafeIterator.hh 1756 2011-01-06 10:10:07Z tho $
00002 //
00003 // Copyright (C) 2008
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_SafeIterator_
00027 #define HH_SENF_Packets_SafeIterator_ 1
00028 
00029 #ifndef HH_SENF_Packets_Packets_
00030 #error "Don't include 'SafeIterator.hh' directly, include 'Packets.hh'"
00031 #endif
00032 
00033 // Custom includes
00034 #include <boost/iterator/iterator_facade.hpp>
00035 
00036 //#include "SafeIterator.mpp"
00037 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00038 
00039 namespace senf {
00040 
00052     class safe_data_iterator
00053         : public boost::iterator_facade< safe_data_iterator,
00054                                          PacketData::value_type,
00055                                          boost::random_access_traversal_tag >,
00056           public comparable_safe_bool<safe_data_iterator>
00057     {
00058     public:
00059         typedef PacketData::size_type size_type;
00060 
00061         safe_data_iterator(); 
00062         explicit safe_data_iterator(PacketData & data);
00064         safe_data_iterator(PacketData & data, PacketData::iterator i);
00066         explicit safe_data_iterator(PacketParserBase const & parser);
00068 
00071         safe_data_iterator & operator=(PacketData::iterator i); 
00072 
00074         safe_data_iterator & operator=(PacketParserBase const & parser);
00076 
00079         operator PacketData::iterator() const; 
00080 
00081         bool boolean_test() const;      
00082 
00083         PacketData & data() const;      
00084 
00085     private:
00086         friend class boost::iterator_core_access;
00087 
00088         // iterator_facade interface
00089 
00090         value_type & dereference() const;
00091         bool equal(safe_data_iterator const & other) const;
00092         difference_type distance_to(safe_data_iterator const & other) const;
00093         void increment();
00094         void decrement();
00095         void advance(difference_type n);
00096 
00097         PacketData::iterator i() const;
00098 
00099         PacketData * data_;
00100         size_type i_;
00101     };
00102 
00120     template <class Parser>
00121     class SafePacketParserWrapper
00122         : public safe_bool< SafePacketParserWrapper<Parser> >
00123     {
00124     public:
00125         //-////////////////////////////////////////////////////////////////////////
00126         // Types
00127 
00128         //-////////////////////////////////////////////////////////////////////////
00130         //\{
00131 
00132         // default copy constructor
00133         // default copy assignment
00134         // default destructor
00135         SafePacketParserWrapper();             
00136 
00137         // conversion constructors
00138         SafePacketParserWrapper(Parser parser); 
00139 
00140         SafePacketParserWrapper & operator=(Parser parser); 
00141 
00142         //\}
00143         //-////////////////////////////////////////////////////////////////////////
00144 
00145         Parser & operator*() const;       
00146 
00148         Parser * operator->() const; 
00149 
00151         bool boolean_test() const;      
00152 
00153     protected:
00154 
00155     private:
00156         mutable boost::optional<Parser> parser_;
00157         senf::safe_data_iterator i_;
00158     };
00159 
00160 }
00161 
00162 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00163 #endif
00164 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_SafeIterator_i_)
00165 #define HH_SENF_Packets_SafeIterator_i_
00166 #include "SafeIterator.cci"
00167 //#include "SafeIterator.ct"
00168 #include "SafeIterator.cti"
00169 #endif
00170 
00171 
00172 // Local Variables:
00173 // mode: c++
00174 // fill-column: 100
00175 // comment-column: 40
00176 // c-file-style: "senf"
00177 // indent-tabs-mode: nil
00178 // ispell-local-dictionary: "american"
00179 // compile-command: "scons -u test"
00180 // End:

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