1#ifndef SDL3PP_RESOURCE_H_
2#define SDL3PP_RESOURCE_H_
23 : m_resource(std::move(resource))
45 constexpr explicit operator bool()
const {
return m_resource; }
51 constexpr bool operator==(std::nullopt_t)
const {
return !m_resource; }
54 constexpr bool operator==(std::nullptr_t)
const {
return !m_resource; }
57 constexpr T
get()
const {
return m_resource; }
62 T result = std::move(m_resource);
63 m_resource = newResource;
86template<
class REF,
class UNIQUE>
89 bool m_owning =
false;
108 : REF(other.release())
117 : REF(other.release())
118 , m_owning(other.m_owning)
120 other.m_owning =
false;
128 REF::operator=(REF(other.release()));
129 m_owning = other.m_owning;
130 other.m_owning =
false;
137 if (m_owning) REF::reset();
154template<
class REF,
class UNIQUE>
163 : REF(other.release())
172 release(other.release());
177 operator UNIQUE() {
return UNIQUE{REF::release()}; }
A optional reference to resource.
Definition SDL3pp_resource.h:88
OptionalResource & operator=(OptionalResource &&other)
Assignment operator.
Definition SDL3pp_resource.h:126
constexpr OptionalResource(const REF &other)
Constructs from a reference.
Definition SDL3pp_resource.h:95
~OptionalResource()
Destructor.
Definition SDL3pp_resource.h:135
OptionalResource(OptionalResource &&other)
Move ctor.
Definition SDL3pp_resource.h:116
constexpr OptionalResource(UNIQUE &&other)
Constructs from a moved from unique.
Definition SDL3pp_resource.h:107
constexpr OptionalResource(const UNIQUE &other)
Constructs from a reference.
Definition SDL3pp_resource.h:101
A SDL managed resource.
Definition SDL3pp_resource.h:17
constexpr bool operator==(const Resource &other) const =default
Comparison.
constexpr T operator->()
Access to fields.
Definition SDL3pp_resource.h:71
constexpr T release(T newResource={})
Return contained resource and empties or replace value.
Definition SDL3pp_resource.h:60
constexpr Resource(T resource={})
Constructs the underlying resource.
Definition SDL3pp_resource.h:22
constexpr Resource(std::nullptr_t)
Equivalent to default ctor.
Definition SDL3pp_resource.h:28
constexpr const T operator->() const
Access to fields.
Definition SDL3pp_resource.h:68
constexpr bool operator==(std::nullptr_t) const
Comparison.
Definition SDL3pp_resource.h:54
constexpr T get() const
Return contained resource;.
Definition SDL3pp_resource.h:57
constexpr bool operator==(std::nullopt_t) const
Comparison.
Definition SDL3pp_resource.h:51
constexpr Resource(std::nullopt_t)
Equivalent to default ctor.
Definition SDL3pp_resource.h:34
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
A detached reference to resource that might be transformed into an owned handle.
Definition SDL3pp_resource.h:156
constexpr DetachedResource(DetachedResource &&other)
Move ctor.
Definition SDL3pp_resource.h:162
constexpr DetachedResource & operator=(DetachedResource &&other)
Move assignment.
Definition SDL3pp_resource.h:170