uvw 3.1.0
Loading...
Searching...
No Matches
uv_type.hpp
1#ifndef UVW_UV_TYPE_INCLUDE_H
2#define UVW_UV_TYPE_INCLUDE_H
3
4#include <memory>
5#include <type_traits>
6#include <utility>
7#include "config.h"
8#include "loop.h"
9
10namespace uvw {
11
17template<typename U>
18struct uv_type {
19 explicit uv_type(loop::token token, std::shared_ptr<loop> ref) noexcept
20 : owner{std::move(ref)}, resource{} {}
21
22 uv_type(const uv_type &) = delete;
23 uv_type(uv_type &&) = delete;
24
25 uv_type &operator=(const uv_type &) = delete;
26 uv_type &operator=(uv_type &&) = delete;
27
32 virtual int init() {
33 return 0;
34 }
35
40 loop &parent() const noexcept {
41 return *owner;
42 }
43
59 const U *raw() const noexcept {
60 return &resource;
61 }
62
78 U *raw() noexcept {
79 return &resource;
80 }
81
82private:
83 std::shared_ptr<loop> owner;
84 U resource;
85};
86
87} // namespace uvw
88
89#endif // UVW_UV_TYPE_INCLUDE_H
The loop class.
Definition: loop.h:60
Common class for almost all the resources available in uvw.
Definition: resource.hpp:18
uvw default namespace.
Definition: async.h:8
Wrapper class for underlying types.
Definition: uv_type.hpp:18
const U * raw() const noexcept
Gets the underlying raw data structure.
Definition: uv_type.hpp:59
loop & parent() const noexcept
Gets the loop from which the resource was originated.
Definition: uv_type.hpp:40
virtual int init()
Initializes the handle.
Definition: uv_type.hpp:32
U * raw() noexcept
Gets the underlying raw data structure.
Definition: uv_type.hpp:78