diff options
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; } } |