80template <
class ObjectType,
class ReferenceCountingType = ReferenceCountedObject>
127 bool operator!= (ObjectType*
object)
const noexcept {
return get() != object; }
139 inline ObjectType* get()
const noexcept {
return owner; }
140 void clearPointer()
noexcept { owner =
nullptr; }
165 jassert (sharedPointer ==
nullptr || sharedPointer->
get() ==
nullptr);
173 if (sharedPointer ==
nullptr)
180 jassert (sharedPointer->
get() !=
nullptr);
183 return sharedPointer;
192 if (sharedPointer !=
nullptr)
193 sharedPointer->clearPointer();
199 return sharedPointer ==
nullptr ? 0 : (sharedPointer->getReferenceCount() - 1);
205 JUCE_DECLARE_NON_COPYABLE (
Master)
214 return o->masterReference.getSharedPointer (
o);
241#define JUCE_DECLARE_WEAK_REFERENCEABLE(Class) \
242 struct WeakRefMaster : public juce::WeakReference<Class>::Master { ~WeakRefMaster() { this->clear(); } }; \
243 WeakRefMaster masterReference; \
244 friend class juce::WeakReference<Class>; \
Holds a resizable array of primitive or copy-by-value objects.
ReferencedType * get() const noexcept
Returns the object that this pointer references.
This class is embedded inside an object to which you want to attach WeakReference pointers.
int getNumActiveWeakReferences() const noexcept
Returns the number of WeakReferences that are out there pointing to this object.
void clear() noexcept
The object that owns this master pointer should call this before it gets destroyed,...
SharedRef getSharedPointer(ObjectType *object)
The first call to this method will create an internal object that is shared by all weak references to...
This class is used internally by the WeakReference class - don't use it directly in your code!
This class acts as a pointer which will automatically become null if the object to which it points is...
WeakReference()=default
Creates a null WeakReference.
ObjectType * get() const noexcept
Returns the object that this pointer refers to, or null if the object no longer exists.
ObjectType * operator->() noexcept
Returns the object that this pointer refers to, or null if the object no longer exists.
WeakReference(WeakReference &&other) noexcept
Move constructor.
WeakReference & operator=(const WeakReference &other)
Copies another pointer to this one.
const ObjectType * operator->() const noexcept
Returns the object that this pointer refers to, or null if the object no longer exists.
WeakReference(const WeakReference &other) noexcept
Creates a copy of another WeakReference.
bool wasObjectDeleted() const noexcept
This returns true if this reference has been pointing at an object, but that object has since been de...
WeakReference(ObjectType *object)
Creates a WeakReference that points at the given object.