88 jassert (getReferenceCount() > 0);
100 jassert (getReferenceCount() > 0);
101 return --refCount == 0;
126 jassert (getReferenceCount() == 0);
140 friend struct ContainerDeletePolicy<ReferenceCountedObject>;
176 jassert (getReferenceCount() > 0);
188 jassert (getReferenceCount() > 0);
189 return --refCount == 0;
214 jassert (getReferenceCount() == 0);
249template <
class ObjectType>
267 : referencedObject (refCountedObject)
269 incIfNotNull (refCountedObject);
276 : referencedObject (&refCountedObject)
278 refCountedObject.incReferenceCount();
285 : referencedObject (other.referencedObject)
287 incIfNotNull (referencedObject);
292 : referencedObject (other.referencedObject)
294 other.referencedObject =
nullptr;
300 template <
typename Convertible>
302 : referencedObject (other.get())
304 incIfNotNull (referencedObject);
313 return operator= (other.referencedObject);
320 template <
typename Convertible>
333 if (newObject !=
nullptr)
347 if (referencedObject != &newObject)
349 newObject.incReferenceCount();
350 auto* oldObject = referencedObject;
351 referencedObject = &newObject;
352 decIfNotNull (oldObject);
368 std::swap (referencedObject, other.referencedObject);
378 decIfNotNull (referencedObject);
390 auto oldObject = referencedObject;
391 referencedObject =
nullptr;
392 decIfNotNull (oldObject);
398 jassert (referencedObject !=
nullptr);
399 return referencedObject;
408 bool operator== (
decltype (
nullptr)) const noexcept {
return referencedObject ==
nullptr; }
410 bool operator!= (
decltype (
nullptr)) const noexcept {
return referencedObject !=
nullptr; }
413 bool operator== (
const ObjectType* other)
const noexcept {
return referencedObject == other; }
417 bool operator!= (
const ObjectType* other)
const noexcept {
return referencedObject != other; }
421 #if JUCE_STRICT_REFCOUNTEDPOINTER
423 explicit operator bool() const noexcept {
return referencedObject !=
nullptr; }
446 o->incReferenceCount();
451 if (o !=
nullptr && o->decReferenceCountWithoutDeleting())
452 ContainerDeletePolicy<ReferencedType>::destroy (o);
459template <
typename Type>
460bool operator== (
const Type* object1,
const ReferenceCountedObjectPtr<Type>& object2)
noexcept
462 return object1 == object2.get();
466template <
typename Type>
467bool operator!= (
const Type* object1,
const ReferenceCountedObjectPtr<Type>& object2)
noexcept
469 return object1 != object2.get();
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.
#define JUCE_API
This macro is added to all JUCE public class declarations.
Used by container classes as an indirect way to delete an object of a particular type.