2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: vector.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxVector<T>
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-21 10:51:28 -04:00
|
|
|
wxVector<T> is a template class which implements most of the @c std::vector
|
|
|
|
class and can be used like it.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
If wxWidgets is compiled in STL mode, wxVector will just be a typedef to
|
|
|
|
@c std::vector. Just like for @c std::vector, objects stored in wxVector<T>
|
|
|
|
need to be @e assignable but don't have to be @e "default constructible".
|
2008-03-21 10:51:28 -04:00
|
|
|
|
|
|
|
Please refer to the STL documentation for further information.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-22 12:07:29 -04:00
|
|
|
@nolibrary
|
2008-03-21 10:51:28 -04:00
|
|
|
@category{containers}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2010-04-07 16:32:25 -04:00
|
|
|
@see @ref overview_container, wxList<T>, wxArray<T>, wxVectorSort<T>
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-21 10:51:28 -04:00
|
|
|
template<typename T>
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxVector<T>
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
2008-03-21 10:51:28 -04:00
|
|
|
typedef size_t size_type;
|
2008-09-16 08:43:11 -04:00
|
|
|
typedef size_t difference_type;
|
2008-03-21 10:51:28 -04:00
|
|
|
typedef T value_type;
|
2008-09-16 08:43:11 -04:00
|
|
|
typedef value_type* pointer;
|
2008-03-21 10:51:28 -04:00
|
|
|
typedef value_type* iterator;
|
|
|
|
typedef const value_type* const_iterator;
|
|
|
|
typedef value_type& reference;
|
|
|
|
|
2008-09-16 08:43:11 -04:00
|
|
|
/**
|
|
|
|
Reverse iterator interface
|
|
|
|
*/
|
|
|
|
class reverse_iterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
reverse_iterator();
|
|
|
|
explicit reverse_iterator(iterator it);
|
|
|
|
reverse_iterator(const reverse_iterator& it);
|
|
|
|
reference operator*() const;
|
|
|
|
pointer operator->() const;
|
|
|
|
iterator base() const;
|
|
|
|
reverse_iterator& operator++();
|
|
|
|
reverse_iterator operator++(int);
|
|
|
|
reverse_iterator& operator--();
|
|
|
|
reverse_iterator operator--(int);
|
|
|
|
reverse_iterator operator+(difference_type n) const;
|
|
|
|
reverse_iterator& operator+=(difference_type n);
|
|
|
|
reverse_iterator operator-(difference_type n) const;
|
|
|
|
reverse_iterator& operator-=(difference_type n);
|
|
|
|
reference operator[](difference_type n) const;
|
|
|
|
bool operator ==(const reverse_iterator& it) const;
|
|
|
|
bool operator !=(const reverse_iterator& it) const;
|
|
|
|
};
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
*/
|
2008-03-21 10:51:28 -04:00
|
|
|
wxVector();
|
|
|
|
|
2008-11-29 17:28:44 -05:00
|
|
|
/**
|
|
|
|
Constructor initializing the vector with the given number of
|
|
|
|
default-constructed objects.
|
|
|
|
*/
|
|
|
|
wxVector(size_type size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructor initializing the vector with the given number of
|
|
|
|
copies of the given object.
|
|
|
|
*/
|
|
|
|
wxVector(size_type size, const value_type& value);
|
|
|
|
|
2008-03-21 10:51:28 -04:00
|
|
|
/**
|
|
|
|
Copy onstructor.
|
|
|
|
*/
|
|
|
|
wxVector(const wxVector<T>& c);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-03-21 10:51:28 -04:00
|
|
|
~wxVector();
|
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Returns item at position @a idx.
|
2008-03-21 10:51:28 -04:00
|
|
|
*/
|
|
|
|
const value_type& at(size_type idx) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Returns item at position @a idx.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-21 10:51:28 -04:00
|
|
|
value_type& at(size_type idx);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-21 10:51:28 -04:00
|
|
|
Return the last item.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-21 10:51:28 -04:00
|
|
|
const value_type& back() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return the last item.
|
|
|
|
*/
|
|
|
|
value_type& back();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return iterator to beginning of the vector.
|
|
|
|
*/
|
|
|
|
const_iterator begin() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return iterator to beginning of the vector.
|
|
|
|
*/
|
2008-03-21 10:51:28 -04:00
|
|
|
iterator begin();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-09-16 08:43:11 -04:00
|
|
|
/**
|
|
|
|
Return reverse iterator to end of the vector.
|
|
|
|
*/
|
|
|
|
reverse_iterator rbegin();
|
2008-12-11 08:45:04 -05:00
|
|
|
|
2008-09-16 08:43:11 -04:00
|
|
|
/**
|
|
|
|
Return reverse iterator to beginning of the vector.
|
|
|
|
*/
|
|
|
|
reverse_iterator rend();
|
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-03-21 10:51:28 -04:00
|
|
|
Returns vector's current capacity, i.e. how much memory is allocated.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-21 10:51:28 -04:00
|
|
|
@see reserve()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
size_type capacity() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Clears the vector.
|
|
|
|
*/
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the vector is empty.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool empty() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns iterator to the end of the vector.
|
|
|
|
*/
|
2008-03-21 10:51:28 -04:00
|
|
|
const_iterator end() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns iterator to the end of the vector.
|
|
|
|
*/
|
|
|
|
iterator end();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-21 10:51:28 -04:00
|
|
|
Erase item pointed to by iterator @a it.
|
|
|
|
|
|
|
|
@return Iterator pointing to the item immediately after the erased one.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
iterator erase(iterator it);
|
2008-03-21 10:51:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Erase items in the range @a first to @a last (@a last is not erased).
|
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
@return Iterator pointing to the item immediately after the erased
|
|
|
|
range.
|
2008-03-21 10:51:28 -04:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
iterator erase(iterator first, iterator last);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-21 10:51:28 -04:00
|
|
|
Returns the first item.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-21 10:51:28 -04:00
|
|
|
const value_type& front() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-21 10:51:28 -04:00
|
|
|
Returns the first item.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-21 10:51:28 -04:00
|
|
|
value_type& front();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Insert item @a v at given position @a it.
|
|
|
|
|
|
|
|
@return Iterator for the inserted item.
|
|
|
|
*/
|
|
|
|
iterator insert(iterator it, const value_type& v = value_type());
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Assignment operator.
|
|
|
|
*/
|
2008-04-28 04:26:04 -04:00
|
|
|
wxVector& operator=(const wxVector& vb);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Returns item at position @a idx.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-21 10:51:28 -04:00
|
|
|
const value_type& operator[](size_type idx) const;
|
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Returns item at position @a idx.
|
2008-03-21 10:51:28 -04:00
|
|
|
*/
|
|
|
|
value_type& operator[](size_type idx);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Removes the last item.
|
|
|
|
*/
|
|
|
|
void pop_back();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Adds an item to the end of the vector.
|
|
|
|
*/
|
|
|
|
void push_back(const value_type& v);
|
|
|
|
|
|
|
|
/**
|
2008-03-21 10:51:28 -04:00
|
|
|
Reserves memory for at least @a n items.
|
|
|
|
|
|
|
|
@see capacity()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void reserve(size_type n);
|
2008-04-28 04:26:04 -04:00
|
|
|
|
2008-12-11 08:45:04 -05:00
|
|
|
/**
|
|
|
|
Makes the vector of size @a n.
|
|
|
|
|
|
|
|
If @a n is less than the current size(), the elements at the end of the
|
|
|
|
vector are erased. If it is greater, then the vector is completed with
|
|
|
|
either the copies of the given object @a v or @c value_type() objects
|
|
|
|
until it becomes of size @a n.
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
void resize(size_type n);
|
|
|
|
void resize(size_type n, const value_type& v);
|
|
|
|
//@}
|
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
/**
|
|
|
|
Returns the size of the vector.
|
|
|
|
*/
|
|
|
|
size_type size() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2010-04-07 16:32:25 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sort the contents of a @c wxVector<T>. In a STL build this function will
|
|
|
|
be defined as a thin wrapper around std::sort. To be sortable the
|
|
|
|
contained type must support the less-than operator.
|
|
|
|
|
|
|
|
@code
|
|
|
|
wxVector<SomeClass> v;
|
|
|
|
... // items are added to the vector v...
|
|
|
|
wxVectorSort(v);
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
@see wxVector<T>
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
void wxVectorSort(wxVector<T>& v);
|