Browse Source

Added some begin()/end() methods to the container classes to add compatibility with standard c++ iteration mechanisms.

tags/2021-05-28
Julian Storer 14 years ago
parent
commit
97398dfe49
9 changed files with 184 additions and 52 deletions
  1. +25
    -25
      juce_amalgamated.cpp
  2. +84
    -21
      juce_amalgamated.h
  3. +18
    -0
      src/containers/juce_Array.h
  4. +17
    -0
      src/containers/juce_OwnedArray.h
  5. +20
    -3
      src/containers/juce_ReferenceCountedArray.h
  6. +17
    -0
      src/containers/juce_SortedSet.h
  7. +0
    -1
      src/containers/juce_SparseSet.h
  8. +2
    -1
      src/core/juce_StandardHeader.h
  9. +1
    -1
      src/gui/graphics/geometry/juce_Path.h

+ 25
- 25
juce_amalgamated.cpp View File

@@ -2679,9 +2679,9 @@ BigInteger::~BigInteger()
void BigInteger::swapWith (BigInteger& other) throw()
{
values.swapWith (other.values);
swapVariables (numValues, other.numValues);
swapVariables (highestBit, other.highestBit);
swapVariables (negative, other.negative);
std::swap (numValues, other.numValues);
std::swap (highestBit, other.highestBit);
std::swap (negative, other.negative);
}

BigInteger& BigInteger::operator= (const BigInteger& other)
@@ -3366,7 +3366,7 @@ const BigInteger BigInteger::simpleGCD (BigInteger* m, BigInteger* n)
while (! m->isZero())
{
if (n->compareAbsolute (*m) > 0)
swapVariables (m, n);
std::swap (m, n);

*m -= *n;
}
@@ -3711,7 +3711,7 @@ void MemoryBlock::ensureSize (const size_t minimumSize, const bool initialiseToZ

void MemoryBlock::swapWith (MemoryBlock& other) throw()
{
swapVariables (size, other.size);
std::swap (size, other.size);
data.swapWith (other.data);
}

@@ -4518,8 +4518,8 @@ DynamicObject* var::getObject() const { return type->toObject (value); }

void var::swapWith (var& other) throw()
{
swapVariables (type, other.type);
swapVariables (value, other.value);
std::swap (type, other.type);
std::swap (value, other.value);
}

var& var::operator= (const var& newValue) { type->cleanUp (value); type = newValue.type; type->createCopy (value, newValue.value); return *this; }
@@ -6250,7 +6250,7 @@ void BlowFish::encrypt (uint32& data1, uint32& data2) const throw()
{
l ^= p[i];
r ^= F(l);
swapVariables (l, r);
std::swap (l, r);
}

data1 = r ^ p[17];
@@ -6266,7 +6266,7 @@ void BlowFish::decrypt (uint32& data1, uint32& data2) const throw()
{
l ^= p[i];
r ^= F(l);
swapVariables (l, r);
std::swap (l, r);
}

data1 = r ^ p[0];
@@ -11707,7 +11707,7 @@ String::String (const String& other) throw()

void String::swapWith (String& other) throw()
{
swapVariables (text, other.text);
std::swap (text, other.text);
}

String& String::operator= (const String& other) throw()
@@ -27673,7 +27673,7 @@ MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
void MidiBuffer::swapWith (MidiBuffer& other) throw()
{
data.swapWith (other.data);
swapVariables <int> (bytesUsed, other.bytesUsed);
std::swap (bytesUsed, other.bytesUsed);
}

MidiBuffer::~MidiBuffer()
@@ -49930,7 +49930,7 @@ void Slider::setMinAndMaxValues (double newMinValue, double newMaxValue, bool se
|| style == ThreeValueHorizontal || style == ThreeValueVertical);

if (newMaxValue < newMinValue)
swapVariables (newMaxValue, newMinValue);
std::swap (newMaxValue, newMinValue);

newMinValue = constrainedValue (newMinValue);
newMaxValue = constrainedValue (newMaxValue);
@@ -56132,13 +56132,13 @@ private:
int rowStart = firstSelected->getRowNumberInTree();
int rowEnd = lastSelected->getRowNumberInTree();
if (rowStart > rowEnd)
swapVariables (rowStart, rowEnd);
std::swap (rowStart, rowEnd);

int ourRow = item->getRowNumberInTree();
int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;

if (ourRow > otherEnd)
swapVariables (ourRow, otherEnd);
std::swap (ourRow, otherEnd);

for (int i = ourRow; i <= otherEnd; ++i)
owner.getItemOnRow (i)->setSelected (true, false);
@@ -64347,7 +64347,7 @@ void TabbedButtonBar::resized()
int length = getHeight();

if (orientation == TabsAtTop || orientation == TabsAtBottom)
swapVariables (depth, length);
std::swap (depth, length);

const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
+ getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
@@ -67131,7 +67131,7 @@ void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
}

if (positionTitleBarButtonsOnLeft)
swapVariables (minimiseButton, maximiseButton);
std::swap (minimiseButton, maximiseButton);

if (maximiseButton != 0)
{
@@ -67267,7 +67267,7 @@ void LookAndFeel::createTabButtonShape (Path& p,
if (orientation == TabbedButtonBar::TabsAtLeft
|| orientation == TabbedButtonBar::TabsAtRight)
{
swapVariables (length, depth);
std::swap (length, depth);
}

const float indent = (float) getTabButtonOverlap ((int) depth);
@@ -67355,7 +67355,7 @@ void LookAndFeel::drawTabButtonText (Graphics& g,
if (orientation == TabbedButtonBar::TabsAtLeft
|| orientation == TabbedButtonBar::TabsAtRight)
{
swapVariables (length, depth);
std::swap (length, depth);
}

Font font (depth * 0.6f);
@@ -67426,7 +67426,7 @@ void LookAndFeel::drawTabButton (Graphics& g,
if (orientation == TabbedButtonBar::TabsAtLeft
|| orientation == TabbedButtonBar::TabsAtRight)
{
swapVariables (length, depth);
std::swap (length, depth);
}

Path tabShape;
@@ -68761,7 +68761,7 @@ void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
}

if (positionTitleBarButtonsOnLeft)
swapVariables (minimiseButton, maximiseButton);
std::swap (minimiseButton, maximiseButton);

if (maximiseButton != 0)
{
@@ -75677,7 +75677,7 @@ void MidiKeyboardComponent::resized()
if (w > 0 && h > 0)
{
if (orientation != horizontalKeyboard)
swapVariables (w, h);
std::swap (w, h);

blackNoteLength = roundToInt (h * 0.7f);

@@ -80370,8 +80370,8 @@ bool RelativePointPath::operator!= (const RelativePointPath& other) const throw(
void RelativePointPath::swapWith (RelativePointPath& other) throw()
{
elements.swapWithArray (other.elements);
swapVariables (usesNonZeroWinding, other.usesNonZeroWinding);
swapVariables (containsDynamicPoints, other.containsDynamicPoints);
std::swap (usesNonZeroWinding, other.usesNonZeroWinding);
std::swap (containsDynamicPoints, other.containsDynamicPoints);
}

void RelativePointPath::createPath (Path& path, Expression::Scope* scope) const
@@ -81994,7 +81994,7 @@ EdgeTable::EdgeTable (const Rectangle<int>& bounds_,

if (y1 > y2)
{
swapVariables (y1, y2);
std::swap (y1, y2);
direction = 1;
}

@@ -253218,7 +253218,7 @@ MidiOutput* MidiOutput::openDevice (int index)
{
MidiOutHandle* const han = MidiOutHandle::activeHandles.getUnchecked(i);

if (han != 0 && han->deviceId == deviceId)
if (han->deviceId == deviceId)
{
han->refCount++;



+ 84
- 21
juce_amalgamated.h View File

@@ -73,7 +73,7 @@ namespace JuceDummyNamespace {}
*/
#define JUCE_MAJOR_VERSION 1
#define JUCE_MINOR_VERSION 53
#define JUCE_BUILDNUMBER 65
#define JUCE_BUILDNUMBER 66

/** Current Juce version number.

@@ -784,6 +784,7 @@ namespace JuceDummyNamespace {}
#include <cstring>
#include <cstdio>
#include <iostream>
#include <vector>

#if JUCE_USE_INTRINSICS
#include <intrin.h>
@@ -1235,14 +1236,11 @@ inline bool isPositiveAndNotGreaterThan (const int valueToTest, const int upperL
}
#endif

/** Handy function to swap two values over.
*/
/** Handy function to swap two values. */
template <typename Type>
inline void swapVariables (Type& variable1, Type& variable2)
{
const Type tempVal = variable1;
variable1 = variable2;
variable2 = tempVal;
std::swap (variable1, variable2);
}

#if JUCE_VC6
@@ -6091,7 +6089,7 @@ public:
*/
void swapWith (HeapBlock <ElementType>& other) throw()
{
swapVariables (data, other.data);
std::swap (data, other.data);
}

/** This fills the block with zeros, up to the number of elements specified.
@@ -6187,7 +6185,7 @@ public:
void swapWith (ArrayAllocationBase <ElementType, TypeOfCriticalSectionToUse>& other) throw()
{
elements.swapWith (other.elements);
swapVariables (numAllocated, other.numAllocated);
std::swap (numAllocated, other.numAllocated);
}

HeapBlock <ElementType> elements;
@@ -6250,7 +6248,7 @@ static void sortArray (ElementComparator& comparator,
{
if (comparator.compareElements (array[i], array [i + 1]) > 0)
{
swapVariables (array[i], array[i + 1]);
std::swap (array[i], array[i + 1]);

if (i > firstElement)
i -= 2;
@@ -6278,14 +6276,14 @@ static void sortArray (ElementComparator& comparator,
if (comparator.compareElements (array[k], array [maxIndex]) > 0)
maxIndex = k;

swapVariables (array[j], array[maxIndex]);
std::swap (array[j], array[maxIndex]);
--j;
}
}
else
{
const int mid = firstElement + (size >> 1);
swapVariables (array[mid], array[firstElement]);
std::swap (array[mid], array[firstElement]);

int i = firstElement;
int j = lastElement + 1;
@@ -6303,10 +6301,10 @@ static void sortArray (ElementComparator& comparator,
if (j < i)
break;

swapVariables (array[i], array[j]);
std::swap (array[i], array[j]);
}

swapVariables (array[j], array[firstElement]);
std::swap (array[j], array[firstElement]);

if (j - 1 - firstElement >= lastElement - i)
{
@@ -6980,6 +6978,7 @@ public:
bool operator== (const OtherArrayType& other) const
{
const ScopedLockType lock (getLock());
const typename OtherArrayType::ScopedLockType lock2 (other.getLock());

if (numUsed != other.numUsed)
return false;
@@ -7121,6 +7120,22 @@ public:
return data.elements;
}

/** Returns a pointer to the first element in the array.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ElementType* begin() const throw()
{
return data.elements;
}

/** Returns a pointer to the element which follows the last element in the array.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ElementType* end() const throw()
{
return data.elements + numUsed;
}

/** Finds the index of the first element which matches the value passed in.

This will search the array for the given object, and return the index
@@ -9755,6 +9770,22 @@ public:
return data.elements;
}

/** Returns a pointer to the first element in the array.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ObjectClass** begin() const throw()
{
return data.elements;
}

/** Returns a pointer to the element which follows the last element in the array.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ObjectClass** end() const throw()
{
return data.elements + numUsed;
}

/** Finds the index of an object which might be in the array.

@param objectToLookFor the object to look for
@@ -10513,7 +10544,7 @@ public:
// this happens, you must have done something dodgy!
jassert (object != other.object);

swapVariables (object, other.object);
std::swap (object, other.object);
}

private:
@@ -10848,7 +10879,7 @@ public:
const ScopedLockType lock2 (otherHashMap.getLock());

slots.swapWithArray (otherHashMap.slots);
swapVariables (totalNumItems, otherHashMap.totalNumItems);
std::swap (totalNumItems, otherHashMap.totalNumItems);
}

/** Returns the CriticalSection that locks this structure.
@@ -13832,6 +13863,22 @@ public:
: static_cast <ObjectClass*> (0);
}

/** Returns a pointer to the first element in the array.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ObjectClass** begin() const throw()
{
return data.elements;
}

/** Returns a pointer to the element which follows the last element in the array.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ObjectClass** end() const throw()
{
return data.elements + numUsed;
}

/** Finds the index of the first occurrence of an object in the array.

@param objectToLookFor the object to look for
@@ -14233,8 +14280,8 @@ public:
if (isPositiveAndBelow (index1, numUsed)
&& isPositiveAndBelow (index2, numUsed))
{
swapVariables (data.elements [index1],
data.elements [index2]);
std::swap (data.elements [index1],
data.elements [index2]);
}
}

@@ -14294,7 +14341,7 @@ public:
const ScopedLockType lock2 (otherArray.getLock());

data.swapWith (otherArray.data);
swapVariables (numUsed, otherArray.numUsed);
std::swap (numUsed, otherArray.numUsed);
}

/** Compares this array to another one.
@@ -14666,6 +14713,22 @@ public:
return numUsed > 0 ? data.elements [numUsed - 1] : ElementType();
}

/** Returns a pointer to the first element in the set.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ElementType* begin() const throw()
{
return data.elements;
}

/** Returns a pointer to the element which follows the last element in the set.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ElementType* end() const throw()
{
return data.elements + numUsed;
}

/** Finds the index of the first element which matches the value passed in.

This will search the set for the given object, and return the index
@@ -20412,7 +20475,7 @@ public:
void swapWith (OptionalScopedPointer<ObjectType>& other) throw()
{
object.swapWith (other.object);
swapVariables (shouldDelete, other.shouldDelete);
std::swap (shouldDelete, other.shouldDelete);
}

private:
@@ -21490,8 +21553,8 @@ private:

@see LocalisedStrings
*/
#define TRANS(stringLiteral) \
LocalisedStrings::translateWithCurrentMappings (stringLiteral)
#define TRANS(stringLiteral) \
JUCE_NAMESPACE::LocalisedStrings::translateWithCurrentMappings (stringLiteral)

/**
Used to convert strings to localised foreign-language versions.


+ 18
- 0
src/containers/juce_Array.h View File

@@ -141,6 +141,7 @@ public:
bool operator== (const OtherArrayType& other) const
{
const ScopedLockType lock (getLock());
const typename OtherArrayType::ScopedLockType lock2 (other.getLock());
if (numUsed != other.numUsed)
return false;
@@ -284,6 +285,23 @@ public:
return data.elements;
}
//==============================================================================
/** Returns a pointer to the first element in the array.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ElementType* begin() const throw()
{
return data.elements;
}
/** Returns a pointer to the element which follows the last element in the array.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ElementType* end() const throw()
{
return data.elements + numUsed;
}
//==============================================================================
/** Finds the index of the first element which matches the value passed in.


+ 17
- 0
src/containers/juce_OwnedArray.h View File

@@ -158,6 +158,23 @@ public:
return data.elements;
}
//==============================================================================
/** Returns a pointer to the first element in the array.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ObjectClass** begin() const throw()
{
return data.elements;
}
/** Returns a pointer to the element which follows the last element in the array.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ObjectClass** end() const throw()
{
return data.elements + numUsed;
}
//==============================================================================
/** Finds the index of an object which might be in the array.


+ 20
- 3
src/containers/juce_ReferenceCountedArray.h View File

@@ -171,6 +171,23 @@ public:
: static_cast <ObjectClass*> (0);
}
//==============================================================================
/** Returns a pointer to the first element in the array.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ObjectClass** begin() const throw()
{
return data.elements;
}
/** Returns a pointer to the element which follows the last element in the array.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ObjectClass** end() const throw()
{
return data.elements + numUsed;
}
//==============================================================================
/** Finds the index of the first occurrence of an object in the array.
@@ -574,8 +591,8 @@ public:
if (isPositiveAndBelow (index1, numUsed)
&& isPositiveAndBelow (index2, numUsed))
{
swapVariables (data.elements [index1],
data.elements [index2]);
std::swap (data.elements [index1],
data.elements [index2]);
}
}
@@ -636,7 +653,7 @@ public:
const ScopedLockType lock2 (otherArray.getLock());
data.swapWith (otherArray.data);
swapVariables (numUsed, otherArray.numUsed);
std::swap (numUsed, otherArray.numUsed);
}
//==============================================================================


+ 17
- 0
src/containers/juce_SortedSet.h View File

@@ -224,6 +224,23 @@ public:
return numUsed > 0 ? data.elements [numUsed - 1] : ElementType();
}
//==============================================================================
/** Returns a pointer to the first element in the set.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ElementType* begin() const throw()
{
return data.elements;
}
/** Returns a pointer to the element which follows the last element in the set.
This method is provided for compatibility with standard C++ iteration mechanisms.
*/
inline ElementType* end() const throw()
{
return data.elements + numUsed;
}
//==============================================================================
/** Finds the index of the first element which matches the value passed in.


+ 0
- 1
src/containers/juce_SparseSet.h View File

@@ -26,7 +26,6 @@
#ifndef __JUCE_SPARSESET_JUCEHEADER__
#define __JUCE_SPARSESET_JUCEHEADER__
#include "juce_ArrayAllocationBase.h"
#include "../maths/juce_Range.h"
#include "../threads/juce_CriticalSection.h"


+ 2
- 1
src/core/juce_StandardHeader.h View File

@@ -33,7 +33,7 @@
*/
#define JUCE_MAJOR_VERSION 1
#define JUCE_MINOR_VERSION 53
#define JUCE_BUILDNUMBER 65
#define JUCE_BUILDNUMBER 66
/** Current Juce version number.
@@ -96,6 +96,7 @@
#include <cstring>
#include <cstdio>
#include <iostream>
#include <vector>
#if JUCE_USE_INTRINSICS
#include <intrin.h>


+ 1
- 1
src/gui/graphics/geometry/juce_Path.h View File

@@ -30,7 +30,7 @@
#include "juce_Line.h"
#include "juce_Rectangle.h"
#include "../contexts/juce_Justification.h"
#include "../../../containers/juce_Array.h"
#include "../../../containers/juce_ArrayAllocationBase.h"
#include "../../../io/streams/juce_InputStream.h"
#include "../../../io/streams/juce_OutputStream.h"
class Image;


Loading…
Cancel
Save