24#include "IReferenceCounted.h"
40template <
class ReferenceCounted,
41 class =
typename std::enable_if<std::is_base_of<IReferenceCounted,
42 ReferenceCounted>::value>::type>
45 ReferenceCounted *
value =
nullptr;
56 template <
typename B,
class =
typename std::enable_if<std::is_convertible<B *,
57 ReferenceCounted *>
::value>::type>
63 template <
typename B,
class =
typename std::enable_if<std::is_convertible<B *,
64 ReferenceCounted *>
::value>::type>
75 explicit irr_ptr(ReferenceCounted *
object)
noexcept {
reset(
object); }
91 template <
typename B,
class =
typename std::enable_if<std::is_convertible<B *,
92 ReferenceCounted *>
::value>::type>
99 template <
typename B,
class =
typename std::enable_if<std::is_convertible<B *,
100 ReferenceCounted *>
::value>::type>
109 explicit operator ReferenceCounted *()
const noexcept {
return value; }
110 explicit operator bool() const noexcept {
return !!
value; }
114 ReferenceCounted *
get() const noexcept {
return value; }
121 ReferenceCounted *
object =
value;
129 void reset(ReferenceCounted *
object =
nullptr) noexcept
139 void grab(ReferenceCounted *
object)
noexcept
154template <
class ReferenceCounted>
162template <
typename ReferenceCounted>
165 return a.
get() == b.get();
168template <
typename ReferenceCounted>
174template <
typename ReferenceCounted>
180template <
typename ReferenceCounted>
183 return a.get() != b.get();
186template <
typename ReferenceCounted>
192template <
typename ReferenceCounted>
200template <
class T,
class... Args>
203 return irr_ptr<T>(
new T(std::forward<Args>(args)...));
Shared pointer for IrrLicht objects.
Definition irr_ptr.h:44
void grab(ReferenceCounted *object) noexcept
Drops stored pointer replacing it with the given one.
Definition irr_ptr.h:139
irr_ptr(ReferenceCounted *object) noexcept
Constructs a shared pointer out of a plain one to control object lifetime.
Definition irr_ptr.h:75
irr_ptr & operator=(const irr_ptr &b) noexcept
Definition irr_ptr.h:79
irr_ptr(const irr_ptr< B > &b) noexcept
Definition irr_ptr.h:58
irr_ptr(irr_ptr &&b) noexcept
Definition irr_ptr.h:54
void reset(ReferenceCounted *object=nullptr) noexcept
Drops stored pointer replacing it with the given one.
Definition irr_ptr.h:129
irr_ptr & operator=(irr_ptr< B > &&b) noexcept
Definition irr_ptr.h:101
ReferenceCounted & operator*() const noexcept
Definition irr_ptr.h:107
irr_ptr()
Definition irr_ptr.h:48
ReferenceCounted * get() const noexcept
Returns the stored pointer.
Definition irr_ptr.h:114
irr_ptr & operator=(irr_ptr &&b) noexcept
Definition irr_ptr.h:85
irr_ptr & operator=(const irr_ptr< B > &b) noexcept
Definition irr_ptr.h:93
ReferenceCounted * operator->() const noexcept
Definition irr_ptr.h:108
irr_ptr(const irr_ptr &b) noexcept
Definition irr_ptr.h:52
irr_ptr(irr_ptr< B > &&b) noexcept
Definition irr_ptr.h:65
~irr_ptr()
Definition irr_ptr.h:77
ReferenceCounted * value
Definition irr_ptr.h:45
ReferenceCounted * release() noexcept
Returns the stored pointer, erasing it from this class.
Definition irr_ptr.h:119
irr_ptr(std::nullptr_t) noexcept
Definition irr_ptr.h:50
irr_ptr< T > make_irr(Args &&... args)
Same as std::make_unique<T>, but for irr_ptr.
Definition irr_ptr.h:201
bool operator!=(const irr_ptr< ReferenceCounted > &a, const irr_ptr< ReferenceCounted > &b) noexcept
Definition irr_ptr.h:181
bool operator==(const irr_ptr< ReferenceCounted > &a, const irr_ptr< ReferenceCounted > &b) noexcept
Definition irr_ptr.h:163
irr_ptr< ReferenceCounted > grab(ReferenceCounted *object) noexcept
Constructs a shared pointer as a secondary reference to an object.
Definition irr_ptr.h:155