56template <
typename ElementType,
57 typename TypeOfCriticalSectionToUse = DummyCriticalSection,
58 int minimumAllocatedSize = 0>
79 : values (std::move (
other.values))
86 template <
typename TypeToCreateFrom>
97 template <
typename TypeToCreateFrom>
129 template <
typename TypeToCreateFrom>
130 Array (
const std::initializer_list<TypeToCreateFrom>& items)
155 values = std::move (
other.values);
165 template <
class OtherArrayType>
170 return values ==
other;
178 template <
class OtherArrayType>
196 values.setAllocatedSize (0);
209 void fill (
const ParameterType& newValue)
noexcept
213 for (
auto&
e : *
this)
222 return values.
size();
244 return values.getValueWithDefault (index);
259 return values[index];
274 return values[index];
302 return values.
begin();
311 return values.
begin();
347 return static_cast<int> (
e - values.
begin());
508 values.
add (newValue);
539 template <
typename Type>
548 template <
typename TypeToCreateFrom>
549 void addArray (
const std::initializer_list<TypeToCreateFrom>& items)
561 template <
typename Type>
577 template <
class OtherArrayType>
590 template <
class OtherArrayType>
608 template <
class OtherArrayType>
609 typename std::enable_if<! std::is_pointer<OtherArrayType>::value,
void>::type
650 template <
class ElementComparator>
654 auto index = findInsertIndexInSortedArray (comparator, values.
begin(),
newElement, 0, values.
size());
686 template <
typename ElementComparator,
typename TargetValueType>
689 ignoreUnused (comparator);
694 for (
int s = 0,
e = values.
size();;)
771 jassert (values.
begin() !=
nullptr);
796 for (
int i = 0; i < values.
size(); ++i)
820 for (
int i = values.
size(); --i >= 0;)
843 template <
typename PredicateType>
849 for (
int i = values.
size(); --i >= 0;)
878 startIndex = jlimit (0, values.
size(), startIndex);
884 minimiseStorageAfterRemoval();
905 minimiseStorageAfterRemoval();
914 template <
class OtherArrayType>
928 for (
int i = values.
size(); --i >= 0;)
942 template <
class OtherArrayType>
956 for (
int i = values.
size(); --i >= 0;)
1010 values.shrinkToNoMoreThan (values.
size());
1062 template <
class ElementComparator>
1067 ignoreUnused (comparator);
1097 minimiseStorageAfterRemoval();
1100 void minimiseStorageAfterRemoval()
A basic object container.
Holds a resizable array of primitive or copy-by-value objects.
int removeIf(PredicateType &&predicate)
Removes items from the array.
Array(ElementType &&firstNewElement, OtherElements... otherElements)
Initalises an Array from a list of items.
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.
void ensureStorageAllocated(int minNumElements)
Increases the array's internal storage to hold a minimum number of elements.
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)
Initalises 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)
Initalises from a raw array of values.
int size() const noexcept
Returns the current number of elements in the array.
void 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.
ElementType * begin() const 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 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 * getRawDataPointer() noexcept
Returns a pointer to the actual array data.
Array(ElementType &&singleElementToAdd)
Initalises 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.
ElementType removeAndReturn(int indexToRemove)
Removes an element from the array.
Array(const ElementType &firstNewElement, OtherElements... otherElements)
Initalises an Array from a list of items.
ElementType operator[](int index) const
Returns one of the elements in the array.
Array(const ElementType &singleElementToAdd)
Initalises an Array of size 1 containing a single element.
ElementType & getReference(int index) const noexcept
Returns a direct reference to one of the elements in the array, without checking the index passed in.
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 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.
void removeValuesNotIn(const OtherArrayType &otherArray)
Removes any elements which are not found in another array.
std::enable_if<!std::is_pointer< OtherArrayType >::value, void >::type addArray(const OtherArrayType &arrayToAddFrom, int startIndex, int numElementsToAdd=-1)
Adds elements from another array to the end of this array.
ElementType * data() const noexcept
Returns a pointer to the first element in the array.
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 getLast() const noexcept
Returns the last element in the array, or a default value if the array is empty.
void add(ElementType &&firstNewElement, OtherElements... otherElements)
Appends multiple new elements at the end of the array.
ElementType * end() const noexcept
Returns a pointer to the element which follows the last element in the array.