From 58a99ff139aadc5c0f16febfe5a5cc7e46d1b3b3 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 12 Dec 2017 16:24:40 +0000 Subject: [PATCH] Dragged the singleton macros into the 21st century.. Cleaned up their implementation and gave them new upper-case names to match juce official style. The old names are still defined to avoid breaking old code, but please update before they get deprecated! --- .../Source/Application/jucer_Main.cpp | 2 +- .../LiveBuildEngine/jucer_CompileEngineDLL.h | 5 +- .../analytics/juce_Analytics.cpp | 2 +- .../juce_analytics/analytics/juce_Analytics.h | 2 +- .../native/juce_win32_Midi.cpp | 4 +- .../VST/juce_VST_Wrapper.cpp | 4 +- modules/juce_core/memory/juce_Singleton.h | 324 +++++++++--------- .../native/juce_android_Messaging.cpp | 10 +- .../native/juce_linux_Messaging.cpp | 4 +- .../native/juce_win32_WinRTWrapper.cpp | 2 +- .../native/juce_win32_WinRTWrapper.h | 2 +- modules/juce_graphics/fonts/juce_Font.cpp | 4 +- .../juce_graphics/images/juce_ImageCache.cpp | 4 +- .../native/juce_freetype_Fonts.cpp | 4 +- .../components/juce_ModalComponentManager.cpp | 2 +- .../components/juce_ModalComponentManager.h | 2 +- .../filebrowser/juce_ContentSharer.cpp | 2 +- .../filebrowser/juce_ContentSharer.h | 2 +- .../misc/juce_JUCESplashScreen.cpp | 4 +- .../juce_gui_basics/native/juce_linux_X11.cpp | 2 +- .../juce_gui_basics/native/juce_linux_X11.h | 2 +- .../native/juce_mac_MainMenu.mm | 4 +- .../native/juce_mac_Windowing.mm | 4 +- .../native/juce_win32_Windowing.cpp | 8 +- .../windows/juce_TopLevelWindow.cpp | 4 +- .../misc/juce_LiveConstantEditor.cpp | 6 +- .../misc/juce_LiveConstantEditor.h | 2 +- .../misc/juce_PushNotifications.cpp | 2 +- .../misc/juce_PushNotifications.h | 2 +- modules/juce_video/native/juce_win32_Video.h | 4 +- 30 files changed, 211 insertions(+), 214 deletions(-) diff --git a/extras/Projucer/Source/Application/jucer_Main.cpp b/extras/Projucer/Source/Application/jucer_Main.cpp index 79f0d4de87..a4f8eaf227 100644 --- a/extras/Projucer/Source/Application/jucer_Main.cpp +++ b/extras/Projucer/Source/Application/jucer_Main.cpp @@ -52,7 +52,7 @@ #include "../LiveBuildEngine/UI/jucer_ComponentListComponent.h" #include "../LiveBuildEngine/jucer_CompileEngineServer.h" -juce_ImplementSingleton (CompileEngineDLL); +JUCE_IMPLEMENT_SINGLETON (CompileEngineDLL) struct ProjucerAppClasses { diff --git a/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineDLL.h b/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineDLL.h index 91ace68a95..b2e7574c88 100644 --- a/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineDLL.h +++ b/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineDLL.h @@ -29,7 +29,7 @@ #include "jucer_LiveCodeBuilderDLL.h" //============================================================================== -struct CompileEngineDLL : DeletedAtShutdown +struct CompileEngineDLL : private DeletedAtShutdown { CompileEngineDLL() { @@ -39,6 +39,7 @@ struct CompileEngineDLL : DeletedAtShutdown ~CompileEngineDLL() { shutdown(); + clearSingletonInstance(); } bool tryLoadDll() @@ -117,7 +118,7 @@ struct CompileEngineDLL : DeletedAtShutdown return userAppData.getChildFile ("Projucer").getChildFile (String ("CompileEngine-") + ProjectInfo::versionString); } - juce_DeclareSingleton (CompileEngineDLL, false) + JUCE_DECLARE_SINGLETON (CompileEngineDLL, false) private: DynamicLibrary dll; diff --git a/modules/juce_analytics/analytics/juce_Analytics.cpp b/modules/juce_analytics/analytics/juce_Analytics.cpp index 44f9768f68..faa5da95e8 100644 --- a/modules/juce_analytics/analytics/juce_Analytics.cpp +++ b/modules/juce_analytics/analytics/juce_Analytics.cpp @@ -62,6 +62,6 @@ void Analytics::setSuspended (bool shouldBeSuspended) isSuspended = shouldBeSuspended; } -juce_ImplementSingleton (Analytics) +JUCE_IMPLEMENT_SINGLETON (Analytics) } diff --git a/modules/juce_analytics/analytics/juce_Analytics.h b/modules/juce_analytics/analytics/juce_Analytics.h index 9864d62d37..1e46cd0afa 100644 --- a/modules/juce_analytics/analytics/juce_Analytics.h +++ b/modules/juce_analytics/analytics/juce_Analytics.h @@ -80,7 +80,7 @@ public: void setSuspended (bool shouldBeSuspended); #ifndef DOXYGEN - juce_DeclareSingleton (Analytics, false) + JUCE_DECLARE_SINGLETON (Analytics, false) #endif private: diff --git a/modules/juce_audio_devices/native/juce_win32_Midi.cpp b/modules/juce_audio_devices/native/juce_win32_Midi.cpp index fac58ba7d9..e61cac416e 100644 --- a/modules/juce_audio_devices/native/juce_win32_Midi.cpp +++ b/modules/juce_audio_devices/native/juce_win32_Midi.cpp @@ -1107,7 +1107,7 @@ public: MidiServiceType* getService(); - juce_DeclareSingleton (MidiService, false) + JUCE_DECLARE_SINGLETON (MidiService, false) private: MidiService(); @@ -1115,7 +1115,7 @@ private: ScopedPointer internal; }; -juce_ImplementSingleton (MidiService) +JUCE_IMPLEMENT_SINGLETON (MidiService) MidiService::~MidiService() { diff --git a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp index a7b07de4f0..728957af24 100644 --- a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp @@ -189,12 +189,12 @@ struct SharedMessageThread : public Thread {} } - juce_DeclareSingleton (SharedMessageThread, false) + JUCE_DECLARE_SINGLETON (SharedMessageThread, false) bool initialised = false; }; -juce_ImplementSingleton (SharedMessageThread) +JUCE_IMPLEMENT_SINGLETON (SharedMessageThread) #endif diff --git a/modules/juce_core/memory/juce_Singleton.h b/modules/juce_core/memory/juce_Singleton.h index 8745ea8f1b..3152dafe5c 100644 --- a/modules/juce_core/memory/juce_Singleton.h +++ b/modules/juce_core/memory/juce_Singleton.h @@ -25,12 +25,115 @@ namespace juce //============================================================================== /** - Macro to declare member variables and methods for a singleton class. + Used by the JUCE_DECLARE_SINGLETON macros to manage a static pointer + to a singleton instance. - To use this, add the line juce_DeclareSingleton (MyClass, doNotRecreateAfterDeletion) + 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. +*/ +template +struct SingletonHolder : private MutexType // (inherited so we can use the empty-base-class optimisation) +{ + SingletonHolder() noexcept {} + + ~SingletonHolder() + { + /* The static singleton holder is being deleted before the object that it holds + has been deleted. This could mean that you've forgotten to call clearSingletonInstance() + in the class's destructor, or have failed to delete it before your app shuts down. + If you're having trouble cleaning up your singletons, perhaps consider using the + SharedResourcePointer class instead. + */ + jassert (instance == nullptr); + } + + /** Returns the current instance, or creates a new instance if there isn't one. */ + Type* get() + { + if (instance == nullptr) + { + typename MutexType::ScopedLockType sl (*this); + + if (instance == nullptr) + { + if (onlyCreateOncePerRun) + { + static bool createdOnceAlready = false; + + if (createdOnceAlready) + { + // This means that the doNotRecreateAfterDeletion flag was set + // and you tried to create the singleton more than once. + jassertfalse; + return nullptr; + } + + createdOnceAlready = true; + } + + static bool alreadyInside = false; + + if (alreadyInside) + { + // This means that your object's constructor has done something which has + // ended up causing a recursive loop of singleton creation.. + jassertfalse; + } + else + { + alreadyInside = true; + getWithoutChecking(); + alreadyInside = false; + } + } + } + + return instance; + } + + /** 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. + */ + Type* getWithoutChecking() + { + if (instance == nullptr) + { + auto newObject = new Type(); // (create into a local so that instance is still null during construction) + instance = newObject; + } + + return instance; + } + + /** Deletes and resets the current instance, if there is one. */ + void deleteInstance() + { + typename MutexType::ScopedLockType sl (*this); + auto old = instance; + instance = nullptr; + delete old; + } + + /** Called by the class's destructor to clear the pointer if it is currently set to the given object. */ + void clear (Type* expectedObject) noexcept + { + if (instance == expectedObject) + instance = nullptr; + } + + Type* instance = nullptr; +}; + + +//============================================================================== +/** + Macro to generate the appropriate methods and boilerplate for a singleton class. + + To use this, add the line JUCE_DECLARE_SINGLETON(MyClass, doNotRecreateAfterDeletion) to the class's definition. - Then put a macro juce_ImplementSingleton (MyClass) along with the class's + Then put a macro JUCE_IMPLEMENT_SINGLETON(MyClass) along with the class's implementation code. It's also a very good idea to also add the call clearSingletonInstance() in your class's @@ -42,12 +145,9 @@ namespace juce e.g. @code - class MySingleton + struct MySingleton { - public: - MySingleton() - { - } + MySingleton() {} ~MySingleton() { @@ -56,14 +156,15 @@ namespace juce clearSingletonInstance(); } - juce_DeclareSingleton (MySingleton, false) + JUCE_DECLARE_SINGLETON (MySingleton, false) }; - juce_ImplementSingleton (MySingleton) + // ..and this goes in a suitable .cpp file: + JUCE_IMPLEMENT_SINGLETON (MySingleton) // example of usage: - MySingleton* m = MySingleton::getInstance(); // creates the singleton if there isn't already one. + auto* m = MySingleton::getInstance(); // creates the singleton if there isn't already one. ... @@ -77,84 +178,38 @@ namespace juce objects being accidentally re-created during your app's shutdown code. If you know that your object will only be created and deleted by a single thread, you - can use the slightly more efficient juce_DeclareSingleton_SingleThreaded() macro instead + can use the slightly more efficient JUCE_DECLARE_SINGLETON_SINGLETHREADED macro instead of this one. - @see juce_ImplementSingleton, juce_DeclareSingleton_SingleThreaded + @see JUCE_IMPLEMENT_SINGLETON, JUCE_DECLARE_SINGLETON_SINGLETHREADED */ -#define juce_DeclareSingleton(classname, doNotRecreateAfterDeletion) \ +#define JUCE_DECLARE_SINGLETON(Classname, doNotRecreateAfterDeletion) \ \ - static classname* _singletonInstance; \ - static juce::CriticalSection _singletonLock; \ + static juce::SingletonHolder singletonHolder; \ + friend decltype (singletonHolder); \ \ - static classname* JUCE_CALLTYPE getInstance() \ - { \ - if (_singletonInstance == nullptr) \ - {\ - const juce::ScopedLock sl (_singletonLock); \ -\ - if (_singletonInstance == nullptr) \ - { \ - static bool alreadyInside = false; \ - static bool createdOnceAlready = false; \ -\ - const bool problem = alreadyInside || ((doNotRecreateAfterDeletion) && createdOnceAlready); \ - jassert (! problem); \ - if (! problem) \ - { \ - createdOnceAlready = true; \ - alreadyInside = true; \ - classname* newObject = new classname(); /* (use a stack variable to avoid setting the newObject value before the class has finished its constructor) */ \ - alreadyInside = false; \ -\ - _singletonInstance = newObject; \ - } \ - } \ - } \ -\ - return _singletonInstance; \ - } \ -\ - static inline classname* JUCE_CALLTYPE getInstanceWithoutCreating() noexcept\ - { \ - return _singletonInstance; \ - } \ -\ - static void JUCE_CALLTYPE deleteInstance() \ - { \ - const juce::ScopedLock sl (_singletonLock); \ - if (_singletonInstance != nullptr) \ - { \ - classname* const old = _singletonInstance; \ - _singletonInstance = nullptr; \ - delete old; \ - } \ - } \ -\ - void clearSingletonInstance() noexcept\ - { \ - if (_singletonInstance == this) \ - _singletonInstance = nullptr; \ - } + static Classname* JUCE_CALLTYPE getInstance() { return singletonHolder.get(); } \ + static Classname* JUCE_CALLTYPE getInstanceWithoutCreating() noexcept { return singletonHolder.instance; } \ + static void JUCE_CALLTYPE deleteInstance() noexcept { singletonHolder.deleteInstance(); } \ + void clearSingletonInstance() noexcept { singletonHolder.clear (this); } //============================================================================== -/** This is a counterpart to the juce_DeclareSingleton macro. +/** This is a counterpart to the JUCE_DECLARE_SINGLETON macros. - After adding the juce_DeclareSingleton to the class definition, this macro has + After adding the JUCE_DECLARE_SINGLETON to the class definition, this macro has to be used in the cpp file. */ -#define juce_ImplementSingleton(classname) \ +#define JUCE_IMPLEMENT_SINGLETON(Classname) \ \ - classname* classname::_singletonInstance = nullptr; \ - juce::CriticalSection classname::_singletonLock; + decltype (Classname::singletonHolder) Classname::singletonHolder; //============================================================================== /** Macro to declare member variables and methods for a singleton class. - This is exactly the same as juce_DeclareSingleton, but doesn't use a critical + This is exactly the same as JUCE_DECLARE_SINGLETON, but doesn't use a critical section to make access to it thread-safe. If you know that your object will only ever be created or deleted by a single thread, then this is a more efficient version to use. @@ -164,120 +219,61 @@ namespace juce object, getInstance() will refuse to create another one. This can be useful to stop objects being accidentally re-created during your app's shutdown code. - See the documentation for juce_DeclareSingleton for more information about - how to use it, the only difference being that you have to use - juce_ImplementSingleton_SingleThreaded instead of juce_ImplementSingleton. + See the documentation for JUCE_DECLARE_SINGLETON for more information about + how to use it. Just like JUCE_DECLARE_SINGLETON you need to also have a + corresponding JUCE_IMPLEMENT_SINGLETON statement somewhere in your code. - @see juce_ImplementSingleton_SingleThreaded, juce_DeclareSingleton, juce_DeclareSingleton_SingleThreaded_Minimal + @see JUCE_IMPLEMENT_SINGLETON, JUCE_DECLARE_SINGLETON, JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL */ -#define juce_DeclareSingleton_SingleThreaded(classname, doNotRecreateAfterDeletion) \ +#define JUCE_DECLARE_SINGLETON_SINGLETHREADED(Classname, doNotRecreateAfterDeletion) \ \ - static classname* _singletonInstance; \ + static juce::SingletonHolder singletonHolder; \ + friend decltype (singletonHolder); \ \ - static classname* getInstance() \ - { \ - if (_singletonInstance == nullptr) \ - { \ - static bool alreadyInside = false; \ - static bool createdOnceAlready = false; \ -\ - const bool problem = alreadyInside || ((doNotRecreateAfterDeletion) && createdOnceAlready); \ - jassert (! problem); \ - if (! problem) \ - { \ - createdOnceAlready = true; \ - alreadyInside = true; \ - classname* newObject = new classname(); /* (use a stack variable to avoid setting the newObject value before the class has finished its constructor) */ \ - alreadyInside = false; \ -\ - _singletonInstance = newObject; \ - } \ - } \ -\ - return _singletonInstance; \ - } \ -\ - static inline classname* getInstanceWithoutCreating() noexcept\ - { \ - return _singletonInstance; \ - } \ -\ - static void deleteInstance() \ - { \ - if (_singletonInstance != nullptr) \ - { \ - classname* const old = _singletonInstance; \ - _singletonInstance = nullptr; \ - delete old; \ - } \ - } \ -\ - void clearSingletonInstance() noexcept\ - { \ - if (_singletonInstance == this) \ - _singletonInstance = nullptr; \ - } + static Classname* JUCE_CALLTYPE getInstance() { return singletonHolder.get(); } \ + static Classname* JUCE_CALLTYPE getInstanceWithoutCreating() noexcept { return singletonHolder.instance; } \ + static void JUCE_CALLTYPE deleteInstance() noexcept { singletonHolder.deleteInstance(); } \ + void clearSingletonInstance() noexcept { singletonHolder.clear (this); } + //============================================================================== /** Macro to declare member variables and methods for a singleton class. - This is like juce_DeclareSingleton_SingleThreaded, but doesn't do any checking + This is like JUCE_DECLARE_SINGLETON_SINGLETHREADED, but doesn't do any checking for recursion or repeated instantiation. It's intended for use as a lightweight version of a singleton, where you're using it in very straightforward circumstances and don't need the extra checking. - Just use the normal juce_ImplementSingleton_SingleThreaded as the counterpart - to this declaration, as you would with juce_DeclareSingleton_SingleThreaded. + Just use the normal JUCE_IMPLEMENT_SINGLETON_SINGLETHREADED as the counterpart + to this declaration, as you would with JUCE_DECLARE_SINGLETON_SINGLETHREADED. - See the documentation for juce_DeclareSingleton for more information about + See the documentation for JUCE_DECLARE_SINGLETON for more information about how to use it, the only difference being that you have to use - juce_ImplementSingleton_SingleThreaded instead of juce_ImplementSingleton. + JUCE_IMPLEMENT_SINGLETON_SINGLETHREADED instead of JUCE_IMPLEMENT_SINGLETON. - @see juce_ImplementSingleton_SingleThreaded, juce_DeclareSingleton + @see JUCE_IMPLEMENT_SINGLETON_SINGLETHREADED, JUCE_DECLARE_SINGLETON */ -#define juce_DeclareSingleton_SingleThreaded_Minimal(classname) \ +#define JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL(Classname) \ \ - static classname* _singletonInstance; \ + static juce::SingletonHolder singletonHolder; \ + friend decltype (singletonHolder); \ \ - static classname* getInstance() \ - { \ - if (_singletonInstance == nullptr) \ - _singletonInstance = new classname(); \ -\ - return _singletonInstance; \ - } \ -\ - static inline classname* getInstanceWithoutCreating() noexcept\ - { \ - return _singletonInstance; \ - } \ -\ - static void deleteInstance() \ - { \ - if (_singletonInstance != nullptr) \ - { \ - classname* const old = _singletonInstance; \ - _singletonInstance = nullptr; \ - delete old; \ - } \ - } \ -\ - void clearSingletonInstance() noexcept\ - { \ - if (_singletonInstance == this) \ - _singletonInstance = nullptr; \ - } + static Classname* JUCE_CALLTYPE getInstance() { return singletonHolder.getWithoutChecking(); } \ + static Classname* JUCE_CALLTYPE getInstanceWithoutCreating() noexcept { return singletonHolder.instance; } \ + static void JUCE_CALLTYPE deleteInstance() noexcept { singletonHolder.deleteInstance(); } \ + void clearSingletonInstance() noexcept { singletonHolder.clear (this); } //============================================================================== -/** This is a counterpart to the juce_DeclareSingleton_SingleThreaded macro. - - After adding juce_DeclareSingleton_SingleThreaded or juce_DeclareSingleton_SingleThreaded_Minimal - to the class definition, this macro has to be used somewhere in the cpp file. -*/ -#define juce_ImplementSingleton_SingleThreaded(classname) \ -\ - classname* classname::_singletonInstance = nullptr; +#ifndef DOXYGEN + // These are ancient macros, and have now been updated with new names to match the JUCE style guide, + // so please update your code to use the newer versions! + #define juce_DeclareSingleton(Classname, doNotRecreate) JUCE_DECLARE_SINGLETON(Classname, doNotRecreate) + #define juce_DeclareSingleton_SingleThreaded(Classname, doNotRecreate) JUCE_DECLARE_SINGLETON_SINGLETHREADED(Classname, doNotRecreate) + #define juce_DeclareSingleton_SingleThreaded_Minimal(Classname) JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL(Classname) + #define juce_ImplementSingleton(Classname) JUCE_IMPLEMENT_SINGLETON(Classname) + #define juce_ImplementSingleton_SingleThreaded(Classname) JUCE_IMPLEMENT_SINGLETON(Classname) +#endif } // namespace juce diff --git a/modules/juce_events/native/juce_android_Messaging.cpp b/modules/juce_events/native/juce_android_Messaging.cpp index ec4124720b..7fa14730f3 100644 --- a/modules/juce_events/native/juce_android_Messaging.cpp +++ b/modules/juce_events/native/juce_android_Messaging.cpp @@ -34,7 +34,7 @@ DECLARE_JNI_CLASS (JNIHandler, "android/os/Handler"); //============================================================================== namespace Android { - class Runnable : public juce::AndroidInterfaceImplementer + class Runnable : public juce::AndroidInterfaceImplementer { public: virtual void run() = 0; @@ -58,7 +58,7 @@ namespace Android struct Handler { - juce_DeclareSingleton (Handler, false) + JUCE_DECLARE_SINGLETON (Handler, false) Handler() : nativeHandler (getEnv()->NewObject (JNIHandler, JNIHandler.constructor)) {} @@ -70,13 +70,13 @@ namespace Android GlobalRef nativeHandler; }; - juce_ImplementSingleton (Handler); + JUCE_IMPLEMENT_SINGLETON (Handler) } //============================================================================== struct AndroidMessageQueue : private Android::Runnable { - juce_DeclareSingleton_SingleThreaded (AndroidMessageQueue, true) + JUCE_DECLARE_SINGLETON_SINGLETHREADED (AndroidMessageQueue, true) AndroidMessageQueue() : self (CreateJavaInterface (this, "java/lang/Runnable").get()) @@ -118,7 +118,7 @@ private: Android::Handler handler; }; -juce_ImplementSingleton_SingleThreaded (AndroidMessageQueue); +JUCE_IMPLEMENT_SINGLETON (AndroidMessageQueue) //============================================================================== void MessageManager::doPlatformSpecificInitialisation() { AndroidMessageQueue::getInstance(); } diff --git a/modules/juce_events/native/juce_linux_Messaging.cpp b/modules/juce_events/native/juce_linux_Messaging.cpp index 35cf97aef2..bd53abc534 100644 --- a/modules/juce_events/native/juce_linux_Messaging.cpp +++ b/modules/juce_events/native/juce_linux_Messaging.cpp @@ -132,7 +132,7 @@ public: } //============================================================================== - juce_DeclareSingleton_SingleThreaded_Minimal (InternalMessageQueue) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (InternalMessageQueue) private: CriticalSection lock; @@ -165,7 +165,7 @@ private: } }; -juce_ImplementSingleton_SingleThreaded (InternalMessageQueue) +JUCE_IMPLEMENT_SINGLETON (InternalMessageQueue) //============================================================================== diff --git a/modules/juce_events/native/juce_win32_WinRTWrapper.cpp b/modules/juce_events/native/juce_win32_WinRTWrapper.cpp index e8d848da42..75b774f0d6 100644 --- a/modules/juce_events/native/juce_win32_WinRTWrapper.cpp +++ b/modules/juce_events/native/juce_win32_WinRTWrapper.cpp @@ -22,5 +22,5 @@ namespace juce { - juce_ImplementSingleton (WinRTWrapper) + JUCE_IMPLEMENT_SINGLETON (WinRTWrapper) } diff --git a/modules/juce_events/native/juce_win32_WinRTWrapper.h b/modules/juce_events/native/juce_win32_WinRTWrapper.h index 4a48e04285..c5fb4974a5 100644 --- a/modules/juce_events/native/juce_win32_WinRTWrapper.h +++ b/modules/juce_events/native/juce_win32_WinRTWrapper.h @@ -26,7 +26,7 @@ namespace juce class WinRTWrapper : public DeletedAtShutdown { public: - juce_DeclareSingleton (WinRTWrapper, true) + JUCE_DECLARE_SINGLETON (WinRTWrapper, true) class ScopedHString { diff --git a/modules/juce_graphics/fonts/juce_Font.cpp b/modules/juce_graphics/fonts/juce_Font.cpp index 24a8762179..1dec474709 100644 --- a/modules/juce_graphics/fonts/juce_Font.cpp +++ b/modules/juce_graphics/fonts/juce_Font.cpp @@ -60,7 +60,7 @@ public: clearSingletonInstance(); } - juce_DeclareSingleton (TypefaceCache, false) + JUCE_DECLARE_SINGLETON (TypefaceCache, false) void setSize (const int numToCache) { @@ -157,7 +157,7 @@ private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TypefaceCache) }; -juce_ImplementSingleton (TypefaceCache) +JUCE_IMPLEMENT_SINGLETON (TypefaceCache) void Typeface::setTypefaceCacheSize (int numFontsToCache) { diff --git a/modules/juce_graphics/images/juce_ImageCache.cpp b/modules/juce_graphics/images/juce_ImageCache.cpp index e565f5e5e6..a2fce16afe 100644 --- a/modules/juce_graphics/images/juce_ImageCache.cpp +++ b/modules/juce_graphics/images/juce_ImageCache.cpp @@ -33,7 +33,7 @@ struct ImageCache::Pimpl : private Timer, Pimpl() {} ~Pimpl() { clearSingletonInstance(); } - juce_DeclareSingleton_SingleThreaded_Minimal (ImageCache::Pimpl) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (ImageCache::Pimpl) Image getFromHashCode (const int64 hashCode) noexcept { @@ -111,7 +111,7 @@ struct ImageCache::Pimpl : private Timer, JUCE_DECLARE_NON_COPYABLE (Pimpl) }; -juce_ImplementSingleton_SingleThreaded (ImageCache::Pimpl) +JUCE_IMPLEMENT_SINGLETON (ImageCache::Pimpl) //============================================================================== diff --git a/modules/juce_graphics/native/juce_freetype_Fonts.cpp b/modules/juce_graphics/native/juce_freetype_Fonts.cpp index a813ec61b1..9da1efc1c1 100644 --- a/modules/juce_graphics/native/juce_freetype_Fonts.cpp +++ b/modules/juce_graphics/native/juce_freetype_Fonts.cpp @@ -229,7 +229,7 @@ public: sansSerif.addIfNotAlreadyThere (faces.getUnchecked(i)->family); } - juce_DeclareSingleton_SingleThreaded_Minimal (FTTypefaceList) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (FTTypefaceList) private: FTLibWrapper::Ptr library; @@ -288,7 +288,7 @@ private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FTTypefaceList) }; -juce_ImplementSingleton_SingleThreaded (FTTypefaceList) +JUCE_IMPLEMENT_SINGLETON (FTTypefaceList) //============================================================================== diff --git a/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp b/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp index 06e005a55b..44019820fd 100644 --- a/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp +++ b/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp @@ -90,7 +90,7 @@ ModalComponentManager::~ModalComponentManager() clearSingletonInstance(); } -juce_ImplementSingleton_SingleThreaded (ModalComponentManager) +JUCE_IMPLEMENT_SINGLETON (ModalComponentManager) //============================================================================== diff --git a/modules/juce_gui_basics/components/juce_ModalComponentManager.h b/modules/juce_gui_basics/components/juce_ModalComponentManager.h index 698b3e1b53..f5bd1ca7e5 100644 --- a/modules/juce_gui_basics/components/juce_ModalComponentManager.h +++ b/modules/juce_gui_basics/components/juce_ModalComponentManager.h @@ -75,7 +75,7 @@ public: //============================================================================== #ifndef DOXYGEN - juce_DeclareSingleton_SingleThreaded_Minimal (ModalComponentManager) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (ModalComponentManager) #endif //============================================================================== diff --git a/modules/juce_gui_basics/filebrowser/juce_ContentSharer.cpp b/modules/juce_gui_basics/filebrowser/juce_ContentSharer.cpp index 82c7bd8221..3a9e81580e 100644 --- a/modules/juce_gui_basics/filebrowser/juce_ContentSharer.cpp +++ b/modules/juce_gui_basics/filebrowser/juce_ContentSharer.cpp @@ -148,7 +148,7 @@ private: #endif //============================================================================== -juce_ImplementSingleton (ContentSharer) +JUCE_IMPLEMENT_SINGLETON (ContentSharer) ContentSharer::ContentSharer() {} ContentSharer::~ContentSharer() { clearSingletonInstance(); } diff --git a/modules/juce_gui_basics/filebrowser/juce_ContentSharer.h b/modules/juce_gui_basics/filebrowser/juce_ContentSharer.h index 091268b08e..ce33fca056 100644 --- a/modules/juce_gui_basics/filebrowser/juce_ContentSharer.h +++ b/modules/juce_gui_basics/filebrowser/juce_ContentSharer.h @@ -36,7 +36,7 @@ namespace juce class JUCE_API ContentSharer { public: - juce_DeclareSingleton (ContentSharer, false) + JUCE_DECLARE_SINGLETON (ContentSharer, false) /** Shares the given files. Each URL should be either a full file path or it should point to a resource within the application bundle. For diff --git a/modules/juce_gui_basics/misc/juce_JUCESplashScreen.cpp b/modules/juce_gui_basics/misc/juce_JUCESplashScreen.cpp index cb62443937..e460917038 100644 --- a/modules/juce_gui_basics/misc/juce_JUCESplashScreen.cpp +++ b/modules/juce_gui_basics/misc/juce_JUCESplashScreen.cpp @@ -78,10 +78,10 @@ struct ReportingThreadContainer : public ChangeListener, ScopedPointer reportingThread; - juce_DeclareSingleton_SingleThreaded_Minimal (ReportingThreadContainer) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (ReportingThreadContainer) }; -juce_ImplementSingleton_SingleThreaded (ReportingThreadContainer) +JUCE_IMPLEMENT_SINGLETON (ReportingThreadContainer) //============================================================================== struct ReportingThread : public Thread, diff --git a/modules/juce_gui_basics/native/juce_linux_X11.cpp b/modules/juce_gui_basics/native/juce_linux_X11.cpp index 22dfbba5b7..a54ebede7c 100644 --- a/modules/juce_gui_basics/native/juce_linux_X11.cpp +++ b/modules/juce_gui_basics/native/juce_linux_X11.cpp @@ -232,7 +232,7 @@ void XWindowSystem::destroyXDisplay() noexcept LinuxEventLoop::removeWindowSystemFd(); } -juce_ImplementSingleton (XWindowSystem) +JUCE_IMPLEMENT_SINGLETON (XWindowSystem) //============================================================================== ScopedXDisplay::ScopedXDisplay() : display (XWindowSystem::getInstance()->displayRef()) diff --git a/modules/juce_gui_basics/native/juce_linux_X11.h b/modules/juce_gui_basics/native/juce_linux_X11.h index d9e014511e..292e421a3e 100644 --- a/modules/juce_gui_basics/native/juce_linux_X11.h +++ b/modules/juce_gui_basics/native/juce_linux_X11.h @@ -42,7 +42,7 @@ public: XDisplay displayRef() noexcept; XDisplay displayUnref() noexcept; - juce_DeclareSingleton (XWindowSystem, false) + JUCE_DECLARE_SINGLETON (XWindowSystem, false) private: XDisplay display = {}; diff --git a/modules/juce_gui_basics/native/juce_mac_MainMenu.mm b/modules/juce_gui_basics/native/juce_mac_MainMenu.mm index e38e3dd292..c1a2ec774b 100644 --- a/modules/juce_gui_basics/native/juce_mac_MainMenu.mm +++ b/modules/juce_gui_basics/native/juce_mac_MainMenu.mm @@ -56,10 +56,10 @@ struct JuceMainMenuBarHolder : private DeletedAtShutdown NSMenu* mainMenuBar = nil; - juce_DeclareSingleton_SingleThreaded (JuceMainMenuBarHolder, true) + JUCE_DECLARE_SINGLETON_SINGLETHREADED (JuceMainMenuBarHolder, true) }; -juce_ImplementSingleton_SingleThreaded (JuceMainMenuBarHolder) +JUCE_IMPLEMENT_SINGLETON (JuceMainMenuBarHolder) //============================================================================== class JuceMainMenuHandler : private MenuBarModel::Listener, diff --git a/modules/juce_gui_basics/native/juce_mac_Windowing.mm b/modules/juce_gui_basics/native/juce_mac_Windowing.mm index b1119cbbb8..c6e0c7462f 100644 --- a/modules/juce_gui_basics/native/juce_mac_Windowing.mm +++ b/modules/juce_gui_basics/native/juce_mac_Windowing.mm @@ -442,12 +442,12 @@ struct DisplaySettingsChangeCallback : private DeletedAtShutdown const_cast (Desktop::getInstance().getDisplays()).refresh(); } - juce_DeclareSingleton_SingleThreaded_Minimal (DisplaySettingsChangeCallback) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (DisplaySettingsChangeCallback) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DisplaySettingsChangeCallback) }; -juce_ImplementSingleton_SingleThreaded (DisplaySettingsChangeCallback) +JUCE_IMPLEMENT_SINGLETON (DisplaySettingsChangeCallback) static Rectangle convertDisplayRect (NSRect r, CGFloat mainScreenBottom) { diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 7f2b4adb0b..a0ebdb6630 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -755,7 +755,7 @@ struct OnScreenKeyboard : public DeletedAtShutdown, startTimer (10); } - juce_DeclareSingleton_SingleThreaded (OnScreenKeyboard, true) + JUCE_DECLARE_SINGLETON_SINGLETHREADED (OnScreenKeyboard, true) private: OnScreenKeyboard() @@ -803,7 +803,7 @@ private: ComSmartPtr tipInvocation; }; -juce_ImplementSingleton_SingleThreaded (OnScreenKeyboard) +JUCE_IMPLEMENT_SINGLETON (OnScreenKeyboard) //============================================================================== struct HSTRING_PRIVATE; @@ -1606,7 +1606,7 @@ private: LPCTSTR getWindowClassName() const noexcept { return (LPCTSTR) (pointer_sized_uint) atom; } - juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (WindowClassHolder) private: ATOM atom; @@ -3589,7 +3589,7 @@ JUCE_API ComponentPeer* createNonRepaintingEmbeddedWindowsPeer (Component& compo } -juce_ImplementSingleton_SingleThreaded (HWNDComponentPeer::WindowClassHolder) +JUCE_IMPLEMENT_SINGLETON (HWNDComponentPeer::WindowClassHolder) //============================================================================== diff --git a/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp b/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp index 6477be7ec4..16353c2cb9 100644 --- a/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp @@ -35,7 +35,7 @@ public: TopLevelWindowManager() {} ~TopLevelWindowManager() { clearSingletonInstance(); } - juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (TopLevelWindowManager) void checkFocusAsync() { @@ -122,7 +122,7 @@ private: JUCE_DECLARE_NON_COPYABLE (TopLevelWindowManager) }; -juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager) +JUCE_IMPLEMENT_SINGLETON (TopLevelWindowManager) void juce_checkCurrentlyFocusedTopLevelWindow(); void juce_checkCurrentlyFocusedTopLevelWindow() diff --git a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp index fd3258ae1a..7a3121039d 100644 --- a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp +++ b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp @@ -40,7 +40,7 @@ public: AllComponentRepainter() {} ~AllComponentRepainter() { clearSingletonInstance(); } - juce_DeclareSingleton (AllComponentRepainter, false) + JUCE_DECLARE_SINGLETON (AllComponentRepainter, false) void trigger() { @@ -89,8 +89,8 @@ private: } }; -juce_ImplementSingleton (AllComponentRepainter) -juce_ImplementSingleton (ValueList) +JUCE_IMPLEMENT_SINGLETON (AllComponentRepainter) +JUCE_IMPLEMENT_SINGLETON (ValueList) //============================================================================== int64 parseInt (String s) diff --git a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h index 9121a5828f..3571e11d7c 100644 --- a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h +++ b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h @@ -200,7 +200,7 @@ namespace LiveConstantEditor ValueList(); ~ValueList(); - juce_DeclareSingleton (ValueList, false) + JUCE_DECLARE_SINGLETON (ValueList, false) template LiveValue& getValue (const char* file, int line, const Type& initialValue) diff --git a/modules/juce_gui_extra/misc/juce_PushNotifications.cpp b/modules/juce_gui_extra/misc/juce_PushNotifications.cpp index c1efbc0dc0..81c9c34a64 100644 --- a/modules/juce_gui_extra/misc/juce_PushNotifications.cpp +++ b/modules/juce_gui_extra/misc/juce_PushNotifications.cpp @@ -33,7 +33,7 @@ bool PushNotifications::Notification::isValid() const noexcept { return true; } #endif //============================================================================== -juce_ImplementSingleton (PushNotifications) +JUCE_IMPLEMENT_SINGLETON (PushNotifications) PushNotifications::PushNotifications() #if JUCE_PUSH_NOTIFICATIONS diff --git a/modules/juce_gui_extra/misc/juce_PushNotifications.h b/modules/juce_gui_extra/misc/juce_PushNotifications.h index 26e028b305..d59e41c7f2 100644 --- a/modules/juce_gui_extra/misc/juce_PushNotifications.h +++ b/modules/juce_gui_extra/misc/juce_PushNotifications.h @@ -45,7 +45,7 @@ class JUCE_API PushNotifications { public: #ifndef DOXYGEN - juce_DeclareSingleton (PushNotifications, false) + JUCE_DECLARE_SINGLETON (PushNotifications, false) #endif //========================================================================== diff --git a/modules/juce_video/native/juce_win32_Video.h b/modules/juce_video/native/juce_win32_Video.h index f71f9cd385..7432710cf1 100644 --- a/modules/juce_video/native/juce_win32_Video.h +++ b/modules/juce_video/native/juce_win32_Video.h @@ -772,7 +772,7 @@ private: bool isRegistered() const noexcept { return atom != 0; } LPCTSTR getWindowClassName() const noexcept { return (LPCTSTR) (pointer_sized_uint) MAKELONG (atom, 0); } - juce_DeclareSingleton_SingleThreaded_Minimal (NativeWindowClass) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (NativeWindowClass) private: NativeWindowClass() @@ -889,4 +889,4 @@ private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl) }; -juce_ImplementSingleton_SingleThreaded (VideoComponent::Pimpl::DirectShowContext::NativeWindowClass) +JUCE_IMPLEMENT_SINGLETON (VideoComponent::Pimpl::DirectShowContext::NativeWindowClass)