From 59ded504aaf50caf90a8a3da09c02bb3f31fcac5 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 2 Aug 2016 19:35:49 +0200 Subject: [PATCH] docs --- src/uvw/event.hpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/uvw/event.hpp b/src/uvw/event.hpp index 48fc0361..a16df258 100644 --- a/src/uvw/event.hpp +++ b/src/uvw/event.hpp @@ -26,8 +26,18 @@ struct BaseEvent { } +/** + * @brief Generic event type. + * + * Events in `uvw` must be associated with an unique numerical identifier. To do + * that, they shall inherit from this class. + */ template struct Event: details::BaseEvent { + /** + * @brief Gets the unique numerical identifier. + * @return An unique numerical identifier for the given event type. + */ static std::size_t type() noexcept { static std::size_t val = BaseEvent::next(); return val; @@ -35,15 +45,36 @@ struct Event: details::BaseEvent { }; +/** + * @brief The ErrorEvent event. + * + * Custom wrapper around libuv's error constants. + */ struct ErrorEvent: Event { template::value>> explicit ErrorEvent(U val) noexcept : ec{static_cast(val)}, str{uv_strerror(ec)} { } + /** + * @brief Returns the error message for the given error code. + * + * Leaks a few bytes of memory when you call it with an unknown error code. + * + * @return The error message for the given error code. + */ const char * what() const noexcept { return str; } + + /** + * @brief Gets the underlying error code, that is a libuv's error constant. + * @return The underlying error code. + */ int code() const noexcept { return ec; } + /** + * @brief Checks if the event contains a valid error code. + * @return True in case of success, false otherwise. + */ explicit operator bool() const noexcept { return ec < 0; } private: