29 #ifndef JUCE_OWNEDARRAY_H_INCLUDED 30 #define JUCE_OWNEDARRAY_H_INCLUDED 52 template <
class ObjectClass,
75 #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS 97 void clear (
bool deleteObjects =
true)
104 data.setAllocatedSize (0);
143 return data.elements [index];
158 return data.elements [index];
173 return data.elements [0];
203 return data.elements;
212 return data.elements;
222 return data.elements;
237 ObjectClass*
const* e =
data.elements.getData();
238 ObjectClass*
const*
const end_ = e +
numUsed;
240 for (; e != end_; ++e)
241 if (objectToLookFor == *e)
242 return static_cast <
int> (e -
data.elements.getData());
255 ObjectClass*
const* e =
data.elements.getData();
256 ObjectClass*
const*
const end_ = e +
numUsed;
258 for (; e != end_; ++e)
259 if (objectToLookFor == *e)
307 if (indexToInsertAt < 0)
308 return add (newObject);
318 ObjectClass**
const e =
data.elements + indexToInsertAt;
319 const int numToMove =
numUsed - indexToInsertAt;
322 memmove (e + 1, e,
sizeof (ObjectClass*) * (
size_t) numToMove);
342 ObjectClass*
const* newObjects,
343 int numberOfElements)
345 if (numberOfElements > 0)
348 data.ensureAllocatedSize (
numUsed + numberOfElements);
349 ObjectClass** insertPos =
data.elements;
353 insertPos += indexToInsertAt;
354 const size_t numberToMove = (size_t) (
numUsed - indexToInsertAt);
355 memmove (insertPos + numberOfElements, insertPos, numberToMove *
sizeof (ObjectClass*));
364 while (--numberOfElements >= 0)
365 *insertPos++ = *newObjects++;
400 ObjectClass*
set (
int indexToChange, ObjectClass* newObject,
bool deleteOldElement =
true)
402 if (indexToChange >= 0)
411 if (deleteOldElement)
413 toDelete =
data.elements [indexToChange];
415 if (toDelete == newObject)
419 data.elements [indexToChange] = newObject;
446 template <
class OtherArrayType>
447 void addArray (
const OtherArrayType& arrayToAddFrom,
449 int numElementsToAdd = -1)
451 const typename OtherArrayType::ScopedLockType lock1 (arrayToAddFrom.getLock());
460 if (numElementsToAdd < 0 || startIndex + numElementsToAdd > arrayToAddFrom.size())
461 numElementsToAdd = arrayToAddFrom.size() - startIndex;
463 data.ensureAllocatedSize (
numUsed + numElementsToAdd);
464 jassert (numElementsToAdd <= 0 ||
data.elements !=
nullptr);
466 while (--numElementsToAdd >= 0)
468 data.elements [
numUsed] = arrayToAddFrom.getUnchecked (startIndex++);
487 template <
class OtherArrayType>
490 int numElementsToAdd = -1)
492 const typename OtherArrayType::ScopedLockType lock1 (arrayToAddFrom.getLock());
501 if (numElementsToAdd < 0 || startIndex + numElementsToAdd > arrayToAddFrom.size())
502 numElementsToAdd = arrayToAddFrom.size() - startIndex;
504 data.ensureAllocatedSize (
numUsed + numElementsToAdd);
505 jassert (numElementsToAdd <= 0 ||
data.elements !=
nullptr);
507 while (--numElementsToAdd >= 0)
523 template <
class ElementComparator>
529 const int index = findInsertIndexInSortedArray (comparator,
data.elements.getData(), newObject, 0,
numUsed);
530 insert (index, newObject);
546 template <
typename ElementComparator>
555 if (comparator.compareElements (objectToLookFor,
data.elements [s]) == 0)
558 const int halfway = (s + e) / 2;
562 if (comparator.compareElements (objectToLookFor,
data.elements [halfway]) >= 0)
582 void remove (
int indexToRemove,
bool deleteObject =
true)
591 ObjectClass**
const e =
data.elements + indexToRemove;
597 const int numToShift =
numUsed - indexToRemove;
600 memmove (e, e + 1,
sizeof (ObjectClass*) * (
size_t) numToShift);
619 ObjectClass* removedItem =
nullptr;
624 ObjectClass**
const e =
data.elements + indexToRemove;
628 const int numToShift =
numUsed - indexToRemove;
631 memmove (e, e + 1,
sizeof (ObjectClass*) * (
size_t) numToShift);
648 void removeObject (
const ObjectClass* objectToRemove,
bool deleteObject =
true)
651 ObjectClass**
const e =
data.elements.getData();
653 for (
int i = 0; i <
numUsed; ++i)
655 if (objectToRemove == e[i])
657 remove (i, deleteObject);
676 void removeRange (
int startIndex,
int numberToRemove,
bool deleteObjects =
true)
679 const int endIndex =
jlimit (0,
numUsed, startIndex + numberToRemove);
682 if (endIndex > startIndex)
686 for (
int i = startIndex; i < endIndex; ++i)
689 data.elements [i] =
nullptr;
693 const int rangeSize = endIndex - startIndex;
694 ObjectClass** e =
data.elements + startIndex;
695 int numToShift =
numUsed - endIndex;
698 while (--numToShift >= 0)
716 bool deleteObjects =
true)
720 if (howManyToRemove >=
numUsed)
721 clear (deleteObjects);
739 std::swap (
data.elements [index1],
740 data.elements [index2]);
759 if (currentIndex != newIndex)
768 ObjectClass*
const value =
data.elements [currentIndex];
770 if (newIndex > currentIndex)
772 memmove (
data.elements + currentIndex,
773 data.elements + currentIndex + 1,
774 sizeof (ObjectClass*) * (
size_t) (newIndex - currentIndex));
778 memmove (
data.elements + newIndex + 1,
779 data.elements + newIndex,
780 sizeof (ObjectClass*) * (
size_t) (currentIndex - newIndex));
783 data.elements [newIndex] = value;
793 template <
class OtherArrayType>
797 const typename OtherArrayType::ScopedLockType lock2 (otherArray.getLock());
798 data.swapWith (otherArray.data);
824 data.ensureAllocatedSize (minNumElements);
853 template <
class ElementComparator>
854 void sort (ElementComparator& comparator,
861 sortArray (comparator,
data.elements.getData(), 0,
size() - 1, retainOrderOfEquivalentItems);
897 #endif // JUCE_OWNEDARRAY_H_INCLUDED int indexOfSorted(ElementComparator &comparator, const ObjectClass *const objectToLookFor) const noexcept
Definition: juce_OwnedArray.h:547
ObjectType * release() noexcept
Definition: juce_ScopedPointer.h:179
void sort(ElementComparator &comparator, bool retainOrderOfEquivalentItems=false) const noexcept
Definition: juce_OwnedArray.h:854
void swapWith(OtherArrayType &otherArray) noexcept
Definition: juce_OwnedArray.h:794
ObjectClass * getLast() const noexcept
Definition: juce_OwnedArray.h:184
ObjectClass * getUnchecked(const int index) const noexcept
Definition: juce_OwnedArray.h:154
~OwnedArray()
Definition: juce_OwnedArray.h:70
#define noexcept
Definition: juce_CompilerSupport.h:141
int size() const noexcept
Definition: juce_OwnedArray.h:124
void deleteAllObjects()
Definition: juce_OwnedArray.h:887
OwnedArray() noexcept
Definition: juce_OwnedArray.h:60
bool isPositiveAndBelow(Type valueToTest, Type upperLimit) noexcept
Definition: juce_core.h:238
void swap(int index1, int index2) noexcept
Definition: juce_OwnedArray.h:731
Definition: juce_ArrayAllocationBase.h:46
void move(int currentIndex, int newIndex) noexcept
Definition: juce_OwnedArray.h:757
void clear(bool deleteObjects=true)
Definition: juce_OwnedArray.h:97
TypeOfCriticalSectionToUse::ScopedLockType ScopedLockType
Definition: juce_OwnedArray.h:872
void addCopiesOf(const OtherArrayType &arrayToAddFrom, int startIndex=0, int numElementsToAdd=-1)
Definition: juce_OwnedArray.h:488
ObjectClass * getFirst() const noexcept
Definition: juce_OwnedArray.h:166
void ensureStorageAllocated(const int minNumElements) noexcept
Definition: juce_OwnedArray.h:821
int indexOf(const ObjectClass *objectToLookFor) const noexcept
Definition: juce_OwnedArray.h:234
void clearQuick(bool deleteObjects)
Definition: juce_OwnedArray.h:110
Definition: juce_ScopedPointer.h:70
Definition: juce_CriticalSection.h:148
Type * createCopyIfNotNull(const Type *objectToCopy)
Definition: juce_Memory.h:65
const TypeOfCriticalSectionToUse & getLock() const noexcept
Definition: juce_OwnedArray.h:869
Type jlimit(const Type lowerLimit, const Type upperLimit, const Type valueToConstrain) noexcept
Definition: juce_MathsFunctions.h:220
void
Definition: juce_PNGLoader.cpp:1173
Definition: juce_OwnedArray.h:55
JUCE_DEPRECATED_WITH_BODY(void swapWithArray(OwnedArray &other) noexcept,{swapWith(other);}) private int numUsed
Definition: juce_OwnedArray.h:879
void removeRange(int startIndex, int numberToRemove, bool deleteObjects=true)
Definition: juce_OwnedArray.h:676
void minimiseStorageOverheads() noexcept
Definition: juce_OwnedArray.h:809
ObjectClass * addIfNotAlreadyThere(ObjectClass *newObject) noexcept
Definition: juce_OwnedArray.h:377
void addArray(const OtherArrayType &arrayToAddFrom, int startIndex=0, int numElementsToAdd=-1)
Definition: juce_OwnedArray.h:447
JSAMPIMAGE data
Definition: jpeglib.h:945
ObjectClass * add(ObjectClass *newObject) noexcept
Definition: juce_OwnedArray.h:278
int addSorted(ElementComparator &comparator, ObjectClass *const newObject) noexcept
Definition: juce_OwnedArray.h:524
Definition: juce_CriticalSection.h:136
ObjectClass ** getRawDataPointer() noexcept
Definition: juce_OwnedArray.h:201
ObjectClass ** begin() const noexcept
Definition: juce_OwnedArray.h:210
void insertArray(int indexToInsertAt, ObjectClass *const *newObjects, int numberOfElements)
Definition: juce_OwnedArray.h:341
ObjectClass * insert(int indexToInsertAt, ObjectClass *newObject) noexcept
Definition: juce_OwnedArray.h:305
bool contains(const ObjectClass *objectToLookFor) const noexcept
Definition: juce_OwnedArray.h:252
ObjectClass * removeAndReturn(int indexToRemove)
Definition: juce_OwnedArray.h:617
void removeLast(int howManyToRemove=1, bool deleteObjects=true)
Definition: juce_OwnedArray.h:715
ObjectClass * operator[](const int index) const noexcept
Definition: juce_OwnedArray.h:137
ObjectClass ** end() const noexcept
Definition: juce_OwnedArray.h:218
static void destroy(ObjectType *object)
Definition: juce_ContainerDeletePolicy.h:46
void removeObject(const ObjectClass *objectToRemove, bool deleteObject=true)
Definition: juce_OwnedArray.h:648