49 : _p(std::exchange(rhs._p,
nullptr)) {
62 : _p(std::exchange(rhs._p,
nullptr)) {
80 template <
typename... ConstructorArgumentTypes>
81 T&
emplace(ConstructorArgumentTypes&&... constructorArguments) {
83 new T(std::forward<ConstructorArgumentTypes>(constructorArguments)...);
90 void reset() { *
this =
nullptr; }
96 if (this->_p != rhs._p) {
103 pOld->releaseReference();
111 if (this->_p != rhs._p) {
118 pOld->releaseReference();
129 if (this->_p != rhs._p) {
130 std::swap(this->_p, rhs._p);
147 pOld->releaseReference();
168 explicit operator bool() const noexcept {
return this->_p !=
nullptr; }
173 T*
get() const noexcept {
return this->_p; }
179 return this->_p == rhs._p;
183 return this->_p == rhs._p;
190 return !(*
this == rhs);
197 bool operator==(
const T* pRhs)
const noexcept {
return this->_p == pRhs; }
203 bool operator!=(
const T* pRhs)
const noexcept {
return !(*
this == pRhs); }
206 void addReference() noexcept {
208 this->_p->addReference();
212 void releaseReference() noexcept {
214 this->_p->releaseReference();
219 template <
typename U>
friend class IntrusivePointer;
222 template <
typename T,
typename U>
224 const_intrusive_cast(
const IntrusivePointer<U>& p) noexcept {
225 return IntrusivePointer<T>(
const_cast<T*
>(p.get()));
A smart pointer that calls addReference and releaseReference on the controlled object.
bool operator==(const IntrusivePointer< T > &rhs) const noexcept
Returns true if two pointers are equal.
T & emplace(ConstructorArgumentTypes &&... constructorArguments)
Constructs a new instance and assigns it to this IntrusivePointer. If this IntrusivePointer already p...
T * get() const noexcept
Returns the internal pointer.
IntrusivePointer(IntrusivePointer< T > &&rhs) noexcept
Move constructor.
IntrusivePointer & operator=(const IntrusivePointer &rhs) noexcept
Assignment operator.
bool operator!=(const T *pRhs) const noexcept
Returns true if the contents of this pointer is not equal to the given pointer.
IntrusivePointer(IntrusivePointer< U > &&rhs) noexcept
Implicit conversion of an r-value to a pointer to a base (or otherwise convertible) type.
void reset()
Reset this pointer to nullptr.
T & operator*() const noexcept
Dereferencing operator.
IntrusivePointer(const IntrusivePointer< T > &rhs) noexcept
Copy constructor.
bool operator!=(const IntrusivePointer< T > &rhs) const noexcept
Returns true if two pointers are not equal.
IntrusivePointer(const IntrusivePointer< U > &rhs) noexcept
Implicit conversion to a pointer to a base (or otherwise convertible) type.
IntrusivePointer & operator=(IntrusivePointer &&rhs) noexcept
Move assignment operator.
T * operator->() const noexcept
Arrow operator.
~IntrusivePointer() noexcept
Default destructor.
IntrusivePointer & operator=(T *p) noexcept
Assignment operator.
IntrusivePointer(T *p=nullptr) noexcept
Default constructor.
bool operator==(const T *pRhs) const noexcept
Returns true if the contents of this pointer is equal to the given pointer.
Utility classes for Cesium.