37template <
typename Type,
typename MutexType,
bool onlyCreateOncePerRun>
56 if (
auto* ptr = instance.
load())
59 typename MutexType::ScopedLockType
sl (*
this);
61 if (
auto* ptr = instance.
load())
100 if (
auto* p = instance.
load())
111 typename MutexType::ScopedLockType
sl (*
this);
184#define JUCE_DECLARE_SINGLETON(Classname, doNotRecreateAfterDeletion) \
186 static juce::SingletonHolder<Classname, juce::CriticalSection, doNotRecreateAfterDeletion> singletonHolder; \
187 friend juce::SingletonHolder<Classname, juce::CriticalSection, doNotRecreateAfterDeletion>; \
189 static Classname* JUCE_CALLTYPE getInstance() { return singletonHolder.get(); } \
190 static Classname* JUCE_CALLTYPE getInstanceWithoutCreating() noexcept { return singletonHolder.instance; } \
191 static void JUCE_CALLTYPE deleteInstance() noexcept { singletonHolder.deleteInstance(); } \
192 void clearSingletonInstance() noexcept { singletonHolder.clear (this); }
201#define JUCE_IMPLEMENT_SINGLETON(Classname) \
203 decltype (Classname::singletonHolder) Classname::singletonHolder;
226#define JUCE_DECLARE_SINGLETON_SINGLETHREADED(Classname, doNotRecreateAfterDeletion) \
228 static juce::SingletonHolder<Classname, juce::DummyCriticalSection, doNotRecreateAfterDeletion> singletonHolder; \
229 friend decltype (singletonHolder); \
231 static Classname* JUCE_CALLTYPE getInstance() { return singletonHolder.get(); } \
232 static Classname* JUCE_CALLTYPE getInstanceWithoutCreating() noexcept { return singletonHolder.instance; } \
233 static void JUCE_CALLTYPE deleteInstance() noexcept { singletonHolder.deleteInstance(); } \
234 void clearSingletonInstance() noexcept { singletonHolder.clear (this); }
252#define JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL(Classname) \
254 static juce::SingletonHolder<Classname, juce::DummyCriticalSection, false> singletonHolder; \
255 friend decltype (singletonHolder); \
257 static Classname* JUCE_CALLTYPE getInstance() { return singletonHolder.getWithoutChecking(); } \
258 static Classname* JUCE_CALLTYPE getInstanceWithoutCreating() noexcept { return singletonHolder.instance; } \
259 static void JUCE_CALLTYPE deleteInstance() noexcept { singletonHolder.deleteInstance(); } \
260 void clearSingletonInstance() noexcept { singletonHolder.clear (this); }
267 #define juce_DeclareSingleton(Classname, doNotRecreate) JUCE_DECLARE_SINGLETON(Classname, doNotRecreate)
268 #define juce_DeclareSingleton_SingleThreaded(Classname, doNotRecreate) JUCE_DECLARE_SINGLETON_SINGLETHREADED(Classname, doNotRecreate)
269 #define juce_DeclareSingleton_SingleThreaded_Minimal(Classname) JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL(Classname)
270 #define juce_ImplementSingleton(Classname) JUCE_IMPLEMENT_SINGLETON(Classname)
271 #define juce_ImplementSingleton_SingleThreaded(Classname) JUCE_IMPLEMENT_SINGLETON(Classname)
Helper class providing an RAII-based mechanism for temporarily setting and then re-setting a value.
T compare_exchange_strong(T... args)
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Used by the JUCE_DECLARE_SINGLETON macros to manage a static pointer to a singleton instance.
void clear(Type *expectedObject) noexcept
Called by the class's destructor to clear the pointer if it is currently set to the given object.
Type * get()
Returns the current instance, or creates a new instance if there isn't one.
void deleteInstance()
Deletes and resets the current instance, if there is one.
Type * getWithoutChecking()
Returns the current instance, or creates a new instance if there isn't one, but doesn't do any lockin...