Merge pull request #44 from cynnyx/master

docs
This commit is contained in:
Michele Caini 2016-08-02 19:36:41 +02:00 committed by GitHub
commit d077ac95ce

View File

@ -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<typename E>
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<ErrorEvent> {
template<typename U, typename = std::enable_if_t<std::is_integral<U>::value>>
explicit ErrorEvent(U val) noexcept
: ec{static_cast<int>(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: