|
|
|
@@ -146,7 +146,7 @@ public: |
|
|
|
|
|
|
|
@see getUnchecked
|
|
|
|
*/
|
|
|
|
inline ObjectClass* operator[] (const int index) const noexcept
|
|
|
|
inline ObjectClass* operator[] (int index) const noexcept
|
|
|
|
{
|
|
|
|
const ScopedLockType lock (getLock());
|
|
|
|
return values.getValueWithDefault (index);
|
|
|
|
@@ -157,7 +157,7 @@ public: |
|
|
|
This is a faster and less safe version of operator[] which doesn't check the index passed in, so
|
|
|
|
it can be used when you're sure the index is always going to be legal.
|
|
|
|
*/
|
|
|
|
inline ObjectClass* getUnchecked (const int index) const noexcept
|
|
|
|
inline ObjectClass* getUnchecked (int index) const noexcept
|
|
|
|
{
|
|
|
|
const ScopedLockType lock (getLock());
|
|
|
|
return values[index];
|
|
|
|
@@ -267,13 +267,30 @@ public: |
|
|
|
@returns the new object that was added
|
|
|
|
@see set, insert, addIfNotAlreadyThere, addSorted
|
|
|
|
*/
|
|
|
|
ObjectClass* add (ObjectClass* newObject) noexcept
|
|
|
|
ObjectClass* add (ObjectClass* newObject)
|
|
|
|
{
|
|
|
|
const ScopedLockType lock (getLock());
|
|
|
|
values.add (newObject);
|
|
|
|
return newObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Appends a new object to the end of the array.
|
|
|
|
|
|
|
|
Note that the this object will be deleted by the OwnedArray when it
|
|
|
|
is removed, so be careful not to delete it somewhere else.
|
|
|
|
|
|
|
|
Also be careful not to add the same object to the array more than once,
|
|
|
|
as this will obviously cause deletion of dangling pointers.
|
|
|
|
|
|
|
|
@param newObject the new object to add to the array
|
|
|
|
@returns the new object that was added
|
|
|
|
@see set, insert, addIfNotAlreadyThere, addSorted
|
|
|
|
*/
|
|
|
|
ObjectClass* add (std::unique_ptr<ObjectClass> newObject)
|
|
|
|
{
|
|
|
|
return add (newObject.release());
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Inserts a new object into the array at the given index.
|
|
|
|
|
|
|
|
Note that the this object will be deleted by the OwnedArray when it
|
|
|
|
@@ -292,13 +309,36 @@ public: |
|
|
|
@returns the new object that was added
|
|
|
|
@see add, addSorted, addIfNotAlreadyThere, set
|
|
|
|
*/
|
|
|
|
ObjectClass* insert (int indexToInsertAt, ObjectClass* newObject) noexcept
|
|
|
|
ObjectClass* insert (int indexToInsertAt, ObjectClass* newObject)
|
|
|
|
{
|
|
|
|
const ScopedLockType lock (getLock());
|
|
|
|
values.insert (indexToInsertAt, newObject, 1);
|
|
|
|
return newObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Inserts a new object into the array at the given index.
|
|
|
|
|
|
|
|
Note that the this object will be deleted by the OwnedArray when it
|
|
|
|
is removed, so be careful not to delete it somewhere else.
|
|
|
|
|
|
|
|
If the index is less than 0 or greater than the size of the array, the
|
|
|
|
element will be added to the end of the array.
|
|
|
|
Otherwise, it will be inserted into the array, moving all the later elements
|
|
|
|
along to make room.
|
|
|
|
|
|
|
|
Be careful not to add the same object to the array more than once,
|
|
|
|
as this will obviously cause deletion of dangling pointers.
|
|
|
|
|
|
|
|
@param indexToInsertAt the index at which the new element should be inserted
|
|
|
|
@param newObject the new object to add to the array
|
|
|
|
@returns the new object that was added
|
|
|
|
@see add, addSorted, addIfNotAlreadyThere, set
|
|
|
|
*/
|
|
|
|
ObjectClass* insert (int indexToInsertAt, std::unique_ptr<ObjectClass> newObject)
|
|
|
|
{
|
|
|
|
return insert (indexToInsertAt, newObject.release());
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Inserts an array of values into this array at a given position.
|
|
|
|
|
|
|
|
If the index is less than 0 or greater than the size of the array, the
|
|
|
|
@@ -322,25 +362,6 @@ public: |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Appends a new object at the end of the array as long as the array doesn't
|
|
|
|
already contain it.
|
|
|
|
|
|
|
|
If the array already contains a matching object, nothing will be done.
|
|
|
|
|
|
|
|
@param newObject the new object to add to the array
|
|
|
|
@returns true if the new object was added, false otherwise
|
|
|
|
*/
|
|
|
|
bool addIfNotAlreadyThere (ObjectClass* newObject) noexcept
|
|
|
|
{
|
|
|
|
const ScopedLockType lock (getLock());
|
|
|
|
|
|
|
|
if (contains (newObject))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
add (newObject);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Replaces an object in the array with a different one.
|
|
|
|
|
|
|
|
If the index is less than zero, this method does nothing.
|
|
|
|
@@ -390,6 +411,24 @@ public: |
|
|
|
return newObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Replaces an object in the array with a different one.
|
|
|
|
|
|
|
|
If the index is less than zero, this method does nothing.
|
|
|
|
If the index is beyond the end of the array, the new object is added to the end of the array.
|
|
|
|
|
|
|
|
Be careful not to add the same object to the array more than once,
|
|
|
|
as this will obviously cause deletion of dangling pointers.
|
|
|
|
|
|
|
|
@param indexToChange the index whose value you want to change
|
|
|
|
@param newObject the new value to set for this index.
|
|
|
|
@param deleteOldElement whether to delete the object that's being replaced with the new one
|
|
|
|
@see add, insert, remove
|
|
|
|
*/
|
|
|
|
ObjectClass* set (int indexToChange, std::unique_ptr<ObjectClass> newObject, bool deleteOldElement = true)
|
|
|
|
{
|
|
|
|
return set (indexToChange, newObject.release(), deleteOldElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Adds elements from another array to the end of this array.
|
|
|
|
|
|
|
|
@param arrayToAddFrom the array from which to copy the elements
|
|
|
|
@@ -468,14 +507,14 @@ public: |
|
|
|
@see add, sort, indexOfSorted
|
|
|
|
*/
|
|
|
|
template <class ElementComparator>
|
|
|
|
int addSorted (ElementComparator& comparator, ObjectClass* const newObject) noexcept
|
|
|
|
int addSorted (ElementComparator& comparator, ObjectClass* newObject) noexcept
|
|
|
|
{
|
|
|
|
// If you pass in an object with a static compareElements() method, this
|
|
|
|
// avoids getting warning messages about the parameter being unused
|
|
|
|
ignoreUnused (comparator);
|
|
|
|
|
|
|
|
const ScopedLockType lock (getLock());
|
|
|
|
const int index = findInsertIndexInSortedArray (comparator, values.begin(), newObject, 0, values.size());
|
|
|
|
auto index = findInsertIndexInSortedArray (comparator, values.begin(), newObject, 0, values.size());
|
|
|
|
insert (index, newObject);
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
@@ -493,7 +532,7 @@ public: |
|
|
|
@see addSorted, sort
|
|
|
|
*/
|
|
|
|
template <typename ElementComparator>
|
|
|
|
int indexOfSorted (ElementComparator& comparator, const ObjectClass* const objectToLookFor) const noexcept
|
|
|
|
int indexOfSorted (ElementComparator& comparator, const ObjectClass* objectToLookFor) const noexcept
|
|
|
|
{
|
|
|
|
// If you pass in an object with a static compareElements() method, this
|
|
|
|
// avoids getting warning messages about the parameter being unused
|
|
|
|
@@ -722,7 +761,7 @@ public: |
|
|
|
the array won't have to keep dynamically resizing itself as the elements
|
|
|
|
are added, and it'll therefore be more efficient.
|
|
|
|
*/
|
|
|
|
void ensureStorageAllocated (const int minNumElements) noexcept
|
|
|
|
void ensureStorageAllocated (int minNumElements) noexcept
|
|
|
|
{
|
|
|
|
const ScopedLockType lock (getLock());
|
|
|
|
values.ensureAllocatedSize (minNumElements);
|
|
|
|
|