83 jassert (getReferenceCount() > 0);
95 jassert (getReferenceCount() > 0);
96 return --refCount == 0;
121 jassert (getReferenceCount() == 0);
171 jassert (getReferenceCount() > 0);
183 jassert (getReferenceCount() > 0);
184 return --refCount == 0;
209 jassert (getReferenceCount() == 0);
244 template <
class ObjectType>
249 using ReferencedType = ObjectType;
262 : referencedObject (refCountedObject)
264 incIfNotNull (refCountedObject);
271 : referencedObject (&refCountedObject)
273 refCountedObject.incReferenceCount();
280 : referencedObject (other.referencedObject)
282 incIfNotNull (referencedObject);
287 : referencedObject (other.referencedObject)
289 other.referencedObject =
nullptr;
295 template <
typename Convertible>
297 : referencedObject (other.get())
299 incIfNotNull (referencedObject);
308 return operator= (other.referencedObject);
315 template <
typename Convertible>
318 return operator= (other.
get());
328 if (newObject !=
nullptr)
329 return operator= (*newObject);
342 if (referencedObject != &newObject)
344 newObject.incReferenceCount();
345 auto* oldObject = referencedObject;
346 referencedObject = &newObject;
347 decIfNotNull (oldObject);
363 std::swap (referencedObject, other.referencedObject);
373 decIfNotNull (referencedObject);
380 ReferencedType*
get()
const noexcept {
return referencedObject; }
385 auto oldObject = referencedObject;
386 referencedObject =
nullptr;
387 decIfNotNull (oldObject);
391 ReferencedType* operator->()
const noexcept
393 jassert (referencedObject !=
nullptr);
394 return referencedObject;
400 ReferencedType&
operator*() const noexcept { jassert (referencedObject !=
nullptr);
return *referencedObject; }
403 bool operator== (decltype (
nullptr)) const noexcept {
return referencedObject ==
nullptr; }
405 bool operator!= (decltype (
nullptr)) const noexcept {
return referencedObject !=
nullptr; }
408 bool operator== (
const ObjectType* other)
const noexcept {
return referencedObject == other; }
412 bool operator!= (
const ObjectType* other)
const noexcept {
return referencedObject != other; }
416 #if JUCE_STRICT_REFCOUNTEDPOINTER 418 explicit operator bool()
const noexcept {
return referencedObject !=
nullptr; }
427 operator ReferencedType*()
const noexcept {
return referencedObject; }
432 JUCE_DEPRECATED_WITH_BODY (ReferencedType* getObject()
const, {
return get(); })
436 ReferencedType* referencedObject =
nullptr;
438 static void incIfNotNull (ReferencedType* o) noexcept
441 o->incReferenceCount();
444 static void decIfNotNull (ReferencedType* o) noexcept
446 if (o !=
nullptr && o->decReferenceCountWithoutDeleting())
454 template <
typename Type>
457 return object1 == object2.
get();
461 template <
typename Type>
464 return object1 != object2.
get();
#define JUCE_API
This macro is added to all JUCE public class declarations.
bool decReferenceCountWithoutDeleting() noexcept
Decreases the object's reference count.
ReferenceCountedObjectPtr(ReferenceCountedObjectPtr &&other) noexcept
Takes-over the object from another pointer.
void decReferenceCount() noexcept
Decreases the object's reference count.
int getReferenceCount() const noexcept
Returns the object's current reference count.
ReferenceCountedObjectPtr(const ReferenceCountedObjectPtr &other) noexcept
Copies another pointer.
virtual ~SingleThreadedReferenceCountedObject()
Destructor.
void reset() noexcept
Resets this object to a null pointer.
void decReferenceCount() noexcept
Decreases the object's reference count.
void incReferenceCount() noexcept
Increments the object's reference count.
ReferenceCountedObject(ReferenceCountedObject &&) noexcept
Copying from another object does not affect this one's reference-count.
int getReferenceCount() const noexcept
Returns the object's current reference count.
SingleThreadedReferenceCountedObject(const SingleThreadedReferenceCountedObject &)
Copying from another object does not affect this one's reference-count.
void incReferenceCount() noexcept
Increments the object's reference count.
ReferencedType & operator*() const noexcept
Dereferences the object that this pointer references.
void resetReferenceCount() noexcept
Resets the reference count to zero without deleting the object.
SingleThreadedReferenceCountedObject(SingleThreadedReferenceCountedObject &&)
Copying from another object does not affect this one's reference-count.
ReferencedType * get() const noexcept
Returns the object that this pointer references.
~ReferenceCountedObjectPtr()
Destructor.
Used by container classes as an indirect way to delete an object of a particular type.
Adds reference-counting to an object.
virtual ~ReferenceCountedObject()
Destructor.
ReferenceCountedObjectPtr(decltype(nullptr)) noexcept
Creates a pointer to a null object.
A smart-pointer class which points to a reference-counted object.
ReferenceCountedObjectPtr(ReferencedType *refCountedObject) noexcept
Creates a pointer to an object.
A base class which provides methods for reference-counting.
bool decReferenceCountWithoutDeleting() noexcept
Decreases the object's reference count.
ReferenceCountedObject(const ReferenceCountedObject &) noexcept
Copying from another object does not affect this one's reference-count.
ReferenceCountedObjectPtr(const ReferenceCountedObjectPtr< Convertible > &other) noexcept
Copies another pointer.
ReferenceCountedObjectPtr(ReferencedType &refCountedObject) noexcept
Creates a pointer to an object.