From 882ce8e8bf82d333a0dd88567ac11a9b027825b6 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 7 Oct 2024 12:30:43 +0100 Subject: [PATCH] Singleton: Add new macros to simplify singleton creation The INLINE macros allow singletons to be declared and defined in one line, without requiring a separate JUCE_IMPLEMENT_SINGLETON statement. --- .../Source/Application/jucer_AutoUpdater.cpp | 3 - .../Source/Application/jucer_AutoUpdater.h | 2 +- .../analytics/juce_Analytics.cpp | 2 - .../juce_analytics/analytics/juce_Analytics.h | 2 +- .../native/juce_Midi_windows.cpp | 4 +- modules/juce_core/memory/juce_Singleton.h | 60 +++++++++++-------- .../interprocess/juce_ChildProcessManager.cpp | 2 - .../interprocess/juce_ChildProcessManager.h | 2 +- .../native/juce_Messaging_android.cpp | 8 +-- .../native/juce_Messaging_linux.cpp | 8 +-- .../native/juce_Messaging_windows.cpp | 4 +- .../native/juce_WinRTWrapper_windows.cpp | 3 - .../native/juce_WinRTWrapper_windows.h | 2 +- modules/juce_events/timers/juce_Timer.cpp | 4 +- .../contexts/juce_GraphicsContext.cpp | 5 +- modules/juce_graphics/fonts/juce_Font.cpp | 4 +- .../fonts/juce_TypefaceFileCache.h | 4 +- .../juce_graphics/images/juce_ImageCache.cpp | 5 +- .../juce_Direct2DGraphicsContext_windows.cpp | 4 -- .../native/juce_Direct2DMetrics_windows.h | 2 +- .../native/juce_Fonts_android.cpp | 4 +- .../native/juce_Fonts_freetype.cpp | 4 +- .../components/juce_ModalComponentManager.cpp | 3 - .../components/juce_ModalComponentManager.h | 2 +- .../detail/juce_TopLevelWindowManager.h | 4 +- .../juce_Accessibility_windows.cpp | 6 +- .../juce_WindowsUIAWrapper_windows.h | 2 +- .../native/juce_DragAndDrop_windows.cpp | 4 +- .../native/juce_MainMenu_mac.mm | 4 +- .../native/juce_VBlank_windows.cpp | 4 +- .../native/juce_Windowing_mac.mm | 4 +- .../native/juce_Windowing_windows.cpp | 4 +- .../native/juce_XSymbols_linux.cpp | 3 - .../native/juce_XSymbols_linux.h | 2 +- .../native/juce_XWindowSystem_linux.cpp | 2 - .../native/juce_XWindowSystem_linux.h | 2 +- .../misc/juce_LiveConstantEditor.cpp | 5 +- .../misc/juce_LiveConstantEditor.h | 2 +- .../misc/juce_PushNotifications.cpp | 2 - .../misc/juce_PushNotifications.h | 2 +- .../native/juce_WebBrowserComponent_linux.cpp | 4 +- .../in_app_purchases/juce_InAppPurchases.cpp | 2 - .../in_app_purchases/juce_InAppPurchases.h | 2 +- .../juce_video/native/juce_Video_windows.h | 4 +- 44 files changed, 69 insertions(+), 138 deletions(-) diff --git a/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp b/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp index 671d88e8d1d3..42c241d8f00b 100644 --- a/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp +++ b/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp @@ -591,6 +591,3 @@ void LatestVersionCheckerAndUpdater::downloadAndInstall (const VersionInfo::Asse } })); } - -//============================================================================== -JUCE_IMPLEMENT_SINGLETON (LatestVersionCheckerAndUpdater) diff --git a/extras/Projucer/Source/Application/jucer_AutoUpdater.h b/extras/Projucer/Source/Application/jucer_AutoUpdater.h index ed58c6174918..61e2b731cbef 100644 --- a/extras/Projucer/Source/Application/jucer_AutoUpdater.h +++ b/extras/Projucer/Source/Application/jucer_AutoUpdater.h @@ -48,7 +48,7 @@ class LatestVersionCheckerAndUpdater final : public DeletedAtShutdown, void checkForNewVersion (bool isBackgroundCheck); //============================================================================== - JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (LatestVersionCheckerAndUpdater) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE (LatestVersionCheckerAndUpdater) private: //============================================================================== diff --git a/modules/juce_analytics/analytics/juce_Analytics.cpp b/modules/juce_analytics/analytics/juce_Analytics.cpp index c5fac8079fec..54a4a7bd14ee 100644 --- a/modules/juce_analytics/analytics/juce_Analytics.cpp +++ b/modules/juce_analytics/analytics/juce_Analytics.cpp @@ -81,6 +81,4 @@ void Analytics::setSuspended (bool shouldBeSuspended) isSuspended = shouldBeSuspended; } -JUCE_IMPLEMENT_SINGLETON (Analytics) - } diff --git a/modules/juce_analytics/analytics/juce_Analytics.h b/modules/juce_analytics/analytics/juce_Analytics.h index 6c4ecf316c5f..57c728fd8699 100644 --- a/modules/juce_analytics/analytics/juce_Analytics.h +++ b/modules/juce_analytics/analytics/juce_Analytics.h @@ -104,7 +104,7 @@ class JUCE_API Analytics : public DeletedAtShutdown void setSuspended (bool shouldBeSuspended); #ifndef DOXYGEN - JUCE_DECLARE_SINGLETON (Analytics, false) + JUCE_DECLARE_SINGLETON_INLINE (Analytics, false) #endif private: diff --git a/modules/juce_audio_devices/native/juce_Midi_windows.cpp b/modules/juce_audio_devices/native/juce_Midi_windows.cpp index 6a1caba63853..15c0bca0d75d 100644 --- a/modules/juce_audio_devices/native/juce_Midi_windows.cpp +++ b/modules/juce_audio_devices/native/juce_Midi_windows.cpp @@ -1879,7 +1879,7 @@ struct MidiService final : public DeletedAtShutdown return *getInstance()->internal.get(); } - JUCE_DECLARE_SINGLETON (MidiService, false) + JUCE_DECLARE_SINGLETON_INLINE (MidiService, false) private: std::unique_ptr internal; @@ -1889,8 +1889,6 @@ struct MidiService final : public DeletedAtShutdown } }; }; -JUCE_IMPLEMENT_SINGLETON (MidiService) - //============================================================================== static int findDefaultDeviceIndex (const Array& available, const MidiDeviceInfo& defaultDevice) { diff --git a/modules/juce_core/memory/juce_Singleton.h b/modules/juce_core/memory/juce_Singleton.h index 635112feb86f..5c472c5137af 100644 --- a/modules/juce_core/memory/juce_Singleton.h +++ b/modules/juce_core/memory/juce_Singleton.h @@ -135,6 +135,15 @@ struct SingletonHolder : private MutexType // (inherited so we can use the empt std::atomic instance { nullptr }; }; +#ifndef DOXYGEN +#define JUCE_PRIVATE_DECLARE_SINGLETON(Classname, mutex, doNotRecreate, inlineToken, getter) \ + static inlineToken juce::SingletonHolder singletonHolder; \ + friend juce::SingletonHolder; \ + static Classname* JUCE_CALLTYPE getInstance() { return singletonHolder.getter(); } \ + static Classname* JUCE_CALLTYPE getInstanceWithoutCreating() noexcept { return singletonHolder.instance; } \ + static void JUCE_CALLTYPE deleteInstance() noexcept { singletonHolder.deleteInstance(); } \ + void clearSingletonInstance() noexcept { singletonHolder.clear (this); } +#endif //============================================================================== /** @@ -194,27 +203,28 @@ struct SingletonHolder : private MutexType // (inherited so we can use the empt @see JUCE_IMPLEMENT_SINGLETON, JUCE_DECLARE_SINGLETON_SINGLETHREADED */ #define JUCE_DECLARE_SINGLETON(Classname, doNotRecreateAfterDeletion) \ -\ - static juce::SingletonHolder singletonHolder; \ - friend juce::SingletonHolder; \ -\ - 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); } + JUCE_PRIVATE_DECLARE_SINGLETON (Classname, juce::CriticalSection, doNotRecreateAfterDeletion, , get) +/** + The same as JUCE_DECLARE_SINGLETON, but does not require a matching + JUCE_IMPLEMENT_SINGLETON definition. +*/ +#define JUCE_DECLARE_SINGLETON_INLINE(Classname, doNotRecreateAfterDeletion) \ + JUCE_PRIVATE_DECLARE_SINGLETON (Classname, juce::CriticalSection, doNotRecreateAfterDeletion, inline, get) //============================================================================== /** This is a counterpart to the JUCE_DECLARE_SINGLETON macros. After adding the JUCE_DECLARE_SINGLETON to the class definition, this macro has to be used in the cpp file. + + This macro is not required for singletons declared with the INLINE macros, specifically + JUCE_DECLARE_SINGLETON_INLINE, JUCE_DECLARE_SINGLETON_SINGLETHREADED_INLINE, and + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE. */ #define JUCE_IMPLEMENT_SINGLETON(Classname) \ -\ decltype (Classname::singletonHolder) Classname::singletonHolder; - //============================================================================== /** Macro to declare member variables and methods for a singleton class. @@ -236,15 +246,14 @@ struct SingletonHolder : private MutexType // (inherited so we can use the empt @see JUCE_IMPLEMENT_SINGLETON, JUCE_DECLARE_SINGLETON, JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL */ #define JUCE_DECLARE_SINGLETON_SINGLETHREADED(Classname, doNotRecreateAfterDeletion) \ -\ - static juce::SingletonHolder singletonHolder; \ - friend decltype (singletonHolder); \ -\ - 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); } + JUCE_PRIVATE_DECLARE_SINGLETON (Classname, juce::DummyCriticalSection, doNotRecreateAfterDeletion, , get) +/** + The same as JUCE_DECLARE_SINGLETON_SINGLETHREADED, but does not require a matching + JUCE_IMPLEMENT_SINGLETON definition. +*/ +#define JUCE_DECLARE_SINGLETON_SINGLETHREADED_INLINE(Classname, doNotRecreateAfterDeletion) \ + JUCE_PRIVATE_DECLARE_SINGLETON (Classname, juce::DummyCriticalSection, doNotRecreateAfterDeletion, inline, get) //============================================================================== /** @@ -262,15 +271,14 @@ struct SingletonHolder : private MutexType // (inherited so we can use the empt @see JUCE_IMPLEMENT_SINGLETON, JUCE_DECLARE_SINGLETON */ #define JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL(Classname) \ -\ - static juce::SingletonHolder singletonHolder; \ - friend decltype (singletonHolder); \ -\ - 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); } + JUCE_PRIVATE_DECLARE_SINGLETON (Classname, juce::DummyCriticalSection, false, , getWithoutChecking) +/** + The same as JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL, but does not require a matching + JUCE_IMPLEMENT_SINGLETON definition. +*/ +#define JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE(Classname) \ + JUCE_PRIVATE_DECLARE_SINGLETON (Classname, juce::DummyCriticalSection, false, inline, getWithoutChecking) //============================================================================== #ifndef DOXYGEN diff --git a/modules/juce_events/interprocess/juce_ChildProcessManager.cpp b/modules/juce_events/interprocess/juce_ChildProcessManager.cpp index 0b52afabc8de..53b28f71a0d4 100644 --- a/modules/juce_events/interprocess/juce_ChildProcessManager.cpp +++ b/modules/juce_events/interprocess/juce_ChildProcessManager.cpp @@ -55,6 +55,4 @@ void ChildProcessManager::checkProcesses() timer.stopTimer(); } -JUCE_IMPLEMENT_SINGLETON (ChildProcessManager) - } // namespace juce diff --git a/modules/juce_events/interprocess/juce_ChildProcessManager.h b/modules/juce_events/interprocess/juce_ChildProcessManager.h index 5f1eda3ce4fb..caf3994e6e5c 100644 --- a/modules/juce_events/interprocess/juce_ChildProcessManager.h +++ b/modules/juce_events/interprocess/juce_ChildProcessManager.h @@ -57,7 +57,7 @@ namespace juce { public: #ifndef DOXYGEN - JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (ChildProcessManager) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE (ChildProcessManager) #endif /** Creates a new ChildProcess and starts it with the provided arguments. diff --git a/modules/juce_events/native/juce_Messaging_android.cpp b/modules/juce_events/native/juce_Messaging_android.cpp index 85f46384c6a2..eb559d06ca82 100644 --- a/modules/juce_events/native/juce_Messaging_android.cpp +++ b/modules/juce_events/native/juce_Messaging_android.cpp @@ -65,7 +65,7 @@ namespace Android Handler() : nativeHandler (LocalRef (getEnv()->NewObject (AndroidHandler, AndroidHandler.constructor))) {} ~Handler() { clearSingletonInstance(); } - JUCE_DECLARE_SINGLETON (Handler, false) + JUCE_DECLARE_SINGLETON_INLINE (Handler, false) bool post (jobject runnable) { @@ -74,14 +74,12 @@ namespace Android GlobalRef nativeHandler; }; - - JUCE_IMPLEMENT_SINGLETON (Handler) } //============================================================================== struct AndroidMessageQueue final : private Android::Runnable { - JUCE_DECLARE_SINGLETON_SINGLETHREADED (AndroidMessageQueue, true) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_INLINE (AndroidMessageQueue, true) AndroidMessageQueue() : self (CreateJavaInterface (this, "java/lang/Runnable")) @@ -124,8 +122,6 @@ struct AndroidMessageQueue final : private Android::Runnable Android::Handler handler; }; -JUCE_IMPLEMENT_SINGLETON (AndroidMessageQueue) - //============================================================================== void MessageManager::doPlatformSpecificInitialisation() { AndroidMessageQueue::getInstance(); } void MessageManager::doPlatformSpecificShutdown() { AndroidMessageQueue::deleteInstance(); } diff --git a/modules/juce_events/native/juce_Messaging_linux.cpp b/modules/juce_events/native/juce_Messaging_linux.cpp index d18131bbf527..8d4943098f11 100644 --- a/modules/juce_events/native/juce_Messaging_linux.cpp +++ b/modules/juce_events/native/juce_Messaging_linux.cpp @@ -85,7 +85,7 @@ class InternalMessageQueue } //============================================================================== - JUCE_DECLARE_SINGLETON (InternalMessageQueue, false) + JUCE_DECLARE_SINGLETON_INLINE (InternalMessageQueue, false) private: CriticalSection lock; @@ -115,8 +115,6 @@ class InternalMessageQueue } }; -JUCE_IMPLEMENT_SINGLETON (InternalMessageQueue) - //============================================================================== /* Stores callbacks associated with file descriptors (FD). @@ -230,7 +228,7 @@ struct InternalRunLoop void removeListener (LinuxEventLoopInternal::Listener& listener) { listeners.remove (&listener); } //============================================================================== - JUCE_DECLARE_SINGLETON (InternalRunLoop, false) + JUCE_DECLARE_SINGLETON_INLINE (InternalRunLoop, false) private: using SharedCallback = std::shared_ptr>; @@ -282,8 +280,6 @@ struct InternalRunLoop ListenerList listeners; }; -JUCE_IMPLEMENT_SINGLETON (InternalRunLoop) - //============================================================================== namespace LinuxErrorHandling { diff --git a/modules/juce_events/native/juce_Messaging_windows.cpp b/modules/juce_events/native/juce_Messaging_windows.cpp index 6b594ce91996..ae636832824b 100644 --- a/modules/juce_events/native/juce_Messaging_windows.cpp +++ b/modules/juce_events/native/juce_Messaging_windows.cpp @@ -63,7 +63,7 @@ class InternalMessageQueue clearSingletonInstance(); } - JUCE_DECLARE_SINGLETON (InternalMessageQueue, false) + JUCE_DECLARE_SINGLETON_INLINE (InternalMessageQueue, false) //============================================================================== void broadcastMessage (const String& message) @@ -260,8 +260,6 @@ class InternalMessageQueue JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InternalMessageQueue) }; -JUCE_IMPLEMENT_SINGLETON (InternalMessageQueue) - const TCHAR InternalMessageQueue::messageWindowName[] = _T("JUCEWindow"); //============================================================================== diff --git a/modules/juce_events/native/juce_WinRTWrapper_windows.cpp b/modules/juce_events/native/juce_WinRTWrapper_windows.cpp index 2b5a90660573..60b13c4f3365 100644 --- a/modules/juce_events/native/juce_WinRTWrapper_windows.cpp +++ b/modules/juce_events/native/juce_WinRTWrapper_windows.cpp @@ -88,7 +88,4 @@ String WinRTWrapper::hStringToString (HSTRING hstr) return {}; } - -JUCE_IMPLEMENT_SINGLETON (WinRTWrapper) - } diff --git a/modules/juce_events/native/juce_WinRTWrapper_windows.h b/modules/juce_events/native/juce_WinRTWrapper_windows.h index 2b0e20b13714..c71ee67c9b8b 100644 --- a/modules/juce_events/native/juce_WinRTWrapper_windows.h +++ b/modules/juce_events/native/juce_WinRTWrapper_windows.h @@ -42,7 +42,7 @@ class WinRTWrapper : public DeletedAtShutdown ~WinRTWrapper(); bool isInitialised() const noexcept { return initialised; } - JUCE_DECLARE_SINGLETON (WinRTWrapper, false) + JUCE_DECLARE_SINGLETON_INLINE (WinRTWrapper, false) //============================================================================== template diff --git a/modules/juce_events/timers/juce_Timer.cpp b/modules/juce_events/timers/juce_Timer.cpp index e8010eeee726..17662237640e 100644 --- a/modules/juce_events/timers/juce_Timer.cpp +++ b/modules/juce_events/timers/juce_Timer.cpp @@ -77,11 +77,9 @@ class ShutdownDetector : private DeletedAtShutdown JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ShutdownDetector) JUCE_DECLARE_NON_MOVEABLE (ShutdownDetector) - JUCE_DECLARE_SINGLETON (ShutdownDetector, false) + JUCE_DECLARE_SINGLETON_INLINE (ShutdownDetector, false) }; -JUCE_IMPLEMENT_SINGLETON (ShutdownDetector) - class Timer::TimerThread final : private Thread, private ShutdownDetector::Listener { diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp index 0fb76ee9263d..056a6f224512 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp @@ -85,16 +85,13 @@ namespace : configureArrangement (args); } - JUCE_DECLARE_SINGLETON (GlyphArrangementCache, false) + JUCE_DECLARE_SINGLETON_INLINE (GlyphArrangementCache, false) private: LruCache cache; CriticalSection lock; }; - template - juce::SingletonHolder, juce::CriticalSection, false> GlyphArrangementCache::singletonHolder; - //============================================================================== template Rectangle coordsToRectangle (Type x, Type y, Type w, Type h) noexcept diff --git a/modules/juce_graphics/fonts/juce_Font.cpp b/modules/juce_graphics/fonts/juce_Font.cpp index 91d223d8b605..5641606f1b79 100644 --- a/modules/juce_graphics/fonts/juce_Font.cpp +++ b/modules/juce_graphics/fonts/juce_Font.cpp @@ -63,7 +63,7 @@ class TypefaceCache final : private DeletedAtShutdown clearSingletonInstance(); } - JUCE_DECLARE_SINGLETON (TypefaceCache, false) + JUCE_DECLARE_SINGLETON_INLINE (TypefaceCache, false) void setSize (const int numToCache) { @@ -170,8 +170,6 @@ class TypefaceCache final : private DeletedAtShutdown JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TypefaceCache) }; -JUCE_IMPLEMENT_SINGLETON (TypefaceCache) - void Typeface::setTypefaceCacheSize (int numFontsToCache) { TypefaceCache::getInstance()->setSize (numFontsToCache); diff --git a/modules/juce_graphics/fonts/juce_TypefaceFileCache.h b/modules/juce_graphics/fonts/juce_TypefaceFileCache.h index 98fc18050b1d..6a1444d37c8f 100644 --- a/modules/juce_graphics/fonts/juce_TypefaceFileCache.h +++ b/modules/juce_graphics/fonts/juce_TypefaceFileCache.h @@ -61,14 +61,12 @@ class TypefaceFileCache : public DeletedAtShutdown return cachedTypefaces.get (key, std::forward (getTypeface)); } - JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (TypefaceFileCache) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE (TypefaceFileCache) private: LruCache cachedTypefaces; }; -JUCE_IMPLEMENT_SINGLETON (TypefaceFileCache) - } // namespace juce #endif diff --git a/modules/juce_graphics/images/juce_ImageCache.cpp b/modules/juce_graphics/images/juce_ImageCache.cpp index 01287af128f4..d37c5a81909b 100644 --- a/modules/juce_graphics/images/juce_ImageCache.cpp +++ b/modules/juce_graphics/images/juce_ImageCache.cpp @@ -46,7 +46,7 @@ struct ImageCache::Pimpl : private Timer, clearSingletonInstance(); } - JUCE_DECLARE_SINGLETON (ImageCache::Pimpl, false) + JUCE_DECLARE_SINGLETON_INLINE (ImageCache::Pimpl, false) Image getFromHashCode (const int64 hashCode) noexcept { @@ -124,9 +124,6 @@ struct ImageCache::Pimpl : private Timer, JUCE_DECLARE_NON_COPYABLE (Pimpl) }; -JUCE_IMPLEMENT_SINGLETON (ImageCache::Pimpl) - - //============================================================================== Image ImageCache::getFromHashCode (const int64 hashCode) { diff --git a/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp b/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp index f8bde56e2bce..65e007546ace 100644 --- a/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp +++ b/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp @@ -35,10 +35,6 @@ namespace juce { -#if JUCE_DIRECT2D_METRICS -JUCE_IMPLEMENT_SINGLETON (Direct2DMetricsHub) -#endif - struct ScopedBlendCopy { explicit ScopedBlendCopy (ComSmartPtr c) diff --git a/modules/juce_graphics/native/juce_Direct2DMetrics_windows.h b/modules/juce_graphics/native/juce_Direct2DMetrics_windows.h index db4d4011baef..56027a559b7a 100644 --- a/modules/juce_graphics/native/juce_Direct2DMetrics_windows.h +++ b/modules/juce_graphics/native/juce_Direct2DMetrics_windows.h @@ -260,7 +260,7 @@ class Direct2DMetricsHub : public DeletedAtShutdown static constexpr int magicNumber = 0xd2d1; - JUCE_DECLARE_SINGLETON (Direct2DMetricsHub, false) + JUCE_DECLARE_SINGLETON_INLINE (Direct2DMetricsHub, false) private: static String getProcessString() noexcept; diff --git a/modules/juce_graphics/native/juce_Fonts_android.cpp b/modules/juce_graphics/native/juce_Fonts_android.cpp index 013d6a824897..e9cc3eafd608 100644 --- a/modules/juce_graphics/native/juce_Fonts_android.cpp +++ b/modules/juce_graphics/native/juce_Fonts_android.cpp @@ -176,15 +176,13 @@ class MemoryFontCache : public DeletedAtShutdown return {}; } - JUCE_DECLARE_SINGLETON (MemoryFontCache, true) + JUCE_DECLARE_SINGLETON_INLINE (MemoryFontCache, true) private: std::map cache; mutable std::mutex mutex; }; -JUCE_IMPLEMENT_SINGLETON (MemoryFontCache) - StringArray Font::findAllTypefaceNames() { auto results = [&] diff --git a/modules/juce_graphics/native/juce_Fonts_freetype.cpp b/modules/juce_graphics/native/juce_Fonts_freetype.cpp index 699c1c564174..ffa4d8d014ac 100644 --- a/modules/juce_graphics/native/juce_Fonts_freetype.cpp +++ b/modules/juce_graphics/native/juce_Fonts_freetype.cpp @@ -316,7 +316,7 @@ class FTTypefaceList final : private DeletedAtShutdown faces.erase (iter); } - JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (FTTypefaceList) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE (FTTypefaceList) FTLibWrapper::Ptr getLibrary() const { return library; } @@ -373,8 +373,6 @@ class FTTypefaceList final : private DeletedAtShutdown JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FTTypefaceList) }; -JUCE_IMPLEMENT_SINGLETON (FTTypefaceList) - //============================================================================== class FreeTypeTypeface final : public Typeface { diff --git a/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp b/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp index 18a5731eb9b0..7241b9c01172 100644 --- a/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp +++ b/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp @@ -108,9 +108,6 @@ ModalComponentManager::~ModalComponentManager() clearSingletonInstance(); } -JUCE_IMPLEMENT_SINGLETON (ModalComponentManager) - - //============================================================================== void ModalComponentManager::startModal (Key, Component* component, bool autoDelete) { diff --git a/modules/juce_gui_basics/components/juce_ModalComponentManager.h b/modules/juce_gui_basics/components/juce_ModalComponentManager.h index 52364876e3d3..f0a043379b9c 100644 --- a/modules/juce_gui_basics/components/juce_ModalComponentManager.h +++ b/modules/juce_gui_basics/components/juce_ModalComponentManager.h @@ -85,7 +85,7 @@ class JUCE_API ModalComponentManager : private AsyncUpdater, //============================================================================== #ifndef DOXYGEN - JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (ModalComponentManager) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE (ModalComponentManager) #endif //============================================================================== diff --git a/modules/juce_gui_basics/detail/juce_TopLevelWindowManager.h b/modules/juce_gui_basics/detail/juce_TopLevelWindowManager.h index c042093d7ed6..05e5369d68be 100644 --- a/modules/juce_gui_basics/detail/juce_TopLevelWindowManager.h +++ b/modules/juce_gui_basics/detail/juce_TopLevelWindowManager.h @@ -47,7 +47,7 @@ class TopLevelWindowManager : private Timer, clearSingletonInstance(); } - JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (TopLevelWindowManager) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE (TopLevelWindowManager) static void checkCurrentlyFocusedTopLevelWindow() { @@ -140,6 +140,4 @@ class TopLevelWindowManager : private Timer, JUCE_DECLARE_NON_COPYABLE (TopLevelWindowManager) }; -JUCE_IMPLEMENT_SINGLETON (TopLevelWindowManager) - } // namespace juce::detail diff --git a/modules/juce_gui_basics/native/accessibility/juce_Accessibility_windows.cpp b/modules/juce_gui_basics/native/accessibility/juce_Accessibility_windows.cpp index 81391ce47f53..0c98af66dd96 100644 --- a/modules/juce_gui_basics/native/accessibility/juce_Accessibility_windows.cpp +++ b/modules/juce_gui_basics/native/accessibility/juce_Accessibility_windows.cpp @@ -263,11 +263,9 @@ struct SpVoiceWrapper final : public DeletedAtShutdown ComSmartPtr voice; - JUCE_DECLARE_SINGLETON (SpVoiceWrapper, false) + JUCE_DECLARE_SINGLETON_INLINE (SpVoiceWrapper, false) }; -JUCE_IMPLEMENT_SINGLETON (SpVoiceWrapper) - void AccessibilityHandler::postAnnouncement (const String& announcementString, AnnouncementPriority priority) { @@ -329,8 +327,6 @@ namespace WindowsAccessibility } -JUCE_IMPLEMENT_SINGLETON (WindowsUIAWrapper) - JUCE_END_IGNORE_WARNINGS_GCC_LIKE } // namespace juce diff --git a/modules/juce_gui_basics/native/accessibility/juce_WindowsUIAWrapper_windows.h b/modules/juce_gui_basics/native/accessibility/juce_WindowsUIAWrapper_windows.h index 2050df449b59..7672123f8ff1 100644 --- a/modules/juce_gui_basics/native/accessibility/juce_WindowsUIAWrapper_windows.h +++ b/modules/juce_gui_basics/native/accessibility/juce_WindowsUIAWrapper_windows.h @@ -109,7 +109,7 @@ class WindowsUIAWrapper : public DeletedAtShutdown } //============================================================================== - JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (WindowsUIAWrapper) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE (WindowsUIAWrapper) private: //============================================================================== diff --git a/modules/juce_gui_basics/native/juce_DragAndDrop_windows.cpp b/modules/juce_gui_basics/native/juce_DragAndDrop_windows.cpp index fc38f0cb03c8..3d196639973e 100644 --- a/modules/juce_gui_basics/native/juce_DragAndDrop_windows.cpp +++ b/modules/juce_gui_basics/native/juce_DragAndDrop_windows.cpp @@ -311,14 +311,12 @@ namespace DragAndDropHelpers clearSingletonInstance(); } - JUCE_DECLARE_SINGLETON_SINGLETHREADED (ThreadPoolHolder, false) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_INLINE (ThreadPoolHolder, false) // We need to make sure we don't do simultaneous text and file drag and drops, // so use a pool that can only run a single job. ThreadPool pool { ThreadPoolOptions{}.withNumberOfThreads (1) }; }; - - JUCE_IMPLEMENT_SINGLETON (ThreadPoolHolder) } //============================================================================== diff --git a/modules/juce_gui_basics/native/juce_MainMenu_mac.mm b/modules/juce_gui_basics/native/juce_MainMenu_mac.mm index f28670d8eb9f..3ae4e8f1feb9 100644 --- a/modules/juce_gui_basics/native/juce_MainMenu_mac.mm +++ b/modules/juce_gui_basics/native/juce_MainMenu_mac.mm @@ -71,11 +71,9 @@ NSMenu* mainMenuBar = nil; - JUCE_DECLARE_SINGLETON_SINGLETHREADED (JuceMainMenuBarHolder, true) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_INLINE (JuceMainMenuBarHolder, true) }; -JUCE_IMPLEMENT_SINGLETON (JuceMainMenuBarHolder) - //============================================================================== class JuceMainMenuHandler final : private MenuBarModel::Listener, private DeletedAtShutdown diff --git a/modules/juce_gui_basics/native/juce_VBlank_windows.cpp b/modules/juce_gui_basics/native/juce_VBlank_windows.cpp index d92288b0f39c..4b8773401518 100644 --- a/modules/juce_gui_basics/native/juce_VBlank_windows.cpp +++ b/modules/juce_gui_basics/native/juce_VBlank_windows.cpp @@ -265,7 +265,7 @@ class VBlankDispatcher final : public DeletedAtShutdown threads.end()); } - JUCE_DECLARE_SINGLETON_SINGLETHREADED (VBlankDispatcher, false) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_INLINE (VBlankDispatcher, false) private: //============================================================================== @@ -304,6 +304,4 @@ class VBlankDispatcher final : public DeletedAtShutdown JUCE_DECLARE_NON_MOVEABLE (VBlankDispatcher) }; -JUCE_IMPLEMENT_SINGLETON (VBlankDispatcher) - } // namespace juce diff --git a/modules/juce_gui_basics/native/juce_Windowing_mac.mm b/modules/juce_gui_basics/native/juce_Windowing_mac.mm index 3163101d3522..5cc63ce9aacf 100644 --- a/modules/juce_gui_basics/native/juce_Windowing_mac.mm +++ b/modules/juce_gui_basics/native/juce_Windowing_mac.mm @@ -424,12 +424,10 @@ static void displayReconfigurationCallback (CGDirectDisplayID, CGDisplayChangeSu std::function forceDisplayUpdate; - JUCE_DECLARE_SINGLETON (DisplaySettingsChangeCallback, false) + JUCE_DECLARE_SINGLETON_INLINE (DisplaySettingsChangeCallback, false) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DisplaySettingsChangeCallback) }; -JUCE_IMPLEMENT_SINGLETON (DisplaySettingsChangeCallback) - static Rectangle convertDisplayRect (NSRect r, CGFloat mainScreenBottom) { r.origin.y = mainScreenBottom - (r.origin.y + r.size.height); diff --git a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp index e0d8833a7e50..c9434b09665e 100644 --- a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp +++ b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp @@ -2290,7 +2290,7 @@ class HWNDComponentPeer final : public ComponentPeer LPCTSTR getWindowClassName() const noexcept { return (LPCTSTR) (pointer_sized_uint) atom; } - JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (WindowClassHolder) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE (WindowClassHolder) private: ATOM atom; @@ -5556,8 +5556,6 @@ JUCE_API ComponentPeer* createNonRepaintingEmbeddedWindowsPeer (Component& compo return nullptr; } -JUCE_IMPLEMENT_SINGLETON (HWNDComponentPeer::WindowClassHolder) - //============================================================================== bool KeyPress::isKeyCurrentlyDown (const int keyCode) { diff --git a/modules/juce_gui_basics/native/juce_XSymbols_linux.cpp b/modules/juce_gui_basics/native/juce_XSymbols_linux.cpp index bab7aea43d0c..ba01288e6d5b 100644 --- a/modules/juce_gui_basics/native/juce_XSymbols_linux.cpp +++ b/modules/juce_gui_basics/native/juce_XSymbols_linux.cpp @@ -243,7 +243,4 @@ bool X11Symbols::loadAllSymbols() return true; } -//============================================================================== -JUCE_IMPLEMENT_SINGLETON (X11Symbols) - } // namespace juce diff --git a/modules/juce_gui_basics/native/juce_XSymbols_linux.h b/modules/juce_gui_basics/native/juce_XSymbols_linux.h index d101aa6f9881..8370a6158933 100644 --- a/modules/juce_gui_basics/native/juce_XSymbols_linux.h +++ b/modules/juce_gui_basics/native/juce_XSymbols_linux.h @@ -596,7 +596,7 @@ class JUCE_API X11Symbols #endif //============================================================================== - JUCE_DECLARE_SINGLETON (X11Symbols, false) + JUCE_DECLARE_SINGLETON_INLINE (X11Symbols, false) private: X11Symbols() = default; diff --git a/modules/juce_gui_basics/native/juce_XWindowSystem_linux.cpp b/modules/juce_gui_basics/native/juce_XWindowSystem_linux.cpp index 31fafd61cdb5..57d8ae6f88ef 100644 --- a/modules/juce_gui_basics/native/juce_XWindowSystem_linux.cpp +++ b/modules/juce_gui_basics/native/juce_XWindowSystem_linux.cpp @@ -3999,8 +3999,6 @@ void XWindowSystem::windowMessageReceive (XEvent& event) } //============================================================================== -JUCE_IMPLEMENT_SINGLETON (XWindowSystem) - Image createSnapshotOfNativeWindow (void* window) { ::Window root; diff --git a/modules/juce_gui_basics/native/juce_XWindowSystem_linux.h b/modules/juce_gui_basics/native/juce_XWindowSystem_linux.h index 36ccfebd97b7..e8733d1d213a 100644 --- a/modules/juce_gui_basics/native/juce_XWindowSystem_linux.h +++ b/modules/juce_gui_basics/native/juce_XWindowSystem_linux.h @@ -261,7 +261,7 @@ class XWindowSystem : public DeletedAtShutdown bool isParentWindowOf (::Window, ::Window possibleChild) const; //============================================================================== - JUCE_DECLARE_SINGLETON (XWindowSystem, false) + JUCE_DECLARE_SINGLETON_INLINE (XWindowSystem, false) private: XWindowSystem(); diff --git a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp index 391f567189a8..1ef3ae655604 100644 --- a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp +++ b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp @@ -45,7 +45,7 @@ class AllComponentRepainter final : private Timer, AllComponentRepainter() {} ~AllComponentRepainter() override { clearSingletonInstance(); } - JUCE_DECLARE_SINGLETON (AllComponentRepainter, false) + JUCE_DECLARE_SINGLETON_INLINE (AllComponentRepainter, false) void trigger() { @@ -94,9 +94,6 @@ class AllComponentRepainter final : private Timer, } }; -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 167cddef8533..0b5f052cf5b6 100644 --- a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h +++ b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h @@ -203,7 +203,7 @@ namespace juce::LiveConstantEditor ValueList(); ~ValueList() override; - JUCE_DECLARE_SINGLETON (ValueList, false) + JUCE_DECLARE_SINGLETON_INLINE (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 c9b70984843e..4b6bca78be0d 100644 --- a/modules/juce_gui_extra/misc/juce_PushNotifications.cpp +++ b/modules/juce_gui_extra/misc/juce_PushNotifications.cpp @@ -81,8 +81,6 @@ PushNotifications::Notification::Notification (const Notification& other) } //============================================================================== -JUCE_IMPLEMENT_SINGLETON (PushNotifications) - PushNotifications::PushNotifications() #if JUCE_PUSH_NOTIFICATIONS : pimpl (new Pimpl (*this)) diff --git a/modules/juce_gui_extra/misc/juce_PushNotifications.h b/modules/juce_gui_extra/misc/juce_PushNotifications.h index 7a497874e903..b3d7b550b1b6 100644 --- a/modules/juce_gui_extra/misc/juce_PushNotifications.h +++ b/modules/juce_gui_extra/misc/juce_PushNotifications.h @@ -55,7 +55,7 @@ class JUCE_API PushNotifications : private DeletedAtShutdown { public: #ifndef DOXYGEN - JUCE_DECLARE_SINGLETON (PushNotifications, false) + JUCE_DECLARE_SINGLETON_INLINE (PushNotifications, false) #endif //============================================================================== diff --git a/modules/juce_gui_extra/native/juce_WebBrowserComponent_linux.cpp b/modules/juce_gui_extra/native/juce_WebBrowserComponent_linux.cpp index 38033d7adc1e..f92dfbe4e683 100644 --- a/modules/juce_gui_extra/native/juce_WebBrowserComponent_linux.cpp +++ b/modules/juce_gui_extra/native/juce_WebBrowserComponent_linux.cpp @@ -255,7 +255,7 @@ class WebKitSymbols final : public DeletedAtShutdown (gpointer), void) //============================================================================== - JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (WebKitSymbols) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE (WebKitSymbols) private: WebKitSymbols() = default; @@ -417,8 +417,6 @@ class WebKitSymbols final : public DeletedAtShutdown JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WebKitSymbols) }; -JUCE_IMPLEMENT_SINGLETON (WebKitSymbols) - //============================================================================== extern "C" int juce_gtkWebkitMain (int argc, const char* const* argv); diff --git a/modules/juce_product_unlocking/in_app_purchases/juce_InAppPurchases.cpp b/modules/juce_product_unlocking/in_app_purchases/juce_InAppPurchases.cpp index 19cf10a46587..77bc754103cc 100644 --- a/modules/juce_product_unlocking/in_app_purchases/juce_InAppPurchases.cpp +++ b/modules/juce_product_unlocking/in_app_purchases/juce_InAppPurchases.cpp @@ -36,8 +36,6 @@ namespace juce { //============================================================================== -JUCE_IMPLEMENT_SINGLETON (InAppPurchases) - InAppPurchases::InAppPurchases() #if JUCE_ANDROID || JUCE_IOS || JUCE_MAC : pimpl (new Pimpl (*this)) diff --git a/modules/juce_product_unlocking/in_app_purchases/juce_InAppPurchases.h b/modules/juce_product_unlocking/in_app_purchases/juce_InAppPurchases.h index 159ee890fca6..9e7718b66a6b 100644 --- a/modules/juce_product_unlocking/in_app_purchases/juce_InAppPurchases.h +++ b/modules/juce_product_unlocking/in_app_purchases/juce_InAppPurchases.h @@ -50,7 +50,7 @@ class JUCE_API InAppPurchases : private DeletedAtShutdown { public: #ifndef DOXYGEN - JUCE_DECLARE_SINGLETON (InAppPurchases, false) + JUCE_DECLARE_SINGLETON_INLINE (InAppPurchases, false) #endif //============================================================================== diff --git a/modules/juce_video/native/juce_Video_windows.h b/modules/juce_video/native/juce_Video_windows.h index 0aebba910dc0..fb05716e649b 100644 --- a/modules/juce_video/native/juce_Video_windows.h +++ b/modules/juce_video/native/juce_Video_windows.h @@ -849,7 +849,7 @@ struct VideoComponent::Pimpl : public Component, bool isRegistered() const noexcept { return atom != 0; } LPCTSTR getWindowClassName() const noexcept { return (LPCTSTR) (pointer_sized_uint) MAKELONG (atom, 0); } - JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (NativeWindowClass) + JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE (NativeWindowClass) private: NativeWindowClass() @@ -965,5 +965,3 @@ struct VideoComponent::Pimpl : public Component, JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl) }; - -JUCE_IMPLEMENT_SINGLETON (VideoComponent::Pimpl::DirectShowContext::NativeWindowClass)