issue #2790: Adds Vector<T>::sort method, adds Vector::removeObject(object, toRemoved).

This commit is contained in:
James Chen 2013-12-07 14:18:42 +08:00
parent a12a101548
commit 6f13a111ae
1 changed files with 13 additions and 2 deletions

View File

@ -230,13 +230,14 @@ public:
}
/** Remove a certain object */
void removeObject(T object)
void removeObject(T object, bool toRelease = true)
{
CCASSERT(object != nullptr, "The object should not be nullptr");
auto iter = std::find(_data.begin(), _data.end(), object);
if (iter != _data.end())
_data.erase(iter);
object->release();
if (toRelease)
object->release();
}
/** Removes an element with a certain index */
@ -341,6 +342,16 @@ public:
});
}
void sort(const std::function<bool(T, T)>& callback)
{
if (empty())
return;
std::sort(_data.begin(), _data.end(), [&callback](T a, T b) -> bool{
return callback(a, b);
});
}
// ------------------------------------------
// Iterators
// ------------------------------------------