JUCE

- Main Page
- Related Pages
- Topics
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
SingletonHolder< Type, MutexType, onlyCreateOncePerRun > Struct Template Reference
juce_core » memory

Used by the JUCE_DECLARE_SINGLETON macros to manage a static pointer to a singleton instance. More...

`#include <juce_Singleton.h>`

Inherits MutexType.

## Public Member Functions
| SingletonHolder ()=default
| ~SingletonHolder ()
Type * | get ()
| Returns the current instance, or creates a new instance if there isn't one.
Type * | getWithoutChecking ()
| Returns the current instance, or creates a new instance if there isn't one, but doesn't do any locking, or checking for recursion or error conditions.
void | deleteInstance ()
| Deletes and resets the current instance, if there is one.
void | clear (Type *expectedObject) noexcept
| Called by the class's destructor to clear the pointer if it is currently set to the given object.

## Public Attributes
std::atomic< Type * > | instance { nullptr }

## Detailed Description

template<typename Type, typename MutexType, bool onlyCreateOncePerRun>
struct SingletonHolder< Type, MutexType, onlyCreateOncePerRun >

Used by the JUCE_DECLARE_SINGLETON macros to manage a static pointer to a singleton instance.

You generally won't use this directly, but see the macros JUCE_DECLARE_SINGLETON, JUCE_DECLARE_SINGLETON_SINGLETHREADED, JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL, and JUCE_IMPLEMENT_SINGLETON for how it is intended to be used.

## Constructor & Destructor Documentation

## ◆ SingletonHolder()

template<typename Type , typename MutexType , bool onlyCreateOncePerRun>

SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::SingletonHolder | ( |  | ) |
| default

## ◆ ~SingletonHolder()

template<typename Type , typename MutexType , bool onlyCreateOncePerRun>

SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::~SingletonHolder | ( |  | ) |

References SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::instance, and jassert.

## Member Function Documentation

## ◆ get()

template<typename Type , typename MutexType , bool onlyCreateOncePerRun>

Type * SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::get | ( |  | ) |

Returns the current instance, or creates a new instance if there isn't one.

References SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::getWithoutChecking(), SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::instance, and jassertfalse.

## ◆ getWithoutChecking()

template<typename Type , typename MutexType , bool onlyCreateOncePerRun>

Type * SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::getWithoutChecking | ( |  | ) |

Returns the current instance, or creates a new instance if there isn't one, but doesn't do any locking, or checking for recursion or error conditions.

References SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::instance.

Referenced by SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::get().

## ◆ deleteInstance()

template<typename Type , typename MutexType , bool onlyCreateOncePerRun>

void SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::deleteInstance | ( |  | ) |

Deletes and resets the current instance, if there is one.

References SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::instance.

## ◆ clear()

template<typename Type , typename MutexType , bool onlyCreateOncePerRun>

void SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::clear | ( | Type * | expectedObject | ) |
| noexcept

Called by the class's destructor to clear the pointer if it is currently set to the given object.

References SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::instance.

## Member Data Documentation

## ◆ instance

template<typename Type , typename MutexType , bool onlyCreateOncePerRun>

std::atomic<Type*> SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::instance { nullptr }

Referenced by SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::clear(), SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::deleteInstance(), SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::get(), SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::getWithoutChecking(), and SingletonHolder< Type, MutexType, onlyCreateOncePerRun >::~SingletonHolder().

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

- juce_Singleton.h