Loading...
Searching...
No Matches
juce::OptionalScopedPointer< ObjectType > Class Template Reference

`#include <juce_OptionalScopedPointer.h>`

## Public Member Functions

| OptionalScopedPointer ()=default
| OptionalScopedPointer (ObjectType *objectToHold, bool takeOwnership)
| OptionalScopedPointer (OptionalScopedPointer &&other) noexcept
| OptionalScopedPointer (std::unique_ptr< ObjectType > &&ptr) noexcept
| OptionalScopedPointer (ObjectType &ref) noexcept
OptionalScopedPointer & | operator= (OptionalScopedPointer &&other) noexcept
| ~OptionalScopedPointer () noexcept
| operator ObjectType * () const noexcept
ObjectType * | get () const noexcept
ObjectType & | operator* () const noexcept
ObjectType * | operator-> () const noexcept
ObjectType * | release () noexcept
void | reset () noexcept
void | clear ()
void | set (ObjectType *newObject, bool takeOwnership)
void | setOwned (ObjectType *newObject)
void | setNonOwned (ObjectType *newObject)
bool | willDeleteObject () const noexcept
void | swapWith (OptionalScopedPointer< ObjectType > &other) noexcept

## Detailed Description

template<class ObjectType>
class juce::OptionalScopedPointer< ObjectType >

Holds a pointer to an object which can optionally be deleted when this pointer goes out of scope.

This acts in many ways like a std::unique_ptr, but allows you to specify whether or not the object is deleted.

Definition at line 37 of file juce_OptionalScopedPointer.h.

## Constructor & Destructor Documentation

## OptionalScopedPointer() [1/5]

template<class ObjectType>

juce::OptionalScopedPointer< ObjectType >::OptionalScopedPointer | ( |  | ) |

default

Creates an empty OptionalScopedPointer.

## OptionalScopedPointer() [2/5]

template<class ObjectType>

juce::OptionalScopedPointer< ObjectType >::OptionalScopedPointer | ( | ObjectType * | objectToHold,
|  | bool | takeOwnership )

inline

Creates an OptionalScopedPointer to point to a given object, and specifying whether the OptionalScopedPointer will delete it.

If takeOwnership is true, then the OptionalScopedPointer will act like a std::unique_ptr, deleting the object when it is itself deleted. If this parameter is false, then the OptionalScopedPointer just holds a normal pointer to the object, and won't delete it.

Definition at line 51 of file juce_OptionalScopedPointer.h.

## OptionalScopedPointer() [3/5]

template<class ObjectType>

juce::OptionalScopedPointer< ObjectType >::OptionalScopedPointer | ( | OptionalScopedPointer< ObjectType > && | other | ) |

inline noexcept

Takes ownership of the object that another OptionalScopedPointer holds.

Like a normal std::unique_ptr, the objectToTransferFrom object will become null, as ownership of the managed object is transferred to this object.

The flag to indicate whether or not to delete the managed object is also copied from the source object.

Definition at line 65 of file juce_OptionalScopedPointer.h.

## OptionalScopedPointer() [4/5]

template<class ObjectType>

juce::OptionalScopedPointer< ObjectType >::OptionalScopedPointer | ( | std::unique_ptr< ObjectType > && | ptr | ) |

inline explicit noexcept

Takes ownership of the object owned by ptr.

Definition at line 72 of file juce_OptionalScopedPointer.h.

## OptionalScopedPointer() [5/5]

template<class ObjectType>

juce::OptionalScopedPointer< ObjectType >::OptionalScopedPointer | ( | ObjectType & | ref | ) |

inline explicit noexcept

Points to the same object as ref, but does not take ownership.

Definition at line 78 of file juce_OptionalScopedPointer.h.

## ~OptionalScopedPointer()

template<class ObjectType>

juce::OptionalScopedPointer< ObjectType >::~OptionalScopedPointer | ( |  | ) |

inline noexcept

The destructor may or may not delete the object that is being held, depending on the takeOwnership flag that was specified when the object was first passed into an OptionalScopedPointer constructor.

Definition at line 102 of file juce_OptionalScopedPointer.h.

## Member Function Documentation

## clear()

template<class ObjectType>

void juce::OptionalScopedPointer< ObjectType >::clear | ( |  | ) |

inline

Does the same thing as reset().

Definition at line 138 of file juce_OptionalScopedPointer.h.

## get()

template<class ObjectType>

ObjectType * juce::OptionalScopedPointer< ObjectType >::get | ( |  | ) | const

inline noexcept

Returns the object that this pointer is managing.

Definition at line 112 of file juce_OptionalScopedPointer.h.

Referenced by juce::OptionalScopedPointer< ConvolutionMessageQueue >::set().

## operator ObjectType *()

template<class ObjectType>

juce::OptionalScopedPointer< ObjectType >::operator ObjectType * | ( |  | ) | const

inline noexcept

Returns the object that this pointer is managing.

Definition at line 109 of file juce_OptionalScopedPointer.h.

## operator*()

template<class ObjectType>

ObjectType & juce::OptionalScopedPointer< ObjectType >::operator* | ( |  | ) | const

inline noexcept

Returns the object that this pointer is managing.

Definition at line 115 of file juce_OptionalScopedPointer.h.

## operator->()

template<class ObjectType>

ObjectType * juce::OptionalScopedPointer< ObjectType >::operator-> | ( |  | ) | const

inline noexcept

Lets you access methods and properties of the object that this pointer is holding.

Definition at line 118 of file juce_OptionalScopedPointer.h.

## operator=()

template<class ObjectType>

OptionalScopedPointer & juce::OptionalScopedPointer< ObjectType >::operator= | ( | OptionalScopedPointer< ObjectType > && | other | ) |

inline noexcept

Takes ownership of the object that another OptionalScopedPointer holds.

Like a normal std::unique_ptr, the objectToTransferFrom object will become null, as ownership of the managed object is transferred to this object.

The ownership flag that says whether or not to delete the managed object is also copied from the source object.

Definition at line 91 of file juce_OptionalScopedPointer.h.

## release()

template<class ObjectType>

ObjectType * juce::OptionalScopedPointer< ObjectType >::release | ( |  | ) |

inline noexcept

Removes the current object from this OptionalScopedPointer without deleting it. This will return the current object, and set this OptionalScopedPointer to a null pointer.

Definition at line 124 of file juce_OptionalScopedPointer.h.

## reset()

template<class ObjectType>

void juce::OptionalScopedPointer< ObjectType >::reset | ( |  | ) |

inline noexcept

Resets this pointer to null, possibly deleting the object that it holds, if it has ownership of it.

Definition at line 129 of file juce_OptionalScopedPointer.h.

Referenced by juce::OptionalScopedPointer< ConvolutionMessageQueue >::clear(), juce::OptionalScopedPointer< ConvolutionMessageQueue >::set(), and juce::OptionalScopedPointer< ConvolutionMessageQueue >::~OptionalScopedPointer().

## set()

template<class ObjectType>

void juce::OptionalScopedPointer< ObjectType >::set | ( | ObjectType * | newObject,
|  | bool | takeOwnership )

inline

Makes this OptionalScopedPointer point at a new object, specifying whether the OptionalScopedPointer will take ownership of the object.

If takeOwnership is true, then the OptionalScopedPointer will act like a std::unique_ptr, deleting the object when it is itself deleted. If this parameter is false, then the OptionalScopedPointer just holds a normal pointer to the object, and won't delete it.

Definition at line 147 of file juce_OptionalScopedPointer.h.

Referenced by juce::OptionalScopedPointer< ConvolutionMessageQueue >::setNonOwned(), and juce::OptionalScopedPointer< ConvolutionMessageQueue >::setOwned().

## setNonOwned()

template<class ObjectType>

void juce::OptionalScopedPointer< ObjectType >::setNonOwned | ( | ObjectType * | newObject | ) |

inline

Makes this OptionalScopedPointer point at a new object, but will not take ownership of that object.

Definition at line 165 of file juce_OptionalScopedPointer.h.

## setOwned()

template<class ObjectType>

void juce::OptionalScopedPointer< ObjectType >::setOwned | ( | ObjectType * | newObject | ) |

inline

Makes this OptionalScopedPointer point at a new object, and take ownership of that object.

Definition at line 159 of file juce_OptionalScopedPointer.h.

## swapWith()

template<class ObjectType>

void juce::OptionalScopedPointer< ObjectType >::swapWith | ( | OptionalScopedPointer< ObjectType > & | other | ) |

inline noexcept

Swaps this object with another OptionalScopedPointer. The two objects simply exchange their states.

Definition at line 179 of file juce_OptionalScopedPointer.h.

Referenced by juce::OptionalScopedPointer< ConvolutionMessageQueue >::operator=().

## willDeleteObject()

template<class ObjectType>

bool juce::OptionalScopedPointer< ObjectType >::willDeleteObject | ( |  | ) | const

inline noexcept

Returns true if the target object will be deleted when this pointer object is deleted.

Definition at line 173 of file juce_OptionalScopedPointer.h.

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

- juce_OptionalScopedPointer.h