From: tho Date: Tue, 7 Sep 2010 08:32:42 +0000 (+0000) Subject: Packets: added Packet::is_shared() member X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=5312bddbdf89d033cccea36c492a035358be750c;p=senf.git Packets: added Packet::is_shared() member git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1710 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/Packet.cci b/senf/Packets/Packet.cci index e5f9f4d..cb9e4de 100644 --- a/senf/Packets/Packet.cci +++ b/senf/Packets/Packet.cci @@ -191,6 +191,12 @@ prefix_ bool senf::Packet::valid() return *this; } +prefix_ bool senf::Packet::is_shared() + const +{ + return ptr()->is_shared() || (ptr()->impl().refcount() > 1); +} + template prefix_ Parser senf::operator<<(Parser target, ConcretePacket const & packet) { diff --git a/senf/Packets/Packet.hh b/senf/Packets/Packet.hh index 090cd66..6693d0d 100644 --- a/senf/Packets/Packet.hh +++ b/senf/Packets/Packet.hh @@ -492,7 +492,11 @@ namespace senf { unsigned long id() const; ///< Unique packet id /**< Get a unique packet id. If two packets have the same - id, they share the internal data representation.. */ + id, they share the internal data representation. */ + + bool is_shared() const; ///< check if this packet shares data with any another packet handle. + /**< This method returns true if there is any other packet + handle pointing to any header in the packet chain. */ ///@} diff --git a/senf/Packets/Packet.test.cc b/senf/Packets/Packet.test.cc index 8fe9771..557e7f8 100644 --- a/senf/Packets/Packet.test.cc +++ b/senf/Packets/Packet.test.cc @@ -178,8 +178,18 @@ SENF_AUTO_UNIT_TEST(packet) BOOST_CHECK( packet.first() == packet ); BOOST_CHECK( packet.last() == packet.next() ); + BOOST_CHECK( ! packet.is_shared() ); + { + senf::Packet p2 (packet); + BOOST_CHECK( packet.is_shared() ); + BOOST_CHECK( p2.is_shared() ); + } + BOOST_CHECK( ! packet.is_shared() ); + senf::Packet p2 (packet.next()); BOOST_CHECK( p2 ); + BOOST_CHECK( packet.is_shared() ); + BOOST_CHECK( p2.is_shared() ); packet.parseNextAs(); BOOST_CHECK_EQUAL( packet.size(), 12u ); BOOST_CHECK_EQUAL( packet.next().size(), 8u ); @@ -188,6 +198,7 @@ SENF_AUTO_UNIT_TEST(packet) BOOST_CHECK( packet.next().as() ); p2 = packet.next().clone(); + BOOST_CHECK( ! packet.is_shared() ); BOOST_REQUIRE( p2 ); packet.next().append( p2 ); BOOST_REQUIRE( packet.next().next() );