JUCE  v5.1.1-3-g1a0b28c73
JUCE API
ReferenceCountedObjectPtr< ReferenceCountedObjectClass > Class Template Reference

A smart-pointer class which points to a reference-counted object. More...

#include <juce_ReferenceCountedObject.h>

Inheritance diagram for ReferenceCountedObjectPtr< ReferenceCountedObjectClass >:
Collaboration diagram for ReferenceCountedObjectPtr< ReferenceCountedObjectClass >:

Public Types

typedef ReferenceCountedObjectClass ReferencedType
 The class being referenced by this pointer. More...
 

Public Member Functions

 ReferenceCountedObjectPtr () noexcept
 Creates a pointer to a null object. More...
 
 ReferenceCountedObjectPtr (ReferencedType *refCountedObject) noexcept
 Creates a pointer to an object. More...
 
 ReferenceCountedObjectPtr (decltype(nullptr)) noexcept
 Creates a pointer to a null object. More...
 
 ReferenceCountedObjectPtr (const ReferenceCountedObjectPtr &other) noexcept
 Copies another pointer. More...
 
template<typename Convertible >
 ReferenceCountedObjectPtr (const ReferenceCountedObjectPtr< Convertible > &other) noexcept
 Copies another pointer. More...
 
 ReferenceCountedObjectPtr (ReferenceCountedObjectPtr &&other) noexcept
 Takes-over the object from another pointer. More...
 
 ~ReferenceCountedObjectPtr ()
 Destructor. More...
 
ReferencedTypeget () const noexcept
 Returns the object that this pointer references. More...
 
ReferencedTypegetObject () const noexcept
 Returns the object that this pointer references. More...
 
 operator ReferencedType * () const noexcept
 Returns the object that this pointer references. More...
 
ReferencedTypeoperator-> () const noexcept
 
ReferenceCountedObjectPtroperator= (const ReferenceCountedObjectPtr &other)
 Changes this pointer to point at a different object. More...
 
template<typename Convertible >
ReferenceCountedObjectPtroperator= (const ReferenceCountedObjectPtr< Convertible > &other)
 Changes this pointer to point at a different object. More...
 
ReferenceCountedObjectPtroperator= (ReferencedType *const newObject)
 Changes this pointer to point at a different object. More...
 
ReferenceCountedObjectPtroperator= (ReferenceCountedObjectPtr &&other)
 Takes-over the object from another pointer. More...
 

Static Private Member Functions

static void decIfNotNull (ReferencedType *o) noexcept
 
static void incIfNotNull (ReferencedType *o) noexcept
 

Private Attributes

ReferencedTypereferencedObject
 

Detailed Description

template<class ReferenceCountedObjectClass>
class ReferenceCountedObjectPtr< ReferenceCountedObjectClass >

A smart-pointer class which points to a reference-counted object.

The template parameter specifies the class of the object you want to point to - the easiest way to make a class reference-countable is to simply make it inherit from ReferenceCountedObject or SingleThreadedReferenceCountedObject, but if you need to, you can roll your own reference-countable class by implementing a set of methods called incReferenceCount(), decReferenceCount(), and decReferenceCountWithoutDeleting(). See ReferenceCountedObject for examples of how these methods should behave.

When using this class, you'll probably want to create a typedef to abbreviate the full templated name - e.g.

struct MyClass : public ReferenceCountedObject
{
...
See also
ReferenceCountedObject, ReferenceCountedObjectArray

Member Typedef Documentation

◆ ReferencedType

template<class ReferenceCountedObjectClass>
typedef ReferenceCountedObjectClass ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::ReferencedType

The class being referenced by this pointer.

Constructor & Destructor Documentation

◆ ReferenceCountedObjectPtr() [1/6]

template<class ReferenceCountedObjectClass>
ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::ReferenceCountedObjectPtr ( )
inlinenoexcept

Creates a pointer to a null object.

◆ ReferenceCountedObjectPtr() [2/6]

template<class ReferenceCountedObjectClass>
ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::ReferenceCountedObjectPtr ( ReferencedType refCountedObject)
inlinenoexcept

Creates a pointer to an object.

This will increment the object's reference-count.

◆ ReferenceCountedObjectPtr() [3/6]

template<class ReferenceCountedObjectClass>
ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::ReferenceCountedObjectPtr ( decltype(nullptr)  )
inlinenoexcept

Creates a pointer to a null object.

◆ ReferenceCountedObjectPtr() [4/6]

template<class ReferenceCountedObjectClass>
ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::ReferenceCountedObjectPtr ( const ReferenceCountedObjectPtr< ReferenceCountedObjectClass > &  other)
inlinenoexcept

Copies another pointer.

This will increment the object's reference-count.

◆ ReferenceCountedObjectPtr() [5/6]

template<class ReferenceCountedObjectClass>
template<typename Convertible >
ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::ReferenceCountedObjectPtr ( const ReferenceCountedObjectPtr< Convertible > &  other)
inlinenoexcept

Copies another pointer.

This will increment the object's reference-count (if it is non-null).

◆ ReferenceCountedObjectPtr() [6/6]

template<class ReferenceCountedObjectClass>
ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::ReferenceCountedObjectPtr ( ReferenceCountedObjectPtr< ReferenceCountedObjectClass > &&  other)
inlinenoexcept

Takes-over the object from another pointer.

◆ ~ReferenceCountedObjectPtr()

template<class ReferenceCountedObjectClass>
ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::~ReferenceCountedObjectPtr ( )
inline

Destructor.

This will decrement the object's reference-count, which will cause the object to be deleted when the ref-count hits zero.

Member Function Documentation

◆ decIfNotNull()

template<class ReferenceCountedObjectClass>
static void ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::decIfNotNull ( ReferencedType o)
inlinestaticprivatenoexcept

◆ get()

template<class ReferenceCountedObjectClass>
ReferencedType* ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::get ( ) const
inlinenoexcept

Returns the object that this pointer references.

The pointer returned may be null, of course.

Referenced by WeakReference< InterprocessConnection >::get(), ReferenceCountedObjectPtr< ImagePixelData >::operator=(), and WeakReference< InterprocessConnection >::wasObjectDeleted().

◆ getObject()

template<class ReferenceCountedObjectClass>
ReferencedType* ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::getObject ( ) const
inlinenoexcept

Returns the object that this pointer references.

The pointer returned may be null, of course.

◆ incIfNotNull()

template<class ReferenceCountedObjectClass>
static void ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::incIfNotNull ( ReferencedType o)
inlinestaticprivatenoexcept

◆ operator ReferencedType *()

template<class ReferenceCountedObjectClass>
ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::operator ReferencedType * ( ) const
inlinenoexcept

Returns the object that this pointer references.

The pointer returned may be null, of course.

◆ operator->()

template<class ReferenceCountedObjectClass>
ReferencedType* ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::operator-> ( ) const
inlinenoexcept

◆ operator=() [1/4]

template<class ReferenceCountedObjectClass>
ReferenceCountedObjectPtr& ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::operator= ( const ReferenceCountedObjectPtr< ReferenceCountedObjectClass > &  other)
inline

Changes this pointer to point at a different object.

The reference count of the old object is decremented, and it might be deleted if it hits zero. The new object's count is incremented.

◆ operator=() [2/4]

template<class ReferenceCountedObjectClass>
template<typename Convertible >
ReferenceCountedObjectPtr& ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::operator= ( const ReferenceCountedObjectPtr< Convertible > &  other)
inline

Changes this pointer to point at a different object.

The reference count of the old object is decremented, and it might be deleted if it hits zero. The new object's count is incremented.

◆ operator=() [3/4]

template<class ReferenceCountedObjectClass>
ReferenceCountedObjectPtr& ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::operator= ( ReferencedType *const  newObject)
inline

Changes this pointer to point at a different object.

The reference count of the old object is decremented, and it might be deleted if it hits zero. The new object's count is incremented.

◆ operator=() [4/4]

template<class ReferenceCountedObjectClass>
ReferenceCountedObjectPtr& ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::operator= ( ReferenceCountedObjectPtr< ReferenceCountedObjectClass > &&  other)
inline

Takes-over the object from another pointer.

Member Data Documentation

◆ referencedObject

template<class ReferenceCountedObjectClass>
ReferencedType* ReferenceCountedObjectPtr< ReferenceCountedObjectClass >::referencedObject
private

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