1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

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.
This commit is contained in:
reuk 2024-10-07 12:30:43 +01:00
parent 5179f4e720
commit 80ac9a78a0
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
44 changed files with 69 additions and 138 deletions

View file

@ -55,6 +55,4 @@ void ChildProcessManager::checkProcesses()
timer.stopTimer();
}
JUCE_IMPLEMENT_SINGLETON (ChildProcessManager)
} // namespace juce

View file

@ -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.

View file

@ -65,7 +65,7 @@ namespace Android
Handler() : nativeHandler (LocalRef<jobject> (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 @@ private:
Android::Handler handler;
};
JUCE_IMPLEMENT_SINGLETON (AndroidMessageQueue)
//==============================================================================
void MessageManager::doPlatformSpecificInitialisation() { AndroidMessageQueue::getInstance(); }
void MessageManager::doPlatformSpecificShutdown() { AndroidMessageQueue::deleteInstance(); }

View file

@ -85,7 +85,7 @@ public:
}
//==============================================================================
JUCE_DECLARE_SINGLETON (InternalMessageQueue, false)
JUCE_DECLARE_SINGLETON_INLINE (InternalMessageQueue, false)
private:
CriticalSection lock;
@ -115,8 +115,6 @@ private:
}
};
JUCE_IMPLEMENT_SINGLETON (InternalMessageQueue)
//==============================================================================
/*
Stores callbacks associated with file descriptors (FD).
@ -230,7 +228,7 @@ public:
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<std::function<void()>>;
@ -282,8 +280,6 @@ private:
ListenerList<LinuxEventLoopInternal::Listener> listeners;
};
JUCE_IMPLEMENT_SINGLETON (InternalRunLoop)
//==============================================================================
namespace LinuxErrorHandling
{

View file

@ -63,7 +63,7 @@ public:
clearSingletonInstance();
}
JUCE_DECLARE_SINGLETON (InternalMessageQueue, false)
JUCE_DECLARE_SINGLETON_INLINE (InternalMessageQueue, false)
//==============================================================================
void broadcastMessage (const String& message)
@ -260,8 +260,6 @@ private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InternalMessageQueue)
};
JUCE_IMPLEMENT_SINGLETON (InternalMessageQueue)
const TCHAR InternalMessageQueue::messageWindowName[] = _T("JUCEWindow");
//==============================================================================

View file

@ -88,7 +88,4 @@ String WinRTWrapper::hStringToString (HSTRING hstr)
return {};
}
JUCE_IMPLEMENT_SINGLETON (WinRTWrapper)
}

View file

@ -42,7 +42,7 @@ public:
~WinRTWrapper();
bool isInitialised() const noexcept { return initialised; }
JUCE_DECLARE_SINGLETON (WinRTWrapper, false)
JUCE_DECLARE_SINGLETON_INLINE (WinRTWrapper, false)
//==============================================================================
template <class ComClass>

View file

@ -77,11 +77,9 @@ private:
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
{