JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::Component::SafePointer< ComponentType > Class Template Reference

Holds a pointer to some type of Component, which automatically becomes null if the component is deleted. More...

#include <juce_Component.h>

Inheritance diagram for juce::Component::SafePointer< ComponentType >:
Collaboration diagram for juce::Component::SafePointer< ComponentType >:

Public Member Functions

 SafePointer () noexcept
 Creates a null SafePointer. More...
 
 SafePointer (ComponentType *component)
 Creates a SafePointer that points at the given component. More...
 
 SafePointer (const SafePointer &other) noexcept
 Creates a copy of another SafePointer. More...
 
void deleteAndZero ()
 If the component is valid, this deletes it and sets this pointer to null. More...
 
ComponentType * getComponent () const noexcept
 Returns the component that this pointer refers to, or null if the component no longer exists. More...
 
 operator ComponentType * () const noexcept
 Returns the component that this pointer refers to, or null if the component no longer exists. More...
 
bool operator!= (ComponentType *component) const noexcept
 
ComponentType * operator-> () noexcept
 Returns the component that this pointer refers to, or null if the component no longer exists. More...
 
const ComponentType * operator-> () const noexcept
 Returns the component that this pointer refers to, or null if the component no longer exists. More...
 
SafePointeroperator= (const SafePointer &other)
 Copies another pointer to this one. More...
 
SafePointeroperator= (ComponentType *newComponent)
 Copies another pointer to this one. More...
 
bool operator== (ComponentType *component) const noexcept
 

Private Attributes

WeakReference< ComponentweakRef
 

Detailed Description

template<class ComponentType>
class juce::Component::SafePointer< ComponentType >

Holds a pointer to some type of Component, which automatically becomes null if the component is deleted.

If you're using a component which may be deleted by another event that's outside of your control, use a SafePointer instead of a normal pointer to refer to it, and you can test whether it's null before using it to see if something has deleted it.

The ComponentType template parameter must be Component, or some subclass of Component.

You may also want to use a WeakReference<Component> object for the same purpose.

Constructor & Destructor Documentation

◆ SafePointer() [1/3]

template<class ComponentType>
juce::Component::SafePointer< ComponentType >::SafePointer ( )
inlinenoexcept

Creates a null SafePointer.

◆ SafePointer() [2/3]

template<class ComponentType>
juce::Component::SafePointer< ComponentType >::SafePointer ( ComponentType *  component)
inline

Creates a SafePointer that points at the given component.

◆ SafePointer() [3/3]

template<class ComponentType>
juce::Component::SafePointer< ComponentType >::SafePointer ( const SafePointer< ComponentType > &  other)
inlinenoexcept

Creates a copy of another SafePointer.

Member Function Documentation

◆ deleteAndZero()

template<class ComponentType>
void juce::Component::SafePointer< ComponentType >::deleteAndZero ( )
inline

If the component is valid, this deletes it and sets this pointer to null.

◆ getComponent()

template<class ComponentType>
ComponentType* juce::Component::SafePointer< ComponentType >::getComponent ( ) const
inlinenoexcept

Returns the component that this pointer refers to, or null if the component no longer exists.

◆ operator ComponentType *()

template<class ComponentType>
juce::Component::SafePointer< ComponentType >::operator ComponentType * ( ) const
inlinenoexcept

Returns the component that this pointer refers to, or null if the component no longer exists.

◆ operator!=()

template<class ComponentType>
bool juce::Component::SafePointer< ComponentType >::operator!= ( ComponentType *  component) const
inlinenoexcept

◆ operator->() [1/2]

template<class ComponentType>
ComponentType* juce::Component::SafePointer< ComponentType >::operator-> ( )
inlinenoexcept

Returns the component that this pointer refers to, or null if the component no longer exists.

◆ operator->() [2/2]

template<class ComponentType>
const ComponentType* juce::Component::SafePointer< ComponentType >::operator-> ( ) const
inlinenoexcept

Returns the component that this pointer refers to, or null if the component no longer exists.

◆ operator=() [1/2]

template<class ComponentType>
SafePointer& juce::Component::SafePointer< ComponentType >::operator= ( const SafePointer< ComponentType > &  other)
inline

Copies another pointer to this one.

◆ operator=() [2/2]

template<class ComponentType>
SafePointer& juce::Component::SafePointer< ComponentType >::operator= ( ComponentType *  newComponent)
inline

Copies another pointer to this one.

◆ operator==()

template<class ComponentType>
bool juce::Component::SafePointer< ComponentType >::operator== ( ComponentType *  component) const
inlinenoexcept

Member Data Documentation

◆ weakRef

template<class ComponentType>
WeakReference<Component> juce::Component::SafePointer< ComponentType >::weakRef
private

The documentation for this class was generated from the following file: