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;