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/util.h | |
parent | 33faa8e355dc47a126790f1ea3e52d1813aedc69 (diff) |
...
Diffstat (limited to 'include/salticidae/util.h')
-rw-r--r-- | include/salticidae/util.h | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/include/salticidae/util.h b/include/salticidae/util.h index 05e7b66..0324215 100644 --- a/include/salticidae/util.h +++ b/include/salticidae/util.h @@ -271,31 +271,47 @@ class Event { eb(eb), fd(fd), events(events), ev(event_new(eb, fd, events, Event::_then, this)), callback(callback) {} + Event(const Event &other): + eb(other.eb), fd(other.fd), events(other.events), + ev(event_new(eb, fd, events, Event::_then, this)), + callback(other.callback) {} + Event(Event &&other): eb(other.eb), fd(other.fd), events(other.events), - callback(std::move(other.callback)) { - other.clear(); - ev = event_new(eb, fd, events, Event::_then, this); + ev(event_new(eb, fd, events, Event::_then, this)), + callback(std::move(other.callback)) {} + + void swap(Event &other) { + std::swap(eb, other.eb); + std::swap(fd, other.fd); + std::swap(events, other.events); + std::swap(ev, other.ev); + std::swap(callback, other.callback); } + Event &operator=(Event &&other) { - clear(); - other.clear(); - eb = other.eb; - fd = other.fd; - events = other.events; - ev = event_new(eb, fd, events, Event::_then, this); - callback = std::move(other.callback); + if (this != &other) + { + Event tmp(std::move(other)); + tmp.swap(*this); + } return *this; } - ~Event() { clear(); } + Event &operator=(const Event &other) { + if (this != &other) + { + Event tmp(other); + tmp.swap(*this); + } + return *this; + } - void clear() { + ~Event() { if (ev != nullptr) { event_del(ev); event_free(ev); - ev = nullptr; } } |