diff options
author | Determinant <ted.sybil@gmail.com> | 2018-07-12 18:04:52 -0400 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2018-07-12 18:04:52 -0400 |
commit | 53f4c5137da249e5e955809ffe32afa3cf5c3522 (patch) | |
tree | 0b187dc8e2d2d86a223ab79c42bdc471c40bc569 /include/salticidae/msg.h | |
parent | 33faa8e355dc47a126790f1ea3e52d1813aedc69 (diff) |
...
Diffstat (limited to 'include/salticidae/msg.h')
-rw-r--r-- | include/salticidae/msg.h | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/include/salticidae/msg.h b/include/salticidae/msg.h index b9db1b8..798062a 100644 --- a/include/salticidae/msg.h +++ b/include/salticidae/msg.h @@ -93,23 +93,30 @@ class MsgBase { checksum = letoh(_checksum); } + void swap(MsgBase &other) { + std::swap(magic, other.magic); + std::swap(opcode, other.opcode); + std::swap(length, other.length); + std::swap(checksum, other.checksum); + std::swap(payload, other.payload); + std::swap(no_payload, other.no_payload); + } + MsgBase &operator=(const MsgBase &other) { - magic = other.magic; - opcode = other.opcode; - length = other.length; - checksum = other.checksum; - payload = other.payload; - no_payload = other.no_payload; + if (this != &other) + { + MsgBase tmp(other); + tmp.swap(*this); + } return *this; } MsgBase &operator=(MsgBase &&other) { - magic = other.magic; - opcode = std::move(other.opcode); - length = other.length; - checksum = other.checksum; - payload = std::move(other.payload); - no_payload = other.no_payload; + if (this != &other) + { + MsgBase tmp(std::move(other)); + tmp.swap(*this); + } return *this; } |