1#ifndef ENTT_RESOURCE_RESOURCE_HPP
2#define ENTT_RESOURCE_RESOURCE_HPP
5#include "../stl/concepts.hpp"
6#include "../stl/memory.hpp"
7#include "../stl/utility.hpp"
22template<
typename Type>
25 friend class resource;
42 : value{stl::move(res)} {}
56 template<typename Other>
58 : value{other.value, stl::addressof(res)} {}
65 template<
typename Other>
66 requires (!stl::same_as<Type, Other> && stl::constructible_from<Type &, Other &>)
67 resource(
const resource<Other> &other) noexcept
68 : value{other.value} {}
75 template<
typename Other>
76 requires (!stl::same_as<Type, Other> && stl::constructible_from<Type &, Other &>)
78 : value{stl::move(other.value)} {}
87 resource &
operator=(
const resource &)
noexcept =
default;
93 resource &
operator=(resource &&) noexcept = default;
101 template<typename Other>
102 requires (!
stl::same_as<Type, Other> &&
stl::constructible_from<Type &, Other &>)
103 resource &operator=(const resource<Other> &other) noexcept {
114 template<
typename Other>
115 requires (!stl::same_as<Type, Other> && stl::constructible_from<Type &, Other &>)
117 value = stl::move(other.value);
125 void swap(resource &other)
noexcept {
127 swap(value, other.value);
159 [[nodiscard]]
explicit operator bool() const noexcept {
160 return static_cast<bool>(value);
169 template<
typename Other>
170 [[nodiscard]]
bool operator==(
const resource<Other> &other)
const noexcept {
171 return (value == other.value);
180 template<
typename Other>
181 [[nodiscard]]
auto operator<=>(
const resource<Other> &other)
const noexcept {
182 return (value <=> other.value);
195 value = stl::move(other);
Type element_type
Resource type.
resource(const resource &) noexcept=default
Default copy constructor.
auto operator<=>(const resource< Other > &other) const noexcept
Lexicographically compares two handles.
element_type & operator*() const noexcept
Returns a reference to the managed resource.
resource(const resource< Other > &other) noexcept
Copy constructs a handle which shares ownership of the resource.
stl::shared_ptr< element_type > handle_type
Handle type.
resource & operator=(const resource &) noexcept=default
Default copy assignment operator.
element_type * operator->() const noexcept
Returns a pointer to the managed resource.
void reset(handle_type other)
Replaces the managed resource.
void reset()
Releases the ownership of the managed resource.
handle_type handle() const noexcept
Returns the underlying resource handle.
resource & operator=(resource &&) noexcept=default
Default move assignment operator.
resource & operator=(resource< Other > &&other) noexcept
Move assignment operator from foreign handle.
resource(handle_type res) noexcept
Creates a new resource handle.
bool operator==(const resource< Other > &other) const noexcept
Compares two handles.
void swap(resource &other) noexcept
Exchanges the content with that of a given resource.
resource() noexcept
Default constructor.
~resource()=default
Default destructor.
resource(resource< Other > &&other) noexcept
Move constructs a handle which takes ownership of the resource.
resource(resource &&) noexcept=default
Default move constructor.
Custom EnTT namespace for the standard template library.