1 #ifndef ENTT_RESOURCE_RESOURCE_HPP
2 #define ENTT_RESOURCE_RESOURCE_HPP
7 #include "../config/config.h"
22 template<
typename Type>
28 template<
typename Other>
29 static constexpr
bool is_acceptable_v = !std::is_same_v<Type, Other> && std::is_constructible_v<Type &, Other &>;
40 explicit resource(std::shared_ptr<Type> res) ENTT_NOEXCEPT
41 : value{std::move(res)} {}
55 template<typename Other>
57 : value{other.value, std::addressof(res)} {}
64 template<
typename Other,
typename = std::enable_if_t<is_acceptable_v<Other>>>
66 : value{other.value} {}
73 template<
typename Other,
typename = std::enable_if_t<is_acceptable_v<Other>>>
75 : value{std::move(other.value)} {}
95 template<typename Other>
96 std::enable_if_t<is_acceptable_v<Other>,
resource &>
97 operator=(const
resource<Other> &other) ENTT_NOEXCEPT {
108 template<
typename Other>
109 std::enable_if_t<is_acceptable_v<Other>,
resource &>
111 value = std::move(other.value);
128 [[nodiscard]]
operator Type &()
const ENTT_NOEXCEPT {
144 [[nodiscard]]
explicit operator bool() const ENTT_NOEXCEPT {
145 return static_cast<bool>(value);
153 return value.use_count();
157 std::shared_ptr<Type> value;
168 template<
typename Res,
typename Other>
170 return (std::addressof(*lhs) == std::addressof(*rhs));
181 template<
typename ILhs,
typename IRhs>
183 return !(lhs == rhs);
std::enable_if_t< is_acceptable_v< Other >, resource & > operator=(resource< Other > &&other)
Move assignment operator from foreign handle.
long use_count() const
Returns the number of handles pointing the same resource.
resource()
Default constructor.
Type & operator*() const
Returns a reference to the managed resource.
resource(std::shared_ptr< Type > res)
Creates a handle from a weak pointer, namely a resource.
Type * operator->() const
Returns a pointer to the managed resource.
resource(resource< Other > &&other)
Move constructs a handle which takes ownership of the resource.
resource & operator=(resource &&)=default
Default move assignment operator.
resource(const resource &)=default
Default copy constructor.
resource(const resource< Other > &other)
Copy constructs a handle which shares ownership of the resource.
resource(resource &&)=default
Default move constructor.
resource & operator=(const resource &)=default
Default copy assignment operator.
constexpr bool operator==(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs)
Compares two hashed strings.
bool operator!=(const basic_any< Len, Align > &lhs, const basic_any< Len, Align > &rhs)
Checks if two wrappers differ in their content.