LMMS
Loading...
Searching...
No Matches
juce::ReferenceCountedObject Class Reference

#include <juce_ReferenceCountedObject.h>

Inheritance diagram for juce::ReferenceCountedObject:
juce::AudioDeviceManager::LevelMeter juce::AudioProcessorGraph::Node juce::CurrentThreadHolder juce::DynamicObject juce::FTFaceWrapper juce::FTLibWrapper juce::Font::SharedFontInternal juce::ImagePixelData juce::MessageManager::MessageBase juce::RenderingHelpers::CachedGlyphEdgeTable< RendererType > juce::SynthesiserSound juce::Typeface juce::URL::Upload juce::Value::ValueSource juce::ValueTree::SharedObject juce::Win32MidiService::MidiInCollector juce::Win32MidiService::MidiOutHandle juce::XEmbedComponent::Pimpl::SharedKeyWindow juce::dsp::ProcessorState juce::var::VariantType::RefCountedArray

Public Member Functions

void incReferenceCount () noexcept
void decReferenceCount () noexcept
bool decReferenceCountWithoutDeleting () noexcept
int getReferenceCount () const noexcept

Protected Member Functions

 ReferenceCountedObject ()=default
 ReferenceCountedObject (const ReferenceCountedObject &) noexcept
 ReferenceCountedObject (ReferenceCountedObject &&) noexcept
ReferenceCountedObjectoperator= (const ReferenceCountedObject &) noexcept
ReferenceCountedObjectoperator= (ReferenceCountedObject &&) noexcept
virtual ~ReferenceCountedObject ()
void resetReferenceCount () noexcept

Private Attributes

Atomic< intrefCount { 0 }

Friends

struct ContainerDeletePolicy< ReferenceCountedObject >

Detailed Description

A base class which provides methods for reference-counting.

To add reference-counting to a class, derive it from this class, and use the ReferenceCountedObjectPtr class to point to it.

e.g.

class MyClass : public ReferenceCountedObject
{
void foo();
// This is a neat way of declaring a typedef for a pointer class,
// rather than typing out the full templated name each time..
};
MyClass::Ptr p = new MyClass();
MyClass::Ptr p2 = p;
p = nullptr;
p2->foo();
Definition juce_ReferenceCountedObject.h:247
uch * p
Definition crypt.c:594

Once a new ReferenceCountedObject has been assigned to a pointer, be careful not to delete the object manually.

This class uses an Atomic<int> value to hold the reference count, so the reference count can be updated on multiple threads. Note that whilst it's thread-safe to create and delete a ReferenceCountedObjectPtr to a ReferenceCountedObject shared between threads, it's not thread-safe to modify or swap the ReferenceCountedObject.

For a faster but non-thread-safe version, use SingleThreadedReferenceCountedObject instead.

See also
ReferenceCountedObjectPtr, ReferenceCountedArray, SingleThreadedReferenceCountedObject

@tags{Core}

Constructor & Destructor Documentation

◆ ReferenceCountedObject() [1/3]

juce::ReferenceCountedObject::ReferenceCountedObject ( )
protecteddefault

Creates the reference-counted object (with an initial ref count of zero).

◆ ReferenceCountedObject() [2/3]

juce::ReferenceCountedObject::ReferenceCountedObject ( const ReferenceCountedObject & )
inlineprotectednoexcept

Copying from another object does not affect this one's reference-count.

◆ ReferenceCountedObject() [3/3]

juce::ReferenceCountedObject::ReferenceCountedObject ( ReferenceCountedObject && )
inlineprotectednoexcept

Copying from another object does not affect this one's reference-count.

◆ ~ReferenceCountedObject()

virtual juce::ReferenceCountedObject::~ReferenceCountedObject ( )
inlineprotectedvirtual

Destructor.

Member Function Documentation

◆ decReferenceCount()

void juce::ReferenceCountedObject::decReferenceCount ( )
inlinenoexcept

Decreases the object's reference count. If the count gets to zero, the object will be deleted.

◆ decReferenceCountWithoutDeleting()

bool juce::ReferenceCountedObject::decReferenceCountWithoutDeleting ( )
inlinenoexcept

Decreases the object's reference count. If the count gets to zero, the object will not be deleted, but this method will return true, allowing the caller to take care of deletion.

◆ getReferenceCount()

int juce::ReferenceCountedObject::getReferenceCount ( ) const
inlinenoexcept

Returns the object's current reference count.

◆ incReferenceCount()

void juce::ReferenceCountedObject::incReferenceCount ( )
inlinenoexcept

Increments the object's reference count.

This is done automatically by the smart pointer, but is public just in case it's needed for nefarious purposes.

◆ operator=() [1/2]

ReferenceCountedObject & juce::ReferenceCountedObject::operator= ( const ReferenceCountedObject & )
inlineprotectednoexcept

Copying from another object does not affect this one's reference-count.

◆ operator=() [2/2]

ReferenceCountedObject & juce::ReferenceCountedObject::operator= ( ReferenceCountedObject && )
inlineprotectednoexcept

Copying from another object does not affect this one's reference-count.

◆ resetReferenceCount()

void juce::ReferenceCountedObject::resetReferenceCount ( )
inlineprotectednoexcept

Resets the reference count to zero without deleting the object. You should probably never need to use this!

◆ ContainerDeletePolicy< ReferenceCountedObject >

Member Data Documentation

◆ refCount

Atomic<int> juce::ReferenceCountedObject::refCount { 0 }
private

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