@@ -135,6 +135,15 @@ struct SingletonHolder : private MutexType // (inherited so we can use the empt
135135 std::atomic<Type*> instance { nullptr };
136136};
137137
138+ #ifndef DOXYGEN
139+ #define JUCE_PRIVATE_DECLARE_SINGLETON (Classname, mutex, doNotRecreate, inlineToken, getter ) \
140+ static inlineToken juce::SingletonHolder<Classname, mutex, doNotRecreate> singletonHolder; \
141+ friend juce::SingletonHolder<Classname, mutex, doNotRecreate>; \
142+ static Classname* JUCE_CALLTYPE getInstance () { return singletonHolder.getter (); } \
143+ static Classname* JUCE_CALLTYPE getInstanceWithoutCreating () noexcept { return singletonHolder.instance ; } \
144+ static void JUCE_CALLTYPE deleteInstance () noexcept { singletonHolder.deleteInstance (); } \
145+ void clearSingletonInstance () noexcept { singletonHolder.clear (this ); }
146+ #endif
138147
139148// ==============================================================================
140149/* *
@@ -194,27 +203,28 @@ struct SingletonHolder : private MutexType // (inherited so we can use the empt
194203 @see JUCE_IMPLEMENT_SINGLETON, JUCE_DECLARE_SINGLETON_SINGLETHREADED
195204*/
196205#define JUCE_DECLARE_SINGLETON (Classname, doNotRecreateAfterDeletion ) \
197- \
198- static juce::SingletonHolder<Classname, juce::CriticalSection, doNotRecreateAfterDeletion> singletonHolder; \
199- friend juce::SingletonHolder<Classname, juce::CriticalSection, doNotRecreateAfterDeletion>; \
200- \
201- static Classname* JUCE_CALLTYPE getInstance () { return singletonHolder.get (); } \
202- static Classname* JUCE_CALLTYPE getInstanceWithoutCreating () noexcept { return singletonHolder.instance ; } \
203- static void JUCE_CALLTYPE deleteInstance () noexcept { singletonHolder.deleteInstance (); } \
204- void clearSingletonInstance () noexcept { singletonHolder.clear (this ); }
206+ JUCE_PRIVATE_DECLARE_SINGLETON (Classname, juce::CriticalSection, doNotRecreateAfterDeletion, , get)
205207
208+ /* *
209+ The same as JUCE_DECLARE_SINGLETON, but does not require a matching
210+ JUCE_IMPLEMENT_SINGLETON definition.
211+ */
212+ #define JUCE_DECLARE_SINGLETON_INLINE (Classname, doNotRecreateAfterDeletion ) \
213+ JUCE_PRIVATE_DECLARE_SINGLETON (Classname, juce::CriticalSection, doNotRecreateAfterDeletion, inline , get)
206214
207215// ==============================================================================
208216/* * This is a counterpart to the JUCE_DECLARE_SINGLETON macros.
209217
210218 After adding the JUCE_DECLARE_SINGLETON to the class definition, this macro has
211219 to be used in the cpp file.
220+
221+ This macro is not required for singletons declared with the INLINE macros, specifically
222+ JUCE_DECLARE_SINGLETON_INLINE, JUCE_DECLARE_SINGLETON_SINGLETHREADED_INLINE, and
223+ JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE.
212224*/
213225#define JUCE_IMPLEMENT_SINGLETON (Classname ) \
214- \
215226 decltype (Classname::singletonHolder) Classname::singletonHolder;
216227
217-
218228// ==============================================================================
219229/* *
220230 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
236246 @see JUCE_IMPLEMENT_SINGLETON, JUCE_DECLARE_SINGLETON, JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL
237247*/
238248#define JUCE_DECLARE_SINGLETON_SINGLETHREADED (Classname, doNotRecreateAfterDeletion ) \
239- \
240- static juce::SingletonHolder<Classname, juce::DummyCriticalSection, doNotRecreateAfterDeletion> singletonHolder; \
241- friend decltype (singletonHolder); \
242- \
243- static Classname* JUCE_CALLTYPE getInstance () { return singletonHolder.get (); } \
244- static Classname* JUCE_CALLTYPE getInstanceWithoutCreating () noexcept { return singletonHolder.instance ; } \
245- static void JUCE_CALLTYPE deleteInstance () noexcept { singletonHolder.deleteInstance (); } \
246- void clearSingletonInstance () noexcept { singletonHolder.clear (this ); }
249+ JUCE_PRIVATE_DECLARE_SINGLETON (Classname, juce::DummyCriticalSection, doNotRecreateAfterDeletion, , get)
247250
251+ /* *
252+ The same as JUCE_DECLARE_SINGLETON_SINGLETHREADED, but does not require a matching
253+ JUCE_IMPLEMENT_SINGLETON definition.
254+ */
255+ #define JUCE_DECLARE_SINGLETON_SINGLETHREADED_INLINE (Classname, doNotRecreateAfterDeletion ) \
256+ JUCE_PRIVATE_DECLARE_SINGLETON (Classname, juce::DummyCriticalSection, doNotRecreateAfterDeletion, inline , get)
248257
249258// ==============================================================================
250259/* *
@@ -262,15 +271,14 @@ struct SingletonHolder : private MutexType // (inherited so we can use the empt
262271 @see JUCE_IMPLEMENT_SINGLETON, JUCE_DECLARE_SINGLETON
263272*/
264273#define JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (Classname ) \
265- \
266- static juce::SingletonHolder<Classname, juce::DummyCriticalSection, false > singletonHolder; \
267- friend decltype (singletonHolder); \
268- \
269- static Classname* JUCE_CALLTYPE getInstance () { return singletonHolder.getWithoutChecking (); } \
270- static Classname* JUCE_CALLTYPE getInstanceWithoutCreating () noexcept { return singletonHolder.instance ; } \
271- static void JUCE_CALLTYPE deleteInstance () noexcept { singletonHolder.deleteInstance (); } \
272- void clearSingletonInstance () noexcept { singletonHolder.clear (this ); }
274+ JUCE_PRIVATE_DECLARE_SINGLETON (Classname, juce::DummyCriticalSection, false , , getWithoutChecking)
273275
276+ /* *
277+ The same as JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL, but does not require a matching
278+ JUCE_IMPLEMENT_SINGLETON definition.
279+ */
280+ #define JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE (Classname ) \
281+ JUCE_PRIVATE_DECLARE_SINGLETON (Classname, juce::DummyCriticalSection, false , inline , getWithoutChecking)
274282
275283// ==============================================================================
276284#ifndef DOXYGEN
0 commit comments