ReferenceCountedObjectPtr< ObjectType > Class Template Reference
juce_core » memory

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

## Public Types

using | ReferencedType = ObjectType
| The class being referenced by this pointer. More...

## Public Member Functions

| ReferenceCountedObjectPtr ()=default
| Creates a pointer to a null object. More...
| ReferenceCountedObjectPtr (decltype(nullptr)) noexcept
| Creates a pointer to a null object. More...
| ReferenceCountedObjectPtr (ReferencedType *refCountedObject) noexcept
| Creates a pointer to an object. More...
| ReferenceCountedObjectPtr (ReferencedType &refCountedObject) noexcept
| Creates a pointer to an object. More...
| ReferenceCountedObjectPtr (const ReferenceCountedObjectPtr &other) noexcept
| Copies another pointer. More...
| ReferenceCountedObjectPtr (ReferenceCountedObjectPtr &&other) noexcept
| Takes-over the object from another pointer. More...
template<typename Convertible >
| ReferenceCountedObjectPtr (const ReferenceCountedObjectPtr< Convertible > &other) noexcept
| Copies another pointer. More...
ReferenceCountedObjectPtr & | operator= (const ReferenceCountedObjectPtr &other)
| Changes this pointer to point at a different object. More...
template<typename Convertible >
ReferenceCountedObjectPtr & | operator= (const ReferenceCountedObjectPtr< Convertible > &other)
| Changes this pointer to point at a different object. More...
ReferenceCountedObjectPtr & | operator= (ReferencedType *newObject)
| Changes this pointer to point at a different object. More...
ReferenceCountedObjectPtr & | operator= (ReferencedType &newObject)
| Changes this pointer to point at a different object. More...
ReferenceCountedObjectPtr & | operator= (decltype(nullptr))
| Resets this pointer to a null pointer. More...
ReferenceCountedObjectPtr & | operator= (ReferenceCountedObjectPtr &&other) noexcept
| Takes-over the object from another pointer. More...
| ~ReferenceCountedObjectPtr ()
| Destructor. More...
ReferencedType * | get () const noexcept
| Returns the object that this pointer references. More...
void | reset () noexcept
| Resets this object to a null pointer. More...
ReferencedType * | operator-> () const noexcept
ReferencedType & | operator* () const noexcept
| Dereferences the object that this pointer references. More...
bool | operator== (decltype(nullptr)) const noexcept
| Checks whether this pointer is null. More...
bool | operator!= (decltype(nullptr)) const noexcept
| Checks whether this pointer is null. More...
bool | operator== (const ObjectType *other) const noexcept
| Compares two ReferenceCountedObjectPtrs. More...
bool | operator== (const ReferenceCountedObjectPtr &other) const noexcept
| Compares two ReferenceCountedObjectPtrs. More...
bool | operator!= (const ObjectType *other) const noexcept
| Compares two ReferenceCountedObjectPtrs. More...
bool | operator!= (const ReferenceCountedObjectPtr &other) const noexcept
| Compares two ReferenceCountedObjectPtrs. More...
| operator ReferencedType * () const noexcept
| Returns the object that this pointer references. More...

## Static Public Member Functions

static void | decIfNotNull (ReferencedType *o) noexcept

## Static Public Attributes

static JUCE_DEPRECATED_WITH_BODY(ReferencedType *getObject() const, { return get();}) private voi | incIfNotNull )(ReferencedType *o) noexcept

## Detailed Description

### template<class ObjectType>
class ReferenceCountedObjectPtr< ObjectType >

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
{
using Ptr = ReferenceCountedObjectPtr<MyClass>;
...
}

See also
  ReferenceCountedObject, ReferenceCountedObjectArray

## Member Typedef Documentation

## ReferencedType

template<class ObjectType>

using ReferenceCountedObjectPtr< ObjectType >::ReferencedType = ObjectType

The class being referenced by this pointer.

## Constructor & Destructor Documentation

## ReferenceCountedObjectPtr() [1/7]

template<class ObjectType>

ReferenceCountedObjectPtr< ObjectType >::ReferenceCountedObjectPtr | ( |  | ) |

default

Creates a pointer to a null object.

## ReferenceCountedObjectPtr() [2/7]

template<class ObjectType>

ReferenceCountedObjectPtr< ObjectType >::ReferenceCountedObjectPtr | ( | decltype(nullptr) |  | ) |

noexcept

Creates a pointer to a null object.

## ReferenceCountedObjectPtr() [3/7]

template<class ObjectType>

ReferenceCountedObjectPtr< ObjectType >::ReferenceCountedObjectPtr | ( | ReferencedType * | refCountedObject | ) |

noexcept

Creates a pointer to an object.

This will increment the object's reference-count.

## ReferenceCountedObjectPtr() [4/7]

template<class ObjectType>

ReferenceCountedObjectPtr< ObjectType >::ReferenceCountedObjectPtr | ( | ReferencedType & | refCountedObject | ) |

noexcept

Creates a pointer to an object.

This will increment the object's reference-count.

## ReferenceCountedObjectPtr() [5/7]

template<class ObjectType>

ReferenceCountedObjectPtr< ObjectType >::ReferenceCountedObjectPtr | ( | const ReferenceCountedObjectPtr< ObjectType > & | other | ) |

noexcept

Copies another pointer.

This will increment the object's reference-count.

## ReferenceCountedObjectPtr() [6/7]

template<class ObjectType>

ReferenceCountedObjectPtr< ObjectType >::ReferenceCountedObjectPtr | ( | ReferenceCountedObjectPtr< ObjectType > && | other | ) |

noexcept

Takes-over the object from another pointer.

## ReferenceCountedObjectPtr() [7/7]

template<class ObjectType>
template<typename Convertible >

ReferenceCountedObjectPtr< ObjectType >::ReferenceCountedObjectPtr | ( | const ReferenceCountedObjectPtr< Convertible > & | other | ) |

noexcept

Copies another pointer.

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

## ~ReferenceCountedObjectPtr()

template<class ObjectType>

ReferenceCountedObjectPtr< ObjectType >::~ReferenceCountedObjectPtr | ( |  | ) |

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

## operator=() [1/6]

template<class ObjectType>

ReferenceCountedObjectPtr& ReferenceCountedObjectPtr< ObjectType >::operator= | ( | const ReferenceCountedObjectPtr< ObjectType > & | other | ) |

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.

Referenced by ReferenceCountedObjectPtr< ImagePixelData >::operator=().

## operator=() [2/6]

template<class ObjectType>
template<typename Convertible >

ReferenceCountedObjectPtr& ReferenceCountedObjectPtr< ObjectType >::operator= | ( | const ReferenceCountedObjectPtr< Convertible > & | other | ) |

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/6]

template<class ObjectType>

ReferenceCountedObjectPtr& ReferenceCountedObjectPtr< ObjectType >::operator= | ( | ReferencedType * | newObject | ) |

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/6]

template<class ObjectType>

ReferenceCountedObjectPtr& ReferenceCountedObjectPtr< ObjectType >::operator= | ( | ReferencedType & | newObject | ) |

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=() [5/6]

template<class ObjectType>

ReferenceCountedObjectPtr& ReferenceCountedObjectPtr< ObjectType >::operator= | ( | decltype(nullptr) |  | ) |

Resets this pointer to a null pointer.

## operator=() [6/6]

template<class ObjectType>

ReferenceCountedObjectPtr& ReferenceCountedObjectPtr< ObjectType >::operator= | ( | ReferenceCountedObjectPtr< ObjectType > && | other | ) |

noexcept

Takes-over the object from another pointer.

## get()

template<class ObjectType>

ReferencedType* ReferenceCountedObjectPtr< ObjectType >::get | ( |  | ) | const

noexcept

Returns the object that this pointer references.

The pointer returned may be null, of course.

Referenced by ReferenceCountedArray< AudioProcessorGraph::Node >::add(), ReferenceCountedArray< AudioProcessorGraph::Node >::addIfNotAlreadyThere(), WeakReference< LookAndFeel >::get(), WeakReference< ObjectType, ReferenceCountingType >::Master::getSharedPointer(), ReferenceCountedArray< AudioProcessorGraph::Node >::insert(), ReferenceCountedObjectPtr< ImagePixelData >::operator=(), ReferenceCountedArray< AudioProcessorGraph::Node >::removeObject(), ReferenceCountedArray< AudioProcessorGraph::Node >::set(), WeakReference< LookAndFeel >::wasObjectDeleted(), and WeakReference< ObjectType, ReferenceCountingType >::Master::~Master().

## reset()

template<class ObjectType>

void ReferenceCountedObjectPtr< ObjectType >::reset | ( |  | ) |

noexcept

Resets this object to a null pointer.

Referenced by ReferenceCountedObjectPtr< ImagePixelData >::operator=().

## operator->()

template<class ObjectType>

ReferencedType* ReferenceCountedObjectPtr< ObjectType >::operator-> | ( |  | ) | const

noexcept

## operator*()

template<class ObjectType>

ReferencedType& ReferenceCountedObjectPtr< ObjectType >::operator* | ( |  | ) | const

noexcept

Dereferences the object that this pointer references.

The pointer returned may be null, of course.

## operator==() [1/3]

template<class ObjectType>

bool ReferenceCountedObjectPtr< ObjectType >::operator== | ( | decltype(nullptr) |  | ) | const

noexcept

Checks whether this pointer is null.

## operator!=() [1/3]

template<class ObjectType>

bool ReferenceCountedObjectPtr< ObjectType >::operator!= | ( | decltype(nullptr) |  | ) | const

noexcept

Checks whether this pointer is null.

## operator==() [2/3]

template<class ObjectType>

bool ReferenceCountedObjectPtr< ObjectType >::operator== | ( | const ObjectType * | other | ) | const

noexcept

Compares two ReferenceCountedObjectPtrs.

## operator==() [3/3]

template<class ObjectType>

bool ReferenceCountedObjectPtr< ObjectType >::operator== | ( | const ReferenceCountedObjectPtr< ObjectType > & | other | ) | const

noexcept

Compares two ReferenceCountedObjectPtrs.

## operator!=() [2/3]

template<class ObjectType>

bool ReferenceCountedObjectPtr< ObjectType >::operator!= | ( | const ObjectType * | other | ) | const

noexcept

Compares two ReferenceCountedObjectPtrs.

## operator!=() [3/3]

template<class ObjectType>

bool ReferenceCountedObjectPtr< ObjectType >::operator!= | ( | const ReferenceCountedObjectPtr< ObjectType > & | other | ) | const

noexcept

Compares two ReferenceCountedObjectPtrs.

## operator ReferencedType *()

template<class ObjectType>

ReferenceCountedObjectPtr< ObjectType >::operator ReferencedType * | ( |  | ) | const

noexcept

Returns the object that this pointer references.

The pointer returned may be null, of course. Note that this methods allows the compiler to be very lenient with what it allows you to do with the pointer, it's safer to disable this by setting JUCE_STRICT_REFCOUNTEDPOINTER=1, which increased type safety and can prevent some common slip-ups.

## decIfNotNull()

template<class ObjectType>

static void ReferenceCountedObjectPtr< ObjectType >::decIfNotNull | ( | ReferencedType * | o | ) |

static noexcept

Referenced by ReferenceCountedObjectPtr< ImagePixelData >::operator=(), ReferenceCountedObjectPtr< ImagePixelData >::reset(), and ReferenceCountedObjectPtr< ImagePixelData >::~ReferenceCountedObjectPtr().

## Member Data Documentation

## incIfNotNull

template<class ObjectType>

JUCE_DEPRECATED_WITH_BODY (ReferencedType* getObject() const, { return get(); }) private voi ReferenceCountedObjectPtr< ObjectType >::incIfNotNull) (ReferencedType *o) noexcept

static noexcept

Referenced by ReferenceCountedObjectPtr< ImagePixelData >::ReferenceCountedObjectPtr().

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

- juce_ReferenceCountedObject.h

ReferenceCountedObject
A base class which provides methods for reference-counting.
Definition: juce_ReferenceCountedObject.h:66
ReferenceCountedObjectPtr
A smart-pointer class which points to a reference-counted object.
Definition: juce_ReferenceCountedObject.h:247