diff options
author | Determinant <ted.sybil@gmail.com> | 2018-07-12 20:25:41 -0400 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2018-07-12 20:25:41 -0400 |
commit | b98265d732bad274f66de66cb93d891e9c41a112 (patch) | |
tree | 38eb8c584a4a3ab65d833c25eac08fa1b3a6f179 /include/salticidae/util.h | |
parent | 53f4c5137da249e5e955809ffe32afa3cf5c3522 (diff) |
fix bugs
Diffstat (limited to 'include/salticidae/util.h')
-rw-r--r-- | include/salticidae/util.h | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/include/salticidae/util.h b/include/salticidae/util.h index 0324215..de63146 100644 --- a/include/salticidae/util.h +++ b/include/salticidae/util.h @@ -271,47 +271,33 @@ 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), - 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); + callback(std::move(other.callback)) { + other.clear(); + ev = event_new(eb, fd, events, Event::_then, this); } Event &operator=(Event &&other) { - if (this != &other) - { - Event tmp(std::move(other)); - tmp.swap(*this); - } + 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); return *this; } - Event &operator=(const Event &other) { - if (this != &other) - { - Event tmp(other); - tmp.swap(*this); - } - return *this; - } + ~Event() { clear(); } - ~Event() { + void clear() { if (ev != nullptr) { event_del(ev); event_free(ev); + ev = nullptr; } } |