aboutsummaryrefslogtreecommitdiff
path: root/include/salticidae/msg.h
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2018-07-12 18:04:52 -0400
committerDeterminant <ted.sybil@gmail.com>2018-07-12 18:04:52 -0400
commit53f4c5137da249e5e955809ffe32afa3cf5c3522 (patch)
tree0b187dc8e2d2d86a223ab79c42bdc471c40bc569 /include/salticidae/msg.h
parent33faa8e355dc47a126790f1ea3e52d1813aedc69 (diff)
...
Diffstat (limited to 'include/salticidae/msg.h')
-rw-r--r--include/salticidae/msg.h31
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;
}