Public Member Functions

Component::SafePointer< ComponentType > Class Template Reference

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

List of all members.

Public Member Functions

 SafePointer () noexcept
 Creates a null SafePointer.
 SafePointer (ComponentType *const component)
 Creates a SafePointer that points at the given component.
 SafePointer (const SafePointer &other) noexcept
 Creates a copy of another SafePointer.
SafePointeroperator= (const SafePointer &other)
 Copies another pointer to this one.
SafePointeroperator= (ComponentType *const 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-> () noexcept
 Returns the component that this pointer refers to, or null if the component no longer exists.
const 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== (ComponentType *component) const noexcept
bool operator!= (ComponentType *component) const noexcept

Detailed Description

template<class ComponentType>
class 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 typedef 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

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

Creates a null SafePointer.

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

Creates a SafePointer that points at the given component.

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

Creates a copy of another SafePointer.


Member Function Documentation

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

Copies another pointer to this one.

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

Copies another pointer to this one.

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

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

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

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

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

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

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

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

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

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

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

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines