52template <
typename ElementType,
58 using ParameterType =
typename TypeHelpers::ParameterType<ElementType>::type;
71 values.addArray (
other.values.begin(),
other.values.size());
75 : values (std::move (
other.values))
82 template <
typename TypeToCreateFrom>
93 template <
typename TypeToCreateFrom>
125 template <
typename TypeToCreateFrom>
151 values = std::move (
other.values);
161 template <
class OtherArrayType>
165 const typename OtherArrayType::ScopedLockType
lock2 (
other.getLock());
166 return values ==
other;
174 template <
class OtherArrayType>
192 values.setAllocatedSize (0);
205 void fill (
const ParameterType& newValue)
noexcept
209 for (
auto& e : *
this)
218 return values.size();
240 return values.getValueWithDefault (index);
255 return values[index];
270 return values[index];
284 return values[index];
293 return values.getFirst();
303 return values.getLast();
312 return values.begin();
321 return values.begin();
328 inline ElementType*
begin() noexcept
330 return values.begin();
338 return values.begin();
344 inline ElementType*
end() noexcept
360 inline ElementType*
data() noexcept
385 auto e = values.begin();
386 auto endPtr = values.end();
390 return static_cast<int> (e - values.begin());
403 auto e = values.begin();
404 auto endPtr = values.end();
551 values.add (newValue);
582 template <
typename Type>
591 template <
typename TypeToCreateFrom>
595 values.addArray (items);
604 template <
typename Type>
620 template <
class OtherArrayType>
624 const typename OtherArrayType::ScopedLockType
lock2 (
otherArray.getLock());
633 template <
class OtherArrayType>
651 template <
class OtherArrayType>
693 template <
class ElementComparator>
697 auto index = findInsertIndexInSortedArray (comparator, values.begin(),
newElement, 0, values.size());
729 template <
typename ElementComparator,
typename TargetValueType>
771 return ElementType();
789 jassert (values.begin() !=
nullptr);
813 auto* e = values.begin();
815 for (
int i = 0; i < values.size(); ++i)
841 for (
int i = values.size(); --i >= 0;)
864 template <
typename PredicateType>
870 for (
int i = values.size(); --i >= 0;)
899 startIndex =
jlimit (0, values.size(), startIndex);
905 minimiseStorageAfterRemoval();
926 minimiseStorageAfterRemoval();
935 template <
class OtherArrayType>
938 const typename OtherArrayType::ScopedLockType
lock1 (
otherArray.getLock());
949 for (
int i = values.size(); --i >= 0;)
963 template <
class OtherArrayType>
966 const typename OtherArrayType::ScopedLockType
lock1 (
otherArray.getLock());
977 for (
int i = values.size(); --i >= 0;)
1031 values.shrinkToNoMoreThan (values.size());
1083 template <
class ElementComparator>
1099 [[
deprecated (
"This method has been replaced by a more flexible templated version and renamed "
1100 "to swapWith to be more consistent with the names used in other classes.")]]
1111 minimiseStorageAfterRemoval();
1114 void minimiseStorageAfterRemoval()
1122template <
typename ElementType,
typename TypeOfCriticalSectionToUse,
int minimumAllocatedSize>
1123template <
typename ElementComparator,
typename TargetValueType>
1130 for (
int s = 0, e = values.size();;)
1150template <
typename ElementType,
typename TypeOfCriticalSectionToUse,
int minimumAllocatedSize>
1151template <
class ElementComparator>
A basic object container.
Holds a resizable array of primitive or copy-by-value objects.
int removeIf(PredicateType &&predicate)
Removes items from the array.
bool operator==(const OtherArrayType &other) const
Compares this array to another one.
void swapWith(OtherArrayType &otherArray) noexcept
This swaps the contents of this array with those of another array.
void add(ElementType &&newElement)
Appends a new element at the end of the array.
void setUnchecked(int indexToChange, ParameterType newValue)
Replaces an element with a new value without doing any bounds-checking.
bool operator!=(const OtherArrayType &other) const
Compares this array to another one.
typename TypeOfCriticalSectionToUse::ScopedLockType ScopedLockType
Returns the type of scoped lock to use for locking this array.
void addNullTerminatedArray(const Type *const *elementsToAdd)
Adds elements from a null-terminated array of pointers to the end of this array.
ElementType getUnchecked(int index) const
Returns one of the elements in the array, without checking the index passed in.
void insertArray(int indexToInsertAt, const ElementType *newElements, int numberOfElements)
Inserts an array of values into this array at a given position.
bool isEmpty() const noexcept
Returns true if the array is empty, false otherwise.
void removeLast(int howManyToRemove=1)
Removes the last n elements from the array.
Array(const ElementType &firstNewElement, OtherElements &&... otherElements)
Initialises an Array from a list of items.
void ensureStorageAllocated(int minNumElements)
Increases the array's internal storage to hold a minimum number of elements.
std::enable_if_t<! std::is_pointer_v< OtherArrayType >, void > addArray(const OtherArrayType &arrayToAddFrom, int startIndex, int numElementsToAdd=-1)
Adds elements from another array to the end of this array.
void remove(const ElementType *elementToRemove)
Removes an element from the 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.
Array(const TypeToCreateFrom *data)
Initialises from a null-terminated raw array of values.
void clearQuick()
Removes all elements from the array without freeing the array's allocated storage.
void sort()
Sorts the array using a default comparison operation.
int removeAllInstancesOf(ParameterType valueToRemove)
Removes items from the array.
Array(const TypeToCreateFrom *data, int numValues)
Initialises from a raw array of values.
int size() const noexcept
Returns the current number of elements in the array.
int removeFirstMatchingValue(ParameterType valueToRemove)
Removes an item from the array.
void fill(const ParameterType &newValue) noexcept
Fills the Array with the provided value.
void removeRange(int startIndex, int numberToRemove)
Removes a range of elements from the array.
void removeValuesIn(const OtherArrayType &otherArray)
Removes any elements which are also in another array.
const ElementType * end() const noexcept
Returns a pointer to the element which follows the last element in the array.
void remove(int indexToRemove)
Removes an element from the array.
void insert(int indexToInsertAt, ParameterType newElement)
Inserts a new element into the array at a given position.
int indexOfSorted(ElementComparator &comparator, TargetValueType elementToLookFor) const
Finds the index of an element in the array, assuming that the array is sorted.
ElementType getFirst() const noexcept
Returns the first element in the array, or a default value if the array is empty.
ElementType * begin() noexcept
Returns a pointer to the first element in the array.
ElementType * end() noexcept
Returns a pointer to the element which follows the last element in the array.
ElementType * getRawDataPointer() noexcept
Returns a pointer to the actual array data.
Array(ElementType &&singleElementToAdd)
Initialises an Array of size 1 containing a single element.
void addUsingDefaultSort(ParameterType newElement)
Inserts a new element into the array, assuming that the array is sorted.
Array()=default
Creates an empty array.
int indexOf(ParameterType elementToLookFor) const
Finds the index of the first element which matches the value passed in.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
Array(ElementType &&firstNewElement, OtherElements &&... otherElements)
Initialises an Array from a list of items.
ElementType removeAndReturn(int indexToRemove)
Removes an element from the array.
ElementType operator[](int index) const
Returns one of the elements in the array.
Array(const ElementType &singleElementToAdd)
Initialises an Array of size 1 containing a single element.
void set(int indexToChange, ParameterType newValue)
Replaces an element with a new value.
int addSorted(ElementComparator &comparator, ParameterType newElement)
Inserts a new element into the array, assuming that the array is sorted.
bool contains(ParameterType elementToLookFor) const
Returns true if the array contains at least one occurrence of an object.
void insertMultiple(int indexToInsertAt, ParameterType newElement, int numberOfTimesToInsertIt)
Inserts multiple copies of an element into the array at a given position.
void sort(ElementComparator &comparator, bool retainOrderOfEquivalentItems=false)
Sorts the elements in the array.
~Array()=default
Destructor.
void add(ElementType &&firstNewElement, OtherElements &&... otherElements)
Appends multiple new elements at the end of the array.
const ElementType * data() const noexcept
Returns a pointer to the first element in the array.
void resize(int targetNumItems)
This will enlarge or shrink the array to the given number of elements, by adding or removing items fr...
void clear()
Removes all elements from the array.
void move(int currentIndex, int newIndex) noexcept
Moves one of the values to a different position.
void swap(int index1, int index2)
Swaps over two elements in the array.
ElementType * data() noexcept
Returns a pointer to the first element in the array.
void add(const ElementType &firstNewElement, OtherElements &&... otherElements)
Appends multiple new elements at the end of the array.
void removeValuesNotIn(const OtherArrayType &otherArray)
Removes any elements which are not found in another array.
const ElementType * begin() const noexcept
Returns a pointer to the first element in the array.
const ElementType & getReference(int index) const noexcept
Returns a direct reference to one of the elements in the array, without checking the index passed in.
bool addIfNotAlreadyThere(ParameterType newElement)
Appends a new element at the end of the array as long as the array doesn't already contain it.
Array(const Array &other)
Creates a copy of another array.
void minimiseStorageOverheads()
Reduces the amount of storage being used by the array.
void addArray(const OtherArrayType &arrayToAddFrom)
Adds elements from another array to the end of this array.
Array & operator=(const Array &other)
Copies another array.
ElementType & getReference(int index) noexcept
Returns a direct reference to one of the elements in the array, without checking the index passed in.
ElementType getLast() const noexcept
Returns the last element in the array, or a default value if the array is empty.
const ElementType * getRawDataPointer() const noexcept
Returns a pointer to the actual array data.
A simple ElementComparator class that can be used to sort an array of objects that support the '<' op...
constexpr bool exactlyEqual(Type a, Type b)
Equivalent to operator==, but suppresses float-equality warnings.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.