51 : _p(std::exchange(rhs._p,
nullptr)) {
64 : _p(std::exchange(rhs._p,
nullptr)) {
82 template <
typename... ConstructorArgumentTypes>
83 T&
emplace(ConstructorArgumentTypes&&... constructorArguments) {
85 new T(std::forward<ConstructorArgumentTypes>(constructorArguments)...);
92 void reset() { *
this =
nullptr; }
106 pOld->releaseReference();
126 pOld->releaseReference();
137 if (this->_p != rhs._p) {
138 std::swap(this->_p, rhs._p);
155 pOld->releaseReference();
176 explicit operator bool() const noexcept {
return this->_p !=
nullptr; }
181 T*
get() const noexcept {
return this->_p; }
187 return this->_p == rhs._p;
193 return this->_p == rhs._p;
200 return !(*
this == rhs);
208 return !(*
this == rhs);
215 bool operator==(
const T* pRhs)
const noexcept {
return this->_p == pRhs; }
221 bool operator!=(
const T* pRhs)
const noexcept {
return !(*
this == pRhs); }
224 void addReference() noexcept {
226 this->_p->addReference();
230 void releaseReference() noexcept {
232 this->_p->releaseReference();
237 template <
typename U>
friend class IntrusivePointer;
246template <
typename T,
typename U>
260 std::hash<T*> hasher{};
261 return hasher(key.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 * operator->() const noexcept
Arrow operator.
bool operator==(const IntrusivePointer< U > &rhs) const noexcept
Returns true if two pointers are equal.
IntrusivePointer & operator=(const IntrusivePointer &rhs) noexcept
Assignment operator.
IntrusivePointer(IntrusivePointer< T > &&rhs) noexcept
Move constructor.
IntrusivePointer & operator=(IntrusivePointer &&rhs) noexcept
Move assignment operator.
bool operator!=(const T *pRhs) const noexcept
Returns true if the contents of this pointer is not equal to the given pointer.
T & operator*() const noexcept
Dereferencing operator.
IntrusivePointer(IntrusivePointer< U > &&rhs) noexcept
Implicit conversion of an r-value to a pointer to a base (or otherwise convertible) type.
bool operator!=(const IntrusivePointer< U > &rhs) const noexcept
Returns true if two pointers are not equal.
void reset()
Reset this pointer to nullptr.
IntrusivePointer & operator=(const IntrusivePointer< U > &rhs) noexcept
Assigns an IntrusivePointer of another type to this IntrusivePointer.
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=(T *p) noexcept
Assignment operator.
~IntrusivePointer() noexcept
Default destructor.
IntrusivePointer(T *p=nullptr) noexcept
Default constructor.
T * get() const noexcept
Returns the internal pointer.
T & emplace(ConstructorArgumentTypes &&... constructorArguments)
Constructs a new instance and assigns it to this IntrusivePointer. If this IntrusivePointer already p...
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.
IntrusivePointer< T > const_intrusive_cast(const IntrusivePointer< U > &p) noexcept
Casts a const IntrusivePointer to its non-const equivalent.
std::size_t operator()(const CesiumUtility::IntrusivePointer< T > &key) const noexcept
Returns a size_t hash of the provided CesiumUtility::IntrusivePointer<T>.