49template <
class ObjectClass,
class TypeOfCriticalSectionToUse = DummyCriticalSection>
65 values.addArray (other.begin(), other.size());
69 o->incReferenceCount();
74 : values (std::move (other.values))
79 template <
class OtherObjectClass,
class OtherCriticalSection>
83 values.addArray (other.begin(), other.size());
87 o->incReferenceCount();
104 template <
class OtherObjectClass>
116 values = std::move (other.values);
136 values.setAllocatedSize (0);
152 return values.size();
196 return values.getValueWithDefault (index);
205 return values[index];
216 return values.getFirst();
227 return values.getLast();
236 return values.begin();
245 return values.begin();
253 return values.begin();
297 auto* e = values.begin();
303 return static_cast<int> (e - values.begin());
326 auto* e = values.begin();
508 auto** e = values.end();
511 (*(--e))->incReferenceCount();
527 template <
class ElementComparator>
531 auto index = findInsertIndexInSortedArray (comparator, values.begin(),
newObject, 0, values.size());
541 template <
class ElementComparator>
545 auto index = findInsertIndexInSortedArray (comparator, values.begin(),
newObject, 0, values.size());
547 if (index > 0 && comparator.compareElements (
newObject, values[index - 1]) == 0)
565 template <
class ElementComparator>
592 if ((values.size() << 1) < values.capacity())
618 if ((values.size() << 1) < values.capacity())
668 startIndex = jlimit (0, values.size(), startIndex);
669 auto endIndex = jlimit (0, values.size(), startIndex +
numberToRemove);
682 if ((values.size() << 1) < values.capacity())
703 remove (values.size() - 1);
715 if (isPositiveAndBelow (
index1, values.size())
716 && isPositiveAndBelow (
index2, values.size()))
750 template <
class OtherArrayType>
754 const typename OtherArrayType::ScopedLockType
lock2 (
otherArray.getLock());
767 return values == other.values;
806 template <
class ElementComparator>
819 values.shrinkToNoMoreThan (values.size());
846 [[
deprecated (
"This method has been replaced by a more flexible templated version and renamed "
847 "to swapWith to be more consistent with the names used in other classes.")]]
855 void releaseAllObjects()
857 auto i = values.size();
862 values.removeElements (i, 1);
867 static void releaseObject (ObjectClass* o)
869 if (o !=
nullptr && o->decReferenceCountWithoutDeleting())
870 ContainerDeletePolicy<ObjectClass>::destroy (o);
875template <
class ObjectClass,
class TypeOfCriticalSectionToUse>
876template <
class ElementComparator>
882 int s = 0, e = values.size();
903template <
class ObjectClass,
class TypeOfCriticalSectionToUse>
904template <
class ElementComparator>
ReferenceCountedArray(ReferenceCountedArray &&other) noexcept
ObjectClass * add(const ObjectClassPtr &newObject)
bool isEmpty() const noexcept
int indexOf(const ObjectClass *objectToLookFor) const noexcept
ReferenceCountedArray(const ReferenceCountedArray &other) noexcept
int size() const noexcept
void removeLast(int howManyToRemove=1)
ObjectClass *const * end() const noexcept
void minimiseStorageOverheads() noexcept
void set(int indexToChange, ObjectClass *newObject)
ObjectClass *const * begin() const noexcept
ObjectClass * insert(int indexToInsertAt, const ObjectClassPtr &newObject)
ReferenceCountedArray()=default
bool operator!=(const ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse > &other) const noexcept
int indexOfSorted(ElementComparator &comparator, const ObjectClass *objectToLookFor) const noexcept
typename TypeOfCriticalSectionToUse::ScopedLockType ScopedLockType
bool addIfNotAlreadyThere(ObjectClass *newObject)
ObjectClassPtr operator[](int index) const noexcept
void remove(int indexToRemove)
void sort(ElementComparator &comparator, bool retainOrderOfEquivalentItems=false) noexcept
ReferenceCountedArray(const ReferenceCountedArray< OtherObjectClass, OtherCriticalSection > &other) noexcept
bool operator==(const ReferenceCountedArray &other) const noexcept
void removeObject(ObjectClass *objectToRemove)
ObjectClass * getObjectPointer(int index) const noexcept
void swap(int index1, int index2) noexcept
ObjectClassPtr getFirst() const noexcept
void ensureStorageAllocated(const int minNumElements)
void set(int indexToChange, const ObjectClassPtr &newObject)
ObjectClass *const * data() const noexcept
const TypeOfCriticalSectionToUse & getLock() const noexcept
ObjectClassPtr getUnchecked(int index) const noexcept
ObjectClass ** begin() noexcept
void addOrReplaceSorted(ElementComparator &comparator, ObjectClass *newObject) noexcept
bool contains(const ObjectClass *objectToLookFor) const noexcept
void removeRange(int startIndex, int numberToRemove)
ObjectClass * getObjectPointerUnchecked(int index) const noexcept
void move(int currentIndex, int newIndex) noexcept
ObjectClassPtr removeAndReturn(int indexToRemove)
ReferenceCountedArray & operator=(const ReferenceCountedArray &other) noexcept
ObjectClass ** end() noexcept
ObjectClass ** getRawDataPointer() const noexcept
bool contains(const ObjectClassPtr &objectToLookFor) const noexcept
ObjectClass ** data() noexcept
void swapWith(OtherArrayType &otherArray) noexcept
bool addIfNotAlreadyThere(const ObjectClassPtr &newObject)
int addSorted(ElementComparator &comparator, ObjectClass *newObject) noexcept
int indexOf(const ObjectClassPtr &objectToLookFor) const noexcept
ObjectClassPtr getLast() const noexcept
void addArray(const ReferenceCountedArray &arrayToAddFrom, int startIndex=0, int numElementsToAdd=-1) noexcept
ObjectClass * insert(int indexToInsertAt, ObjectClass *newObject)
ObjectClass * add(ObjectClass *newObject)
void removeObject(const ObjectClassPtr &objectToRemove)