From b439452edda2118975f2d11e50976f8715187d78 Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 7 Jul 2016 15:02:05 +0100 Subject: [PATCH] Changed the Array::remove() method to return void, and added an Array::removeAndReturn() method to replace the old functionality --- .../Application/jucer_OpenDocumentManager.cpp | 4 ++-- modules/juce_core/containers/juce_Array.h | 22 ++++++++++++++++++- .../juce_core/containers/juce_ListenerList.h | 5 ++--- .../mouse/juce_SelectedItemSet.h | 6 ++--- .../juce_gui_basics/widgets/juce_Toolbar.cpp | 2 +- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/extras/Projucer/Source/Application/jucer_OpenDocumentManager.cpp b/extras/Projucer/Source/Application/jucer_OpenDocumentManager.cpp index 81b55af4f3..2c185733a2 100644 --- a/extras/Projucer/Source/Application/jucer_OpenDocumentManager.cpp +++ b/extras/Projucer/Source/Application/jucer_OpenDocumentManager.cpp @@ -333,7 +333,7 @@ OpenDocumentManager::Document* RecentDocumentList::getPrevious() if (! canGoToPrevious()) return nullptr; - nextDocs.insert (0, previousDocs.remove (previousDocs.size() - 1)); + nextDocs.insert (0, previousDocs.removeAndReturn (previousDocs.size() - 1)); return previousDocs.getLast(); } @@ -342,7 +342,7 @@ OpenDocumentManager::Document* RecentDocumentList::getNext() if (! canGoToNext()) return nullptr; - OpenDocumentManager::Document* d = nextDocs.remove (0); + OpenDocumentManager::Document* d = nextDocs.removeAndReturn (0); previousDocs.add (d); return d; } diff --git a/modules/juce_core/containers/juce_Array.h b/modules/juce_core/containers/juce_Array.h index 7b536e26b1..ac121e51f1 100644 --- a/modules/juce_core/containers/juce_Array.h +++ b/modules/juce_core/containers/juce_Array.h @@ -791,6 +791,26 @@ public: } //============================================================================== + /** Removes an element from the array. + + This will remove the element at a given index, and move back + all the subsequent elements to close the gap. + If the index passed in is out-of-range, nothing will happen. + + @param indexToRemove the index of the element to remove + @see removeAndReturn, removeFirstMatchingValue, removeAllInstancesOf, removeRange + */ + void remove (int indexToRemove) + { + const ScopedLockType lock (getLock()); + + if (isPositiveAndBelow (indexToRemove, numUsed)) + { + jassert (data.elements != nullptr); + removeInternal (indexToRemove); + } + } + /** Removes an element from the array. This will remove the element at a given index, and move back @@ -801,7 +821,7 @@ public: @returns the element that has been removed @see removeFirstMatchingValue, removeAllInstancesOf, removeRange */ - ElementType remove (const int indexToRemove) + ElementType removeAndReturn (const int indexToRemove) { const ScopedLockType lock (getLock()); diff --git a/modules/juce_core/containers/juce_ListenerList.h b/modules/juce_core/containers/juce_ListenerList.h index edc08771b7..405ddc8770 100644 --- a/modules/juce_core/containers/juce_ListenerList.h +++ b/modules/juce_core/containers/juce_ListenerList.h @@ -292,10 +292,9 @@ public: /** A dummy bail-out checker that always returns false. See the ListenerList notes for more info about bail-out checkers. */ - class DummyBailOutChecker + struct DummyBailOutChecker { - public: - inline bool shouldBailOut() const noexcept { return false; } + bool shouldBailOut() const noexcept { return false; } }; //============================================================================== diff --git a/modules/juce_gui_basics/mouse/juce_SelectedItemSet.h b/modules/juce_gui_basics/mouse/juce_SelectedItemSet.h index 764191b85c..6535e82956 100644 --- a/modules/juce_gui_basics/mouse/juce_SelectedItemSet.h +++ b/modules/juce_gui_basics/mouse/juce_SelectedItemSet.h @@ -75,7 +75,7 @@ public: for (int i = selectedItems.size(); --i >= 0;) if (! other.isSelected (selectedItems.getReference (i))) - itemDeselected (selectedItems.remove (i)); + itemDeselected (selectedItems.removeAndReturn (i)); for (SelectableItemType* i = other.selectedItems.begin(), *e = other.selectedItems.end(); i != e; ++i) { @@ -235,7 +235,7 @@ public: if (i >= 0) { changed(); - itemDeselected (selectedItems.remove (i)); + itemDeselected (selectedItems.removeAndReturn (i)); } } @@ -248,7 +248,7 @@ public: for (int i = selectedItems.size(); --i >= 0;) { - itemDeselected (selectedItems.remove (i)); + itemDeselected (selectedItems.removeAndReturn (i)); i = jmin (i, selectedItems.size()); } } diff --git a/modules/juce_gui_basics/widgets/juce_Toolbar.cpp b/modules/juce_gui_basics/widgets/juce_Toolbar.cpp index c9362c23b5..9d89ca8e64 100644 --- a/modules/juce_gui_basics/widgets/juce_Toolbar.cpp +++ b/modules/juce_gui_basics/widgets/juce_Toolbar.cpp @@ -178,7 +178,7 @@ public: if (ToolbarItemComponent* const tc = dynamic_cast (getChildComponent (i))) { tc->setVisible (false); - const int index = oldIndexes.remove (i); + const int index = oldIndexes.removeAndReturn (i); owner->addChildComponent (tc, index); --i; }