mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-19 01:04:20 +00:00
Reduced the memory footprint of the array classes.
This commit is contained in:
parent
ded4826413
commit
31a102008d
11 changed files with 542 additions and 489 deletions
|
|
@ -137,11 +137,11 @@ public:
|
|||
template <class OtherArrayType>
|
||||
bool operator== (const OtherArrayType& other) const
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (numUsed != other.numUsed)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -149,12 +149,12 @@ public:
|
|||
{
|
||||
if (data.elements [i] != other.data.elements [i])
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -179,14 +179,14 @@ public:
|
|||
*/
|
||||
void clear()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
for (int i = 0; i < numUsed; ++i)
|
||||
data.elements[i].~ElementType();
|
||||
|
||||
data.setAllocatedSize (0);
|
||||
numUsed = 0;
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Removes all elements from the array without freeing the array's allocated storage.
|
||||
|
|
@ -195,13 +195,13 @@ public:
|
|||
*/
|
||||
void clearQuick()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
for (int i = 0; i < numUsed; ++i)
|
||||
data.elements[i].~ElementType();
|
||||
|
||||
numUsed = 0;
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -224,11 +224,11 @@ public:
|
|||
*/
|
||||
inline ElementType operator[] (const int index) const
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
const ElementType result ((((unsigned int) index) < (unsigned int) numUsed)
|
||||
? data.elements [index]
|
||||
: ElementType());
|
||||
lock.exit();
|
||||
data.exit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -244,10 +244,10 @@ public:
|
|||
*/
|
||||
inline const ElementType getUnchecked (const int index) const
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
jassert (((unsigned int) index) < (unsigned int) numUsed);
|
||||
const ElementType result (data.elements [index]);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -263,10 +263,10 @@ public:
|
|||
*/
|
||||
inline ElementType& getReference (const int index) const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
jassert (((unsigned int) index) < (unsigned int) numUsed);
|
||||
ElementType& result = data.elements [index];
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -276,10 +276,10 @@ public:
|
|||
*/
|
||||
inline ElementType getFirst() const
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
const ElementType result ((numUsed > 0) ? data.elements [0]
|
||||
: ElementType());
|
||||
lock.exit();
|
||||
data.exit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -290,10 +290,10 @@ public:
|
|||
*/
|
||||
inline ElementType getLast() const
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
const ElementType result ((numUsed > 0) ? data.elements [numUsed - 1]
|
||||
: ElementType());
|
||||
lock.exit();
|
||||
data.exit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -311,7 +311,7 @@ public:
|
|||
{
|
||||
int result = -1;
|
||||
|
||||
lock.enter();
|
||||
data.enter();
|
||||
const ElementType* e = data.elements;
|
||||
|
||||
for (int i = numUsed; --i >= 0;)
|
||||
|
|
@ -325,7 +325,7 @@ public:
|
|||
++e;
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -336,7 +336,7 @@ public:
|
|||
*/
|
||||
bool contains (const ElementType& elementToLookFor) const
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
const ElementType* e = data.elements;
|
||||
int num = numUsed;
|
||||
|
|
@ -345,7 +345,7 @@ public:
|
|||
{
|
||||
if (elementToLookFor == *e)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -353,7 +353,7 @@ public:
|
|||
++e;
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -365,10 +365,10 @@ public:
|
|||
*/
|
||||
void add (const ElementType& newElement)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
data.ensureAllocatedSize (numUsed + 1);
|
||||
new (data.elements + numUsed++) ElementType (newElement);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Inserts a new element into the array at a given position.
|
||||
|
|
@ -385,7 +385,7 @@ public:
|
|||
*/
|
||||
void insert (int indexToInsertAt, const ElementType& newElement)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
data.ensureAllocatedSize (numUsed + 1);
|
||||
|
||||
if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed)
|
||||
|
|
@ -404,7 +404,7 @@ public:
|
|||
new (data.elements + numUsed++) ElementType (newElement);
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Inserts multiple copies of an element into the array at a given position.
|
||||
|
|
@ -424,7 +424,7 @@ public:
|
|||
{
|
||||
if (numberOfTimesToInsertIt > 0)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
data.ensureAllocatedSize (numUsed + numberOfTimesToInsertIt);
|
||||
ElementType* insertPos;
|
||||
|
||||
|
|
@ -444,7 +444,7 @@ public:
|
|||
while (--numberOfTimesToInsertIt >= 0)
|
||||
new (insertPos++) ElementType (newElement);
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -466,7 +466,7 @@ public:
|
|||
{
|
||||
if (numberOfElements > 0)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
data.ensureAllocatedSize (numUsed + numberOfElements);
|
||||
ElementType* insertPos;
|
||||
|
||||
|
|
@ -486,7 +486,7 @@ public:
|
|||
while (--numberOfElements >= 0)
|
||||
new (insertPos++) ElementType (*newElements++);
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -500,12 +500,12 @@ public:
|
|||
*/
|
||||
void addIfNotAlreadyThere (const ElementType& newElement)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (! contains (newElement))
|
||||
add (newElement);
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Replaces an element with a new value.
|
||||
|
|
@ -521,7 +521,7 @@ public:
|
|||
{
|
||||
jassert (indexToChange >= 0);
|
||||
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (((unsigned int) indexToChange) < (unsigned int) numUsed)
|
||||
{
|
||||
|
|
@ -533,7 +533,7 @@ public:
|
|||
new (data.elements + numUsed++) ElementType (newValue);
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Replaces an element with a new value without doing any bounds-checking.
|
||||
|
|
@ -547,10 +547,10 @@ public:
|
|||
*/
|
||||
void setUnchecked (const int indexToChange, const ElementType& newValue)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
jassert (((unsigned int) indexToChange) < (unsigned int) numUsed);
|
||||
data.elements [indexToChange] = newValue;
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Adds elements from an array to the end of this array.
|
||||
|
|
@ -561,7 +561,7 @@ public:
|
|||
*/
|
||||
void addArray (const ElementType* elementsToAdd, int numElementsToAdd)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (numElementsToAdd > 0)
|
||||
{
|
||||
|
|
@ -571,7 +571,7 @@ public:
|
|||
new (data.elements + numUsed++) ElementType (*elementsToAdd++);
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** This swaps the contents of this array with those of another array.
|
||||
|
|
@ -581,12 +581,12 @@ public:
|
|||
*/
|
||||
void swapWithArray (Array <ElementType>& otherArray) throw()
|
||||
{
|
||||
lock.enter();
|
||||
otherArray.lock.enter();
|
||||
data.enter();
|
||||
otherArray.data.enter();
|
||||
data.swapWith (otherArray.data);
|
||||
swapVariables (numUsed, otherArray.numUsed);
|
||||
otherArray.lock.exit();
|
||||
lock.exit();
|
||||
otherArray.data.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Adds elements from another array to the end of this array.
|
||||
|
|
@ -604,7 +604,7 @@ public:
|
|||
int numElementsToAdd = -1)
|
||||
{
|
||||
arrayToAddFrom.lockArray();
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (startIndex < 0)
|
||||
{
|
||||
|
|
@ -618,7 +618,7 @@ public:
|
|||
while (--numElementsToAdd >= 0)
|
||||
add (arrayToAddFrom.getUnchecked (startIndex++));
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
arrayToAddFrom.unlockArray();
|
||||
}
|
||||
|
||||
|
|
@ -636,9 +636,9 @@ public:
|
|||
template <class ElementComparator>
|
||||
void addSorted (ElementComparator& comparator, const ElementType& newElement)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
insert (findInsertIndexInSortedArray (comparator, (ElementType*) data.elements, newElement, 0, numUsed), newElement);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Finds the index of an element in the array, assuming that the array is sorted.
|
||||
|
|
@ -658,7 +658,7 @@ public:
|
|||
{
|
||||
(void) comparator; // if you pass in an object with a static compareElements() method, this
|
||||
// avoids getting warning messages about the parameter being unused
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
int start = 0;
|
||||
int end = numUsed;
|
||||
|
|
@ -667,12 +667,12 @@ public:
|
|||
{
|
||||
if (start >= end)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return -1;
|
||||
}
|
||||
else if (comparator.compareElements (elementToLookFor, data.elements [start]) == 0)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return start;
|
||||
}
|
||||
else
|
||||
|
|
@ -681,7 +681,7 @@ public:
|
|||
|
||||
if (halfway == start)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return -1;
|
||||
}
|
||||
else if (comparator.compareElements (elementToLookFor, data.elements [halfway]) >= 0)
|
||||
|
|
@ -705,7 +705,7 @@ public:
|
|||
*/
|
||||
ElementType remove (const int indexToRemove)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (((unsigned int) indexToRemove) < (unsigned int) numUsed)
|
||||
{
|
||||
|
|
@ -722,12 +722,12 @@ public:
|
|||
if ((numUsed << 1) < data.numAllocated)
|
||||
minimiseStorageOverheads();
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return removed;
|
||||
}
|
||||
else
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return ElementType();
|
||||
}
|
||||
}
|
||||
|
|
@ -742,7 +742,7 @@ public:
|
|||
*/
|
||||
void removeValue (const ElementType& valueToRemove)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
ElementType* e = data.elements;
|
||||
|
||||
for (int i = numUsed; --i >= 0;)
|
||||
|
|
@ -756,7 +756,7 @@ public:
|
|||
++e;
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Removes a range of elements from the array.
|
||||
|
|
@ -773,7 +773,7 @@ public:
|
|||
*/
|
||||
void removeRange (int startIndex, int numberToRemove)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
const int endIndex = jlimit (0, numUsed, startIndex + numberToRemove);
|
||||
startIndex = jlimit (0, numUsed, startIndex);
|
||||
|
||||
|
|
@ -795,7 +795,7 @@ public:
|
|||
minimiseStorageOverheads();
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Removes the last n elements from the array.
|
||||
|
|
@ -805,7 +805,7 @@ public:
|
|||
*/
|
||||
void removeLast (int howManyToRemove = 1)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (howManyToRemove > numUsed)
|
||||
howManyToRemove = numUsed;
|
||||
|
|
@ -818,7 +818,7 @@ public:
|
|||
if ((numUsed << 1) < data.numAllocated)
|
||||
minimiseStorageOverheads();
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Removes any elements which are also in another array.
|
||||
|
|
@ -830,7 +830,7 @@ public:
|
|||
void removeValuesIn (const OtherArrayType& otherArray)
|
||||
{
|
||||
otherArray.lockArray();
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (this == &otherArray)
|
||||
{
|
||||
|
|
@ -846,7 +846,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
otherArray.unlockArray();
|
||||
}
|
||||
|
||||
|
|
@ -861,7 +861,7 @@ public:
|
|||
void removeValuesNotIn (const OtherArrayType& otherArray)
|
||||
{
|
||||
otherArray.lockArray();
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (this != &otherArray)
|
||||
{
|
||||
|
|
@ -877,7 +877,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
otherArray.unlockArray();
|
||||
}
|
||||
|
||||
|
|
@ -892,7 +892,7 @@ public:
|
|||
void swap (const int index1,
|
||||
const int index2)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (((unsigned int) index1) < (unsigned int) numUsed
|
||||
&& ((unsigned int) index2) < (unsigned int) numUsed)
|
||||
|
|
@ -901,7 +901,7 @@ public:
|
|||
data.elements [index2]);
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Moves one of the values to a different position.
|
||||
|
|
@ -922,7 +922,7 @@ public:
|
|||
{
|
||||
if (currentIndex != newIndex)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (((unsigned int) currentIndex) < (unsigned int) numUsed)
|
||||
{
|
||||
|
|
@ -948,7 +948,7 @@ public:
|
|||
memcpy (data.elements + newIndex, tempCopy, sizeof (ElementType));
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -961,9 +961,9 @@ public:
|
|||
*/
|
||||
void minimiseStorageOverheads()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
data.shrinkToNoMoreThan (numUsed);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Increases the array's internal storage to hold a minimum number of elements.
|
||||
|
|
@ -974,9 +974,9 @@ public:
|
|||
*/
|
||||
void ensureStorageAllocated (const int minNumElements)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
data.ensureAllocatedSize (minNumElements);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -1012,9 +1012,9 @@ public:
|
|||
{
|
||||
(void) comparator; // if you pass in an object with a static compareElements() method, this
|
||||
// avoids getting warning messages about the parameter being unused
|
||||
lock.enter();
|
||||
data.enter();
|
||||
sortArray (comparator, (ElementType*) data.elements, 0, size() - 1, retainOrderOfEquivalentItems);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -1027,7 +1027,7 @@ public:
|
|||
*/
|
||||
void lockArray() const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
}
|
||||
|
||||
/** Unlocks the array's CriticalSection.
|
||||
|
|
@ -1039,7 +1039,7 @@ public:
|
|||
*/
|
||||
void unlockArray() const throw()
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1047,9 +1047,8 @@ public:
|
|||
juce_UseDebuggingNewOperator
|
||||
|
||||
private:
|
||||
ArrayAllocationBase <ElementType> data;
|
||||
ArrayAllocationBase <ElementType, TypeOfCriticalSectionToUse> data;
|
||||
int numUsed;
|
||||
TypeOfCriticalSectionToUse lock;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -36,10 +36,13 @@
|
|||
This class isn't really for public use - it's used by the other
|
||||
array classes, but might come in handy for some purposes.
|
||||
|
||||
It inherits from a critical section class to allow the arrays to use
|
||||
the "empty base class optimisation" pattern to reduce their footprint.
|
||||
|
||||
@see Array, OwnedArray, ReferenceCountedArray
|
||||
*/
|
||||
template <class ElementType>
|
||||
class ArrayAllocationBase
|
||||
template <class ElementType, class TypeOfCriticalSectionToUse>
|
||||
class ArrayAllocationBase : public TypeOfCriticalSectionToUse
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
|
|
@ -99,7 +102,7 @@ public:
|
|||
}
|
||||
|
||||
/** Swap the contents of two objects. */
|
||||
void swapWith (ArrayAllocationBase <ElementType>& other) throw()
|
||||
void swapWith (ArrayAllocationBase <ElementType, TypeOfCriticalSectionToUse>& other) throw()
|
||||
{
|
||||
elements.swapWith (other.elements);
|
||||
swapVariables (numAllocated, other.numAllocated);
|
||||
|
|
@ -111,7 +114,7 @@ public:
|
|||
|
||||
private:
|
||||
ArrayAllocationBase (const ArrayAllocationBase&);
|
||||
const ArrayAllocationBase& operator= (const ArrayAllocationBase&);
|
||||
ArrayAllocationBase& operator= (const ArrayAllocationBase&);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public:
|
|||
/** Clears the array, optionally deleting the objects inside it first. */
|
||||
void clear (const bool deleteObjects = true)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (deleteObjects)
|
||||
{
|
||||
|
|
@ -88,7 +88,7 @@ public:
|
|||
|
||||
data.setAllocatedSize (0);
|
||||
numUsed = 0;
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -110,11 +110,11 @@ public:
|
|||
*/
|
||||
inline ObjectClass* operator[] (const int index) const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
ObjectClass* const result = (((unsigned int) index) < (unsigned int) numUsed)
|
||||
? data.elements [index]
|
||||
: (ObjectClass*) 0;
|
||||
lock.exit();
|
||||
data.exit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -126,10 +126,10 @@ public:
|
|||
*/
|
||||
inline ObjectClass* getUnchecked (const int index) const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
jassert (((unsigned int) index) < (unsigned int) numUsed);
|
||||
ObjectClass* const result = data.elements [index];
|
||||
lock.exit();
|
||||
data.exit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -141,10 +141,10 @@ public:
|
|||
*/
|
||||
inline ObjectClass* getFirst() const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
ObjectClass* const result = (numUsed > 0) ? data.elements [0]
|
||||
: (ObjectClass*) 0;
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -155,10 +155,10 @@ public:
|
|||
*/
|
||||
inline ObjectClass* getLast() const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
ObjectClass* const result = (numUsed > 0) ? data.elements [numUsed - 1]
|
||||
: (ObjectClass*) 0;
|
||||
lock.exit();
|
||||
data.exit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -173,7 +173,7 @@ public:
|
|||
{
|
||||
int result = -1;
|
||||
|
||||
lock.enter();
|
||||
data.enter();
|
||||
ObjectClass* const* e = data.elements;
|
||||
|
||||
for (int i = numUsed; --i >= 0;)
|
||||
|
|
@ -187,7 +187,7 @@ public:
|
|||
++e;
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -198,7 +198,7 @@ public:
|
|||
*/
|
||||
bool contains (const ObjectClass* const objectToLookFor) const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
ObjectClass* const* e = data.elements;
|
||||
int i = numUsed;
|
||||
|
|
@ -210,7 +210,7 @@ public:
|
|||
|| objectToLookFor == *++e
|
||||
|| objectToLookFor == *++e)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -222,7 +222,7 @@ public:
|
|||
{
|
||||
if (objectToLookFor == *e)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +230,7 @@ public:
|
|||
++e;
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -248,10 +248,10 @@ public:
|
|||
*/
|
||||
void add (const ObjectClass* const newObject) throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
data.ensureAllocatedSize (numUsed + 1);
|
||||
data.elements [numUsed++] = const_cast <ObjectClass*> (newObject);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Inserts a new object into the array at the given index.
|
||||
|
|
@ -276,7 +276,7 @@ public:
|
|||
{
|
||||
if (indexToInsertAt >= 0)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (indexToInsertAt > numUsed)
|
||||
indexToInsertAt = numUsed;
|
||||
|
|
@ -292,7 +292,7 @@ public:
|
|||
*e = const_cast <ObjectClass*> (newObject);
|
||||
++numUsed;
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -309,12 +309,12 @@ public:
|
|||
*/
|
||||
void addIfNotAlreadyThere (const ObjectClass* const newObject) throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (! contains (newObject))
|
||||
add (newObject);
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Replaces an object in the array with a different one.
|
||||
|
|
@ -337,7 +337,7 @@ public:
|
|||
if (indexToChange >= 0)
|
||||
{
|
||||
ScopedPointer <ObjectClass> toDelete;
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (indexToChange < numUsed)
|
||||
{
|
||||
|
|
@ -357,7 +357,7 @@ public:
|
|||
data.elements [numUsed++] = const_cast <ObjectClass*> (newObject);
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -378,9 +378,9 @@ public:
|
|||
{
|
||||
(void) comparator; // if you pass in an object with a static compareElements() method, this
|
||||
// avoids getting warning messages about the parameter being unused
|
||||
lock.enter();
|
||||
data.enter();
|
||||
insert (findInsertIndexInSortedArray (comparator, (ObjectClass**) data.elements, newObject, 0, numUsed), newObject);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Finds the index of an object in the array, assuming that the array is sorted.
|
||||
|
|
@ -401,7 +401,7 @@ public:
|
|||
{
|
||||
(void) comparator; // if you pass in an object with a static compareElements() method, this
|
||||
// avoids getting warning messages about the parameter being unused
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
int start = 0;
|
||||
int end = numUsed;
|
||||
|
|
@ -410,12 +410,12 @@ public:
|
|||
{
|
||||
if (start >= end)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return -1;
|
||||
}
|
||||
else if (comparator.compareElements (objectToLookFor, data.elements [start]) == 0)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return start;
|
||||
}
|
||||
else
|
||||
|
|
@ -424,7 +424,7 @@ public:
|
|||
|
||||
if (halfway == start)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return -1;
|
||||
}
|
||||
else if (comparator.compareElements (objectToLookFor, data.elements [halfway]) >= 0)
|
||||
|
|
@ -450,7 +450,7 @@ public:
|
|||
const bool deleteObject = true)
|
||||
{
|
||||
ScopedPointer <ObjectClass> toDelete;
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (((unsigned int) indexToRemove) < (unsigned int) numUsed)
|
||||
{
|
||||
|
|
@ -469,7 +469,7 @@ public:
|
|||
minimiseStorageOverheads();
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Removes a specified object from the array.
|
||||
|
|
@ -483,7 +483,7 @@ public:
|
|||
void removeObject (const ObjectClass* const objectToRemove,
|
||||
const bool deleteObject = true)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
ObjectClass** e = data.elements;
|
||||
|
||||
for (int i = numUsed; --i >= 0;)
|
||||
|
|
@ -497,7 +497,7 @@ public:
|
|||
++e;
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Removes a range of objects from the array.
|
||||
|
|
@ -517,7 +517,7 @@ public:
|
|||
const int numberToRemove,
|
||||
const bool deleteObjects = true)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
const int endIndex = jlimit (0, numUsed, startIndex + numberToRemove);
|
||||
startIndex = jlimit (0, numUsed, startIndex);
|
||||
|
||||
|
|
@ -547,7 +547,7 @@ public:
|
|||
minimiseStorageOverheads();
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Removes the last n objects from the array.
|
||||
|
|
@ -559,7 +559,7 @@ public:
|
|||
void removeLast (int howManyToRemove = 1,
|
||||
const bool deleteObjects = true)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (howManyToRemove >= numUsed)
|
||||
{
|
||||
|
|
@ -571,7 +571,7 @@ public:
|
|||
remove (numUsed - 1, deleteObjects);
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Swaps a pair of objects in the array.
|
||||
|
|
@ -582,7 +582,7 @@ public:
|
|||
void swap (const int index1,
|
||||
const int index2) throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (((unsigned int) index1) < (unsigned int) numUsed
|
||||
&& ((unsigned int) index2) < (unsigned int) numUsed)
|
||||
|
|
@ -591,7 +591,7 @@ public:
|
|||
data.elements [index2]);
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Moves one of the objects to a different position.
|
||||
|
|
@ -612,7 +612,7 @@ public:
|
|||
{
|
||||
if (currentIndex != newIndex)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (((unsigned int) currentIndex) < (unsigned int) numUsed)
|
||||
{
|
||||
|
|
@ -637,7 +637,7 @@ public:
|
|||
data.elements [newIndex] = value;
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -648,12 +648,12 @@ public:
|
|||
*/
|
||||
void swapWithArray (OwnedArray <ObjectClass>& otherArray) throw()
|
||||
{
|
||||
lock.enter();
|
||||
otherArray.lock.enter();
|
||||
data.enter();
|
||||
otherArray.data.enter();
|
||||
data.swapWith (otherArray.data);
|
||||
swapVariables (numUsed, otherArray.numUsed);
|
||||
otherArray.lock.exit();
|
||||
lock.exit();
|
||||
otherArray.data.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -665,9 +665,9 @@ public:
|
|||
*/
|
||||
void minimiseStorageOverheads() throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
data.shrinkToNoMoreThan (numUsed);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Increases the array's internal storage to hold a minimum number of elements.
|
||||
|
|
@ -678,9 +678,9 @@ public:
|
|||
*/
|
||||
void ensureStorageAllocated (const int minNumElements) throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
data.ensureAllocatedSize (minNumElements);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -716,9 +716,9 @@ public:
|
|||
(void) comparator; // if you pass in an object with a static compareElements() method, this
|
||||
// avoids getting warning messages about the parameter being unused
|
||||
|
||||
lock.enter();
|
||||
data.enter();
|
||||
sortArray (comparator, (ObjectClass**) data.elements, 0, size() - 1, retainOrderOfEquivalentItems);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -731,7 +731,7 @@ public:
|
|||
*/
|
||||
void lockArray() const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
}
|
||||
|
||||
/** Unlocks the array's CriticalSection.
|
||||
|
|
@ -743,7 +743,7 @@ public:
|
|||
*/
|
||||
void unlockArray() const throw()
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -751,13 +751,12 @@ public:
|
|||
juce_UseDebuggingNewOperator
|
||||
|
||||
private:
|
||||
ArrayAllocationBase <ObjectClass*> data;
|
||||
ArrayAllocationBase <ObjectClass*, TypeOfCriticalSectionToUse> data;
|
||||
int numUsed;
|
||||
TypeOfCriticalSectionToUse lock;
|
||||
|
||||
// disallow copy constructor and assignment
|
||||
OwnedArray (const OwnedArray&);
|
||||
const OwnedArray& operator= (const OwnedArray&);
|
||||
OwnedArray& operator= (const OwnedArray&);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ public:
|
|||
*/
|
||||
void clear()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
while (numUsed > 0)
|
||||
if (data.elements [--numUsed] != 0)
|
||||
|
|
@ -113,7 +113,7 @@ public:
|
|||
jassert (numUsed == 0);
|
||||
data.setAllocatedSize (0);
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Returns the current number of objects in the array. */
|
||||
|
|
@ -132,11 +132,11 @@ public:
|
|||
*/
|
||||
inline const ReferenceCountedObjectPtr<ObjectClass> operator[] (const int index) const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
const ReferenceCountedObjectPtr<ObjectClass> result ((((unsigned int) index) < (unsigned int) numUsed)
|
||||
? data.elements [index]
|
||||
: (ObjectClass*) 0);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -147,10 +147,10 @@ public:
|
|||
*/
|
||||
inline const ReferenceCountedObjectPtr<ObjectClass> getUnchecked (const int index) const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
jassert (((unsigned int) index) < (unsigned int) numUsed);
|
||||
const ReferenceCountedObjectPtr<ObjectClass> result (data.elements [index]);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -161,10 +161,10 @@ public:
|
|||
*/
|
||||
inline const ReferenceCountedObjectPtr<ObjectClass> getFirst() const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
const ReferenceCountedObjectPtr<ObjectClass> result ((numUsed > 0) ? data.elements [0]
|
||||
: (ObjectClass*) 0);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -176,10 +176,10 @@ public:
|
|||
*/
|
||||
inline const ReferenceCountedObjectPtr<ObjectClass> getLast() const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
const ReferenceCountedObjectPtr<ObjectClass> result ((numUsed > 0) ? data.elements [numUsed - 1]
|
||||
: (ObjectClass*) 0);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -194,7 +194,7 @@ public:
|
|||
{
|
||||
int result = -1;
|
||||
|
||||
lock.enter();
|
||||
data.enter();
|
||||
ObjectClass** e = data.elements;
|
||||
|
||||
for (int i = numUsed; --i >= 0;)
|
||||
|
|
@ -208,7 +208,7 @@ public:
|
|||
++e;
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -219,21 +219,21 @@ public:
|
|||
*/
|
||||
bool contains (const ObjectClass* const objectToLookFor) const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
ObjectClass** e = data.elements;
|
||||
|
||||
for (int i = numUsed; --i >= 0;)
|
||||
{
|
||||
if (objectToLookFor == *e)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return true;
|
||||
}
|
||||
|
||||
++e;
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -246,14 +246,14 @@ public:
|
|||
*/
|
||||
void add (ObjectClass* const newObject) throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
data.ensureAllocatedSize (numUsed + 1);
|
||||
data.elements [numUsed++] = newObject;
|
||||
|
||||
if (newObject != 0)
|
||||
newObject->incReferenceCount();
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Inserts a new object into the array at the given index.
|
||||
|
|
@ -274,7 +274,7 @@ public:
|
|||
{
|
||||
if (indexToInsertAt >= 0)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (indexToInsertAt > numUsed)
|
||||
indexToInsertAt = numUsed;
|
||||
|
|
@ -293,7 +293,7 @@ public:
|
|||
newObject->incReferenceCount();
|
||||
|
||||
++numUsed;
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -310,12 +310,12 @@ public:
|
|||
*/
|
||||
void addIfNotAlreadyThere (ObjectClass* const newObject) throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (! contains (newObject))
|
||||
add (newObject);
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Replaces an object in the array with a different one.
|
||||
|
|
@ -335,7 +335,7 @@ public:
|
|||
{
|
||||
if (indexToChange >= 0)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (newObject != 0)
|
||||
newObject->incReferenceCount();
|
||||
|
|
@ -353,7 +353,7 @@ public:
|
|||
data.elements [numUsed++] = newObject;
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -371,7 +371,7 @@ public:
|
|||
int numElementsToAdd = -1) throw()
|
||||
{
|
||||
arrayToAddFrom.lockArray();
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (startIndex < 0)
|
||||
{
|
||||
|
|
@ -390,7 +390,7 @@ public:
|
|||
add (arrayToAddFrom.getUnchecked (startIndex++));
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
arrayToAddFrom.unlockArray();
|
||||
}
|
||||
|
||||
|
|
@ -409,9 +409,9 @@ public:
|
|||
void addSorted (ElementComparator& comparator,
|
||||
ObjectClass* newObject) throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
insert (findInsertIndexInSortedArray (comparator, (ObjectClass**) data.elements, newObject, 0, numUsed), newObject);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Inserts or replaces an object in the array, assuming it is sorted.
|
||||
|
|
@ -423,7 +423,7 @@ public:
|
|||
void addOrReplaceSorted (ElementComparator& comparator,
|
||||
ObjectClass* newObject) throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
const int index = findInsertIndexInSortedArray (comparator, (ObjectClass**) data.elements, newObject, 0, numUsed);
|
||||
|
||||
if (index > 0 && comparator.compareElements (newObject, data.elements [index - 1]) == 0)
|
||||
|
|
@ -431,7 +431,7 @@ public:
|
|||
else
|
||||
insert (index, newObject); // no match, so insert the new one
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -450,7 +450,7 @@ public:
|
|||
*/
|
||||
void remove (const int indexToRemove)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (((unsigned int) indexToRemove) < (unsigned int) numUsed)
|
||||
{
|
||||
|
|
@ -469,7 +469,7 @@ public:
|
|||
minimiseStorageOverheads();
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Removes the first occurrence of a specified object from the array.
|
||||
|
|
@ -482,9 +482,9 @@ public:
|
|||
*/
|
||||
void removeObject (ObjectClass* const objectToRemove)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
remove (indexOf (objectToRemove));
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Removes a range of objects from the array.
|
||||
|
|
@ -505,7 +505,7 @@ public:
|
|||
void removeRange (const int startIndex,
|
||||
const int numberToRemove)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
const int start = jlimit (0, numUsed, startIndex);
|
||||
const int end = jlimit (0, numUsed, startIndex + numberToRemove);
|
||||
|
|
@ -537,7 +537,7 @@ public:
|
|||
minimiseStorageOverheads();
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Removes the last n objects from the array.
|
||||
|
|
@ -550,7 +550,7 @@ public:
|
|||
*/
|
||||
void removeLast (int howManyToRemove = 1)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (howManyToRemove > numUsed)
|
||||
howManyToRemove = numUsed;
|
||||
|
|
@ -558,7 +558,7 @@ public:
|
|||
while (--howManyToRemove >= 0)
|
||||
remove (numUsed - 1);
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Swaps a pair of objects in the array.
|
||||
|
|
@ -569,7 +569,7 @@ public:
|
|||
void swap (const int index1,
|
||||
const int index2) throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (((unsigned int) index1) < (unsigned int) numUsed
|
||||
&& ((unsigned int) index2) < (unsigned int) numUsed)
|
||||
|
|
@ -578,7 +578,7 @@ public:
|
|||
data.elements [index2]);
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Moves one of the objects to a different position.
|
||||
|
|
@ -599,7 +599,7 @@ public:
|
|||
{
|
||||
if (currentIndex != newIndex)
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (((unsigned int) currentIndex) < (unsigned int) numUsed)
|
||||
{
|
||||
|
|
@ -624,7 +624,7 @@ public:
|
|||
data.elements [newIndex] = value;
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -636,12 +636,12 @@ public:
|
|||
*/
|
||||
void swapWithArray (ReferenceCountedArray<ObjectClass, TypeOfCriticalSectionToUse>& otherArray) throw()
|
||||
{
|
||||
lock.enter();
|
||||
otherArray.lock.enter();
|
||||
data.enter();
|
||||
otherArray.data.enter();
|
||||
data.swapWith (otherArray.data);
|
||||
swapVariables (numUsed, otherArray.numUsed);
|
||||
otherArray.lock.exit();
|
||||
lock.exit();
|
||||
otherArray.data.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -652,7 +652,7 @@ public:
|
|||
bool operator== (const ReferenceCountedArray<ObjectClass, TypeOfCriticalSectionToUse>& other) const throw()
|
||||
{
|
||||
other.lockArray();
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
bool result = numUsed == other.numUsed;
|
||||
|
||||
|
|
@ -668,7 +668,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
other.unlockArray();
|
||||
|
||||
return result;
|
||||
|
|
@ -717,9 +717,9 @@ public:
|
|||
(void) comparator; // if you pass in an object with a static compareElements() method, this
|
||||
// avoids getting warning messages about the parameter being unused
|
||||
|
||||
lock.enter();
|
||||
data.enter();
|
||||
sortArray (comparator, (ObjectClass**) data.elements, 0, size() - 1, retainOrderOfEquivalentItems);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -731,9 +731,9 @@ public:
|
|||
*/
|
||||
void minimiseStorageOverheads() throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
data.shrinkToNoMoreThan (numUsed);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -746,7 +746,7 @@ public:
|
|||
*/
|
||||
void lockArray() const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
}
|
||||
|
||||
/** Unlocks the array's CriticalSection.
|
||||
|
|
@ -758,7 +758,7 @@ public:
|
|||
*/
|
||||
void unlockArray() const throw()
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -766,9 +766,8 @@ public:
|
|||
juce_UseDebuggingNewOperator
|
||||
|
||||
private:
|
||||
ArrayAllocationBase <ObjectClass*> data;
|
||||
ArrayAllocationBase <ObjectClass*, TypeOfCriticalSectionToUse> data;
|
||||
int numUsed;
|
||||
TypeOfCriticalSectionToUse lock;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -93,14 +93,14 @@ public:
|
|||
if (this != &other)
|
||||
{
|
||||
other.lockSet();
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
data.ensureAllocatedSize (other.size());
|
||||
numUsed = other.numUsed;
|
||||
memcpy (data.elements, other.data.elements, numUsed * sizeof (ElementType));
|
||||
minimiseStorageOverheads();
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
other.unlockSet();
|
||||
}
|
||||
|
||||
|
|
@ -117,11 +117,11 @@ public:
|
|||
*/
|
||||
bool operator== (const SortedSet<ElementType>& other) const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (numUsed != other.numUsed)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -129,12 +129,12 @@ public:
|
|||
{
|
||||
if (data.elements [i] != other.data.elements [i])
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -161,10 +161,10 @@ public:
|
|||
*/
|
||||
void clear() throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
data.setAllocatedSize (0);
|
||||
numUsed = 0;
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Removes all elements from the set without freeing the array's allocated storage.
|
||||
|
|
@ -173,9 +173,9 @@ public:
|
|||
*/
|
||||
void clearQuick() throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
numUsed = 0;
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -199,11 +199,11 @@ public:
|
|||
*/
|
||||
inline ElementType operator[] (const int index) const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
const ElementType result = (((unsigned int) index) < (unsigned int) numUsed)
|
||||
? data.elements [index]
|
||||
: (ElementType) 0;
|
||||
lock.exit();
|
||||
data.exit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -218,10 +218,10 @@ public:
|
|||
*/
|
||||
inline ElementType getUnchecked (const int index) const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
jassert (((unsigned int) index) < (unsigned int) numUsed);
|
||||
const ElementType result = data.elements [index];
|
||||
lock.exit();
|
||||
data.exit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -232,10 +232,10 @@ public:
|
|||
*/
|
||||
inline ElementType getFirst() const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
const ElementType result = (numUsed > 0) ? data.elements [0]
|
||||
: (ElementType) 0;
|
||||
lock.exit();
|
||||
data.exit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -246,10 +246,10 @@ public:
|
|||
*/
|
||||
inline ElementType getLast() const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
const ElementType result = (numUsed > 0) ? data.elements [numUsed - 1]
|
||||
: (ElementType) 0;
|
||||
lock.exit();
|
||||
data.exit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -265,7 +265,7 @@ public:
|
|||
*/
|
||||
int indexOf (const ElementType elementToLookFor) const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
int start = 0;
|
||||
int end = numUsed;
|
||||
|
|
@ -274,12 +274,12 @@ public:
|
|||
{
|
||||
if (start >= end)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return -1;
|
||||
}
|
||||
else if (elementToLookFor == data.elements [start])
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return start;
|
||||
}
|
||||
else
|
||||
|
|
@ -288,7 +288,7 @@ public:
|
|||
|
||||
if (halfway == start)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return -1;
|
||||
}
|
||||
else if (elementToLookFor >= data.elements [halfway])
|
||||
|
|
@ -306,7 +306,7 @@ public:
|
|||
*/
|
||||
bool contains (const ElementType elementToLookFor) const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
int start = 0;
|
||||
int end = numUsed;
|
||||
|
|
@ -315,12 +315,12 @@ public:
|
|||
{
|
||||
if (start >= end)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return false;
|
||||
}
|
||||
else if (elementToLookFor == data.elements [start])
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
@ -329,7 +329,7 @@ public:
|
|||
|
||||
if (halfway == start)
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return false;
|
||||
}
|
||||
else if (elementToLookFor >= data.elements [halfway])
|
||||
|
|
@ -348,7 +348,7 @@ public:
|
|||
*/
|
||||
void add (const ElementType newElement) throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
int start = 0;
|
||||
int end = numUsed;
|
||||
|
|
@ -385,7 +385,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Adds elements from an array to this set.
|
||||
|
|
@ -397,12 +397,12 @@ public:
|
|||
void addArray (const ElementType* elementsToAdd,
|
||||
int numElementsToAdd) throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
while (--numElementsToAdd >= 0)
|
||||
add (*elementsToAdd++);
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Adds elements from another set to this one.
|
||||
|
|
@ -420,7 +420,7 @@ public:
|
|||
int numElementsToAdd = -1) throw()
|
||||
{
|
||||
setToAddFrom.lockSet();
|
||||
lock.enter();
|
||||
data.enter();
|
||||
jassert (this != &setToAddFrom);
|
||||
|
||||
if (this != &setToAddFrom)
|
||||
|
|
@ -437,7 +437,7 @@ public:
|
|||
addArray (setToAddFrom.elements + startIndex, numElementsToAdd);
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
setToAddFrom.unlockSet();
|
||||
}
|
||||
|
||||
|
|
@ -454,7 +454,7 @@ public:
|
|||
*/
|
||||
ElementType remove (const int indexToRemove) throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (((unsigned int) indexToRemove) < (unsigned int) numUsed)
|
||||
{
|
||||
|
|
@ -470,12 +470,12 @@ public:
|
|||
if ((numUsed << 1) < data.numAllocated)
|
||||
minimiseStorageOverheads();
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return removed;
|
||||
}
|
||||
else
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -489,9 +489,9 @@ public:
|
|||
*/
|
||||
void removeValue (const ElementType valueToRemove) throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
remove (indexOf (valueToRemove));
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
/** Removes any elements which are also in another set.
|
||||
|
|
@ -503,7 +503,7 @@ public:
|
|||
void removeValuesIn (const OtherSetType& otherSet) throw()
|
||||
{
|
||||
otherSet.lockSet();
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (this == &otherSet)
|
||||
{
|
||||
|
|
@ -519,7 +519,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
otherSet.unlockSet();
|
||||
}
|
||||
|
||||
|
|
@ -534,7 +534,7 @@ public:
|
|||
void removeValuesNotIn (const OtherSetType& otherSet) throw()
|
||||
{
|
||||
otherSet.lockSet();
|
||||
lock.enter();
|
||||
data.enter();
|
||||
|
||||
if (this != &otherSet)
|
||||
{
|
||||
|
|
@ -550,7 +550,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
lock.exit();
|
||||
data.exit();
|
||||
otherSet.lockSet();
|
||||
}
|
||||
|
||||
|
|
@ -563,9 +563,9 @@ public:
|
|||
*/
|
||||
void minimiseStorageOverheads() throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
data.shrinkToNoMoreThan (numUsed);
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -578,7 +578,7 @@ public:
|
|||
*/
|
||||
void lockSet() const throw()
|
||||
{
|
||||
lock.enter();
|
||||
data.enter();
|
||||
}
|
||||
|
||||
/** Unlocks the set's CriticalSection.
|
||||
|
|
@ -590,7 +590,7 @@ public:
|
|||
*/
|
||||
void unlockSet() const throw()
|
||||
{
|
||||
lock.exit();
|
||||
data.exit();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -598,9 +598,8 @@ public:
|
|||
juce_UseDebuggingNewOperator
|
||||
|
||||
private:
|
||||
ArrayAllocationBase <ElementType> data;
|
||||
ArrayAllocationBase <ElementType, TypeOfCriticalSectionToUse> data;
|
||||
int numUsed;
|
||||
TypeOfCriticalSectionToUse lock;
|
||||
|
||||
void insertInternal (const int indexToInsertAt, const ElementType newElement) throw()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -340,7 +340,7 @@ public:
|
|||
|
||||
private:
|
||||
// alternating start/end values of ranges of values that are present.
|
||||
Array<Type> values;
|
||||
Array<Type, DummyCriticalSection> values;
|
||||
|
||||
void simplify() throw()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -532,6 +532,28 @@ void CodeDocument::replaceAllContent (const String& newContent)
|
|||
insert (newContent, 0, true);
|
||||
}
|
||||
|
||||
bool CodeDocument::loadFromStream (InputStream& stream)
|
||||
{
|
||||
replaceAllContent (stream.readEntireStreamAsString());
|
||||
setSavePoint();
|
||||
clearUndoHistory();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CodeDocument::writeToStream (OutputStream& stream)
|
||||
{
|
||||
for (int i = 0; i < lines.size(); ++i)
|
||||
{
|
||||
String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
|
||||
const char* utf8 = temp.toUTF8();
|
||||
|
||||
if (! stream.write (utf8, strlen (utf8)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CodeDocument::setNewLineCharacters (const String& newLine) throw()
|
||||
{
|
||||
jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@
|
|||
#include "../../../utilities/juce_UndoManager.h"
|
||||
#include "../../graphics/colour/juce_Colour.h"
|
||||
#include "../../../containers/juce_VoidArray.h"
|
||||
#include "../../../io/streams/juce_InputStream.h"
|
||||
#include "../../../io/streams/juce_OutputStream.h"
|
||||
class CodeDocumentLine;
|
||||
|
||||
|
||||
|
|
@ -225,6 +227,14 @@ public:
|
|||
*/
|
||||
void replaceAllContent (const String& newContent);
|
||||
|
||||
/** Replaces the editor's contents with the contents of a stream.
|
||||
This will also reset the undo history and save point marker.
|
||||
*/
|
||||
bool loadFromStream (InputStream& stream);
|
||||
|
||||
/** Writes the editor's current contents to a stream. */
|
||||
bool writeToStream (OutputStream& stream);
|
||||
|
||||
//==============================================================================
|
||||
/** Returns the preferred new-line characters for the document.
|
||||
This will be either "\n", "\r\n", or (rarely) "\r".
|
||||
|
|
|
|||
|
|
@ -632,7 +632,7 @@ public:
|
|||
private:
|
||||
friend class PathFlatteningIterator;
|
||||
friend class Path::Iterator;
|
||||
ArrayAllocationBase <float> data;
|
||||
ArrayAllocationBase <float, DummyCriticalSection> data;
|
||||
int numElements;
|
||||
float pathXMin, pathXMax, pathYMin, pathYMax;
|
||||
bool useNonZeroWinding;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue