Loading...
Searching...
No Matches
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>

Public Member Functions

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

Detailed Description

template<class ObjectType>
class 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.

Constructor & Destructor Documentation

◆ OptionalScopedPointer() [1/5]

template<class ObjectType >
OptionalScopedPointer< ObjectType >::OptionalScopedPointer ( )
default

Creates an empty OptionalScopedPointer.

◆ OptionalScopedPointer() [2/5]

template<class ObjectType >
OptionalScopedPointer< ObjectType >::OptionalScopedPointer ( ObjectType * objectToHold,
bool takeOwnership )

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.

◆ OptionalScopedPointer() [3/5]

template<class ObjectType >
OptionalScopedPointer< ObjectType >::OptionalScopedPointer ( OptionalScopedPointer< ObjectType > && other)
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.

◆ OptionalScopedPointer() [4/5]

template<class ObjectType >
OptionalScopedPointer< ObjectType >::OptionalScopedPointer ( std::unique_ptr< ObjectType > && ptr)
explicitnoexcept

Takes ownership of the object owned by ptr.

◆ OptionalScopedPointer() [5/5]

template<class ObjectType >
OptionalScopedPointer< ObjectType >::OptionalScopedPointer ( ObjectType & ref)
explicitnoexcept

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

◆ ~OptionalScopedPointer()

template<class ObjectType >
OptionalScopedPointer< ObjectType >::~OptionalScopedPointer ( )
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.

References OptionalScopedPointer< ObjectType >::reset().

Member Function Documentation

◆ operator=()

template<class ObjectType >
OptionalScopedPointer & OptionalScopedPointer< ObjectType >::operator= ( OptionalScopedPointer< ObjectType > && other)
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.

References OptionalScopedPointer< ObjectType >::swapWith().

◆ operator ObjectType *()

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

Returns the object that this pointer is managing.

◆ get()

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

◆ operator*()

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

Returns the object that this pointer is managing.

◆ operator->()

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

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

◆ release()

template<class ObjectType >
ObjectType * OptionalScopedPointer< ObjectType >::release ( )
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.

◆ reset()

template<class ObjectType >
void OptionalScopedPointer< ObjectType >::reset ( )
noexcept

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

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

◆ clear()

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

Does the same thing as reset().

References OptionalScopedPointer< ObjectType >::reset().

◆ set()

template<class ObjectType >
void OptionalScopedPointer< ObjectType >::set ( ObjectType * newObject,
bool takeOwnership )

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.

References OptionalScopedPointer< ObjectType >::get(), and OptionalScopedPointer< ObjectType >::reset().

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

◆ setOwned()

template<class ObjectType >
void OptionalScopedPointer< ObjectType >::setOwned ( ObjectType * newObject)

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

References OptionalScopedPointer< ObjectType >::set().

Referenced by StandalonePluginHolder::showAudioSettingsDialog().

◆ setNonOwned()

template<class ObjectType >
void OptionalScopedPointer< ObjectType >::setNonOwned ( ObjectType * newObject)

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

References OptionalScopedPointer< ObjectType >::set().

◆ willDeleteObject()

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

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

◆ swapWith()

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

Swaps this object with another OptionalScopedPointer.

The two objects simply exchange their states.

Referenced by OptionalScopedPointer< ObjectType >::operator=().


The documentation for this class was generated from the following file:
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram