From 88faee9b26dcc7aa4f3859aebc1706d908b628f2 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Mon, 26 Nov 2012 15:22:29 -0300 Subject: [PATCH] Added Packet conversion to bool. --- include/packet.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/packet.h b/include/packet.h index bec79e2..4b779c9 100644 --- a/include/packet.h +++ b/include/packet.h @@ -146,8 +146,7 @@ public: * This calls PDU::clone on the rhs's PDU* member. */ Packet(const Packet &rhs) : ts(rhs.timestamp()) { - if(rhs.pdu()) - pdu_ = rhs.pdu()->clone(); + pdu_ = rhs.pdu() ? rhs.pdu()->clone() : 0; } /** @@ -175,7 +174,7 @@ public: /** * Move assignment operator. */ - Packet& operator=(Packet &&rhs){ + Packet& operator=(Packet &&rhs) { if(this != &rhs) { std::swap(pdu_, rhs.pdu_); ts = rhs.timestamp(); @@ -232,6 +231,15 @@ public: pdu_ = 0; return some_pdu; } + + /** + * \brief Tests whether this is Packet contains a valid PDU. + * + * \return true if pdu() == nullptr, false otherwise. + */ + operator bool() const { + return pdu_; + } private: PDU *pdu_; Timestamp ts;