1#ifndef UVW_RESOURCE_INCLUDE_H
2#define UVW_RESOURCE_INCLUDE_H
7#include "underlying_type.hpp"
16template<
typename T,
typename U>
19 using ConstructorAccess =
typename UnderlyingType<T, U>::ConstructorAccess;
21 auto parent()
const noexcept {
22 return this->
loop().loop.get();
25 void leak()
noexcept {
26 sPtr = this->shared_from_this();
29 void reset()
noexcept {
33 bool self()
const noexcept {
34 return static_cast<bool>(sPtr);
38 explicit Resource(ConstructorAccess ca, std::shared_ptr<Loop> ref)
40 this->get()->data =
this;
47 template<
typename R =
void>
48 std::shared_ptr<R>
data()
const {
49 return std::static_pointer_cast<R>(userData);
56 void data(std::shared_ptr<void> uData) {
57 userData = std::move(uData);
61 std::shared_ptr<void> userData{
nullptr};
62 std::shared_ptr<void> sPtr{
nullptr};
Event emitter base class.
Common class for almost all the resources available in uvw.
std::shared_ptr< R > data() const
Gets user-defined data. uvw won't use this field in any case.
void data(std::shared_ptr< void > uData)
Sets arbitrary data. uvw won't use this field in any case.
Wrapper class for underlying types.
Loop & loop() const noexcept
Gets the loop from which the resource was originated.