From: tho Date: Thu, 20 Oct 2011 15:09:03 +0000 (+0000) Subject: Packets: not really a smart but efficient 'shortcut' for ConcretePacket::next() ... X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=51b24c3227717ce5ad8111a99c2d7eea5fa0bd8d;p=senf.git Packets: not really a smart but efficient 'shortcut' for ConcretePacket::next() -> calling nextPacketRange git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1818 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/PPI/Joins.hh b/senf/PPI/Joins.hh index 69d24e0..e75b717 100644 --- a/senf/PPI/Joins.hh +++ b/senf/PPI/Joins.hh @@ -32,8 +32,6 @@ #define HH_SENF_PPI_Joins_ 1 // Custom includes -#include -#include "predecl.hh" #include "Connectors.hh" #include "Module.hh" #include "MultiConnectorMixin.hh" diff --git a/senf/Packets/80211Bundle/RadiotapPacket.cc b/senf/Packets/80211Bundle/RadiotapPacket.cc index 960c9b4..5f51504 100644 --- a/senf/Packets/80211Bundle/RadiotapPacket.cc +++ b/senf/Packets/80211Bundle/RadiotapPacket.cc @@ -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)); diff --git a/senf/Packets/80211Bundle/RadiotapPacket.hh b/senf/Packets/80211Bundle/RadiotapPacket.hh index c1e9a91..9e0a795 100644 --- a/senf/Packets/80211Bundle/RadiotapPacket.hh +++ b/senf/Packets/80211Bundle/RadiotapPacket.hh @@ -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 RadiotapPacket; diff --git a/senf/Packets/Packet.cc b/senf/Packets/Packet.cc index b0fa7cd..2738b6e 100644 --- a/senf/Packets/Packet.cc +++ b/senf/Packets/Packet.cc @@ -37,12 +37,12 @@ #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(); } diff --git a/senf/Packets/Packet.cci b/senf/Packets/Packet.cci index 7f76eff..f35c1c4 100644 --- a/senf/Packets/Packet.cci +++ b/senf/Packets/Packet.cci @@ -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) diff --git a/senf/Packets/Packet.cti b/senf/Packets/Packet.cti index bb2765b..a428565 100644 --- a/senf/Packets/Packet.cti +++ b/senf/Packets/Packet.cti @@ -327,6 +327,16 @@ senf::ConcretePacket::operator->() return ParserProxy(parser()); } +template +prefix_ senf::Packet senf::ConcretePacket::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 diff --git a/senf/Packets/Packet.hh b/senf/Packets/Packet.hh index 4e6147f..af001a5 100644 --- a/senf/Packets/Packet.hh +++ b/senf/Packets/Packet.hh @@ -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 @@ -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 interpreter; diff --git a/senf/Packets/PacketInterpreter.cci b/senf/Packets/PacketInterpreter.cci index 1652db1..b398ec8 100644 --- a/senf/Packets/PacketInterpreter.cci +++ b/senf/Packets/PacketInterpreter.cci @@ -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 diff --git a/senf/Packets/PacketInterpreter.ct b/senf/Packets/PacketInterpreter.ct index 57194b7..e733736 100644 --- a/senf/Packets/PacketInterpreter.ct +++ b/senf/Packets/PacketInterpreter.ct @@ -378,17 +378,16 @@ createInsertBefore(PacketInterpreterBase::ptr packet, senf::NoInit_t) template prefix_ typename senf::PacketInterpreterBase::ptr -senf::PacketInterpreter::FactoryImpl::parseNext(PacketInterpreterBase::ptr packet) +senf::PacketInterpreter::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::create(&packet->impl(),r->begin(),r->end(),Append); + return senf::PacketInterpreter::create(&packet->impl(),range->begin(),range->end(),Append); } template diff --git a/senf/Packets/PacketInterpreter.hh b/senf/Packets/PacketInterpreter.hh index deae9d3..cc49812 100644 --- a/senf/Packets/PacketInterpreter.hh +++ b/senf/Packets/PacketInterpreter.hh @@ -74,7 +74,7 @@ namespace senf { typedef senf::detail::packet::byte byte; typedef boost::iterator_range range; - typedef boost::optional< boost::iterator_range > optional_range; + typedef boost::optional 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 typename PacketInterpreter::ptr parseNextAs(); - ptr parseNextAs(factory_t factory); + ptr parseNextAs(factory_t factory, PacketInterpreterBase::optional_range const & range); template bool is(); template typename PacketInterpreter::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; }; diff --git a/senf/Packets/PacketInterpreter.test.cc b/senf/Packets/PacketInterpreter.test.cc index 094194c..51c0a91 100644 --- a/senf/Packets/PacketInterpreter.test.cc +++ b/senf/Packets/PacketInterpreter.test.cc @@ -68,7 +68,7 @@ SENF_AUTO_UNIT_TEST(packetInterpreterBase) BOOST_CHECK( ! pi1->prev() ); BOOST_CHECK( pi2->is() ); BOOST_CHECK( pi2->as() == pi2 ); - BOOST_CHECK( pi2->parseNextAs(senf::PacketInterpreter::factory()) ); + BOOST_CHECK( pi2->parseNextAs(senf::PacketInterpreter::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::ptr p (senf::PacketInterpreter::create(size_type(12u))); - senf::PacketInterpreterBase::ptr p2 (p->parseNextAs(factory)); + senf::PacketInterpreterBase::ptr p2 (p->parseNextAs(factory, p->nextPacketRange())); BOOST_CHECK( p2->is() ); BOOST_CHECK( ! p2->is() ); BOOST_CHECK_EQUAL( unsigned(boost::size(*p2->nextPacketRange())), 4u );