mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added some overloads to OwnedArray to let items be added from std::unique_ptrs. Also removed OwnedArray::addIfNotAlreadyThere because it's ambiguous about whether the object should be deleted if it fails to be added!
This commit is contained in:
parent
332a9edb57
commit
62ead7dc7d
12 changed files with 94 additions and 56 deletions
|
|
@ -341,7 +341,7 @@ void LibraryModule::getConfigFlags (Project& project, OwnedArray<Project::Config
|
|||
|
||||
if (line.startsWith ("/**") && line.containsIgnoreCase ("Config:"))
|
||||
{
|
||||
std::unique_ptr<Project::ConfigFlag> config (new Project::ConfigFlag());
|
||||
auto config = std::make_unique<Project::ConfigFlag>();
|
||||
config->sourceModuleID = getID();
|
||||
config->symbol = line.fromFirstOccurrenceOf (":", false, false).trim();
|
||||
|
||||
|
|
@ -361,6 +361,7 @@ void LibraryModule::getConfigFlags (Project& project, OwnedArray<Project::Config
|
|||
config->value = project.getConfigFlag (config->symbol);
|
||||
|
||||
i += 2;
|
||||
|
||||
if (lines[i].contains ("#define " + config->symbol))
|
||||
{
|
||||
auto value = lines[i].fromFirstOccurrenceOf ("#define " + config->symbol, false, true).trim();
|
||||
|
|
@ -372,7 +373,7 @@ void LibraryModule::getConfigFlags (Project& project, OwnedArray<Project::Config
|
|||
if (currentValue == "enabled") config->value = true;
|
||||
else if (currentValue == "disabled") config->value = false;
|
||||
|
||||
flags.add (config.release());
|
||||
flags.add (std::move (config));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1231,15 +1231,17 @@ Project::Item Project::Item::createCopy() { Item i (*this); i.state = i.
|
|||
String Project::Item::getID() const { return state [Ids::ID]; }
|
||||
void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, newID, nullptr); }
|
||||
|
||||
Drawable* Project::Item::loadAsImageFile() const
|
||||
std::unique_ptr<Drawable> Project::Item::loadAsImageFile() const
|
||||
{
|
||||
const MessageManagerLock mml (ThreadPoolJob::getCurrentThreadPoolJob());
|
||||
|
||||
if (! mml.lockWasGained())
|
||||
return nullptr;
|
||||
|
||||
return isValid() ? Drawable::createFromImageFile (getFile())
|
||||
: nullptr;
|
||||
if (isValid())
|
||||
return std::unique_ptr<Drawable> (Drawable::createFromImageFile (getFile()));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Project::Item Project::Item::createGroup (Project& project, const String& name, const String& uid, bool isModuleCode)
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ public:
|
|||
Item findItemWithID (const String& targetId) const; // (recursive search)
|
||||
|
||||
String getImageFileID() const;
|
||||
Drawable* loadAsImageFile() const;
|
||||
std::unique_ptr<Drawable> loadAsImageFile() const;
|
||||
|
||||
//==============================================================================
|
||||
Value getNameValue();
|
||||
|
|
|
|||
|
|
@ -2385,15 +2385,11 @@ private:
|
|||
|
||||
void getIconImages (OwnedArray<Drawable>& images) const
|
||||
{
|
||||
std::unique_ptr<Drawable> bigIcon (getBigIcon());
|
||||
if (auto icon = getBigIcon())
|
||||
images.add (std::move (icon));
|
||||
|
||||
if (bigIcon != nullptr)
|
||||
images.add (bigIcon.release());
|
||||
|
||||
std::unique_ptr<Drawable> smallIcon (getSmallIcon());
|
||||
|
||||
if (smallIcon != nullptr)
|
||||
images.add (smallIcon.release());
|
||||
if (auto icon = getSmallIcon())
|
||||
images.add (std::move (icon));
|
||||
}
|
||||
|
||||
void createiOSIconFiles (File appIconSet) const
|
||||
|
|
|
|||
|
|
@ -819,12 +819,12 @@ void ProjectExporter::createDefaultConfigs()
|
|||
}
|
||||
}
|
||||
|
||||
Drawable* ProjectExporter::getBigIcon() const
|
||||
std::unique_ptr<Drawable> ProjectExporter::getBigIcon() const
|
||||
{
|
||||
return project.getMainGroup().findItemWithID (settings [Ids::bigIcon]).loadAsImageFile();
|
||||
}
|
||||
|
||||
Drawable* ProjectExporter::getSmallIcon() const
|
||||
std::unique_ptr<Drawable> ProjectExporter::getSmallIcon() const
|
||||
{
|
||||
return project.getMainGroup().findItemWithID (settings [Ids::smallIcon]).loadAsImageFile();
|
||||
}
|
||||
|
|
@ -833,8 +833,8 @@ Image ProjectExporter::getBestIconForSize (int size, bool returnNullIfNothingBig
|
|||
{
|
||||
Drawable* im = nullptr;
|
||||
|
||||
std::unique_ptr<Drawable> im1 (getSmallIcon());
|
||||
std::unique_ptr<Drawable> im2 (getBigIcon());
|
||||
auto im1 = getSmallIcon();
|
||||
auto im2 = getBigIcon();
|
||||
|
||||
if (im1 != nullptr && im2 != nullptr)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -179,8 +179,8 @@ public:
|
|||
|
||||
void addProjectPathToBuildPathList (StringArray&, const RelativePath&, int index = -1) const;
|
||||
|
||||
Drawable* getBigIcon() const;
|
||||
Drawable* getSmallIcon() const;
|
||||
std::unique_ptr<Drawable> getBigIcon() const;
|
||||
std::unique_ptr<Drawable> getSmallIcon() const;
|
||||
Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const;
|
||||
|
||||
String getExporterIdentifierMacro() const
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ void ProjectSaver::writeProjects (const OwnedArray<LibraryModule>& modules, cons
|
|||
if (specifiedExporterToSave.isNotEmpty() && exp->getName() != specifiedExporterToSave)
|
||||
continue;
|
||||
|
||||
auto* exporter = exporters.add (exp.exporter.release());
|
||||
auto exporter = exporters.add (std::move (exp.exporter));
|
||||
|
||||
exporter->initialiseDependencyPathValues();
|
||||
|
||||
|
|
|
|||
|
|
@ -419,7 +419,7 @@ struct PluginTreeUtils
|
|||
if (current->plugins.size() + current->subFolders.size() > 0)
|
||||
{
|
||||
current->folder = lastType;
|
||||
tree.subFolders.add (current.release());
|
||||
tree.subFolders.add (std::move (current));
|
||||
current.reset (new KnownPluginList::PluginTree());
|
||||
}
|
||||
|
||||
|
|
@ -432,7 +432,7 @@ struct PluginTreeUtils
|
|||
if (current->plugins.size() + current->subFolders.size() > 0)
|
||||
{
|
||||
current->folder = lastType;
|
||||
tree.subFolders.add (current.release());
|
||||
tree.subFolders.add (std::move (current));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ public:
|
|||
|
||||
@see getUnchecked
|
||||
*/
|
||||
inline ObjectClass* operator[] (const int index) const noexcept
|
||||
inline ObjectClass* operator[] (int index) const noexcept
|
||||
{
|
||||
const ScopedLockType lock (getLock());
|
||||
return values.getValueWithDefault (index);
|
||||
|
|
@ -157,7 +157,7 @@ public:
|
|||
This is a faster and less safe version of operator[] which doesn't check the index passed in, so
|
||||
it can be used when you're sure the index is always going to be legal.
|
||||
*/
|
||||
inline ObjectClass* getUnchecked (const int index) const noexcept
|
||||
inline ObjectClass* getUnchecked (int index) const noexcept
|
||||
{
|
||||
const ScopedLockType lock (getLock());
|
||||
return values[index];
|
||||
|
|
@ -267,13 +267,55 @@ public:
|
|||
@returns the new object that was added
|
||||
@see set, insert, addIfNotAlreadyThere, addSorted
|
||||
*/
|
||||
ObjectClass* add (ObjectClass* newObject) noexcept
|
||||
ObjectClass* add (ObjectClass* newObject)
|
||||
{
|
||||
const ScopedLockType lock (getLock());
|
||||
values.add (newObject);
|
||||
return newObject;
|
||||
}
|
||||
|
||||
/** Appends a new object to the end of the array.
|
||||
|
||||
Note that the this object will be deleted by the OwnedArray when it
|
||||
is removed, so be careful not to delete it somewhere else.
|
||||
|
||||
Also be careful not to add the same object to the array more than once,
|
||||
as this will obviously cause deletion of dangling pointers.
|
||||
|
||||
@param newObject the new object to add to the array
|
||||
@returns the new object that was added
|
||||
@see set, insert, addIfNotAlreadyThere, addSorted
|
||||
*/
|
||||
ObjectClass* add (std::unique_ptr<ObjectClass> newObject)
|
||||
{
|
||||
return add (newObject.release());
|
||||
}
|
||||
|
||||
/** Inserts a new object into the array at the given index.
|
||||
|
||||
Note that the this object will be deleted by the OwnedArray when it
|
||||
is removed, so be careful not to delete it somewhere else.
|
||||
|
||||
If the index is less than 0 or greater than the size of the array, the
|
||||
element will be added to the end of the array.
|
||||
Otherwise, it will be inserted into the array, moving all the later elements
|
||||
along to make room.
|
||||
|
||||
Be careful not to add the same object to the array more than once,
|
||||
as this will obviously cause deletion of dangling pointers.
|
||||
|
||||
@param indexToInsertAt the index at which the new element should be inserted
|
||||
@param newObject the new object to add to the array
|
||||
@returns the new object that was added
|
||||
@see add, addSorted, addIfNotAlreadyThere, set
|
||||
*/
|
||||
ObjectClass* insert (int indexToInsertAt, ObjectClass* newObject)
|
||||
{
|
||||
const ScopedLockType lock (getLock());
|
||||
values.insert (indexToInsertAt, newObject, 1);
|
||||
return newObject;
|
||||
}
|
||||
|
||||
/** Inserts a new object into the array at the given index.
|
||||
|
||||
Note that the this object will be deleted by the OwnedArray when it
|
||||
|
|
@ -292,11 +334,9 @@ public:
|
|||
@returns the new object that was added
|
||||
@see add, addSorted, addIfNotAlreadyThere, set
|
||||
*/
|
||||
ObjectClass* insert (int indexToInsertAt, ObjectClass* newObject) noexcept
|
||||
ObjectClass* insert (int indexToInsertAt, std::unique_ptr<ObjectClass> newObject)
|
||||
{
|
||||
const ScopedLockType lock (getLock());
|
||||
values.insert (indexToInsertAt, newObject, 1);
|
||||
return newObject;
|
||||
return insert (indexToInsertAt, newObject.release());
|
||||
}
|
||||
|
||||
/** Inserts an array of values into this array at a given position.
|
||||
|
|
@ -322,25 +362,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
/** Appends a new object at the end of the array as long as the array doesn't
|
||||
already contain it.
|
||||
|
||||
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 new object was added, false otherwise
|
||||
*/
|
||||
bool addIfNotAlreadyThere (ObjectClass* newObject) noexcept
|
||||
{
|
||||
const ScopedLockType lock (getLock());
|
||||
|
||||
if (contains (newObject))
|
||||
return false;
|
||||
|
||||
add (newObject);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Replaces an object in the array with a different one.
|
||||
|
||||
If the index is less than zero, this method does nothing.
|
||||
|
|
@ -390,6 +411,24 @@ public:
|
|||
return newObject;
|
||||
}
|
||||
|
||||
/** Replaces an object in the array with a different one.
|
||||
|
||||
If the index is less than zero, this method does nothing.
|
||||
If the index is beyond the end of the array, the new object is added to the end of the array.
|
||||
|
||||
Be careful not to add the same object to the array more than once,
|
||||
as this will obviously cause deletion of dangling pointers.
|
||||
|
||||
@param indexToChange the index whose value you want to change
|
||||
@param newObject the new value to set for this index.
|
||||
@param deleteOldElement whether to delete the object that's being replaced with the new one
|
||||
@see add, insert, remove
|
||||
*/
|
||||
ObjectClass* set (int indexToChange, std::unique_ptr<ObjectClass> newObject, bool deleteOldElement = true)
|
||||
{
|
||||
return set (indexToChange, newObject.release(), deleteOldElement);
|
||||
}
|
||||
|
||||
/** Adds elements from another array to the end of this array.
|
||||
|
||||
@param arrayToAddFrom the array from which to copy the elements
|
||||
|
|
@ -468,14 +507,14 @@ public:
|
|||
@see add, sort, indexOfSorted
|
||||
*/
|
||||
template <class ElementComparator>
|
||||
int addSorted (ElementComparator& comparator, ObjectClass* const newObject) noexcept
|
||||
int addSorted (ElementComparator& comparator, ObjectClass* newObject) noexcept
|
||||
{
|
||||
// If you pass in an object with a static compareElements() method, this
|
||||
// avoids getting warning messages about the parameter being unused
|
||||
ignoreUnused (comparator);
|
||||
|
||||
const ScopedLockType lock (getLock());
|
||||
const int index = findInsertIndexInSortedArray (comparator, values.begin(), newObject, 0, values.size());
|
||||
auto index = findInsertIndexInSortedArray (comparator, values.begin(), newObject, 0, values.size());
|
||||
insert (index, newObject);
|
||||
return index;
|
||||
}
|
||||
|
|
@ -493,7 +532,7 @@ public:
|
|||
@see addSorted, sort
|
||||
*/
|
||||
template <typename ElementComparator>
|
||||
int indexOfSorted (ElementComparator& comparator, const ObjectClass* const objectToLookFor) const noexcept
|
||||
int indexOfSorted (ElementComparator& comparator, const ObjectClass* objectToLookFor) const noexcept
|
||||
{
|
||||
// If you pass in an object with a static compareElements() method, this
|
||||
// avoids getting warning messages about the parameter being unused
|
||||
|
|
@ -722,7 +761,7 @@ public:
|
|||
the array won't have to keep dynamically resizing itself as the elements
|
||||
are added, and it'll therefore be more efficient.
|
||||
*/
|
||||
void ensureStorageAllocated (const int minNumElements) noexcept
|
||||
void ensureStorageAllocated (int minNumElements) noexcept
|
||||
{
|
||||
const ScopedLockType lock (getLock());
|
||||
values.ensureAllocatedSize (minNumElements);
|
||||
|
|
|
|||
|
|
@ -1183,7 +1183,7 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
|||
if (matchIf (TokenTypes::comma))
|
||||
{
|
||||
std::unique_ptr<BlockStatement> block (new BlockStatement (location));
|
||||
block->statements.add (s.release());
|
||||
block->statements.add (std::move (s));
|
||||
block->statements.add (parseVar());
|
||||
return block.release();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ bool UndoManager::perform (UndoableAction* newAction)
|
|||
}
|
||||
|
||||
totalUnitsStored += action->getSizeInUnits();
|
||||
actionSet->actions.add (action.release());
|
||||
actionSet->actions.add (std::move (action));
|
||||
newTransaction = false;
|
||||
|
||||
moveFutureTransactionsToStash();
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ bool DirectoryContentsList::addFile (const File& file, const bool isDir,
|
|||
if (files.getUnchecked(i)->filename == info->filename)
|
||||
return false;
|
||||
|
||||
files.add (info.release());
|
||||
files.add (std::move (info));
|
||||
|
||||
std::sort (files.begin(), files.end(), [] (const FileInfo* a, const FileInfo* b)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue