Packets: not really a smart but efficient 'shortcut' for ConcretePacket::next() ...
tho [Thu, 20 Oct 2011 15:09:03 +0000 (15:09 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1818 270642c3-0616-0410-b53a-bc976706d245

senf/PPI/Joins.hh
senf/Packets/80211Bundle/RadiotapPacket.cc
senf/Packets/80211Bundle/RadiotapPacket.hh
senf/Packets/Packet.cc
senf/Packets/Packet.cci
senf/Packets/Packet.cti
senf/Packets/Packet.hh
senf/Packets/PacketInterpreter.cci
senf/Packets/PacketInterpreter.ct
senf/Packets/PacketInterpreter.hh
senf/Packets/PacketInterpreter.test.cc

index 69d24e0..e75b717 100644 (file)
@@ -32,8 +32,6 @@
 #define HH_SENF_PPI_Joins_ 1
 
 // Custom includes
-#include <boost/ptr_container/ptr_vector.hpp>
-#include "predecl.hh"
 #include "Connectors.hh"
 #include "Module.hh"
 #include "MultiConnectorMixin.hh"
index 960c9b4..5f51504 100644 (file)
@@ -312,7 +312,7 @@ prefix_ senf::PacketInterpreterBase::factory_t senf::RadiotapPacketType::nextPac
 }
 
 prefix_ senf::RadiotapPacketType::optional_range
-senf::RadiotapPacketType::nextPacketRange(packet p)
+senf::RadiotapPacketType::nextPacketRange(packet const & p)
 {
     parser rtParser (p.parser());
     size_type h (senf::bytes(rtParser));
index c1e9a91..9e0a795 100644 (file)
@@ -327,7 +327,7 @@ namespace senf {
         static void init(packet p);
         static void dump(packet p, std::ostream & os);
         static factory_t nextPacketType(packet p);
-        static optional_range nextPacketRange(packet p);
+        static optional_range nextPacketRange(packet const & p);
     };
 
     typedef ConcretePacket<RadiotapPacketType> RadiotapPacket;
index b0fa7cd..2738b6e 100644 (file)
 #define prefix_
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
 
-prefix_ senf::Packet senf::Packet::getNext()
+prefix_ senf::Packet senf::Packet::getNext(PacketInterpreterBase::optional_range const & range)
     const
 {
     factory_t factory (ptr()->nextPacketType());
     if (factory)
-        return parseNextAs(factory);
+        return parseNextAs(factory, range);
     else
         return parseNextAs<DataPacket>();
 }
index 7f76eff..f35c1c4 100644 (file)
@@ -71,7 +71,7 @@ prefix_ senf::Packet senf::Packet::next(NoThrow_t)
     PacketInterpreterBase::ptr p (ptr()->next());
     if (p) return Packet(p);
     PacketInterpreterBase::optional_range r (ptr()->nextPacketRange());
-    return (r && ! r->empty()) ? getNext() : Packet();
+    return (r && ! r->empty()) ? getNext(r) : Packet();
 }
 
 prefix_ senf::Packet senf::Packet::next()
@@ -112,7 +112,13 @@ prefix_ senf::Packet senf::Packet::last()
 prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory)
     const
 {
-    return Packet(ptr()->parseNextAs(factory));
+    return Packet(ptr()->parseNextAs(factory, ptr()->nextPacketRange()));
+}
+
+prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory, PacketInterpreterBase::optional_range const & range)
+    const
+{
+    return Packet(ptr()->parseNextAs(factory, range));
 }
 
 prefix_ senf::Packet senf::Packet::append(Packet const & packet)
index bb2765b..a428565 100644 (file)
@@ -327,6 +327,16 @@ senf::ConcretePacket<PacketType>::operator->()
     return ParserProxy(parser());
 }
 
+template <class PacketType>
+prefix_ senf::Packet senf::ConcretePacket<PacketType>::next(NoThrow_t)
+    const
+{
+    PacketInterpreterBase::ptr p (Packet::ptr()->next());
+    if (p) return Packet(p);
+    PacketInterpreterBase::optional_range r (type::nextPacketRange(*this));
+    return (r && ! r->empty()) ? getNext(r) : Packet();
+}
+
 // private members
 
 template <class PacketType>
index 4e6147f..af001a5 100644 (file)
@@ -518,10 +518,11 @@ namespace senf {
 
         PacketInterpreterBase::ptr const & ptr() const;
 
-    private:
-        Packet getNext() const;
+        Packet parseNextAs(factory_t factory, PacketInterpreterBase::optional_range const & range) const;
+        Packet getNext(PacketInterpreterBase::optional_range const & range) const;
         Packet getLast() const;
 
+    private:
         PacketInterpreterBase::ptr packet_;
 
         template <class PacketType>
@@ -772,7 +773,11 @@ namespace senf {
                                              itself, only it's members.
                                              \see \ref packetparser for the %parser interface */
 
-    protected:
+#ifndef DOXYGEN
+        using Packet::next;
+
+        Packet next(NoThrow_t) const;
+#endif
 
     private:
         typedef PacketInterpreter<PacketType> interpreter;
index 1652db1..b398ec8 100644 (file)
@@ -68,9 +68,9 @@ prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::last()
 }
 
 prefix_ senf::PacketInterpreterBase::ptr
-senf::PacketInterpreterBase::parseNextAs(factory_t factory)
+senf::PacketInterpreterBase::parseNextAs(factory_t factory, PacketInterpreterBase::optional_range const & range)
 {
-    return factory->parseNext(ptr(this));
+    return factory->parseNext(ptr(this), range);
 }
 
 // Data access
index 57194b7..e733736 100644 (file)
@@ -378,17 +378,16 @@ createInsertBefore(PacketInterpreterBase::ptr packet, senf::NoInit_t)
 
 template <class PacketType>
 prefix_ typename senf::PacketInterpreterBase::ptr
-senf::PacketInterpreter<PacketType>::FactoryImpl::parseNext(PacketInterpreterBase::ptr packet)
+senf::PacketInterpreter<PacketType>::FactoryImpl::parseNext(PacketInterpreterBase::ptr packet, PacketInterpreterBase::optional_range const & range)
     const
 {
-    optional_range r (packet->nextPacketRange());
-    if (!r)
+    if (!range)
         throw InvalidPacketChainException();
 
     if (packet->next())
         packet->impl().truncateInterpreters(packet->next().get());
 
-    return senf::PacketInterpreter<PacketType>::create(&packet->impl(),r->begin(),r->end(),Append);
+    return senf::PacketInterpreter<PacketType>::create(&packet->impl(),range->begin(),range->end(),Append);
 }
 
 template <class PacketType>
index deae9d3..cc49812 100644 (file)
@@ -74,7 +74,7 @@ namespace senf {
         typedef senf::detail::packet::byte byte;
 
         typedef boost::iterator_range<iterator> range;
-        typedef boost::optional< boost::iterator_range<iterator> > optional_range;
+        typedef boost::optional<range> optional_range;
         typedef optional_range no_range;
 
         enum Append_t { Append };
@@ -121,7 +121,7 @@ namespace senf {
 
             // Parse next packet in chain
 
-            virtual ptr parseNext(ptr packet) const = 0;
+            virtual ptr parseNext(ptr packet, PacketInterpreterBase::optional_range const & range) const = 0;
         };
 
         typedef Factory const * factory_t;
@@ -152,7 +152,7 @@ namespace senf {
         ptr last();
 
         template <class Type> typename PacketInterpreter<Type>::ptr parseNextAs();
-                                       ptr                          parseNextAs(factory_t factory);
+                                       ptr                          parseNextAs(factory_t factory, PacketInterpreterBase::optional_range const & range);
         template <class Type>          bool                         is();
         template <class Type> typename PacketInterpreter<Type>::ptr as();
 
@@ -396,7 +396,7 @@ namespace senf {
 
             // Parse next packet in chain
 
-            virtual PacketInterpreterBase::ptr parseNext(PacketInterpreterBase::ptr packet)
+            virtual PacketInterpreterBase::ptr parseNext(PacketInterpreterBase::ptr packet, PacketInterpreterBase::optional_range const & range)
                 const;
         };
 
index 094194c..51c0a91 100644 (file)
@@ -68,7 +68,7 @@ SENF_AUTO_UNIT_TEST(packetInterpreterBase)
         BOOST_CHECK( ! pi1->prev() );
         BOOST_CHECK( pi2->is<VoidPacket>() );
         BOOST_CHECK( pi2->as<VoidPacket>() == pi2 );
-        BOOST_CHECK( pi2->parseNextAs(senf::PacketInterpreter<VoidPacket>::factory()) );
+        BOOST_CHECK( pi2->parseNextAs(senf::PacketInterpreter<VoidPacket>::factory(), pi2->nextPacketRange()) );
         BOOST_CHECK( pi2->typeId() == pi1->typeId() );
 
         pi1->data().insert(pi1->data().begin(),2,0x01u);
@@ -302,7 +302,7 @@ SENF_AUTO_UNIT_TEST(packetInterpreter_factory)
         senf::PacketInterpreter<VoidPacket>::ptr p
             (senf::PacketInterpreter<VoidPacket>::create(size_type(12u)));
 
-        senf::PacketInterpreterBase::ptr p2 (p->parseNextAs(factory));
+        senf::PacketInterpreterBase::ptr p2 (p->parseNextAs(factory, p->nextPacketRange()));
         BOOST_CHECK( p2->is<OtherPacket>() );
         BOOST_CHECK( ! p2->is<VoidPacket>() );
         BOOST_CHECK_EQUAL( unsigned(boost::size(*p2->nextPacketRange())), 4u );