return *this;
}
+prefix_ bool senf::Packet::is_shared()
+ const
+{
+ return ptr()->is_shared() || (ptr()->impl().refcount() > 1);
+}
+
template <class PacketType, class Parser>
prefix_ Parser senf::operator<<(Parser target, ConcretePacket<PacketType> const & packet)
{
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. */
///@}
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<FooPacket>();
BOOST_CHECK_EQUAL( packet.size(), 12u );
BOOST_CHECK_EQUAL( packet.next().size(), 8u );
BOOST_CHECK( packet.next().as<FooPacket>() );
p2 = packet.next().clone();
+ BOOST_CHECK( ! packet.is_shared() );
BOOST_REQUIRE( p2 );
packet.next().append( p2 );
BOOST_REQUIRE( packet.next().next() );