80 template <
class ObjectType,
class ReferenceCountingType = ReferenceCountedObject>
106 ObjectType*
get()
const noexcept {
return holder !=
nullptr ? holder->
get() :
nullptr; }
109 operator ObjectType*()
const noexcept {
return get(); }
115 const ObjectType*
operator->() const noexcept {
return get(); }
126 bool operator== (ObjectType*
object)
const noexcept {
return get() ==
object; }
127 bool operator!= (ObjectType*
object)
const noexcept {
return get() !=
object; }
137 explicit SharedPointer (ObjectType* obj) noexcept : owner (obj) {}
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)
211 static inline SharedRef getRef (ObjectType* o)
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>; \
bool wasObjectDeleted() const noexcept
This returns true if this reference has been pointing at an object, but that object has since been de...
void clear() noexcept
The object that owns this master pointer should call this before it gets destroyed, to zero all the references to this object that may be out there.
SharedRef getSharedPointer(ObjectType *object)
The first call to this method will create an internal object that is shared by all weak references to...
int getNumActiveWeakReferences() const noexcept
Returns the number of WeakReferences that are out there pointing to this object.
ReferencedType * get() const noexcept
Returns the object that this pointer references.
This class acts as a pointer which will automatically become null if the object to which it points is...
ObjectType * operator->() noexcept
Returns the object that this pointer refers to, or null if the object no longer exists.
WeakReference(ObjectType *object)
Creates a WeakReference that points at the given object.
const 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.
WeakReference(WeakReference &&other) noexcept
Move constructor.
WeakReference(const WeakReference &other) noexcept
Creates a copy of another WeakReference.
This class is embedded inside an object to which you want to attach WeakReference pointers...
This class is used internally by the WeakReference class - don't use it directly in your code! ...
WeakReference & operator=(const WeakReference &other)
Copies another pointer to this one.