issue #2790: Vector::remove —> Vector::erase.

This commit is contained in:
James Chen 2013-12-11 17:50:30 +08:00
parent b66fccb5ab
commit 093e310cab
1 changed files with 48 additions and 30 deletions

View File

@ -37,6 +37,34 @@ template<class T>
class CC_DLL Vector
{
public:
// ------------------------------------------
// Iterators
// ------------------------------------------
typedef typename std::vector<T>::iterator iterator;
typedef typename std::vector<T>::const_iterator const_iterator;
typedef typename std::vector<T>::reverse_iterator reverse_iterator;
typedef typename std::vector<T>::const_reverse_iterator const_reverse_iterator;
iterator begin() { return _data.begin(); }
const_iterator begin() const { return _data.begin(); }
iterator end() { return _data.end(); }
const_iterator end() const { return _data.end(); }
const_iterator cbegin() const { return _data.cbegin(); }
const_iterator cend() const { return _data.cend(); }
reverse_iterator rbegin() { return _data.rbegin(); }
const_reverse_iterator rbegin() const { return _data.rbegin(); }
reverse_iterator rend() { return _data.rend(); }
const_reverse_iterator rend() const { return _data.rend(); }
const_reverse_iterator crbegin() const { return _data.crbegin(); }
const_reverse_iterator crend() const { return _data.crend(); }
/** Constructor */
Vector<T>()
: _data()
{
@ -228,9 +256,9 @@ public:
_data.pop_back();
last->release();
}
/** Remove a certain object */
void removeObject(T object, bool toRelease = true)
void erase(T object, bool toRelease = true)
{
CCASSERT(object != nullptr, "The object should not be nullptr");
auto iter = std::find(_data.begin(), _data.end(), object);
@ -241,7 +269,24 @@ public:
}
/** Removes an element with a certain index */
void remove(int index)
iterator erase(const_iterator position)
{
CCASSERT(position >= _data.begin() && position < _data.end(), "Invalid position!");
(*position)->release();
return _data.erase(position);
}
iterator erase(const_iterator first, const_iterator last)
{
for (auto iter = first; iter != last; ++iter)
{
(*iter)->release();
}
return _data.erase(first, last);
}
void erase(int index)
{
CCASSERT(!_data.empty() && index >=0 && index < size(), "Invalid index!");
auto it = std::next( begin(), index );
@ -352,33 +397,6 @@ public:
});
}
// ------------------------------------------
// Iterators
// ------------------------------------------
typedef typename std::vector<T>::iterator iterator;
typedef typename std::vector<T>::const_iterator const_iterator;
typedef typename std::vector<T>::reverse_iterator reverse_iterator;
typedef typename std::vector<T>::const_reverse_iterator const_reverse_iterator;
iterator begin() { return _data.begin(); }
const_iterator begin() const { return _data.begin(); }
iterator end() { return _data.end(); }
const_iterator end() const { return _data.end(); }
const_iterator cbegin() const { return _data.cbegin(); }
const_iterator cend() const { return _data.cend(); }
reverse_iterator rbegin() { return _data.rbegin(); }
const_reverse_iterator rbegin() const { return _data.rbegin(); }
reverse_iterator rend() { return _data.rend(); }
const_reverse_iterator rend() const { return _data.rend(); }
const_reverse_iterator crbegin() const { return _data.crbegin(); }
const_reverse_iterator crend() const { return _data.crend(); }
protected:
void addRefForAllObjects()