mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Return object in OwnedArray add routines
This commit is contained in:
@@ -242,14 +242,23 @@ public:
|
||||
as this will obviously cause deletion of dangling pointers.
|
||||
|
||||
@param newObject the new object to add to the array
|
||||
@returns the object that was added
|
||||
|
||||
@see set, insert, addIfNotAlreadyThere, addSorted
|
||||
*/
|
||||
void add (const ObjectClass* const newObject) noexcept
|
||||
ObjectClass const& add (ObjectClass const* const newObject) noexcept
|
||||
{
|
||||
const ScopedLockType lock (getLock());
|
||||
data.ensureAllocatedSize (numUsed + 1);
|
||||
bassert (data.elements != nullptr);
|
||||
data.elements [numUsed++] = const_cast <ObjectClass*> (newObject);
|
||||
return *newObject;
|
||||
}
|
||||
|
||||
ObjectClass& add (ObjectClass* const newObject) noexcept
|
||||
{
|
||||
add (const_cast <ObjectClass const*> (newObject));
|
||||
return *newObject;
|
||||
}
|
||||
|
||||
/** Inserts a new object into the array at the given index.
|
||||
@@ -267,10 +276,12 @@ public:
|
||||
|
||||
@param indexToInsertAt the index at which the new element should be inserted
|
||||
@param newObject the new object to add to the array
|
||||
@returns the object that was added
|
||||
|
||||
@see add, addSorted, addIfNotAlreadyThere, set
|
||||
*/
|
||||
void insert (int indexToInsertAt,
|
||||
const ObjectClass* const newObject) noexcept
|
||||
ObjectClass const& insert (int indexToInsertAt,
|
||||
ObjectClass const* const newObject) noexcept
|
||||
{
|
||||
if (indexToInsertAt >= 0)
|
||||
{
|
||||
@@ -295,6 +306,15 @@ public:
|
||||
{
|
||||
add (newObject);
|
||||
}
|
||||
|
||||
return *newObject;
|
||||
}
|
||||
|
||||
ObjectClass& insert (int indexToInsertAt,
|
||||
ObjectClass* const newObject) noexcept
|
||||
{
|
||||
insert (indexToInsertAt, const_cast <ObjectClass const*> (newObject));
|
||||
return *newObject;
|
||||
}
|
||||
|
||||
/** Inserts an array of values into this array at a given position.
|
||||
@@ -343,13 +363,22 @@ 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 object
|
||||
*/
|
||||
void addIfNotAlreadyThere (const ObjectClass* const newObject) noexcept
|
||||
ObjectClass const& addIfNotAlreadyThere (ObjectClass const* const newObject) noexcept
|
||||
{
|
||||
const ScopedLockType lock (getLock());
|
||||
|
||||
if (! contains (newObject))
|
||||
add (newObject);
|
||||
|
||||
return *newObject;
|
||||
}
|
||||
|
||||
ObjectClass& addIfNotAlreadyThere (ObjectClass* const newObject) noexcept
|
||||
{
|
||||
addIfNotAlreadyThere (const_cast <ObjectClass const*> (newObject));
|
||||
return *newObject;
|
||||
}
|
||||
|
||||
/** Replaces an object in the array with a different one.
|
||||
@@ -363,11 +392,13 @@ public:
|
||||
@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
|
||||
@returns the object that was set
|
||||
|
||||
@see add, insert, remove
|
||||
*/
|
||||
void set (const int indexToChange,
|
||||
const ObjectClass* const newObject,
|
||||
const bool deleteOldElement = true)
|
||||
ObjectClass const& set (int const indexToChange,
|
||||
ObjectClass const* const newObject,
|
||||
bool const deleteOldElement = true)
|
||||
{
|
||||
if (indexToChange >= 0)
|
||||
{
|
||||
@@ -404,6 +435,16 @@ public:
|
||||
bassertfalse; // you're trying to set an object at a negative index, which doesn't have
|
||||
// any effect - but since the object is not being added, it may be leaking..
|
||||
}
|
||||
|
||||
return *newObject;
|
||||
}
|
||||
|
||||
ObjectClass& set (int const indexToChange,
|
||||
ObjectClass* const newObject,
|
||||
bool const deleteOldElement = true)
|
||||
{
|
||||
set (indexToChange, const_cast <ObjectClass const*> (newObject), deleteOldElement);
|
||||
return *newObject;
|
||||
}
|
||||
|
||||
/** Adds elements from another array to the end of this array.
|
||||
|
||||
Reference in New Issue
Block a user