Implement move ctor/assignment

This commit is contained in:
Atlante45 2015-07-07 12:47:23 -07:00
parent 9889dcdd64
commit e2bd9532b7
2 changed files with 41 additions and 6 deletions

View file

@ -64,6 +64,41 @@ Packet::Packet(PacketType::Value type, qint64 size) :
}
}
Packet::Packet(const Packet& other) {
*this = other;
}
Packet& Packet::operator=(const Packet& other) {
_packetSize = other._packetSize;
_packet = std::unique_ptr<char>(new char(_packetSize));
memcpy(_packet.get(), other._packet.get(), _packetSize);
_payloadStart = _packet.get() + (other._payloadStart - other._packet.get());
_position = other._position;
_capacity = other._capacity;
_sizeUsed = other._sizeUsed;
return *this;
}
Packet::Packet(Packet&& other) {
*this = std::move(other);
}
Packet& Packet::operator=(Packet&& other) {
_packetSize = other._packetSize;
_packet = std::move(other._packet);
_payloadStart = other._payloadStart;
_position = other._position;
_capacity = other._capacity;
_sizeUsed = other._sizeUsed;
return *this;
}
PacketType::Value Packet::getPacketType() const {
return (PacketType::Value)arithmeticCodingValueFromBuffer(_packet.get());
}

View file

@ -20,10 +20,10 @@
class Packet : public QIODevice {
public:
static std::unique_ptr<Packet> create(PacketType::Value type, int64_t size = -1);
using SequenceNumber = uint16_t;
static std::unique_ptr<Packet> create(PacketType::Value type, int64_t size = -1);
static qint64 localHeaderSize(PacketType::Value type);
static qint64 maxPayloadSize(PacketType::Value type);
@ -57,10 +57,10 @@ public:
protected:
Packet(PacketType::Value type, int64_t size);
Packet(Packet&&) = delete;
Packet(const Packet&) = delete;
Packet& operator=(Packet&&) = delete;
Packet& operator=(const Packet&) = delete;
Packet(const Packet& other);
Packet& operator=(const Packet& other);
Packet(Packet&& other);
Packet& operator=(Packet&& other);
// QIODevice virtual functions
virtual qint64 writeData(const char* data, qint64 maxSize);