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

Packet.hh

Go to the documentation of this file.
00001 // $Id: Packet.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_Packet_
00027 #define HH_SENF_Packets_Packet_ 1
00028 
00029 // Custom includes
00030 #include <boost/operators.hpp>
00031 #include <boost/utility.hpp>
00032 #include <boost/type_traits/is_integral.hpp>
00033 #include <senf/Utils/Tags.hh>
00034 #include <senf/Utils/safe_bool.hh>
00035 #include "PacketInterpreter.hh"
00036 
00037 //#include "Packet.mpp"
00038 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00039 
00040 namespace senf {
00041 
00096     template <class PackeType> class ConcretePacket;
00097 
00099     //\{
00100 
00140     class Packet
00141         : public safe_bool<Packet>,
00142           public boost::equality_comparable<Packet>
00143     {
00144     public:
00145         //-////////////////////////////////////////////////////////////////////////
00146         // Types
00147 
00148         typedef void type;              
00149         typedef senf::detail::packet::size_type size_type;
00151         typedef PacketInterpreterBase::factory_t factory_t; 
00152 
00153         //-////////////////////////////////////////////////////////////////////////
00155         //\{
00156 
00157         // default copy constructor
00158         // default copy assignment
00159         // default destructor
00160 
00161         Packet();                       
00162 
00165         Packet clone() const;           
00166 
00171         // conversion constructors
00172 
00173         template <class PacketType>
00174         Packet(ConcretePacket<PacketType> const & packet);
00176 
00180         //\}
00181         //-////////////////////////////////////////////////////////////////////////
00182 
00184         //\{
00185 
00186         Packet      next() const;       
00187 
00189         Packet      next(NoThrow_t) const; 
00190 
00192         template <class OtherPacket> OtherPacket next() const;
00194 
00198         template <class OtherPacket> OtherPacket next(NoThrow_t) const;
00200 
00203         template <class OtherPacket> OtherPacket find() const;
00205 
00208         template <class OtherPacket> OtherPacket find(NoThrow_t) const;
00210 
00214         Packet      prev() const;       
00215 
00217         Packet      prev(NoThrow_t) const; 
00218 
00220         template <class OtherPacket> OtherPacket prev() const;
00222 
00226         template <class OtherPacket> OtherPacket prev(NoThrow_t) const;
00228 
00231         template <class OtherPacket> OtherPacket rfind() const;
00233 
00236         template <class OtherPacket> OtherPacket rfind(NoThrow_t) const;
00238 
00243         Packet      first() const;      
00244         template <class OtherPacket> OtherPacket first() const;
00246 
00249         Packet      last() const;       
00250         template <class OtherPacket> OtherPacket last() const;
00252 
00256         template <class OtherPacket> OtherPacket parseNextAs() const;
00258 
00268         Packet      parseNextAs(factory_t factory) const;
00270 
00281         template <class OtherPacket> bool        is() const;
00283         template <class OtherPacket> OtherPacket as() const;
00285 
00291         template <class OtherPacket> OtherPacket as(NoThrow_t) const;
00293 
00301         Packet append(Packet const & packet) const; 
00302 
00312         void reparse() const;           
00313 
00316         //\}
00317 
00319         //\{
00320 
00321         PacketData & data() const;      
00322         size_type size() const;         
00323 
00326         //\}
00327 
00329         //\{
00330 
00331         template <class Annotation>
00332         Annotation & annotation();      
00333 
00388         template <class Annotation>
00389         Annotation const & annotation() const; 
00390 
00392         void clearAnnotations();        
00393 
00397         //\}
00398 
00400         //\{
00401 
00402         bool operator==(Packet const & other) const; 
00403 
00405         bool boolean_test() const;      
00406 
00407         bool valid() const;             
00408 
00415         void finalizeThis();            
00416 
00429         template <class Other>
00430         void finalizeTo();              
00431 
00449         void finalizeTo(Packet const & other);  
00450 
00461         void finalizeAll();             
00462 
00482         void dump(std::ostream & os) const; 
00483 
00490         TypeIdValue typeId() const;     
00491 
00495         factory_t factory() const;      
00496 
00501         unsigned long id() const;       
00502 
00505         bool is_shared() const;         
00506 
00509         //\}
00510 
00511     protected:
00512         explicit Packet(PacketInterpreterBase::ptr const & packet);
00513 
00514         PacketInterpreterBase::ptr const & ptr() const;
00515 
00516     private:
00517         Packet getNext() const;
00518         Packet getLast() const;
00519 
00520         PacketInterpreterBase::ptr packet_;
00521 
00522         template <class PacketType>
00523         friend class ConcretePacket;
00524         friend class PacketParserBase;
00525     };
00526 
00564     template <class PacketType>
00565     class ConcretePacket
00566         : public Packet
00567     {
00568     public:
00569         //-////////////////////////////////////////////////////////////////////////
00570         // Types
00571 
00572         typedef PacketType type;
00573         typedef typename PacketType::parser Parser;
00574 
00575         //-////////////////////////////////////////////////////////////////////////
00577         //\{
00578 
00579         // default copy constructor
00580         // default copy assignment
00581         // default destructor
00582         // no conversion constructors
00583 
00584         ConcretePacket();               
00585 
00589         static factory_t factory();     
00590 
00593         // Create completely new packet
00594 
00595         static ConcretePacket create(); 
00596 
00598         static ConcretePacket create(senf::NoInit_t); 
00599 
00603         static ConcretePacket create(size_type size); 
00604 
00612         static ConcretePacket create(size_type size, senf::NoInit_t);
00614 
00619 #ifndef DOXYGEN
00620         template <class ForwardReadableRange>
00621         static ConcretePacket create(
00622             ForwardReadableRange const & range,
00623             typename boost::disable_if< boost::is_integral<ForwardReadableRange> >::type * = 0);
00624 #else
00625         template <class ForwardReadableRange>
00626         static ConcretePacket create(ForwardReadableRange const & range);
00628 
00635 #endif
00636 
00637         // Create packet as new packet after a given packet
00638 
00639         static ConcretePacket createAfter(Packet const & packet);
00641 
00645         static ConcretePacket createAfter(Packet const & packet, senf::NoInit_t);
00647 
00654         static ConcretePacket createAfter(Packet const & packet, size_type size);
00656 
00667         static ConcretePacket createAfter(Packet const & packet, size_type size, senf::NoInit_t);
00669 
00677 #ifndef DOXYGEN
00678         template <class ForwardReadableRange>
00679         static ConcretePacket createAfter(
00680             Packet const & packet,
00681             ForwardReadableRange const & range,
00682             typename boost::disable_if< boost::is_integral<ForwardReadableRange> >::type * = 0);
00683 #else
00684         template <class ForwardReadableRange>
00685         static ConcretePacket createAfter(Packet const & packet,
00686                                           ForwardReadableRange const & range);
00688 
00697 #endif
00698 
00699         // Create packet as new packet (header) before a given packet
00700 
00701         static ConcretePacket createBefore(Packet const & packet);
00703 
00711         static ConcretePacket createBefore(Packet const & packet, senf::NoInit_t);
00713 
00721         static ConcretePacket createInsertBefore(Packet const & packet);
00723 
00728         static ConcretePacket createInsertBefore(Packet const & packet, senf::NoInit_t);
00730 
00735         // Create a clone of the current packet
00736 
00737         ConcretePacket clone() const;
00738 
00739         //\}
00740         //-////////////////////////////////////////////////////////////////////////
00741 
00742         // Field access
00743 
00744         struct ParserProxy
00745         {
00746             ParserProxy(Parser const & p) : p_ (p) {}
00747             Parser * operator->() { return &p_; }
00748             Parser p_;
00749         };
00750 
00751         ParserProxy operator->() const;    
00752 
00763         Parser parser() const;          
00764 
00770     protected:
00771 
00772     private:
00773         typedef PacketInterpreter<PacketType> interpreter;
00774 
00775         ConcretePacket(typename interpreter::ptr const & packet_);
00776 
00777         interpreter * ptr() const;
00778 
00779         friend class Packet;
00780         friend class PacketInterpreter<PacketType>;
00781     };
00782 
00789     template <class PacketType, class Parser>
00790     Parser operator<<(Parser target, ConcretePacket<PacketType> const & packet);
00791 
00792     //\}
00793 
00794 }
00795 
00796 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00797 #endif
00798 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_Packet_i_)
00799 #define HH_SENF_Packets_Packet_i_
00800 #include "Packet.cci"
00801 #include "Packet.ct"
00802 #include "Packet.cti"
00803 #endif
00804 
00805 
00806 // Local Variables:
00807 // mode: c++
00808 // fill-column: 100
00809 // c-file-style: "senf"
00810 // indent-tabs-mode: nil
00811 // ispell-local-dictionary: "american"
00812 // compile-command: "scons -u test"
00813 // comment-column: 40
00814 // End:
00815 

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