A smart-pointer class which points to a reference-counted object. More...
#include <juce_ReferenceCountedObject.h>
Public Types | |
using | ReferencedType = ObjectType |
The class being referenced by this pointer. | |
Public Member Functions | |
ReferenceCountedObjectPtr ()=default | |
Creates a pointer to a null object. | |
ReferenceCountedObjectPtr (decltype(nullptr)) noexcept | |
Creates a pointer to a null object. | |
ReferenceCountedObjectPtr (ReferencedType *refCountedObject) noexcept | |
Creates a pointer to an object. | |
ReferenceCountedObjectPtr (ReferencedType &refCountedObject) noexcept | |
Creates a pointer to an object. | |
ReferenceCountedObjectPtr (const ReferenceCountedObjectPtr &other) noexcept | |
Copies another pointer. | |
ReferenceCountedObjectPtr (ReferenceCountedObjectPtr &&other) noexcept | |
Takes-over the object from another pointer. | |
template<typename Convertible > | |
ReferenceCountedObjectPtr (const ReferenceCountedObjectPtr< Convertible > &other) noexcept | |
Copies another pointer. | |
ReferenceCountedObjectPtr & | operator= (const ReferenceCountedObjectPtr &other) |
Changes this pointer to point at a different object. | |
template<typename Convertible > | |
ReferenceCountedObjectPtr & | operator= (const ReferenceCountedObjectPtr< Convertible > &other) |
Changes this pointer to point at a different object. | |
ReferenceCountedObjectPtr & | operator= (ReferencedType *newObject) |
Changes this pointer to point at a different object. | |
ReferenceCountedObjectPtr & | operator= (ReferencedType &newObject) |
Changes this pointer to point at a different object. | |
ReferenceCountedObjectPtr & | operator= (decltype(nullptr)) |
Resets this pointer to a null pointer. | |
ReferenceCountedObjectPtr & | operator= (ReferenceCountedObjectPtr &&other) noexcept |
Takes-over the object from another pointer. | |
~ReferenceCountedObjectPtr () | |
Destructor. | |
ReferencedType * | get () const noexcept |
Returns the object that this pointer references. | |
void | reset () noexcept |
Resets this object to a null pointer. | |
ReferencedType * | operator-> () const noexcept |
ReferencedType & | operator* () const noexcept |
Dereferences the object that this pointer references. | |
bool | operator== (decltype(nullptr)) const noexcept |
Checks whether this pointer is null. | |
bool | operator!= (decltype(nullptr)) const noexcept |
Checks whether this pointer is null. | |
bool | operator== (const ObjectType *other) const noexcept |
Compares two ReferenceCountedObjectPtrs. | |
bool | operator== (const ReferenceCountedObjectPtr &other) const noexcept |
Compares two ReferenceCountedObjectPtrs. | |
bool | operator!= (const ObjectType *other) const noexcept |
Compares two ReferenceCountedObjectPtrs. | |
bool | operator!= (const ReferenceCountedObjectPtr &other) const noexcept |
Compares two ReferenceCountedObjectPtrs. | |
operator ReferencedType * () const noexcept | |
Returns the object that this pointer references. | |
A smart-pointer class which points to a reference-counted object.
The template parameter specifies the class of the object you want to point to - the easiest way to make a class reference-countable is to simply make it inherit from ReferenceCountedObject or SingleThreadedReferenceCountedObject, but if you need to, you can roll your own reference-countable class by implementing a set of methods called incReferenceCount(), decReferenceCount(), and decReferenceCountWithoutDeleting(). See ReferenceCountedObject for examples of how these methods should behave.
When using this class, you'll probably want to create a typedef to abbreviate the full templated name - e.g.
using ReferenceCountedObjectPtr< ObjectType >::ReferencedType = ObjectType |
The class being referenced by this pointer.
|
default |
Creates a pointer to a null object.
|
noexcept |
Creates a pointer to a null object.
|
noexcept |
Creates a pointer to an object.
This will increment the object's reference-count.
|
noexcept |
Creates a pointer to an object.
This will increment the object's reference-count.
|
noexcept |
Copies another pointer.
This will increment the object's reference-count.
|
noexcept |
Takes-over the object from another pointer.
|
noexcept |
Copies another pointer.
This will increment the object's reference-count (if it is non-null).
ReferenceCountedObjectPtr< ObjectType >::~ReferenceCountedObjectPtr | ( | ) |
Destructor.
This will decrement the object's reference-count, which will cause the object to be deleted when the ref-count hits zero.
ReferenceCountedObjectPtr & ReferenceCountedObjectPtr< ObjectType >::operator= | ( | const ReferenceCountedObjectPtr< ObjectType > & | other | ) |
Changes this pointer to point at a different object.
The reference count of the old object is decremented, and it might be deleted if it hits zero. The new object's count is incremented.
References ReferenceCountedObjectPtr< ObjectType >::operator=().
Referenced by ReferenceCountedObjectPtr< ObjectType >::operator=(), ReferenceCountedObjectPtr< ObjectType >::operator=(), and ReferenceCountedObjectPtr< ObjectType >::operator=().
ReferenceCountedObjectPtr & ReferenceCountedObjectPtr< ObjectType >::operator= | ( | const ReferenceCountedObjectPtr< Convertible > & | other | ) |
Changes this pointer to point at a different object.
The reference count of the old object is decremented, and it might be deleted if it hits zero. The new object's count is incremented.
References ReferenceCountedObjectPtr< ObjectType >::get(), and ReferenceCountedObjectPtr< ObjectType >::operator=().
ReferenceCountedObjectPtr & ReferenceCountedObjectPtr< ObjectType >::operator= | ( | ReferencedType * | newObject | ) |
Changes this pointer to point at a different object.
The reference count of the old object is decremented, and it might be deleted if it hits zero. The new object's count is incremented.
References ReferenceCountedObjectPtr< ObjectType >::operator=(), and ReferenceCountedObjectPtr< ObjectType >::reset().
ReferenceCountedObjectPtr & ReferenceCountedObjectPtr< ObjectType >::operator= | ( | ReferencedType & | newObject | ) |
Changes this pointer to point at a different object.
The reference count of the old object is decremented, and it might be deleted if it hits zero. The new object's count is incremented.
ReferenceCountedObjectPtr & ReferenceCountedObjectPtr< ObjectType >::operator= | ( | decltype(nullptr) | ) |
Resets this pointer to a null pointer.
References ReferenceCountedObjectPtr< ObjectType >::reset().
|
noexcept |
Takes-over the object from another pointer.
|
noexcept |
Returns the object that this pointer references.
The pointer returned may be null, of course.
Referenced by ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::add(), ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::addIfNotAlreadyThere(), WeakReference< ObjectType, ReferenceCountingType >::get(), WeakReference< ObjectType, ReferenceCountingType >::Master::getSharedPointer(), ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::insert(), ReferenceCountedObjectPtr< ObjectType >::operator=(), ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::removeObject(), ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::set(), WeakReference< ObjectType, ReferenceCountingType >::wasObjectDeleted(), and WeakReference< ObjectType, ReferenceCountingType >::Master::~Master().
|
noexcept |
Resets this object to a null pointer.
Referenced by ReferenceCountedObjectPtr< ObjectType >::operator=(), and ReferenceCountedObjectPtr< ObjectType >::operator=().
|
noexcept |
References jassert.
|
noexcept |
Dereferences the object that this pointer references.
The pointer returned may be null, of course.
References jassert.
|
noexcept |
Checks whether this pointer is null.
|
noexcept |
Checks whether this pointer is null.
|
noexcept |
Compares two ReferenceCountedObjectPtrs.
|
noexcept |
Compares two ReferenceCountedObjectPtrs.
|
noexcept |
Compares two ReferenceCountedObjectPtrs.
|
noexcept |
Compares two ReferenceCountedObjectPtrs.
|
noexcept |
Returns the object that this pointer references.
The pointer returned may be null, of course. Note that this methods allows the compiler to be very lenient with what it allows you to do with the pointer, it's safer to disable this by setting JUCE_STRICT_REFCOUNTEDPOINTER=1, which increased type safety and can prevent some common slip-ups.