Browse Source

Changed addIfNotAlreadyThere method of all array classes to return a bool, indicating whether the object was added or not.

tags/2021-05-28
Timur Doumler 9 years ago
parent
commit
fc69dc00db
7 changed files with 38 additions and 19 deletions
  1. +7
    -3
      modules/juce_core/containers/juce_Array.h
  2. +6
    -5
      modules/juce_core/containers/juce_OwnedArray.h
  3. +8
    -3
      modules/juce_core/containers/juce_ReferenceCountedArray.h
  4. +3
    -2
      modules/juce_core/files/juce_FileSearchPath.cpp
  5. +5
    -2
      modules/juce_core/files/juce_FileSearchPath.h
  6. +6
    -3
      modules/juce_core/text/juce_StringArray.cpp
  7. +3
    -1
      modules/juce_core/text/juce_StringArray.h

+ 7
- 3
modules/juce_core/containers/juce_Array.h View File

@@ -540,13 +540,17 @@ public:
will be done.
@param newElement the new object to add to the array
@return true if the element was added to the array; false otherwise.
*/
void addIfNotAlreadyThere (ParameterType newElement)
bool addIfNotAlreadyThere (ParameterType newElement)
{
const ScopedLockType lock (getLock());
if (! contains (newElement))
add (newElement);
if (contains (newElement))
return false;
add (newElement);
return true;
}
/** Replaces an element with a new value.


+ 6
- 5
modules/juce_core/containers/juce_OwnedArray.h View File

@@ -378,16 +378,17 @@ public:
If the array already contains a matching object, nothing will be done.
@param newObject the new object to add to the array
@returns the new object that was added
@returns true if the new object was added, false otherwise
*/
ObjectClass* addIfNotAlreadyThere (ObjectClass* newObject) noexcept
bool addIfNotAlreadyThere (ObjectClass* newObject) noexcept
{
const ScopedLockType lock (getLock());
if (! contains (newObject))
add (newObject);
if (contains (newObject))
return false;
return newObject;
add (newObject);
return true;
}
/** Replaces an object in the array with a different one.


+ 8
- 3
modules/juce_core/containers/juce_ReferenceCountedArray.h View File

@@ -386,12 +386,17 @@ public:
If the array already contains a matching object, nothing will be done.
@param newObject the new object to add to the array
@returns true if the object has been added, false otherwise
*/
void addIfNotAlreadyThere (ObjectClass* const newObject) noexcept
bool addIfNotAlreadyThere (ObjectClass* const newObject) noexcept
{
const ScopedLockType lock (getLock());
if (! contains (newObject))
add (newObject);
if (contains (newObject))
return false;
add (newObject);
return true;
}
/** Replaces an object in the array with a different one.


+ 3
- 2
modules/juce_core/files/juce_FileSearchPath.cpp View File

@@ -87,13 +87,14 @@ void FileSearchPath::add (const File& dir, const int insertIndex)
directories.insert (insertIndex, dir.getFullPathName());
}
void FileSearchPath::addIfNotAlreadyThere (const File& dir)
bool FileSearchPath::addIfNotAlreadyThere (const File& dir)
{
for (int i = 0; i < directories.size(); ++i)
if (File (directories[i]) == dir)
return;
return false;
add (dir);
return true;
}
void FileSearchPath::remove (const int index)


+ 5
- 2
modules/juce_core/files/juce_FileSearchPath.h View File

@@ -92,8 +92,11 @@ public:
void add (const File& directoryToAdd,
int insertIndex = -1);
/** Adds a new directory to the search path if it's not already in there. */
void addIfNotAlreadyThere (const File& directoryToAdd);
/** Adds a new directory to the search path if it's not already in there.
@return true if the directory has been added, false otherwise.
*/
bool addIfNotAlreadyThere (const File& directoryToAdd);
/** Removes a directory from the search path. */
void remove (int indexToRemove);


+ 6
- 3
modules/juce_core/text/juce_StringArray.cpp View File

@@ -152,10 +152,13 @@ void StringArray::insert (const int index, const String& newString)
strings.insert (index, newString);
}
void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
bool StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
{
if (! contains (newString, ignoreCase))
add (newString);
if (contains (newString, ignoreCase))
return false;
add (newString);
return true;
}
void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)


+ 3
- 1
modules/juce_core/text/juce_StringArray.h View File

@@ -191,8 +191,10 @@ public:
/** Adds a string to the array as long as it's not already in there.
The search can optionally be case-insensitive.
@return true if the string has been added, false otherwise.
*/
void addIfNotAlreadyThere (const String& stringToAdd, bool ignoreCase = false);
bool addIfNotAlreadyThere (const String& stringToAdd, bool ignoreCase = false);
/** Replaces one of the strings in the array with another one.


Loading…
Cancel
Save