47template <
class ObjectClass,
48 class TypeOfCriticalSectionToUse = DummyCriticalSection>
68 : values (std::move (other.values))
73 OwnedArray (
const std::initializer_list<ObjectClass*>& items)
83 values = std::move (other.values);
88 template <
class OtherObjectClass,
class OtherCriticalSection>
90 : values (std::move (other.values))
95 template <
class OtherObjectClass,
class OtherCriticalSection>
100 values = std::move (other.values);
110 values.setAllocatedSize (0);
131 return values.size();
151 return values.getValueWithDefault (index);
162 return values[index];
173 return values.getFirst();
184 return values.getLast();
193 return values.begin();
202 return values.begin();
210 return values.begin();
254 auto* e = values.begin();
256 for (; e != values.end(); ++e)
258 return static_cast<int> (e - values.begin());
271 auto* e = values.begin();
273 for (; e != values.end(); ++e)
405 std::unique_ptr<ObjectClass>
toDelete;
464 template <
class OtherArrayType>
475 template <
typename OtherArrayType>
476 void addArray (
const std::initializer_list<OtherArrayType>& items)
479 values.addArray (items);
496 template <
class OtherArrayType>
517 values.add (createCopyIfNotNull (
arrayToAddFrom.getUnchecked (startIndex++)));
532 template <
class ElementComparator>
547 template <
typename ElementComparator>
563 std::unique_ptr<ObjectClass>
toDelete;
579 if ((values.size() << 1) < values.capacity())
603 if ((values.size() << 1) < values.capacity())
622 for (
int i = 0; i < values.size(); ++i)
648 auto endIndex = jlimit (0, values.size(), startIndex +
numberToRemove);
649 startIndex = jlimit (0, values.size(), startIndex);
664 if ((values.size() << 1) < values.capacity())
724 template <
class OtherArrayType>
728 const typename OtherArrayType::ScopedLockType
lock2 (
otherArray.getLock());
742 values.shrinkToNoMoreThan (values.size());
783 template <
class ElementComparator>
798 [[
deprecated (
"This method has been replaced by a more flexible templated version and renamed "
799 "to swapWith to be more consistent with the names used in other classes.")]]
807 void deleteAllObjects()
809 auto i = values.size();
814 values.removeElements (i, 1);
819 template <
class OtherObjectClass,
class OtherCriticalSection>
822 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OwnedArray)
826template <
class ObjectClass,
class TypeOfCriticalSectionToUse>
827template <
class ElementComparator>
833 auto index = findInsertIndexInSortedArray (comparator, values.begin(),
newObject, 0, values.size());
838template <
class ObjectClass,
class TypeOfCriticalSectionToUse>
839template <
typename ElementComparator>
845 int s = 0, e = values.size();
866template <
class ObjectClass,
class TypeOfCriticalSectionToUse>
867template <
typename ElementComparator>
ObjectClass *const * data() const noexcept
int size() const noexcept
ObjectClass * getUnchecked(int index) const noexcept
ObjectClass * set(int indexToChange, ObjectClass *newObject, bool deleteOldElement=true)
ObjectClass * removeAndReturn(int indexToRemove)
ObjectClass * add(std::unique_ptr< ObjectClass > newObject)
ObjectClass * set(int indexToChange, std::unique_ptr< ObjectClass > newObject, bool deleteOldElement=true)
void addCopiesOf(const OtherArrayType &arrayToAddFrom, int startIndex=0, int numElementsToAdd=-1)
void addArray(const OtherArrayType &arrayToAddFrom, int startIndex=0, int numElementsToAdd=-1)
bool isEmpty() const noexcept
void swapWith(OtherArrayType &otherArray) noexcept
void remove(int indexToRemove, bool deleteObject=true)
typename TypeOfCriticalSectionToUse::ScopedLockType ScopedLockType
void ensureStorageAllocated(int minNumElements) noexcept
ObjectClass * getFirst() const noexcept
void minimiseStorageOverheads() noexcept
void clear(bool deleteObjects=true)
void removeLast(int howManyToRemove=1, bool deleteObjects=true)
int indexOf(const ObjectClass *objectToLookFor) const noexcept
ObjectClass * add(ObjectClass *newObject)
ObjectClass ** begin() noexcept
OwnedArray(OwnedArray< OtherObjectClass, OtherCriticalSection > &&other) noexcept
void swap(int index1, int index2) noexcept
int indexOfSorted(ElementComparator &comparator, const ObjectClass *objectToLookFor) const noexcept
ObjectClass * insert(int indexToInsertAt, std::unique_ptr< ObjectClass > newObject)
void clearQuick(bool deleteObjects)
void removeObject(const ObjectClass *objectToRemove, bool deleteObject=true)
ObjectClass *const * begin() const noexcept
ObjectClass *const * end() const noexcept
ObjectClass ** end() noexcept
OwnedArray & operator=(OwnedArray &&other) noexcept
OwnedArray(OwnedArray &&other) noexcept
void insertArray(int indexToInsertAt, ObjectClass *const *newObjects, int numberOfElements)
void move(int currentIndex, int newIndex) noexcept
int addSorted(ElementComparator &comparator, ObjectClass *newObject) noexcept
const TypeOfCriticalSectionToUse & getLock() const noexcept
void addArray(const std::initializer_list< OtherArrayType > &items)
void sort(ElementComparator &comparator, bool retainOrderOfEquivalentItems=false) noexcept
ObjectClass * insert(int indexToInsertAt, ObjectClass *newObject)
ObjectClass * operator[](int index) const noexcept
ObjectClass ** getRawDataPointer() noexcept
ObjectClass ** data() noexcept
OwnedArray(const std::initializer_list< ObjectClass * > &items)
void removeRange(int startIndex, int numberToRemove, bool deleteObjects=true)
ObjectClass * getLast() const noexcept
bool contains(const ObjectClass *objectToLookFor) const noexcept