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

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

#include <juce_OptionalScopedPointer.h>

Inheritance diagram for juce::OptionalScopedPointer< ObjectType >:
Collaboration diagram for juce::OptionalScopedPointer< ObjectType >:

Public Member Functions

 OptionalScopedPointer ()
 Creates an empty OptionalScopedPointer. More...
 
 OptionalScopedPointer (ObjectType *objectToHold, bool takeOwnership)
 Creates an OptionalScopedPointer to point to a given object, and specifying whether the OptionalScopedPointer will delete it. More...
 
 OptionalScopedPointer (OptionalScopedPointer &objectToTransferFrom)
 Takes ownership of the object that another OptionalScopedPointer holds. More...
 
 ~OptionalScopedPointer ()
 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. More...
 
void clear ()
 Does the same thing as reset(). More...
 
ObjectType * get () const noexcept
 Returns the object that this pointer is managing. More...
 
 operator ObjectType * () const noexcept
 Returns the object that this pointer is managing. More...
 
ObjectType & operator* () const noexcept
 Returns the object that this pointer is managing. More...
 
ObjectType * operator-> () const noexcept
 Lets you access methods and properties of the object that this pointer is holding. More...
 
OptionalScopedPointeroperator= (OptionalScopedPointer &objectToTransferFrom)
 Takes ownership of the object that another OptionalScopedPointer holds. More...
 
ObjectType * release () noexcept
 Removes the current object from this OptionalScopedPointer without deleting it. More...
 
void reset ()
 Resets this pointer to null, possibly deleting the object that it holds, if it has ownership of it. More...
 
void set (ObjectType *newObject, bool takeOwnership)
 Makes this OptionalScopedPointer point at a new object, specifying whether the OptionalScopedPointer will take ownership of the object. More...
 
void setNonOwned (ObjectType *newObject)
 Makes this OptionalScopedPointer point at a new object, but will not take ownership of that object. More...
 
void setOwned (ObjectType *newObject)
 Makes this OptionalScopedPointer point at a new object, and take ownership of that object. More...
 
void swapWith (OptionalScopedPointer< ObjectType > &other) noexcept
 Swaps this object with another OptionalScopedPointer. More...
 
bool willDeleteObject () const noexcept
 Returns true if the target object will be deleted when this pointer object is deleted. More...
 

Private Member Functions

void setOwned (const ScopedPointer< ObjectType > &)=delete
 

Private Attributes

ScopedPointer< ObjectType > object
 
bool shouldDelete
 

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 ScopedPointer, but allows you to specify whether or not the object is deleted.

See also
ScopedPointer

{Core}

Constructor & Destructor Documentation

◆ OptionalScopedPointer() [1/3]

template<class ObjectType>
juce::OptionalScopedPointer< ObjectType >::OptionalScopedPointer ( )
inline

Creates an empty OptionalScopedPointer.

◆ OptionalScopedPointer() [2/3]

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 ScopedPointer, 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.

◆ OptionalScopedPointer() [3/3]

template<class ObjectType>
juce::OptionalScopedPointer< ObjectType >::OptionalScopedPointer ( OptionalScopedPointer< ObjectType > &  objectToTransferFrom)
inline

Takes ownership of the object that another OptionalScopedPointer holds.

Like a normal ScopedPointer, 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.

◆ ~OptionalScopedPointer()

template<class ObjectType>
juce::OptionalScopedPointer< ObjectType >::~OptionalScopedPointer ( )
inline

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.

Member Function Documentation

◆ clear()

template<class ObjectType>
void juce::OptionalScopedPointer< ObjectType >::clear ( )
inline

Does the same thing as reset().

◆ get()

template<class ObjectType>
ObjectType* juce::OptionalScopedPointer< ObjectType >::get ( ) const
inlinenoexcept

Returns the object that this pointer is managing.

◆ operator ObjectType *()

template<class ObjectType>
juce::OptionalScopedPointer< ObjectType >::operator ObjectType * ( ) const
inlinenoexcept

Returns the object that this pointer is managing.

◆ operator*()

template<class ObjectType>
ObjectType& juce::OptionalScopedPointer< ObjectType >::operator* ( ) const
inlinenoexcept

Returns the object that this pointer is managing.

◆ operator->()

template<class ObjectType>
ObjectType* juce::OptionalScopedPointer< ObjectType >::operator-> ( ) const
inlinenoexcept

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

◆ operator=()

template<class ObjectType>
OptionalScopedPointer& juce::OptionalScopedPointer< ObjectType >::operator= ( OptionalScopedPointer< ObjectType > &  objectToTransferFrom)
inline

Takes ownership of the object that another OptionalScopedPointer holds.

Like a normal ScopedPointer, 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.

◆ release()

template<class ObjectType>
ObjectType* juce::OptionalScopedPointer< ObjectType >::release ( )
inlinenoexcept

Removes the current object from this OptionalScopedPointer without deleting it.

This will return the current object, and set this OptionalScopedPointer to a null pointer.

◆ reset()

template<class ObjectType>
void juce::OptionalScopedPointer< ObjectType >::reset ( )
inline

◆ 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 ScopedPointer, 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.

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

◆ setOwned() [1/2]

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.

◆ setOwned() [2/2]

template<class ObjectType>
void juce::OptionalScopedPointer< ObjectType >::setOwned ( const ScopedPointer< ObjectType > &  )
privatedelete

◆ swapWith()

template<class ObjectType>
void juce::OptionalScopedPointer< ObjectType >::swapWith ( OptionalScopedPointer< ObjectType > &  other)
inlinenoexcept

Swaps this object with another OptionalScopedPointer.

The two objects simply exchange their states.

◆ willDeleteObject()

template<class ObjectType>
bool juce::OptionalScopedPointer< ObjectType >::willDeleteObject ( ) const
inlinenoexcept

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

Member Data Documentation

◆ object

◆ shouldDelete


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