Loading...
Searching...
No Matches
juce::Component::SafePointer< ComponentType > Class Template Reference

## 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.

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

- juce_gui_basics/components/juce_Component.h

## Public Member Functions

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

## Constructors and Destructors

## SafePointer() [1/3]

template<class ComponentType>

juce::Component::SafePointer< ComponentType >::SafePointer | ( |  | ) |

default

Creates a null SafePointer.

Referenced by operator!=(), operator=(), operator=(), operator==(), and 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 | ) |

inline noexcept

Creates a copy of another SafePointer.

References SafePointer().

## Member Functions

## operator=() [1/2]

template<class ComponentType>

SafePointer & juce::Component::SafePointer< ComponentType >::operator= | ( | const SafePointer< ComponentType > & | other | ) |

inline

Copies another pointer to this one.

References SafePointer().

## operator=() [2/2]

template<class ComponentType>

SafePointer & juce::Component::SafePointer< ComponentType >::operator= | ( | ComponentType * | newComponent | ) |

inline

Copies another pointer to this one.

References SafePointer().

## getComponent()

template<class ComponentType>

ComponentType * juce::Component::SafePointer< ComponentType >::getComponent | ( |  | ) | const

inline noexcept

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

Referenced by operator ComponentType *(), and operator->().

## operator ComponentType *()

template<class ComponentType>

juce::Component::SafePointer< ComponentType >::operator ComponentType * | ( |  | ) | const

inline noexcept

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

References getComponent().

## operator->()

template<class ComponentType>

ComponentType * juce::Component::SafePointer< ComponentType >::operator-> | ( |  | ) | const

inline noexcept

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

References getComponent().

## 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.

## operator==() [1/2]

template<class ComponentType>

bool juce::Component::SafePointer< ComponentType >::operator== | ( | SafePointer< ComponentType > | other | ) | const

inline noexcept

References SafePointer().

## operator!=() [1/2]

template<class ComponentType>

bool juce::Component::SafePointer< ComponentType >::operator!= | ( | SafePointer< ComponentType > | other | ) | const

inline noexcept

References SafePointer().

## operator==() [2/2]

template<class ComponentType>

bool juce::Component::SafePointer< ComponentType >::operator== | ( | ComponentType * | component | ) | const

inline noexcept

## operator!=() [2/2]

template<class ComponentType>

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

inline noexcept

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited