diff --git a/include/pdu.h b/include/pdu.h index 8633ff0..dd79a01 100644 --- a/include/pdu.h +++ b/include/pdu.h @@ -34,6 +34,7 @@ #include #include #include "macros.h" +#include "cxxstd.h" /** \brief The Tins namespace. */ @@ -116,15 +117,33 @@ namespace Tins { PPPOE }; - /** \brief PDU constructor + /** + * \brief PDU constructor * * Must be called by subclasses in their constructors. * \param flag The flag identifier for the subclass' PDU. * \param next_pdu The child PDU. Can be obviated. */ PDU(PDU *next_pdu = 0); + + #if TINS_IS_CXX11 + /** + * \brief Move constructor. + * + * \param rhs The PDU to be moved. + */ + PDU(PDU &&rhs); + + /** + * \brief Move assignment operator. + * + * \param rhs The PDU to be moved. + */ + PDU& operator=(PDU &&rhs); + #endif - /** \brief PDU destructor. + /** + * \brief PDU destructor. * * Deletes the inner pdu, as a consequence every child pdu is * deleted. diff --git a/src/pdu.cpp b/src/pdu.cpp index 4aca838..f639e66 100644 --- a/src/pdu.cpp +++ b/src/pdu.cpp @@ -38,6 +38,19 @@ PDU::PDU(PDU *next_pdu) : _inner_pdu(next_pdu) { } +#if TINS_IS_CXX11 +PDU::PDU(PDU &&rhs) +: _inner_pdu(0) +{ + std::swap(_inner_pdu, rhs._inner_pdu); +} + +PDU& PDU::operator=(PDU &&rhs) { + std::swap(_inner_pdu, rhs._inner_pdu); + return *this; +} +#endif + PDU::PDU(const PDU &other) : _inner_pdu(0) { copy_inner_pdu(other); }