26#ifndef WATER_ARRAY_H_INCLUDED
27#define WATER_ARRAY_H_INCLUDED
55template <
typename ElementType,
size_t minimumAllocatedSize = 0>
81 new (
data.elements +
i) ElementType (other.data.elements[
i]);
88 template <
typename TypeToCreateFrom>
91 while (*values != TypeToCreateFrom())
102 template <
typename TypeToCreateFrom>
107 for (
int i = 0;
i < numValues; ++
i)
108 new (
data.elements +
i) ElementType (values[
i]);
137 template <
class OtherArrayType>
144 if (! (
data.elements [
i] == other.data.elements [
i]))
155 template <
class OtherArrayType>
172 data.setAllocatedSize (0);
213 return data.elements [index];
216 return ElementType();
231 return data.elements [index];
246 return data.elements [index];
258 return data.elements[0];
261 return ElementType();
276 return ElementType();
285 return data.elements;
294 return data.elements;
304 return data.elements;
321 const ElementType*
e =
data.elements.getData();
322 const ElementType*
const end_ =
e +
numUsed;
324 for (;
e != end_; ++
e)
325 if (elementToLookFor == *
e)
326 return static_cast<int> (
e -
data.elements.getData());
338 const ElementType*
e =
data.elements.getData();
339 const ElementType*
const end_ =
e +
numUsed;
341 for (;
e != end_; ++
e)
342 if (elementToLookFor == *
e)
354 bool add (
const ElementType& newElement)
noexcept
356 if (!
data.ensureAllocatedSize (
static_cast<size_t>(
numUsed + 1)))
359 new (
data.elements +
numUsed++) ElementType (newElement);
382 ElementType*
const insertPos =
data.elements + indexToInsertAt;
383 const int numberToMove =
numUsed - indexToInsertAt;
385 if (numberToMove > 0)
386 data.moveMemory (insertPos + 1, insertPos, numberToMove);
388 new (insertPos) ElementType (newElement);
393 new (
data.elements +
numUsed++) ElementType (newElement);
412 int numberOfTimesToInsertIt)
414 if (numberOfTimesToInsertIt > 0)
416 if (!
data.ensureAllocatedSize (
numUsed + numberOfTimesToInsertIt))
419 ElementType* insertPos;
423 insertPos =
data.elements + indexToInsertAt;
424 const int numberToMove =
numUsed - indexToInsertAt;
425 data.moveMemory (insertPos + numberOfTimesToInsertIt, insertPos, numberToMove);
432 numUsed += numberOfTimesToInsertIt;
434 while (--numberOfTimesToInsertIt >= 0)
436 new (insertPos) ElementType (newElement);
458 bool insertArray (
int indexToInsertAt,
459 const ElementType* newElements,
460 int numberOfElements)
462 if (numberOfElements > 0)
464 if (!
data.ensureAllocatedSize (
numUsed + numberOfElements))
467 ElementType* insertPos =
data.elements;
471 insertPos += indexToInsertAt;
472 const int numberToMove =
numUsed - indexToInsertAt;
473 std::memmove (insertPos + numberOfElements, insertPos, (
size_t) numberToMove *
sizeof (ElementType));
482 while (--numberOfElements >= 0)
483 new (insertPos++) ElementType (*newElements++);
504 return add (newElement);
523 data.elements [indexToChange] = newValue;
525 else if (indexToChange >= 0)
528 new (
data.elements +
numUsed++) ElementType (newValue);
544 data.elements [indexToChange] = newValue;
554 template <
typename Type>
555 void addArray (
const Type* elementsToAdd,
int numElementsToAdd)
557 if (numElementsToAdd > 0)
559 data.ensureAllocatedSize (
numUsed + numElementsToAdd);
561 while (--numElementsToAdd >= 0)
563 new (
data.elements +
numUsed) ElementType (*elementsToAdd++);
575 template <
typename Type>
579 for (
const Type*
const*
e = elementsToAdd; *
e !=
nullptr; ++
e)
590 template <
class OtherArrayType>
591 void swapWith (OtherArrayType& otherArray)
noexcept
593 data.swapWith (otherArray.data);
594 std::swap (
numUsed, otherArray.numUsed);
606 template <
class OtherArrayType>
607 void addArray (
const OtherArrayType& arrayToAddFrom,
609 int numElementsToAdd = -1)
617 if (numElementsToAdd < 0 || startIndex + numElementsToAdd > arrayToAddFrom.size())
618 numElementsToAdd = arrayToAddFrom.size() - startIndex;
620 while (--numElementsToAdd >= 0)
621 add (arrayToAddFrom.getUnchecked (startIndex++));
635 const int numToAdd = targetNumItems -
numUsed;
638 else if (numToAdd < 0)
654 template <
class ElementComparator>
658 insert (index, newElement);
673 DefaultElementComparator <ElementType> comparator;
689 template <
typename ElementComparator,
typename TargetValueType>
690 int indexOfSorted (ElementComparator& comparator, TargetValueType elementToLookFor)
const
700 if (comparator.compareElements (elementToLookFor,
data.elements [
s]) == 0)
703 const int halfway = (
s +
e) / 2;
707 if (comparator.compareElements (elementToLookFor,
data.elements [halfway]) >= 0)
748 ElementType removed (
data.elements[indexToRemove]);
753 return ElementType();
766 void remove (
const ElementType* elementToRemove)
768 wassert (elementToRemove !=
nullptr);
770 const int indexToRemove =
int (elementToRemove -
data.elements);
791 ElementType*
const e =
data.elements;
795 if (valueToRemove ==
e[
i])
818 if (valueToRemove ==
data.elements[
i])
839 template <
typename PredicateType>
846 if (predicate (
data.elements[
i]) ==
true)
870 const int endIndex =
jlimit (0,
numUsed, startIndex + numberToRemove);
872 numberToRemove = endIndex - startIndex;
874 if (numberToRemove > 0)
877 ElementType*
const e =
data.elements + startIndex;
879 const int numToShift =
numUsed - endIndex;
881 data.moveMemory (
e,
e + numberToRemove, numToShift);
883 for (
int i = 0;
i < numberToRemove; ++
i)
884 e[numToShift +
i].~ElementType();
886 ElementType* dst =
data.elements + startIndex;
887 ElementType* src = dst + numberToRemove;
889 const int numToShift =
numUsed - endIndex;
890 for (
int i = 0;
i < numToShift; ++
i)
891 data.moveElement (dst++, std::move (*(src++)));
893 for (
int i = 0;
i < numberToRemove; ++
i)
894 (dst++)->~ElementType();
912 for (
int i = 1;
i <= howManyToRemove; ++
i)
924 template <
class OtherArrayType>
927 if (
this == &otherArray)
933 if (otherArray.size() > 0)
936 if (otherArray.contains (
data.elements [
i]))
949 template <
class OtherArrayType>
952 if (
this != &otherArray)
954 if (otherArray.size() <= 0)
961 if (! otherArray.contains (
data.elements [
i]))
981 std::swap (
data.elements [index1],
982 data.elements [index2]);
1006 return data.ensureAllocatedSize (minNumElements);
1046 template <
class ElementComparator>
1047 void sort (ElementComparator& comparator,
1048 const bool retainOrderOfEquivalentItems =
false)
1052 sortArray (comparator,
data.elements.getData(), 0,
size() - 1, retainOrderOfEquivalentItems);
1057 ArrayAllocationBase <ElementType>
data;
1063 ElementType*
const e =
data.elements + indexToRemove;
1065 const int numberToShift =
numUsed - indexToRemove;
1067 if (numberToShift > 0)
1068 data.moveMemory (
e,
e + 1,
static_cast<size_t>(numberToShift));
1076 data.elements[
i].~ElementType();
1083 const size_t snumUsed =
static_cast<size_t>(
numUsed);
1085 if (
data.numAllocated >
jmax (minimumAllocatedSize, snumUsed * 2U))
1086 data.shrinkToNoMoreThan (
jmax (snumUsed,
jmax (minimumAllocatedSize, 64U /
sizeof (ElementType))));
#define CARLA_SAFE_ASSERT_RETURN(cond, ret)
Definition CarlaDefines.h:190
#define CARLA_SAFE_ASSERT_BREAK(cond)
Definition CarlaDefines.h:188
#define noexcept
Definition DistrhoDefines.h:72
Array() noexcept
Definition Array.h:64
Array & operator=(const Array &other) noexcept
Definition Array.h:120
void removeInternal(const int indexToRemove)
Definition Array.h:1060
~Array() noexcept
Definition Array.h:112
ElementType & getReference(const int index) const noexcept
Definition Array.h:243
int indexOf(ParameterType elementToLookFor) const
Definition Array.h:319
void deleteAllElements() noexcept
Definition Array.h:1073
void clearQuick() noexcept
Definition Array.h:179
typedef PARAMETER_TYPE(ElementType) ParameterType
Array(const TypeToCreateFrom *values, int numValues) noexcept
Definition Array.h:103
bool operator!=(const OtherArrayType &other) const
Definition Array.h:156
void resize(const int targetNumItems)
Definition Array.h:631
Array(const Array< ElementType > &other) noexcept
Definition Array.h:73
void addArray(const Type *elementsToAdd, int numElementsToAdd)
Definition Array.h:555
int removeAllInstancesOf(ParameterType valueToRemove)
Definition Array.h:812
void removeFirstMatchingValue(ParameterType valueToRemove)
Definition Array.h:789
void removeLast(int howManyToRemove=1)
Definition Array.h:907
int indexOfSorted(ElementComparator &comparator, TargetValueType elementToLookFor) const
Definition Array.h:690
bool add(const ElementType &newElement) noexcept
Definition Array.h:354
void remove(const ElementType *elementToRemove)
Definition Array.h:766
ElementType * begin() const noexcept
Definition Array.h:292
void swapWith(OtherArrayType &otherArray) noexcept
Definition Array.h:591
bool ensureStorageAllocated(const int minNumElements) noexcept
Definition Array.h:1004
int size() const noexcept
Definition Array.h:187
void sort()
Definition Array.h:1014
void swap(const int index1, const int index2)
Definition Array.h:975
ElementType * end() const noexcept
Definition Array.h:300
bool minimiseStorageOverheads() noexcept
Definition Array.h:993
void setUnchecked(const int indexToChange, ParameterType newValue)
Definition Array.h:541
bool insertMultiple(int indexToInsertAt, ParameterType newElement, int numberOfTimesToInsertIt)
Definition Array.h:411
bool addIfNotAlreadyThere(ParameterType newElement)
Definition Array.h:499
void minimiseStorageAfterRemoval()
Definition Array.h:1079
bool operator==(const OtherArrayType &other) const
Definition Array.h:138
ElementType getUnchecked(const int index) const
Definition Array.h:228
int addSorted(ElementComparator &comparator, ParameterType newElement)
Definition Array.h:655
void remove(int indexToRemove)
Definition Array.h:724
void addUsingDefaultSort(ParameterType newElement)
Definition Array.h:671
bool insert(int indexToInsertAt, ParameterType newElement) noexcept
Definition Array.h:375
ArrayAllocationBase< ElementType > data
Definition Array.h:1057
ElementType operator[](const int index) const
Definition Array.h:208
void addNullTerminatedArray(const Type *const *elementsToAdd)
Definition Array.h:576
int numUsed
Definition Array.h:1058
void removeRange(int startIndex, int numberToRemove)
Definition Array.h:868
ElementType getLast() const
Definition Array.h:268
void removeValuesIn(const OtherArrayType &otherArray)
Definition Array.h:925
ElementType getFirst() const
Definition Array.h:253
void clear() noexcept
Definition Array.h:169
Array(const TypeToCreateFrom *values) noexcept
Definition Array.h:89
bool contains(ParameterType elementToLookFor) const
Definition Array.h:336
void removeValuesNotIn(const OtherArrayType &otherArray)
Definition Array.h:950
ElementType * getRawDataPointer() noexcept
Definition Array.h:283
void set(const int indexToChange, ParameterType newValue)
Definition Array.h:516
void addArray(const OtherArrayType &arrayToAddFrom, int startIndex=0, int numElementsToAdd=-1)
Definition Array.h:607
void sort(ElementComparator &comparator, const bool retainOrderOfEquivalentItems=false)
Definition Array.h:1047
bool isEmpty() const noexcept
Definition Array.h:193
ElementType removeAndReturn(const int indexToRemove)
Definition Array.h:743
Array() noexcept
Definition Array.h:64
int removeIf(PredicateType predicate)
Definition Array.h:840
Definition ElementComparator.h:179
* e
Definition inflate.c:1404
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
ParameterType
Definition CarlaBackend.h:763
JSAMPIMAGE data
Definition jpeglib.h:945
#define wassert(expression)
Definition AudioSampleBuffer.h:33
static int findInsertIndexInSortedArray(ElementComparator &comparator, ElementType *const array, const ElementType newElement, int firstElement, int lastElement)
Definition ElementComparator.h:119
bool isPositiveAndBelow(Type valueToTest, Type upperLimit) noexcept
Definition MathsFunctions.h:187
void ignoreUnused(const Type1 &) noexcept
Definition MathsFunctions.h:237
Type jmax(const Type a, const Type b)
Definition MathsFunctions.h:48
Type jlimit(const Type lowerLimit, const Type upperLimit, const Type valueToConstrain) noexcept
Definition MathsFunctions.h:169
static void sortArray(ElementComparator &comparator, ElementType *const array, int firstElement, int lastElement, const bool retainOrderOfEquivalentItems)
Definition ElementComparator.h:79
typedef int(UZ_EXP MsgFn)()
#define const
Definition zconf.h:137