mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 18:36:45 +02:00
Implement move ctor/assignment
This commit is contained in:
parent
9889dcdd64
commit
e2bd9532b7
2 changed files with 41 additions and 6 deletions
|
@ -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 {
|
PacketType::Value Packet::getPacketType() const {
|
||||||
return (PacketType::Value)arithmeticCodingValueFromBuffer(_packet.get());
|
return (PacketType::Value)arithmeticCodingValueFromBuffer(_packet.get());
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
|
|
||||||
class Packet : public QIODevice {
|
class Packet : public QIODevice {
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<Packet> create(PacketType::Value type, int64_t size = -1);
|
|
||||||
|
|
||||||
using SequenceNumber = uint16_t;
|
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 localHeaderSize(PacketType::Value type);
|
||||||
static qint64 maxPayloadSize(PacketType::Value type);
|
static qint64 maxPayloadSize(PacketType::Value type);
|
||||||
|
|
||||||
|
@ -57,10 +57,10 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Packet(PacketType::Value type, int64_t size);
|
Packet(PacketType::Value type, int64_t size);
|
||||||
Packet(Packet&&) = delete;
|
Packet(const Packet& other);
|
||||||
Packet(const Packet&) = delete;
|
Packet& operator=(const Packet& other);
|
||||||
Packet& operator=(Packet&&) = delete;
|
Packet(Packet&& other);
|
||||||
Packet& operator=(const Packet&) = delete;
|
Packet& operator=(Packet&& other);
|
||||||
|
|
||||||
// QIODevice virtual functions
|
// QIODevice virtual functions
|
||||||
virtual qint64 writeData(const char* data, qint64 maxSize);
|
virtual qint64 writeData(const char* data, qint64 maxSize);
|
||||||
|
|
Loading…
Reference in a new issue