Add iterators to wxVector, use std::vector in STL mode, correct wxVector::erase()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47712 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -200,7 +200,7 @@ public:
|
|||||||
if( ptr == m_vec.size() ) return;
|
if( ptr == m_vec.size() ) return;
|
||||||
if( doDelete )
|
if( doDelete )
|
||||||
delete m_vec[ptr].data;
|
delete m_vec[ptr].data;
|
||||||
m_vec.erase( ptr );
|
m_vec.erase( m_vec.begin() + ptr );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -244,7 +244,7 @@ public:
|
|||||||
{
|
{
|
||||||
if( doDelete )
|
if( doDelete )
|
||||||
delete m_vec[todel].data;
|
delete m_vec[todel].data;
|
||||||
m_vec.erase( todel );
|
m_vec.erase( m_vec.begin() + todel );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
@@ -14,10 +14,8 @@
|
|||||||
|
|
||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
|
|
||||||
#if 0 // wxUSE_STL
|
#if wxUSE_STL
|
||||||
|
|
||||||
// FIXME: can't do this yet, wxVector::erase() is different (takes index,
|
|
||||||
// not iterator)
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#define wxVector std::vector
|
#define wxVector std::vector
|
||||||
|
|
||||||
@@ -29,6 +27,8 @@ class wxVector
|
|||||||
public:
|
public:
|
||||||
typedef size_t size_type;
|
typedef size_t size_type;
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
|
typedef value_type* iterator;
|
||||||
|
typedef value_type& reference;
|
||||||
|
|
||||||
wxVector() : m_allocsize(16), m_size(0), m_capacity(0), m_objects(0) {}
|
wxVector() : m_allocsize(16), m_size(0), m_capacity(0), m_objects(0) {}
|
||||||
|
|
||||||
@@ -110,10 +110,28 @@ public:
|
|||||||
const value_type& back() const { return at(size() - 1); }
|
const value_type& back() const { return at(size() - 1); }
|
||||||
value_type& back() { return at(size() - 1); }
|
value_type& back() { return at(size() - 1); }
|
||||||
|
|
||||||
size_type erase(size_type idx)
|
iterator begin() { return m_objects[0]; }
|
||||||
|
iterator end() { return m_objects[size()]; }
|
||||||
|
|
||||||
|
iterator erase(iterator first, iterator last)
|
||||||
{
|
{
|
||||||
|
size_type idx = first - begin();
|
||||||
|
RemoveAt(idx, last - first);
|
||||||
|
return begin() + idx;
|
||||||
|
}
|
||||||
|
iterator erase(iterator it)
|
||||||
|
{
|
||||||
|
size_type idx = it - begin();
|
||||||
RemoveAt(idx);
|
RemoveAt(idx);
|
||||||
return idx;
|
return begin() + idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
iterator insert(iterator it, const value_type& v = value_type())
|
||||||
|
{
|
||||||
|
wxCHECK2(Alloc(size() + 1), return 0);
|
||||||
|
size_type idx = it - begin();
|
||||||
|
InsertAt(new value_type(o), idx);
|
||||||
|
return begin() + idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -141,6 +159,19 @@ private:
|
|||||||
m_size++;
|
m_size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InsertAt(size_type idx, value_type *obj)
|
||||||
|
{
|
||||||
|
wxASSERT(idx <= m_size);
|
||||||
|
wxASSERT(m_size < m_capacity);
|
||||||
|
if (idx < m_size)
|
||||||
|
memmove(
|
||||||
|
m_objects + idx + 1,
|
||||||
|
m_objects + idx,
|
||||||
|
( m_size - idx ) * sizeof(value_type*) );
|
||||||
|
|
||||||
|
m_size++;
|
||||||
|
}
|
||||||
|
|
||||||
void RemoveAt(size_type idx)
|
void RemoveAt(size_type idx)
|
||||||
{
|
{
|
||||||
wxASSERT(idx < m_size);
|
wxASSERT(idx < m_size);
|
||||||
@@ -149,10 +180,25 @@ private:
|
|||||||
memcpy(
|
memcpy(
|
||||||
m_objects + idx,
|
m_objects + idx,
|
||||||
m_objects + idx + 1,
|
m_objects + idx + 1,
|
||||||
( m_size - idx - 1 ) * sizeof(void*) );
|
( m_size - idx - 1 ) * sizeof(value_type*) );
|
||||||
m_size--;
|
m_size--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RemoveAt(size_type idx, size_type count)
|
||||||
|
{
|
||||||
|
if (count == 0)
|
||||||
|
return;
|
||||||
|
wxASSERT(idx < m_size);
|
||||||
|
size_type i;
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
delete m_objects[idx+1];
|
||||||
|
if (idx < m_size - count)
|
||||||
|
memcpy(
|
||||||
|
m_objects + idx,
|
||||||
|
m_objects + idx + count,
|
||||||
|
( m_size - idx - count ) * sizeof(value_type*) );
|
||||||
|
m_size -= count;
|
||||||
|
}
|
||||||
bool Copy(const wxVector& vb)
|
bool Copy(const wxVector& vb)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
Reference in New Issue
Block a user