53template <
class ObjectClass,
class TypeOfCriticalSectionToUse = DummyCriticalSection>
73 o->incReferenceCount();
78 : values (std::move (
other.values))
83 template <
class OtherObjectClass,
class OtherCriticalSection>
91 o->incReferenceCount();
108 template <
class OtherObjectClass>
120 values = std::move (
other.values);
140 values.setAllocatedSize (0);
156 return values.
size();
200 return values.getValueWithDefault (index);
209 return values[index];
240 return values.
begin();
249 return values.
begin();
277 auto**
e = values.
begin();
283 return static_cast<int> (
e - values.
begin());
306 auto**
e = values.
begin();
473 auto**
e = values.
end();
476 (*(--
e))->incReferenceCount();
492 template <
class ElementComparator>
496 auto index = findInsertIndexInSortedArray (comparator, values.
begin(),
newObject, 0, values.
size());
506 template <
class ElementComparator>
510 auto index = findInsertIndexInSortedArray (comparator, values.
begin(),
newObject, 0, values.
size());
512 if (index > 0 && comparator.compareElements (
newObject, values[index - 1]) == 0)
530 template <
class ElementComparator>
534 ignoreUnused (comparator);
536 int s = 0,
e = values.
size();
581 if ((values.
size() << 1) < values.capacity())
607 if ((values.
size() << 1) < values.capacity())
657 startIndex = jlimit (0, values.
size(), startIndex);
663 for (
int i = startIndex; i < endIndex; ++i)
665 releaseObject (values[i]);
671 if ((values.
size() << 1) < values.capacity())
704 if (isPositiveAndBelow (
index1, values.
size())
705 && isPositiveAndBelow (
index2, values.
size()))
739 template <
class OtherArrayType>
756 return values ==
other.values;
795 template <
class ElementComparator>
801 ignoreUnused (comparator);
817 values.shrinkToNoMoreThan (values.
size());
851 ArrayBase<ObjectClass*, TypeOfCriticalSectionToUse> values;
853 void releaseAllObjects()
855 for (
auto&
v : values)
861 static void releaseObject (ObjectClass* o)
863 if (o !=
nullptr && o->decReferenceCountWithoutDeleting())
864 ContainerDeletePolicy<ObjectClass>::destroy (o);
A basic object container.
Holds a resizable array of primitive or copy-by-value objects.
void swapWith(OtherArrayType &otherArray) noexcept
This swaps the contents of this array with those of another array.
const TypeOfCriticalSectionToUse & getLock() const noexcept
Returns the CriticalSection that locks this array.
void addArray(const Type *elementsToAdd, int numElementsToAdd)
Adds elements from an array to the end of this array.
int size() const noexcept
Returns the current number of elements in the array.
ElementType * begin() const noexcept
Returns a pointer to the first element in the array.
void insert(int indexToInsertAt, ParameterType newElement)
Inserts a new element into the array at a given position.
ElementType getFirst() const noexcept
Returns the first element in the array, or a default value if the array is empty.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
void clear()
Removes all elements from the array.
void move(int currentIndex, int newIndex) noexcept
Moves one of the values to a different position.
ElementType getLast() const noexcept
Returns the last element in the array, or a default value if the array is empty.
ElementType * end() const noexcept
Returns a pointer to the element which follows the last element in the array.
Holds a list of objects derived from ReferenceCountedObject, or which implement basic reference-count...
ReferenceCountedArray(ReferenceCountedArray &&other) noexcept
Moves from another array.
ObjectClass * add(const ObjectClassPtr &newObject)
Appends a new object to the end of the array.
bool isEmpty() const noexcept
Returns true if the array is empty, false otherwise.
int indexOf(const ObjectClass *objectToLookFor) const noexcept
Finds the index of the first occurrence of an object in the array.
ReferenceCountedArray(const ReferenceCountedArray &other) noexcept
Creates a copy of another array.
int size() const noexcept
Returns the current number of objects in the array.
void removeLast(int howManyToRemove=1)
Removes the last n objects from the array.
ObjectClass ** end() const noexcept
Returns a pointer to the element which follows the last element in the array.
void minimiseStorageOverheads() noexcept
Reduces the amount of storage being used by the array.
void set(int indexToChange, ObjectClass *newObject)
Replaces an object in the array with a different one.
ObjectClass * insert(int indexToInsertAt, const ObjectClassPtr &newObject)
Inserts a new object into the array at the given index.
ReferenceCountedArray()=default
Creates an empty array.
bool operator!=(const ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse > &other) const noexcept
Compares this array to another one.
int indexOfSorted(ElementComparator &comparator, const ObjectClass *objectToLookFor) const noexcept
Finds the index of an object in the array, assuming that the array is sorted.
typename TypeOfCriticalSectionToUse::ScopedLockType ScopedLockType
Returns the type of scoped lock to use for locking this array.
bool addIfNotAlreadyThere(ObjectClass *newObject)
Appends a new object at the end of the array as long as the array doesn't already contain it.
ObjectClass ** begin() const noexcept
Returns a pointer to the first element in the array.
ObjectClassPtr operator[](int index) const noexcept
Returns a pointer to the object at this index in the array.
void remove(int indexToRemove)
Removes an object from the array.
ObjectClass ** data() const noexcept
Returns a pointer to the first element in the array.
void sort(ElementComparator &comparator, bool retainOrderOfEquivalentItems=false) const noexcept
Sorts the elements in the array.
ReferenceCountedArray(const ReferenceCountedArray< OtherObjectClass, OtherCriticalSection > &other) noexcept
Creates a copy of another array.
bool operator==(const ReferenceCountedArray &other) const noexcept
Compares this array to another one.
void removeObject(ObjectClass *objectToRemove)
Removes the first occurrence of a specified object from the array.
ObjectClass * getObjectPointer(int index) const noexcept
Returns a raw pointer to the object at this index in the array.
void swap(int index1, int index2) noexcept
Swaps a pair of objects in the array.
ObjectClassPtr getFirst() const noexcept
Returns a pointer to the first object in the array.
void ensureStorageAllocated(const int minNumElements)
Increases the array's internal storage to hold a minimum number of elements.
~ReferenceCountedArray()
Destructor.
void clearQuick()
Removes all objects from the array without freeing the array's allocated storage.
const TypeOfCriticalSectionToUse & getLock() const noexcept
Returns the CriticalSection that locks this array.
ObjectClassPtr getUnchecked(int index) const noexcept
Returns a pointer to the object at this index in the array, without checking whether the index is in-...
void addOrReplaceSorted(ElementComparator &comparator, ObjectClass *newObject) noexcept
Inserts or replaces an object in the array, assuming it is sorted.
bool contains(const ObjectClass *objectToLookFor) const noexcept
Returns true if the array contains a specified object.
void removeRange(int startIndex, int numberToRemove)
Removes a range of objects from the array.
ObjectClass * getObjectPointerUnchecked(int index) const noexcept
Returns a raw pointer to the object at this index in the array, without checking whether the index is...
void move(int currentIndex, int newIndex) noexcept
Moves one of the objects to a different position.
ObjectClassPtr removeAndReturn(int indexToRemove)
Removes and returns an object from the array.
ReferenceCountedArray & operator=(const ReferenceCountedArray &other) noexcept
Copies another array into this one.
void clear()
Removes all objects from the array.
ObjectClass ** getRawDataPointer() const noexcept
Returns a pointer to the actual array data.
bool contains(const ObjectClassPtr &objectToLookFor) const noexcept
Returns true if the array contains a specified object.
void swapWith(OtherArrayType &otherArray) noexcept
This swaps the contents of this array with those of another array.
bool addIfNotAlreadyThere(const ObjectClassPtr &newObject)
Appends a new object at the end of the array as long as the array doesn't already contain it.
int addSorted(ElementComparator &comparator, ObjectClass *newObject) noexcept
Inserts a new object into the array assuming that the array is sorted.
int indexOf(const ObjectClassPtr &objectToLookFor) const noexcept
Finds the index of the first occurrence of an object in the array.
ObjectClassPtr getLast() const noexcept
Returns a pointer to the last object in the array.
void addArray(const ReferenceCountedArray &arrayToAddFrom, int startIndex=0, int numElementsToAdd=-1) noexcept
Adds elements from another array to the end of this array.
ObjectClass * insert(int indexToInsertAt, ObjectClass *newObject)
Inserts a new object into the array at the given index.
ObjectClass * add(ObjectClass *newObject)
Appends a new object to the end of the array.
void removeObject(const ObjectClassPtr &objectToRemove)
Removes the first occurrence of a specified object from the array.