JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Friends | List of all members
juce::ReferenceCountedObject Class Reference

A base class which provides methods for reference-counting. More...

#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::Value::ValueSource juce::ValueTree::SharedObject juce::XEmbedComponent::Pimpl::SharedKeyWindow juce::dsp::ProcessorState juce::var::VariantType::RefCountedArray

Public Member Functions

void incReferenceCount () noexcept
 Increments the object's reference count.
 
void decReferenceCount () noexcept
 Decreases the object's reference count.
 
bool decReferenceCountWithoutDeleting () noexcept
 Decreases the object's reference count.
 
int getReferenceCount () const noexcept
 Returns the object's current reference count.
 

Protected Member Functions

 ReferenceCountedObject ()=default
 Creates the reference-counted object (with an initial ref count of zero).
 
 ReferenceCountedObject (const ReferenceCountedObject &) noexcept
 Copying from another object does not affect this one's reference-count.
 
 ReferenceCountedObject (ReferenceCountedObject &&) noexcept
 Copying from another object does not affect this one's reference-count.
 
ReferenceCountedObjectoperator= (const ReferenceCountedObject &) noexcept
 Copying from another object does not affect this one's reference-count.
 
ReferenceCountedObjectoperator= (ReferenceCountedObject &&) noexcept
 Copying from another object does not affect this one's reference-count.
 
virtual ~ReferenceCountedObject ()
 Destructor.
 
void resetReferenceCount () noexcept
 Resets the reference count to zero without deleting the object.
 

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.

{
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();
A smart-pointer class which points to a reference-counted object.
A base class which provides methods for reference-counting.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88

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}

Definition at line 65 of file juce_ReferenceCountedObject.h.

Constructor & Destructor Documentation

◆ ReferenceCountedObject() [1/2]

juce::ReferenceCountedObject::ReferenceCountedObject ( const ReferenceCountedObject )
protectednoexcept

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

Definition at line 110 of file juce_ReferenceCountedObject.h.

◆ ReferenceCountedObject() [2/2]

juce::ReferenceCountedObject::ReferenceCountedObject ( ReferenceCountedObject &&  )
protectednoexcept

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

Definition at line 112 of file juce_ReferenceCountedObject.h.

◆ ~ReferenceCountedObject()

virtual juce::ReferenceCountedObject::~ReferenceCountedObject ( )
protectedvirtual

Destructor.

Definition at line 119 of file juce_ReferenceCountedObject.h.

Member Function Documentation

◆ decReferenceCount()

void juce::ReferenceCountedObject::decReferenceCount ( )
noexcept

Decreases the object's reference count.

If the count gets to zero, the object will be deleted.

Definition at line 82 of file juce_ReferenceCountedObject.h.

◆ decReferenceCountWithoutDeleting()

bool juce::ReferenceCountedObject::decReferenceCountWithoutDeleting ( )
noexcept

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.

Definition at line 94 of file juce_ReferenceCountedObject.h.

◆ getReferenceCount()

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

Returns the object's current reference count.

Definition at line 101 of file juce_ReferenceCountedObject.h.

◆ incReferenceCount()

void juce::ReferenceCountedObject::incReferenceCount ( )
noexcept

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.

Definition at line 74 of file juce_ReferenceCountedObject.h.

◆ operator=() [1/2]

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

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

Definition at line 114 of file juce_ReferenceCountedObject.h.

◆ operator=() [2/2]

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

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

Definition at line 116 of file juce_ReferenceCountedObject.h.

◆ resetReferenceCount()

void juce::ReferenceCountedObject::resetReferenceCount ( )
protectednoexcept

Resets the reference count to zero without deleting the object.

You should probably never need to use this!

Definition at line 128 of file juce_ReferenceCountedObject.h.

Friends And Related Symbol Documentation

◆ ContainerDeletePolicy< ReferenceCountedObject >

Definition at line 135 of file juce_ReferenceCountedObject.h.


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