mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added JUCE_DECLARE_WEAK_REFERENCEABLE macro to make it easier to creat weak-referenceable classes
This commit is contained in:
parent
b44cb8b710
commit
1aaa598a5f
13 changed files with 50 additions and 62 deletions
|
|
@ -72,7 +72,6 @@ JucerTreeViewBase::JucerTreeViewBase() : textX (0)
|
|||
|
||||
JucerTreeViewBase::~JucerTreeViewBase()
|
||||
{
|
||||
masterReference.clear();
|
||||
}
|
||||
|
||||
void JucerTreeViewBase::refreshSubItems()
|
||||
|
|
|
|||
|
|
@ -110,10 +110,9 @@ private:
|
|||
friend class ItemSelectionTimer;
|
||||
ScopedPointer<Timer> delayedSelectionTimer;
|
||||
|
||||
WeakReference<JucerTreeViewBase>::Master masterReference;
|
||||
friend class WeakReference<JucerTreeViewBase>;
|
||||
|
||||
void invokeShowDocument();
|
||||
|
||||
JUCE_DECLARE_WEAK_REFERENCEABLE (JucerTreeViewBase)
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -1440,16 +1440,7 @@ struct ASIOAudioIODevice::ASIOCallbackFunctions <sizeof(currentASIODev) / sizeof
|
|||
class ASIOAudioIODeviceType : public AudioIODeviceType
|
||||
{
|
||||
public:
|
||||
ASIOAudioIODeviceType()
|
||||
: AudioIODeviceType ("ASIO"),
|
||||
hasScanned (false)
|
||||
{
|
||||
}
|
||||
|
||||
~ASIOAudioIODeviceType()
|
||||
{
|
||||
masterReference.clear();
|
||||
}
|
||||
ASIOAudioIODeviceType() : AudioIODeviceType ("ASIO") {}
|
||||
|
||||
//==============================================================================
|
||||
void scanForDevices()
|
||||
|
|
@ -1545,13 +1536,13 @@ public:
|
|||
callDeviceChangeListeners();
|
||||
}
|
||||
|
||||
WeakReference<ASIOAudioIODeviceType>::Master masterReference;
|
||||
JUCE_DECLARE_WEAK_REFERENCEABLE (ASIOAudioIODeviceType)
|
||||
|
||||
private:
|
||||
StringArray deviceNames;
|
||||
Array<CLSID> classIds;
|
||||
|
||||
bool hasScanned;
|
||||
bool hasScanned = false;
|
||||
|
||||
//==============================================================================
|
||||
static bool checkClassIsOk (const String& classId)
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ namespace juce
|
|||
friend class WeakReference<MyObject>;
|
||||
};
|
||||
|
||||
OR: just use the handy JUCE_DECLARE_WEAK_REFERENCEABLE macro to do all this for you.
|
||||
|
||||
// Here's an example of using a pointer..
|
||||
|
||||
MyObject* n = new MyObject();
|
||||
|
|
@ -202,4 +204,31 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Macro to easily allow a class to be made weak-referenceable.
|
||||
This can be inserted in a class definition to add the requisite weak-ref boilerplate to that class.
|
||||
e.g.
|
||||
|
||||
@code
|
||||
class MyObject
|
||||
{
|
||||
public:
|
||||
MyObject();
|
||||
~MyObject();
|
||||
|
||||
private:
|
||||
JUCE_DECLARE_WEAK_REFERENCEABLE (MyObject)
|
||||
};
|
||||
@endcode
|
||||
|
||||
@see WeakReference, WeakReference::Master
|
||||
*/
|
||||
#define JUCE_DECLARE_WEAK_REFERENCEABLE(Class) \
|
||||
struct WeakRefMaster : public WeakReference<Class>::Master { ~WeakRefMaster() { this->clear(); } }; \
|
||||
WeakRefMaster masterReference; \
|
||||
friend class WeakReference<Class>; \
|
||||
|
||||
|
||||
} // namespace juce
|
||||
|
|
|
|||
|
|
@ -59,8 +59,6 @@ ActionBroadcaster::~ActionBroadcaster()
|
|||
{
|
||||
// all event-based objects must be deleted BEFORE juce is shut down!
|
||||
jassert (MessageManager::getInstanceWithoutCreating() != nullptr);
|
||||
|
||||
masterReference.clear();
|
||||
}
|
||||
|
||||
void ActionBroadcaster::addActionListener (ActionListener* const listener)
|
||||
|
|
|
|||
|
|
@ -64,15 +64,13 @@ public:
|
|||
|
||||
private:
|
||||
//==============================================================================
|
||||
friend class WeakReference<ActionBroadcaster>;
|
||||
WeakReference<ActionBroadcaster>::Master masterReference;
|
||||
|
||||
class ActionMessage;
|
||||
friend class ActionMessage;
|
||||
|
||||
SortedSet<ActionListener*> actionListeners;
|
||||
CriticalSection actionListenerLock;
|
||||
|
||||
JUCE_DECLARE_WEAK_REFERENCEABLE (ActionBroadcaster)
|
||||
JUCE_DECLARE_NON_COPYABLE (ActionBroadcaster)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -26,22 +26,16 @@ namespace juce
|
|||
struct InterprocessConnection::ConnectionThread : public Thread
|
||||
{
|
||||
ConnectionThread (InterprocessConnection& c) : Thread ("JUCE IPC"), owner (c) {}
|
||||
|
||||
void run() override { owner.runThread(); }
|
||||
|
||||
private:
|
||||
InterprocessConnection& owner;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConnectionThread)
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
|
||||
const uint32 magicMessageHeaderNumber)
|
||||
: callbackConnectionState (false),
|
||||
useMessageThread (callbacksOnMessageThread),
|
||||
magicMessageHeader (magicMessageHeaderNumber),
|
||||
pipeReceiveMessageTimeout (-1)
|
||||
InterprocessConnection::InterprocessConnection (bool callbacksOnMessageThread, uint32 magicMessageHeaderNumber)
|
||||
: useMessageThread (callbacksOnMessageThread),
|
||||
magicMessageHeader (magicMessageHeaderNumber)
|
||||
{
|
||||
thread = new ConnectionThread (*this);
|
||||
}
|
||||
|
|
@ -207,7 +201,7 @@ struct ConnectionStateMessage : public MessageManager::MessageBase
|
|||
|
||||
void messageCallback() override
|
||||
{
|
||||
if (InterprocessConnection* const ipc = owner)
|
||||
if (auto* ipc = owner.get())
|
||||
{
|
||||
if (connectionMade)
|
||||
ipc->connectionMade();
|
||||
|
|
@ -256,7 +250,7 @@ struct DataDeliveryMessage : public Message
|
|||
|
||||
void messageCallback() override
|
||||
{
|
||||
if (InterprocessConnection* const ipc = owner)
|
||||
if (auto* ipc = owner.get())
|
||||
ipc->messageReceived (data);
|
||||
}
|
||||
|
||||
|
|
@ -331,7 +325,7 @@ void InterprocessConnection::runThread()
|
|||
{
|
||||
if (socket != nullptr)
|
||||
{
|
||||
const int ready = socket->waitUntilReady (true, 0);
|
||||
auto ready = socket->waitUntilReady (true, 0);
|
||||
|
||||
if (ready < 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -176,15 +176,13 @@ public:
|
|||
|
||||
private:
|
||||
//==============================================================================
|
||||
WeakReference<InterprocessConnection>::Master masterReference;
|
||||
friend class WeakReference<InterprocessConnection>;
|
||||
CriticalSection pipeAndSocketLock;
|
||||
ScopedPointer<StreamingSocket> socket;
|
||||
ScopedPointer<NamedPipe> pipe;
|
||||
bool callbackConnectionState;
|
||||
bool callbackConnectionState = false;
|
||||
const bool useMessageThread;
|
||||
const uint32 magicMessageHeader;
|
||||
int pipeReceiveMessageTimeout;
|
||||
int pipeReceiveMessageTimeout = -1;
|
||||
|
||||
friend class InterprocessConnectionServer;
|
||||
void initialiseWithSocket (StreamingSocket*);
|
||||
|
|
@ -202,6 +200,7 @@ private:
|
|||
void runThread();
|
||||
int writeData (void*, int);
|
||||
|
||||
JUCE_DECLARE_WEAK_REFERENCEABLE (InterprocessConnection)
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InterprocessConnection)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -49,14 +49,8 @@ private:
|
|||
};
|
||||
|
||||
//==============================================================================
|
||||
ApplicationCommandTarget::ApplicationCommandTarget()
|
||||
{
|
||||
}
|
||||
|
||||
ApplicationCommandTarget::~ApplicationCommandTarget()
|
||||
{
|
||||
masterReference.clear();
|
||||
}
|
||||
ApplicationCommandTarget::ApplicationCommandTarget() {}
|
||||
ApplicationCommandTarget::~ApplicationCommandTarget() {}
|
||||
|
||||
//==============================================================================
|
||||
bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
|
||||
|
|
|
|||
|
|
@ -231,14 +231,12 @@ public:
|
|||
|
||||
private:
|
||||
//==============================================================================
|
||||
WeakReference<ApplicationCommandTarget>::Master masterReference;
|
||||
friend class WeakReference<ApplicationCommandTarget>;
|
||||
|
||||
class CommandMessage;
|
||||
friend class CommandMessage;
|
||||
|
||||
bool tryToInvoke (const InvocationInfo&, bool async);
|
||||
|
||||
JUCE_DECLARE_WEAK_REFERENCEABLE (ApplicationCommandTarget)
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ApplicationCommandTarget)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -32,11 +32,6 @@ class ComponentAnimator::AnimationTask
|
|||
public:
|
||||
AnimationTask (Component* c) noexcept : component (c) {}
|
||||
|
||||
~AnimationTask()
|
||||
{
|
||||
masterReference.clear();
|
||||
}
|
||||
|
||||
void reset (const Rectangle<int>& finalBounds,
|
||||
float finalAlpha,
|
||||
int millisecondsToSpendMoving,
|
||||
|
|
@ -186,9 +181,6 @@ public:
|
|||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProxyComponent)
|
||||
};
|
||||
|
||||
WeakReference<AnimationTask>::Master masterReference;
|
||||
friend class WeakReference<AnimationTask>;
|
||||
|
||||
WeakReference<Component> component;
|
||||
ScopedPointer<Component> proxy;
|
||||
|
||||
|
|
@ -208,6 +200,7 @@ private:
|
|||
+ (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
|
||||
}
|
||||
|
||||
JUCE_DECLARE_WEAK_REFERENCEABLE (AnimationTask)
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AnimationTask)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ extern GetTypefaceForFont juce_getTypefaceForFont;
|
|||
|
||||
//==============================================================================
|
||||
LookAndFeel::LookAndFeel()
|
||||
: useNativeAlertWindows (false)
|
||||
{
|
||||
/* if this fails it means you're trying to create a LookAndFeel object before
|
||||
the static Colours have been initialised. That ain't gonna work. It probably
|
||||
|
|
@ -51,7 +50,6 @@ LookAndFeel::LookAndFeel()
|
|||
|
||||
LookAndFeel::~LookAndFeel()
|
||||
{
|
||||
masterReference.clear();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -212,9 +212,6 @@ public:
|
|||
|
||||
private:
|
||||
//==============================================================================
|
||||
friend class WeakReference<LookAndFeel>;
|
||||
WeakReference<LookAndFeel>::Master masterReference;
|
||||
|
||||
struct ColourSetting
|
||||
{
|
||||
int colourID;
|
||||
|
|
@ -226,8 +223,9 @@ private:
|
|||
|
||||
SortedSet<ColourSetting> colours;
|
||||
String defaultSans, defaultSerif, defaultFixed;
|
||||
bool useNativeAlertWindows;
|
||||
bool useNativeAlertWindows = false;
|
||||
|
||||
JUCE_DECLARE_WEAK_REFERENCEABLE (LookAndFeel)
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LookAndFeel)
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue