diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index c1d1434747..05b2d4b5c7 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -44301,6 +44301,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")); @@ -68311,7 +68333,7 @@ public: Desktop::getInstance().removeGlobalMouseListener (this); jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent()); - delete activeSubMenu; + activeSubMenu = 0; deleteAllChildren(); attachedCompWatcher = 0; @@ -68431,7 +68453,7 @@ public: { jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent()); - deleteAndZero (activeSubMenu); + activeSubMenu = 0; currentChild = 0; exitModalState (item != 0 ? item->itemId : 0); @@ -68749,7 +68771,7 @@ public: private: Window* owner; PopupMenu::ItemComponent* currentChild; - Window* activeSubMenu; + ScopedPointer activeSubMenu; Component* menuBarComponent; ApplicationCommandManager** managerOfChosenCommand; Component* componentAttachedTo; @@ -69111,7 +69133,7 @@ private: bool showSubMenuFor (PopupMenu::ItemComponent* const childComp) { jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent()); - deleteAndZero (activeSubMenu); + activeSubMenu = 0; if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu()) { diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 3609e53faa..c6672628fa 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -1558,8 +1558,8 @@ private: #endif // __JUCE_HEAPBLOCK_JUCEHEADER__ /********* End of inlined file: juce_HeapBlock.h *********/ -template -class ArrayAllocationBase +template +class ArrayAllocationBase : public TypeOfCriticalSectionToUse { public: @@ -1597,7 +1597,7 @@ public: setAllocatedSize (maxNumElements); } - void swapWith (ArrayAllocationBase & other) throw() + void swapWith (ArrayAllocationBase & other) throw() { elements.swapWith (other.elements); swapVariables (numAllocated, other.numAllocated); @@ -1608,7 +1608,7 @@ public: private: ArrayAllocationBase (const ArrayAllocationBase&); - const ArrayAllocationBase& operator= (const ArrayAllocationBase&); + ArrayAllocationBase& operator= (const ArrayAllocationBase&); }; #endif // __JUCE_ARRAYALLOCATIONBASE_JUCEHEADER__ @@ -1929,11 +1929,11 @@ public: template bool operator== (const OtherArrayType& other) const { - lock.enter(); + data.enter(); if (numUsed != other.numUsed) { - lock.exit(); + data.exit(); return false; } @@ -1941,12 +1941,12 @@ public: { if (data.elements [i] != other.data.elements [i]) { - lock.exit(); + data.exit(); return false; } } - lock.exit(); + data.exit(); return true; } @@ -1958,25 +1958,25 @@ 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(); } void clearQuick() { - lock.enter(); + data.enter(); for (int i = 0; i < numUsed; ++i) data.elements[i].~ElementType(); numUsed = 0; - lock.exit(); + data.exit(); } inline int size() const throw() @@ -1986,50 +1986,50 @@ 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; } 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; } 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; } inline ElementType getFirst() const { - lock.enter(); + data.enter(); const ElementType result ((numUsed > 0) ? data.elements [0] : ElementType()); - lock.exit(); + data.exit(); return result; } inline ElementType getLast() const { - lock.enter(); + data.enter(); const ElementType result ((numUsed > 0) ? data.elements [numUsed - 1] : ElementType()); - lock.exit(); + data.exit(); return result; } @@ -2038,7 +2038,7 @@ public: { int result = -1; - lock.enter(); + data.enter(); const ElementType* e = data.elements; for (int i = numUsed; --i >= 0;) @@ -2052,13 +2052,13 @@ public: ++e; } - lock.exit(); + data.exit(); return result; } bool contains (const ElementType& elementToLookFor) const { - lock.enter(); + data.enter(); const ElementType* e = data.elements; int num = numUsed; @@ -2067,7 +2067,7 @@ public: { if (elementToLookFor == *e) { - lock.exit(); + data.exit(); return true; } @@ -2075,21 +2075,21 @@ public: ++e; } - lock.exit(); + data.exit(); return false; } void add (const ElementType& newElement) { - lock.enter(); + data.enter(); data.ensureAllocatedSize (numUsed + 1); new (data.elements + numUsed++) ElementType (newElement); - lock.exit(); + data.exit(); } void insert (int indexToInsertAt, const ElementType& newElement) { - lock.enter(); + data.enter(); data.ensureAllocatedSize (numUsed + 1); if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed) @@ -2108,7 +2108,7 @@ public: new (data.elements + numUsed++) ElementType (newElement); } - lock.exit(); + data.exit(); } void insertMultiple (int indexToInsertAt, const ElementType& newElement, @@ -2116,7 +2116,7 @@ public: { if (numberOfTimesToInsertIt > 0) { - lock.enter(); + data.enter(); data.ensureAllocatedSize (numUsed + numberOfTimesToInsertIt); ElementType* insertPos; @@ -2136,7 +2136,7 @@ public: while (--numberOfTimesToInsertIt >= 0) new (insertPos++) ElementType (newElement); - lock.exit(); + data.exit(); } } @@ -2146,7 +2146,7 @@ public: { if (numberOfElements > 0) { - lock.enter(); + data.enter(); data.ensureAllocatedSize (numUsed + numberOfElements); ElementType* insertPos; @@ -2166,25 +2166,25 @@ public: while (--numberOfElements >= 0) new (insertPos++) ElementType (*newElements++); - lock.exit(); + data.exit(); } } void addIfNotAlreadyThere (const ElementType& newElement) { - lock.enter(); + data.enter(); if (! contains (newElement)) add (newElement); - lock.exit(); + data.exit(); } void set (const int indexToChange, const ElementType& newValue) { jassert (indexToChange >= 0); - lock.enter(); + data.enter(); if (((unsigned int) indexToChange) < (unsigned int) numUsed) { @@ -2196,20 +2196,20 @@ public: new (data.elements + numUsed++) ElementType (newValue); } - lock.exit(); + data.exit(); } 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(); } void addArray (const ElementType* elementsToAdd, int numElementsToAdd) { - lock.enter(); + data.enter(); if (numElementsToAdd > 0) { @@ -2219,17 +2219,17 @@ public: new (data.elements + numUsed++) ElementType (*elementsToAdd++); } - lock.exit(); + data.exit(); } void swapWithArray (Array & 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(); } template @@ -2238,7 +2238,7 @@ public: int numElementsToAdd = -1) { arrayToAddFrom.lockArray(); - lock.enter(); + data.enter(); if (startIndex < 0) { @@ -2252,16 +2252,16 @@ public: while (--numElementsToAdd >= 0) add (arrayToAddFrom.getUnchecked (startIndex++)); - lock.exit(); + data.exit(); arrayToAddFrom.unlockArray(); } template 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(); } template @@ -2269,7 +2269,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; @@ -2278,12 +2278,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 @@ -2292,7 +2292,7 @@ public: if (halfway == start) { - lock.exit(); + data.exit(); return -1; } else if (comparator.compareElements (elementToLookFor, data.elements [halfway]) >= 0) @@ -2305,7 +2305,7 @@ public: ElementType remove (const int indexToRemove) { - lock.enter(); + data.enter(); if (((unsigned int) indexToRemove) < (unsigned int) numUsed) { @@ -2322,19 +2322,19 @@ public: if ((numUsed << 1) < data.numAllocated) minimiseStorageOverheads(); - lock.exit(); + data.exit(); return removed; } else { - lock.exit(); + data.exit(); return ElementType(); } } void removeValue (const ElementType& valueToRemove) { - lock.enter(); + data.enter(); ElementType* e = data.elements; for (int i = numUsed; --i >= 0;) @@ -2348,12 +2348,12 @@ public: ++e; } - lock.exit(); + data.exit(); } void removeRange (int startIndex, int numberToRemove) { - lock.enter(); + data.enter(); const int endIndex = jlimit (0, numUsed, startIndex + numberToRemove); startIndex = jlimit (0, numUsed, startIndex); @@ -2375,12 +2375,12 @@ public: minimiseStorageOverheads(); } - lock.exit(); + data.exit(); } void removeLast (int howManyToRemove = 1) { - lock.enter(); + data.enter(); if (howManyToRemove > numUsed) howManyToRemove = numUsed; @@ -2393,14 +2393,14 @@ public: if ((numUsed << 1) < data.numAllocated) minimiseStorageOverheads(); - lock.exit(); + data.exit(); } template void removeValuesIn (const OtherArrayType& otherArray) { otherArray.lockArray(); - lock.enter(); + data.enter(); if (this == &otherArray) { @@ -2416,7 +2416,7 @@ public: } } - lock.exit(); + data.exit(); otherArray.unlockArray(); } @@ -2424,7 +2424,7 @@ public: void removeValuesNotIn (const OtherArrayType& otherArray) { otherArray.lockArray(); - lock.enter(); + data.enter(); if (this != &otherArray) { @@ -2440,14 +2440,14 @@ public: } } - lock.exit(); + data.exit(); otherArray.unlockArray(); } 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) @@ -2456,14 +2456,14 @@ public: data.elements [index2]); } - lock.exit(); + data.exit(); } void move (const int currentIndex, int newIndex) throw() { if (currentIndex != newIndex) { - lock.enter(); + data.enter(); if (((unsigned int) currentIndex) < (unsigned int) numUsed) { @@ -2489,22 +2489,22 @@ public: memcpy (data.elements + newIndex, tempCopy, sizeof (ElementType)); } - lock.exit(); + data.exit(); } } void minimiseStorageOverheads() { - lock.enter(); + data.enter(); data.shrinkToNoMoreThan (numUsed); - lock.exit(); + data.exit(); } void ensureStorageAllocated (const int minNumElements) { - lock.enter(); + data.enter(); data.ensureAllocatedSize (minNumElements); - lock.exit(); + data.exit(); } template @@ -2513,27 +2513,26 @@ 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(); } void lockArray() const throw() { - lock.enter(); + data.enter(); } void unlockArray() const throw() { - lock.exit(); + data.exit(); } juce_UseDebuggingNewOperator private: - ArrayAllocationBase data; + ArrayAllocationBase data; int numUsed; - TypeOfCriticalSectionToUse lock; }; #endif // __JUCE_ARRAY_JUCEHEADER__ @@ -3440,7 +3439,7 @@ public: void clear (const bool deleteObjects = true) { - lock.enter(); + data.enter(); if (deleteObjects) { @@ -3450,7 +3449,7 @@ public: data.setAllocatedSize (0); numUsed = 0; - lock.exit(); + data.exit(); } inline int size() const throw() @@ -3460,40 +3459,40 @@ 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; } 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; } 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; } 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; } @@ -3502,7 +3501,7 @@ public: { int result = -1; - lock.enter(); + data.enter(); ObjectClass* const* e = data.elements; for (int i = numUsed; --i >= 0;) @@ -3516,13 +3515,13 @@ public: ++e; } - lock.exit(); + data.exit(); return result; } bool contains (const ObjectClass* const objectToLookFor) const throw() { - lock.enter(); + data.enter(); ObjectClass* const* e = data.elements; int i = numUsed; @@ -3534,7 +3533,7 @@ public: || objectToLookFor == *++e || objectToLookFor == *++e) { - lock.exit(); + data.exit(); return true; } @@ -3546,7 +3545,7 @@ public: { if (objectToLookFor == *e) { - lock.exit(); + data.exit(); return true; } @@ -3554,16 +3553,16 @@ public: ++e; } - lock.exit(); + data.exit(); return false; } void add (const ObjectClass* const newObject) throw() { - lock.enter(); + data.enter(); data.ensureAllocatedSize (numUsed + 1); data.elements [numUsed++] = const_cast (newObject); - lock.exit(); + data.exit(); } void insert (int indexToInsertAt, @@ -3571,7 +3570,7 @@ public: { if (indexToInsertAt >= 0) { - lock.enter(); + data.enter(); if (indexToInsertAt > numUsed) indexToInsertAt = numUsed; @@ -3587,7 +3586,7 @@ public: *e = const_cast (newObject); ++numUsed; - lock.exit(); + data.exit(); } else { @@ -3597,12 +3596,12 @@ public: void addIfNotAlreadyThere (const ObjectClass* const newObject) throw() { - lock.enter(); + data.enter(); if (! contains (newObject)) add (newObject); - lock.exit(); + data.exit(); } void set (const int indexToChange, @@ -3612,7 +3611,7 @@ public: if (indexToChange >= 0) { ScopedPointer toDelete; - lock.enter(); + data.enter(); if (indexToChange < numUsed) { @@ -3632,7 +3631,7 @@ public: data.elements [numUsed++] = const_cast (newObject); } - lock.exit(); + data.exit(); } } @@ -3642,9 +3641,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(); } template @@ -3653,7 +3652,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; @@ -3662,12 +3661,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 @@ -3676,7 +3675,7 @@ public: if (halfway == start) { - lock.exit(); + data.exit(); return -1; } else if (comparator.compareElements (objectToLookFor, data.elements [halfway]) >= 0) @@ -3691,7 +3690,7 @@ public: const bool deleteObject = true) { ScopedPointer toDelete; - lock.enter(); + data.enter(); if (((unsigned int) indexToRemove) < (unsigned int) numUsed) { @@ -3710,13 +3709,13 @@ public: minimiseStorageOverheads(); } - lock.exit(); + data.exit(); } void removeObject (const ObjectClass* const objectToRemove, const bool deleteObject = true) { - lock.enter(); + data.enter(); ObjectClass** e = data.elements; for (int i = numUsed; --i >= 0;) @@ -3730,14 +3729,14 @@ public: ++e; } - lock.exit(); + data.exit(); } void removeRange (int startIndex, const int numberToRemove, const bool deleteObjects = true) { - lock.enter(); + data.enter(); const int endIndex = jlimit (0, numUsed, startIndex + numberToRemove); startIndex = jlimit (0, numUsed, startIndex); @@ -3767,13 +3766,13 @@ public: minimiseStorageOverheads(); } - lock.exit(); + data.exit(); } void removeLast (int howManyToRemove = 1, const bool deleteObjects = true) { - lock.enter(); + data.enter(); if (howManyToRemove >= numUsed) { @@ -3785,13 +3784,13 @@ public: remove (numUsed - 1, deleteObjects); } - lock.exit(); + data.exit(); } 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) @@ -3800,7 +3799,7 @@ public: data.elements [index2]); } - lock.exit(); + data.exit(); } void move (const int currentIndex, @@ -3808,7 +3807,7 @@ public: { if (currentIndex != newIndex) { - lock.enter(); + data.enter(); if (((unsigned int) currentIndex) < (unsigned int) numUsed) { @@ -3833,32 +3832,32 @@ public: data.elements [newIndex] = value; } - lock.exit(); + data.exit(); } } void swapWithArray (OwnedArray & 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(); } void minimiseStorageOverheads() throw() { - lock.enter(); + data.enter(); data.shrinkToNoMoreThan (numUsed); - lock.exit(); + data.exit(); } void ensureStorageAllocated (const int minNumElements) throw() { - lock.enter(); + data.enter(); data.ensureAllocatedSize (minNumElements); - lock.exit(); + data.exit(); } template @@ -3868,27 +3867,26 @@ 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(); } void lockArray() const throw() { - lock.enter(); + data.enter(); } void unlockArray() const throw() { - lock.exit(); + data.exit(); } juce_UseDebuggingNewOperator private: - ArrayAllocationBase data; + ArrayAllocationBase data; int numUsed; - TypeOfCriticalSectionToUse lock; // disallow copy constructor and assignment OwnedArray (const OwnedArray&); @@ -4811,7 +4809,7 @@ public: void clear() { - lock.enter(); + data.enter(); while (numUsed > 0) if (data.elements [--numUsed] != 0) @@ -4820,7 +4818,7 @@ public: jassert (numUsed == 0); data.setAllocatedSize (0); - lock.exit(); + data.exit(); } inline int size() const throw() @@ -4830,39 +4828,39 @@ public: inline const ReferenceCountedObjectPtr operator[] (const int index) const throw() { - lock.enter(); + data.enter(); const ReferenceCountedObjectPtr result ((((unsigned int) index) < (unsigned int) numUsed) ? data.elements [index] : (ObjectClass*) 0); - lock.exit(); + data.exit(); return result; } inline const ReferenceCountedObjectPtr getUnchecked (const int index) const throw() { - lock.enter(); + data.enter(); jassert (((unsigned int) index) < (unsigned int) numUsed); const ReferenceCountedObjectPtr result (data.elements [index]); - lock.exit(); + data.exit(); return result; } inline const ReferenceCountedObjectPtr getFirst() const throw() { - lock.enter(); + data.enter(); const ReferenceCountedObjectPtr result ((numUsed > 0) ? data.elements [0] : (ObjectClass*) 0); - lock.exit(); + data.exit(); return result; } inline const ReferenceCountedObjectPtr getLast() const throw() { - lock.enter(); + data.enter(); const ReferenceCountedObjectPtr result ((numUsed > 0) ? data.elements [numUsed - 1] : (ObjectClass*) 0); - lock.exit(); + data.exit(); return result; } @@ -4871,7 +4869,7 @@ public: { int result = -1; - lock.enter(); + data.enter(); ObjectClass** e = data.elements; for (int i = numUsed; --i >= 0;) @@ -4885,40 +4883,40 @@ public: ++e; } - lock.exit(); + data.exit(); return result; } 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; } 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(); } void insert (int indexToInsertAt, @@ -4926,7 +4924,7 @@ public: { if (indexToInsertAt >= 0) { - lock.enter(); + data.enter(); if (indexToInsertAt > numUsed) indexToInsertAt = numUsed; @@ -4945,7 +4943,7 @@ public: newObject->incReferenceCount(); ++numUsed; - lock.exit(); + data.exit(); } else { @@ -4955,12 +4953,12 @@ public: void addIfNotAlreadyThere (ObjectClass* const newObject) throw() { - lock.enter(); + data.enter(); if (! contains (newObject)) add (newObject); - lock.exit(); + data.exit(); } void set (const int indexToChange, @@ -4968,7 +4966,7 @@ public: { if (indexToChange >= 0) { - lock.enter(); + data.enter(); if (newObject != 0) newObject->incReferenceCount(); @@ -4986,7 +4984,7 @@ public: data.elements [numUsed++] = newObject; } - lock.exit(); + data.exit(); } } @@ -4995,7 +4993,7 @@ public: int numElementsToAdd = -1) throw() { arrayToAddFrom.lockArray(); - lock.enter(); + data.enter(); if (startIndex < 0) { @@ -5014,7 +5012,7 @@ public: add (arrayToAddFrom.getUnchecked (startIndex++)); } - lock.exit(); + data.exit(); arrayToAddFrom.unlockArray(); } @@ -5022,16 +5020,16 @@ 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(); } template 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) @@ -5039,12 +5037,12 @@ public: else insert (index, newObject); // no match, so insert the new one - lock.exit(); + data.exit(); } void remove (const int indexToRemove) { - lock.enter(); + data.enter(); if (((unsigned int) indexToRemove) < (unsigned int) numUsed) { @@ -5063,20 +5061,20 @@ public: minimiseStorageOverheads(); } - lock.exit(); + data.exit(); } void removeObject (ObjectClass* const objectToRemove) { - lock.enter(); + data.enter(); remove (indexOf (objectToRemove)); - lock.exit(); + data.exit(); } 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); @@ -5108,12 +5106,12 @@ public: minimiseStorageOverheads(); } - lock.exit(); + data.exit(); } void removeLast (int howManyToRemove = 1) { - lock.enter(); + data.enter(); if (howManyToRemove > numUsed) howManyToRemove = numUsed; @@ -5121,13 +5119,13 @@ public: while (--howManyToRemove >= 0) remove (numUsed - 1); - lock.exit(); + data.exit(); } 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) @@ -5136,7 +5134,7 @@ public: data.elements [index2]); } - lock.exit(); + data.exit(); } void move (const int currentIndex, @@ -5144,7 +5142,7 @@ public: { if (currentIndex != newIndex) { - lock.enter(); + data.enter(); if (((unsigned int) currentIndex) < (unsigned int) numUsed) { @@ -5169,24 +5167,24 @@ public: data.elements [newIndex] = value; } - lock.exit(); + data.exit(); } } void swapWithArray (ReferenceCountedArray& 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(); } bool operator== (const ReferenceCountedArray& other) const throw() { other.lockArray(); - lock.enter(); + data.enter(); bool result = numUsed == other.numUsed; @@ -5202,7 +5200,7 @@ public: } } - lock.exit(); + data.exit(); other.unlockArray(); return result; @@ -5220,34 +5218,33 @@ 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(); } void minimiseStorageOverheads() throw() { - lock.enter(); + data.enter(); data.shrinkToNoMoreThan (numUsed); - lock.exit(); + data.exit(); } void lockArray() const throw() { - lock.enter(); + data.enter(); } void unlockArray() const throw() { - lock.exit(); + data.exit(); } juce_UseDebuggingNewOperator private: - ArrayAllocationBase data; + ArrayAllocationBase data; int numUsed; - TypeOfCriticalSectionToUse lock; }; #endif // __JUCE_REFERENCECOUNTEDARRAY_JUCEHEADER__ @@ -5299,14 +5296,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(); } @@ -5315,11 +5312,11 @@ public: bool operator== (const SortedSet& other) const throw() { - lock.enter(); + data.enter(); if (numUsed != other.numUsed) { - lock.exit(); + data.exit(); return false; } @@ -5327,12 +5324,12 @@ public: { if (data.elements [i] != other.data.elements [i]) { - lock.exit(); + data.exit(); return false; } } - lock.exit(); + data.exit(); return true; } @@ -5343,17 +5340,17 @@ public: void clear() throw() { - lock.enter(); + data.enter(); data.setAllocatedSize (0); numUsed = 0; - lock.exit(); + data.exit(); } void clearQuick() throw() { - lock.enter(); + data.enter(); numUsed = 0; - lock.exit(); + data.exit(); } inline int size() const throw() @@ -5363,48 +5360,48 @@ 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; } 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; } 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; } 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; } int indexOf (const ElementType elementToLookFor) const throw() { - lock.enter(); + data.enter(); int start = 0; int end = numUsed; @@ -5413,12 +5410,12 @@ public: { if (start >= end) { - lock.exit(); + data.exit(); return -1; } else if (elementToLookFor == data.elements [start]) { - lock.exit(); + data.exit(); return start; } else @@ -5427,7 +5424,7 @@ public: if (halfway == start) { - lock.exit(); + data.exit(); return -1; } else if (elementToLookFor >= data.elements [halfway]) @@ -5440,7 +5437,7 @@ public: bool contains (const ElementType elementToLookFor) const throw() { - lock.enter(); + data.enter(); int start = 0; int end = numUsed; @@ -5449,12 +5446,12 @@ public: { if (start >= end) { - lock.exit(); + data.exit(); return false; } else if (elementToLookFor == data.elements [start]) { - lock.exit(); + data.exit(); return true; } else @@ -5463,7 +5460,7 @@ public: if (halfway == start) { - lock.exit(); + data.exit(); return false; } else if (elementToLookFor >= data.elements [halfway]) @@ -5476,7 +5473,7 @@ public: void add (const ElementType newElement) throw() { - lock.enter(); + data.enter(); int start = 0; int end = numUsed; @@ -5513,18 +5510,18 @@ public: } } - lock.exit(); + data.exit(); } void addArray (const ElementType* elementsToAdd, int numElementsToAdd) throw() { - lock.enter(); + data.enter(); while (--numElementsToAdd >= 0) add (*elementsToAdd++); - lock.exit(); + data.exit(); } template @@ -5533,7 +5530,7 @@ public: int numElementsToAdd = -1) throw() { setToAddFrom.lockSet(); - lock.enter(); + data.enter(); jassert (this != &setToAddFrom); if (this != &setToAddFrom) @@ -5550,13 +5547,13 @@ public: addArray (setToAddFrom.elements + startIndex, numElementsToAdd); } - lock.exit(); + data.exit(); setToAddFrom.unlockSet(); } ElementType remove (const int indexToRemove) throw() { - lock.enter(); + data.enter(); if (((unsigned int) indexToRemove) < (unsigned int) numUsed) { @@ -5572,28 +5569,28 @@ public: if ((numUsed << 1) < data.numAllocated) minimiseStorageOverheads(); - lock.exit(); + data.exit(); return removed; } else { - lock.exit(); + data.exit(); return 0; } } void removeValue (const ElementType valueToRemove) throw() { - lock.enter(); + data.enter(); remove (indexOf (valueToRemove)); - lock.exit(); + data.exit(); } template void removeValuesIn (const OtherSetType& otherSet) throw() { otherSet.lockSet(); - lock.enter(); + data.enter(); if (this == &otherSet) { @@ -5609,7 +5606,7 @@ public: } } - lock.exit(); + data.exit(); otherSet.unlockSet(); } @@ -5617,7 +5614,7 @@ public: void removeValuesNotIn (const OtherSetType& otherSet) throw() { otherSet.lockSet(); - lock.enter(); + data.enter(); if (this != &otherSet) { @@ -5633,33 +5630,32 @@ public: } } - lock.exit(); + data.exit(); otherSet.lockSet(); } void minimiseStorageOverheads() throw() { - lock.enter(); + data.enter(); data.shrinkToNoMoreThan (numUsed); - lock.exit(); + data.exit(); } void lockSet() const throw() { - lock.enter(); + data.enter(); } void unlockSet() const throw() { - lock.exit(); + data.exit(); } juce_UseDebuggingNewOperator private: - ArrayAllocationBase data; + ArrayAllocationBase data; int numUsed; - TypeOfCriticalSectionToUse lock; void insertInternal (const int indexToInsertAt, const ElementType newElement) throw() { @@ -5930,7 +5926,7 @@ public: private: // alternating start/end values of ranges of values that are present. - Array values; + Array values; void simplify() throw() { @@ -9947,7 +9943,7 @@ public: private: friend class PathFlatteningIterator; friend class Path::Iterator; - ArrayAllocationBase data; + ArrayAllocationBase data; int numElements; float pathXMin, pathXMax, pathYMin, pathYMax; bool useNonZeroWinding; @@ -20047,6 +20043,10 @@ public: void replaceAllContent (const String& newContent); + bool loadFromStream (InputStream& stream); + + bool writeToStream (OutputStream& stream); + const String getNewLineCharacters() const throw() { return newLineChars; } void setNewLineCharacters (const String& newLine) throw(); diff --git a/src/containers/juce_Array.h b/src/containers/juce_Array.h index 6ed142a4e5..82f950a769 100644 --- a/src/containers/juce_Array.h +++ b/src/containers/juce_Array.h @@ -137,11 +137,11 @@ public: template 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 & 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 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 data; + ArrayAllocationBase data; int numUsed; - TypeOfCriticalSectionToUse lock; }; diff --git a/src/containers/juce_ArrayAllocationBase.h b/src/containers/juce_ArrayAllocationBase.h index 9496bd73c4..1fe63e5062 100644 --- a/src/containers/juce_ArrayAllocationBase.h +++ b/src/containers/juce_ArrayAllocationBase.h @@ -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 ArrayAllocationBase +template +class ArrayAllocationBase : public TypeOfCriticalSectionToUse { public: //============================================================================== @@ -99,7 +102,7 @@ public: } /** Swap the contents of two objects. */ - void swapWith (ArrayAllocationBase & other) throw() + void swapWith (ArrayAllocationBase & 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&); }; diff --git a/src/containers/juce_OwnedArray.h b/src/containers/juce_OwnedArray.h index 8692a2e0c1..3b44834558 100644 --- a/src/containers/juce_OwnedArray.h +++ b/src/containers/juce_OwnedArray.h @@ -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 (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 (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 toDelete; - lock.enter(); + data.enter(); if (indexToChange < numUsed) { @@ -357,7 +357,7 @@ public: data.elements [numUsed++] = const_cast (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 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 & 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 data; + ArrayAllocationBase data; int numUsed; - TypeOfCriticalSectionToUse lock; // disallow copy constructor and assignment OwnedArray (const OwnedArray&); - const OwnedArray& operator= (const OwnedArray&); + OwnedArray& operator= (const OwnedArray&); }; diff --git a/src/containers/juce_ReferenceCountedArray.h b/src/containers/juce_ReferenceCountedArray.h index eca5d8e058..5d2b6ef9f9 100644 --- a/src/containers/juce_ReferenceCountedArray.h +++ b/src/containers/juce_ReferenceCountedArray.h @@ -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 operator[] (const int index) const throw() { - lock.enter(); + data.enter(); const ReferenceCountedObjectPtr 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 getUnchecked (const int index) const throw() { - lock.enter(); + data.enter(); jassert (((unsigned int) index) < (unsigned int) numUsed); const ReferenceCountedObjectPtr result (data.elements [index]); - lock.exit(); + data.exit(); return result; } @@ -161,10 +161,10 @@ public: */ inline const ReferenceCountedObjectPtr getFirst() const throw() { - lock.enter(); + data.enter(); const ReferenceCountedObjectPtr result ((numUsed > 0) ? data.elements [0] : (ObjectClass*) 0); - lock.exit(); + data.exit(); return result; } @@ -176,10 +176,10 @@ public: */ inline const ReferenceCountedObjectPtr getLast() const throw() { - lock.enter(); + data.enter(); const ReferenceCountedObjectPtr 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& 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& 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 data; + ArrayAllocationBase data; int numUsed; - TypeOfCriticalSectionToUse lock; }; diff --git a/src/containers/juce_SortedSet.h b/src/containers/juce_SortedSet.h index 00c79ddc97..1fc8212abe 100644 --- a/src/containers/juce_SortedSet.h +++ b/src/containers/juce_SortedSet.h @@ -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& 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 data; + ArrayAllocationBase data; int numUsed; - TypeOfCriticalSectionToUse lock; void insertInternal (const int indexToInsertAt, const ElementType newElement) throw() { diff --git a/src/containers/juce_SparseSet.h b/src/containers/juce_SparseSet.h index 267c0d76e3..aaed3cb6ae 100644 --- a/src/containers/juce_SparseSet.h +++ b/src/containers/juce_SparseSet.h @@ -340,7 +340,7 @@ public: private: // alternating start/end values of ranges of values that are present. - Array values; + Array values; void simplify() throw() { diff --git a/src/gui/components/code_editor/juce_CodeDocument.cpp b/src/gui/components/code_editor/juce_CodeDocument.cpp index d5dd3277ea..d655a84815 100644 --- a/src/gui/components/code_editor/juce_CodeDocument.cpp +++ b/src/gui/components/code_editor/juce_CodeDocument.cpp @@ -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")); diff --git a/src/gui/components/code_editor/juce_CodeDocument.h b/src/gui/components/code_editor/juce_CodeDocument.h index eedfe47574..edd9776e70 100644 --- a/src/gui/components/code_editor/juce_CodeDocument.h +++ b/src/gui/components/code_editor/juce_CodeDocument.h @@ -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". diff --git a/src/gui/graphics/geometry/juce_Path.h b/src/gui/graphics/geometry/juce_Path.h index fe4dbd8755..508e12068e 100644 --- a/src/gui/graphics/geometry/juce_Path.h +++ b/src/gui/graphics/geometry/juce_Path.h @@ -632,7 +632,7 @@ public: private: friend class PathFlatteningIterator; friend class Path::Iterator; - ArrayAllocationBase data; + ArrayAllocationBase data; int numElements; float pathXMin, pathXMax, pathYMin, pathYMax; bool useNonZeroWinding;