#include <juce_SharedResourcePointer.h>
Public Member Functions | |
SharedResourcePointer ()=default | |
SharedResourcePointer (const SharedResourcePointer &)=default | |
SharedResourcePointer (SharedResourcePointer &&) noexcept=default | |
~SharedResourcePointer ()=default | |
operator SharedObjectType * () const noexcept | |
SharedObjectType & | get () const noexcept |
SharedObjectType & | getObject () const noexcept |
SharedObjectType * | operator-> () const noexcept |
SharedObjectType & | operator* () const noexcept |
int | getReferenceCount () const noexcept |
Static Public Member Functions | |
static std::optional< SharedResourcePointer > | getSharedObjectWithoutCreating () |
A smart-pointer that automatically creates and manages the lifetime of a shared static instance of a class.
The SharedObjectType template type indicates the class to use for the shared object - the only requirements on this class are that it must have a public default constructor and destructor.
The SharedResourcePointer offers a pattern that differs from using a singleton or static instance of an object, because it uses reference-counting to make sure that the underlying shared object is automatically created/destroyed according to the number of SharedResourcePointer objects that exist. When the last one is deleted, the underlying object is also immediately destroyed. This allows you to use scoping to manage the lifetime of a shared resource.
Note: The construction/deletion of the shared object must not involve any code that makes recursive calls to a SharedResourcePointer, or you'll cause a deadlock.
Example:
Definition at line 81 of file juce_SharedResourcePointer.h.
|
default |
Creates an instance of the shared object. If other SharedResourcePointer objects for this type already exist, then this one will simply point to the same shared object that they are already using. Otherwise, if this is the first SharedResourcePointer to be created, then a shared object will be created automatically.
Referenced by getSharedObjectWithoutCreating(), SharedResourcePointer(), SharedResourcePointer(), and ~SharedResourcePointer().
|
default |
Copy constructor.
|
defaultnoexcept |
Move constructor.
|
default |
Destructor. If no other SharedResourcePointer objects exist, this will also delete the shared object to which it refers.
|
inlinenoexcept |
Returns a reference to the shared object.
Definition at line 108 of file juce_SharedResourcePointer.h.
|
inlinenoexcept |
Returns a reference to the shared object.
Definition at line 111 of file juce_SharedResourcePointer.h.
|
inlinenoexcept |
Definition at line 121 of file juce_SharedResourcePointer.h.
|
inlinestatic |
Returns the SharedResourcePointer if one already exists, or a null optional otherwise.
Definition at line 125 of file juce_SharedResourcePointer.h.
Referenced by juce::Timer::callPendingTimersSynchronously().
|
inlinenoexcept |
Returns a pointer to the shared object.
Definition at line 105 of file juce_SharedResourcePointer.h.
|
inlinenoexcept |
Returns a reference to the shared object.
Definition at line 117 of file juce_SharedResourcePointer.h.
|
inlinenoexcept |
Returns a pointer to the shared object.
Definition at line 114 of file juce_SharedResourcePointer.h.