Rename to swapWith and use a template parameter

This commit is contained in:
Vinnie Falco
2013-07-28 03:41:04 -07:00
parent 8c10aed511
commit 217d3bb7a8
8 changed files with 18 additions and 15 deletions

View File

@@ -132,7 +132,7 @@ public:
if (this != &other)
{
Array<ElementType, TypeOfCriticalSectionToUse> otherCopy (other);
swapWithArray (otherCopy);
swapWith (otherCopy);
}
return *this;
@@ -577,7 +577,7 @@ public:
because it just swaps their internal pointers.
*/
template <class OtherArrayType>
void swapWithArray (OtherArrayType& otherArray) noexcept
void swapWith (OtherArrayType& otherArray) noexcept
{
const ScopedLockType lock1 (getLock());
const typename OtherArrayType::ScopedLockType lock2 (otherArray.getLock());

View File

@@ -354,12 +354,13 @@ public:
//==============================================================================
/** Efficiently swaps the contents of two hash-maps. */
void swapWith (HashMap& otherHashMap) noexcept
template <class OtherHashMapType>
void swapWith (OtherHashMapType& otherHashMap) noexcept
{
const ScopedLockType lock1 (getLock());
const ScopedLockType lock2 (otherHashMap.getLock());
const typename OtherHashMapType::ScopedLockType lock2 (otherHashMap.getLock());
slots.swapWithArray (otherHashMap.slots);
slots.swapWith (otherHashMap.slots);
std::swap (totalNumItems, otherHashMap.totalNumItems);
}

View File

@@ -788,10 +788,11 @@ public:
If you need to exchange two arrays, this is vastly quicker than using copy-by-value
because it just swaps their internal pointers.
*/
void swapWithArray (OwnedArray& otherArray) noexcept
template <class OtherArrayType>
void swapWith (OtherArrayType& otherArray) noexcept
{
const ScopedLockType lock1 (getLock());
const ScopedLockType lock2 (otherArray.getLock());
const typename OtherArrayType::ScopedLockType lock2 (otherArray.getLock());
data.swapWith (otherArray.data);
std::swap (numUsed, otherArray.numUsed);

View File

@@ -91,7 +91,7 @@ public:
SharedObjectArray& operator= (const SharedObjectArray& other) noexcept
{
SharedObjectArray otherCopy (other);
swapWithArray (otherCopy);
swapWith (otherCopy);
return *this;
}
@@ -102,7 +102,7 @@ public:
SharedObjectArray<ObjectClass, TypeOfCriticalSectionToUse>& operator= (const SharedObjectArray<OtherObjectClass, TypeOfCriticalSectionToUse>& other) noexcept
{
SharedObjectArray<ObjectClass, TypeOfCriticalSectionToUse> otherCopy (other);
swapWithArray (otherCopy);
swapWith (otherCopy);
return *this;
}
@@ -741,7 +741,7 @@ public:
because it just swaps their internal pointers.
*/
template <class OtherArrayType>
void swapWithArray (OtherArrayType& otherArray) noexcept
void swapWith (OtherArrayType& otherArray) noexcept
{
const ScopedLockType lock1 (getLock());
const typename OtherArrayType::ScopedLockType lock2 (otherArray.getLock());

View File

@@ -443,9 +443,10 @@ public:
If you need to exchange two arrays, this is vastly quicker than using copy-by-value
because it just swaps their internal pointers.
*/
void swapWith (SortedSet& otherSet) noexcept
template <class OtherSortedSetType>
void swapWith (OtherSortedSetType& otherSet) noexcept
{
data.swapWithArray (otherSet.data);
data.swapWith (otherSet.data);
}
//==============================================================================

View File

@@ -122,7 +122,7 @@ bool StringArray::operator!= (const StringArray& other) const noexcept
void StringArray::swapWith (StringArray& other) noexcept
{
strings.swapWithArray (other.strings);
strings.swapWith (other.strings);
}
void StringArray::clear()

View File

@@ -70,7 +70,7 @@ public:
explicit List (SharedObjectArray <Validator>& list)
{
m_list.swapWithArray (list);
m_list.swapWith (list);
}
~List ()

View File

@@ -167,7 +167,7 @@ public:
sorted.addSorted (compare, arrayToSort [i]);
}
arrayToSort.swapWithArray (sorted);
arrayToSort.swapWith (sorted);
}
// Given the old list and the new list for a source, this