84 jassert (getReferenceCount() > 0);
96 jassert (getReferenceCount() > 0);
97 return --refCount == 0;
122 jassert (getReferenceCount() == 0);
136 friend struct ContainerDeletePolicy<ReferenceCountedObject>;
172 jassert (getReferenceCount() > 0);
184 jassert (getReferenceCount() > 0);
185 return --refCount == 0;
210 jassert (getReferenceCount() == 0);
245template <
class ObjectType>
281 : referencedObject (
other.referencedObject)
283 incIfNotNull (referencedObject);
288 : referencedObject (
other.referencedObject)
290 other.referencedObject =
nullptr;
296 template <
typename Convertible>
298 : referencedObject (
other.get())
300 incIfNotNull (referencedObject);
316 template <
typename Convertible>
374 decIfNotNull (referencedObject);
387 referencedObject =
nullptr;
394 jassert (referencedObject !=
nullptr);
395 return referencedObject;
404 bool operator== (
decltype (
nullptr))
const noexcept {
return referencedObject ==
nullptr; }
406 bool operator!= (
decltype (
nullptr))
const noexcept {
return referencedObject !=
nullptr; }
417 #if JUCE_STRICT_REFCOUNTEDPOINTER
419 explicit operator bool()
const noexcept {
return referencedObject !=
nullptr; }
432 [[
deprecated (
"Use the get method instead.")]]
443 o->incReferenceCount();
448 if (
o !=
nullptr &&
o->decReferenceCountWithoutDeleting())
449 ContainerDeletePolicy<ReferencedType>::destroy (
o);
456template <
typename Type>
463template <
typename Type>
A smart-pointer class which points to a reference-counted object.
~ReferenceCountedObjectPtr()
Destructor.
ReferenceCountedObjectPtr & operator=(const ReferenceCountedObjectPtr &other)
Changes this pointer to point at a different object.
ObjectType ReferencedType
The class being referenced by this pointer.
bool operator!=(decltype(nullptr)) const noexcept
Checks whether this pointer is null.
ReferenceCountedObjectPtr(ReferenceCountedObjectPtr &&other) noexcept
Takes-over the object from another pointer.
bool operator==(decltype(nullptr)) const noexcept
Checks whether this pointer is null.
ReferenceCountedObjectPtr(ReferencedType *refCountedObject) noexcept
Creates a pointer to an object.
ReferenceCountedObjectPtr(ReferencedType &refCountedObject) noexcept
Creates a pointer to an object.
ReferenceCountedObjectPtr()=default
Creates a pointer to a null object.
ReferenceCountedObjectPtr(const ReferenceCountedObjectPtr< Convertible > &other) noexcept
Copies another pointer.
void reset() noexcept
Resets this object to a null pointer.
ReferenceCountedObjectPtr(decltype(nullptr)) noexcept
Creates a pointer to a null object.
ReferencedType & operator*() const noexcept
Dereferences the object that this pointer references.
ReferenceCountedObjectPtr(const ReferenceCountedObjectPtr &other) noexcept
Copies another pointer.
ReferencedType * get() const noexcept
Returns the object that this pointer references.
A base class which provides methods for reference-counting.
ReferenceCountedObject(const ReferenceCountedObject &) noexcept
Copying from another object does not affect this one's reference-count.
ReferenceCountedObject(ReferenceCountedObject &&) noexcept
Copying from another object does not affect this one's reference-count.
void resetReferenceCount() noexcept
Resets the reference count to zero without deleting the object.
bool decReferenceCountWithoutDeleting() noexcept
Decreases the object's reference count.
ReferenceCountedObject()=default
Creates the reference-counted object (with an initial ref count of zero).
void incReferenceCount() noexcept
Increments the object's reference count.
int getReferenceCount() const noexcept
Returns the object's current reference count.
void decReferenceCount() noexcept
Decreases the object's reference count.
virtual ~ReferenceCountedObject()
Destructor.
Adds reference-counting to an object.
virtual ~SingleThreadedReferenceCountedObject()
Destructor.
SingleThreadedReferenceCountedObject(SingleThreadedReferenceCountedObject &&)
Copying from another object does not affect this one's reference-count.
SingleThreadedReferenceCountedObject(const SingleThreadedReferenceCountedObject &)
Copying from another object does not affect this one's reference-count.
SingleThreadedReferenceCountedObject()=default
Creates the reference-counted object (with an initial ref count of zero).
void decReferenceCount() noexcept
Decreases the object's reference count.
void incReferenceCount() noexcept
Increments the object's reference count.
int getReferenceCount() const noexcept
Returns the object's current reference count.
bool decReferenceCountWithoutDeleting() noexcept
Decreases the object's reference count.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
A simple wrapper around std::atomic.
Used by container classes as an indirect way to delete an object of a particular type.