80template <
class ObjectType,
class ReferenceCountingType = ReferenceCountedObject>
106 ObjectType*
get() const noexcept {
return holder !=
nullptr ? holder->
get() :
nullptr; }
109 operator ObjectType*()
const noexcept {
return get(); }
123 bool operator== (ObjectType*
object)
const noexcept {
return get() == object; }
124 bool operator!= (ObjectType*
object)
const noexcept {
return get() != object; }
134 explicit SharedPointer (ObjectType* obj) noexcept : owner (obj) {}
136 inline ObjectType* get()
const noexcept {
return owner; }
137 void clearPointer()
noexcept { owner =
nullptr; }
162 jassert (sharedPointer ==
nullptr || sharedPointer->
get() ==
nullptr);
170 if (sharedPointer ==
nullptr)
177 jassert (sharedPointer->
get() !=
nullptr);
180 return sharedPointer;
189 if (sharedPointer !=
nullptr)
190 sharedPointer->clearPointer();
196 return sharedPointer ==
nullptr ? 0 : (sharedPointer->getReferenceCount() - 1);
202 JUCE_DECLARE_NON_COPYABLE (
Master)
208 static inline SharedRef getRef (ObjectType* o)
211 return o->masterReference.getSharedPointer (o);
238#define JUCE_DECLARE_WEAK_REFERENCEABLE(Class) \
239 struct WeakRefMaster : public juce::WeakReference<Class>::Master { ~WeakRefMaster() { this->clear(); } }; \
240 WeakRefMaster masterReference; \
241 friend class juce::WeakReference<Class>; \
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...
ObjectType * operator->() const noexcept
Returns the object that this pointer refers to, or null if the object no longer exists.
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.
WeakReference(WeakReference &&other) noexcept
Move constructor.
WeakReference & operator=(const WeakReference &other)
Copies another pointer to this one.
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.