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

Replaced the badly-named method Array::removeValue() with two new methods: removeFirstMatchingValue() and removeAllInstancesOf(). If you call the old method anywhere, you can just replace any calls with removeFirstMatchingValue(), which does the same job, but whose name makes it clear that not all instances of the value will be removed.

This commit is contained in:
jules 2012-07-07 21:09:10 +01:00
parent 27f1901fe6
commit 591e89cd87
31 changed files with 59 additions and 41 deletions

View file

@ -38,7 +38,7 @@ ProjectType::ProjectType (const String& type_, const String& desc_)
ProjectType::~ProjectType()
{
getAllTypes().removeValue (this);
getAllTypes().removeFirstMatchingValue (this);
}
Array<ProjectType*>& ProjectType::getAllTypes()

View file

@ -180,5 +180,5 @@ void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener)
void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener)
{
const ScopedLock sl (lock);
listeners.removeValue (listener);
listeners.removeFirstMatchingValue (listener);
}

View file

@ -601,7 +601,7 @@ void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callbackToR
const ScopedLock sl (audioCallbackLock);
needsDeinitialising = needsDeinitialising && callbacks.contains (callbackToRemove);
callbacks.removeValue (callbackToRemove);
callbacks.removeFirstMatchingValue (callbackToRemove);
}
if (needsDeinitialising)

View file

@ -45,7 +45,7 @@ public:
~IPhoneAudioIODevice()
{
getSessionHolder().activeDevices.removeValue (this);
getSessionHolder().activeDevices.removeFirstMatchingValue (this);
close();
}

View file

@ -257,7 +257,7 @@ namespace CoreMidiHelpers
{
const ScopedLock sl (callbackLock);
activeCallbacks.removeValue (this);
activeCallbacks.removeFirstMatchingValue (this);
}
if (portAndEndpoint != nullptr && portAndEndpoint->port != 0)

View file

@ -1297,7 +1297,7 @@ Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
pos += samplesPerFrame * framesPerIndexRead;
}
indexes.removeValue (trackStart);
indexes.removeFirstMatchingValue (trackStart);
}
return indexes;

View file

@ -105,7 +105,7 @@ public:
isStarted = false;
midiInReset (deviceHandle);
midiInStop (deviceHandle);
activeMidiCollectors.removeValue (this);
activeMidiCollectors.removeFirstMatchingValue (this);
unprepareAllHeaders();
concatenator.reset();
}
@ -436,7 +436,7 @@ MidiOutput::~MidiOutput()
if (MidiOutHandle::activeHandles.contains (h) && --(h->refCount) == 0)
{
midiOutClose (h->handle);
MidiOutHandle::activeHandles.removeValue (h);
MidiOutHandle::activeHandles.removeFirstMatchingValue (h);
delete h;
}
}

View file

@ -394,7 +394,7 @@ public:
~ModuleHandle()
{
getActiveModules().removeValue (this);
getActiveModules().removeFirstMatchingValue (this);
close();
}
@ -1153,7 +1153,7 @@ public:
closePluginWindow();
#endif
activeVSTWindows.removeValue (this);
activeVSTWindows.removeFirstMatchingValue (this);
plugin.editorBeingDeleted (this);
}
@ -1319,7 +1319,7 @@ public:
void broughtToFront()
{
activeVSTWindows.removeValue (this);
activeVSTWindows.removeFirstMatchingValue (this);
activeVSTWindows.add (this);
#if JUCE_MAC

View file

@ -743,7 +743,7 @@ public:
@param valueToRemove the object to try to remove
@see remove, removeRange
*/
void removeValue (ParameterType valueToRemove)
void removeFirstMatchingValue (ParameterType valueToRemove)
{
const ScopedLockType lock (getLock());
ElementType* const e = data.elements;
@ -758,6 +758,24 @@ public:
}
}
/** Removes an item from the array.
This will remove the first occurrence of the given element from the array.
If the item isn't found, no action is taken.
@param valueToRemove the object to try to remove
@see remove, removeRange
*/
void removeAllInstancesOf (ParameterType valueToRemove)
{
const ScopedLockType lock (getLock());
ElementType* const e = data.elements;
for (int i = numUsed; --i >= 0;)
if (valueToRemove == e[i])
remove (i);
}
/** Removes a range of elements from the array.
This will remove a set of elements, starting from the given index,

View file

@ -31,7 +31,7 @@ JNIClassBase::JNIClassBase (const char* classPath_)
JNIClassBase::~JNIClassBase()
{
getClasses().removeValue (this);
getClasses().removeFirstMatchingValue (this);
}
Array<JNIClassBase*>& JNIClassBase::getClasses()

View file

@ -58,7 +58,7 @@ OutputStream::OutputStream()
OutputStream::~OutputStream()
{
#if JUCE_DEBUG
danglingStreamChecker.activeStreams.removeValue (this);
danglingStreamChecker.activeStreams.removeFirstMatchingValue (this);
#endif
}

View file

@ -202,7 +202,7 @@ bool ThreadPool::removeJob (ThreadPoolJob* const job,
}
else
{
jobs.removeValue (job);
jobs.removeFirstMatchingValue (job);
addToDeleteList (deletionList, job);
}
}
@ -351,7 +351,7 @@ bool ThreadPool::runNextJob()
if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
{
jobs.removeValue (job);
jobs.removeFirstMatchingValue (job);
addToDeleteList (deletionList, job);
jobFinishedSignal.signal();

View file

@ -59,11 +59,11 @@ void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
const ScopedLock sl2 (callbackLock);
const ScopedLock sl3 (listLock);
clients.removeValue (client);
clients.removeFirstMatchingValue (client);
}
else
{
clients.removeValue (client);
clients.removeFirstMatchingValue (client);
}
}
@ -156,7 +156,7 @@ void TimeSliceThread::run()
if (msUntilNextCall >= 0)
clientBeingCalled->nextCallTime += RelativeTime::milliseconds (msUntilNextCall);
else
clients.removeValue (clientBeingCalled);
clients.removeFirstMatchingValue (clientBeingCalled);
clientBeingCalled = nullptr;
}

View file

@ -31,7 +31,7 @@ UnitTest::UnitTest (const String& name_)
UnitTest::~UnitTest()
{
getAllTests().removeValue (this);
getAllTests().removeFirstMatchingValue (this);
}
Array<UnitTest*>& UnitTest::getAllTests()

View file

@ -115,7 +115,7 @@ public:
// Listeners can't be null pointers!
jassert (listenerToRemove != nullptr);
listeners.removeValue (listenerToRemove);
listeners.removeFirstMatchingValue (listenerToRemove);
}
/** Returns the number of registered listeners. */

View file

@ -34,7 +34,7 @@ DeletedAtShutdown::DeletedAtShutdown()
DeletedAtShutdown::~DeletedAtShutdown()
{
const SpinLock::ScopedLockType sl (deletedAtShutdownLock);
getObjects().removeValue (this);
getObjects().removeFirstMatchingValue (this);
}
void DeletedAtShutdown::deleteAll()

View file

@ -2907,7 +2907,7 @@ void Component::addKeyListener (KeyListener* const newListener)
void Component::removeKeyListener (KeyListener* const listenerToRemove)
{
if (keyListeners != nullptr)
keyListeners->removeValue (listenerToRemove);
keyListeners->removeFirstMatchingValue (listenerToRemove);
}
bool Component::keyPressed (const KeyPress&) { return false; }

View file

@ -119,7 +119,7 @@ void Desktop::addDesktopComponent (Component* const c)
void Desktop::removeDesktopComponent (Component* const c)
{
desktopComponents.removeValue (c);
desktopComponents.removeFirstMatchingValue (c);
}
void Desktop::componentBroughtToFront (Component* const c)

View file

@ -96,7 +96,7 @@ void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMove
void ComponentMovementWatcher::componentBeingDeleted (Component& comp)
{
registeredParentComps.removeValue (&comp);
registeredParentComps.removeFirstMatchingValue (&comp);
if (component == &comp)
unregister();

View file

@ -258,7 +258,7 @@ bool MultiDocumentPanel::closeDocument (Component* component,
if (shouldDelete)
delete component;
components.removeValue (component);
components.removeFirstMatchingValue (component);
if (isFullscreenWhenOneDocument() && components.size() == 1)
{
@ -294,7 +294,7 @@ bool MultiDocumentPanel::closeDocument (Component* component,
if (tabComponent != nullptr && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
tabComponent = nullptr;
components.removeValue (component);
components.removeFirstMatchingValue (component);
if (components.size() > 0 && tabComponent == nullptr)
addAndMakeVisible (components.getFirst());
@ -515,7 +515,7 @@ void MultiDocumentPanel::updateOrder()
if (current != nullptr)
{
components.removeValue (current);
components.removeFirstMatchingValue (current);
components.add (current);
}
}

View file

@ -287,7 +287,7 @@ public:
~Window()
{
getActiveWindows().removeValue (this);
getActiveWindows().removeFirstMatchingValue (this);
Desktop::getInstance().removeGlobalMouseListener (this);
activeSubMenu = nullptr;
items.clear();

View file

@ -77,7 +77,7 @@ public:
if (isStandard)
{
const SpinLock::ScopedLockType sl (lock);
getCursors().removeValue (this);
getCursors().removeFirstMatchingValue (this);
}
delete this;

View file

@ -836,7 +836,7 @@ public:
if (isKeyDown)
keysCurrentlyDown.addIfNotAlreadyThere (keyCode);
else
keysCurrentlyDown.removeValue (keyCode);
keysCurrentlyDown.removeFirstMatchingValue (keyCode);
}
}

View file

@ -265,7 +265,7 @@ void RelativeCoordinatePositionerBase::componentChildrenChanged (Component& chan
void RelativeCoordinatePositionerBase::componentBeingDeleted (Component& comp)
{
jassert (sourceComponents.contains (&comp));
sourceComponents.removeValue (&comp);
sourceComponents.removeFirstMatchingValue (&comp);
registeredOk = false;
}
@ -277,7 +277,7 @@ void RelativeCoordinatePositionerBase::markersChanged (MarkerList*)
void RelativeCoordinatePositionerBase::markerListBeingDeleted (MarkerList* markerList)
{
jassert (sourceMarkerLists.contains (markerList));
sourceMarkerLists.removeValue (markerList);
sourceMarkerLists.removeFirstMatchingValue (markerList);
}
void RelativeCoordinatePositionerBase::apply()

View file

@ -480,7 +480,7 @@ void TableHeaderComponent::addListener (Listener* const newListener)
void TableHeaderComponent::removeListener (Listener* const listenerToRemove)
{
listeners.removeValue (listenerToRemove);
listeners.removeFirstMatchingValue (listenerToRemove);
}
//==============================================================================

View file

@ -325,8 +325,8 @@ Component* AlertWindow::removeCustomComponent (const int index)
if (c != nullptr)
{
customComps.removeValue (c);
allComps.removeValue (c);
customComps.removeFirstMatchingValue (c);
allComps.removeFirstMatchingValue (c);
removeChildComponent (c);
updateLayout (false);

View file

@ -45,7 +45,7 @@ ComponentPeer::ComponentPeer (Component* const component_, const int styleFlags_
ComponentPeer::~ComponentPeer()
{
heavyweightPeers.removeValue (this);
heavyweightPeers.removeFirstMatchingValue (this);
Desktop::getInstance().triggerFocusCallback();
}

View file

@ -92,7 +92,7 @@ public:
if (currentActive == w)
currentActive = nullptr;
windows.removeValue (w);
windows.removeFirstMatchingValue (w);
if (windows.size() == 0)
deleteInstance();

View file

@ -458,7 +458,7 @@ void CodeDocument::Position::setPositionMaintained (const bool isMaintained)
{
// If this happens, you may have deleted the document while there are Position objects that are still using it...
jassert (owner->positionsToMaintain.contains (this));
owner->positionsToMaintain.removeValue (this);
owner->positionsToMaintain.removeFirstMatchingValue (this);
}
}
}

View file

@ -328,7 +328,7 @@ ActiveXControlComponent::ActiveXControlComponent()
ActiveXControlComponent::~ActiveXControlComponent()
{
deleteControl();
ActiveXHelpers::activeXComps.removeValue (this);
ActiveXHelpers::activeXComps.removeFirstMatchingValue (this);
}
void ActiveXControlComponent::paint (Graphics& g)

View file

@ -56,7 +56,7 @@ public:
{
{
const ScopedLock sl (contextListLock);
contextList.removeValue (this);
contextList.removeFirstMatchingValue (this);
}
android.activity.callVoidMethod (JuceAppActivity.deleteView, glView.get());