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