2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: vector.h
|
2008-03-10 15:24:38 +00:00
|
|
|
// Purpose: interface of wxVector<T>
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-21 14:51:28 +00: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 14:43:31 +00:00
|
|
|
|
2008-04-28 08:26:04 +00: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 14:51:28 +00:00
|
|
|
|
|
|
|
Please refer to the STL documentation for further information.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-22 16:07:29 +00:00
|
|
|
@nolibrary
|
2008-03-21 14:51:28 +00:00
|
|
|
@category{containers}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2010-04-07 20:32:25 +00:00
|
|
|
@see @ref overview_container, wxList<T>, wxArray<T>, wxVectorSort<T>
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-21 14:51:28 +00:00
|
|
|
template<typename T>
|
2008-03-08 14:43:31 +00:00
|
|
|
class wxVector<T>
|
2008-03-08 13:52:38 +00:00
|
|
|
{
|
|
|
|
public:
|
2008-03-21 14:51:28 +00:00
|
|
|
typedef size_t size_type;
|
2008-09-16 12:43:11 +00:00
|
|
|
typedef size_t difference_type;
|
2008-03-21 14:51:28 +00:00
|
|
|
typedef T value_type;
|
2008-09-16 12:43:11 +00:00
|
|
|
typedef value_type* pointer;
|
2008-03-21 14:51:28 +00:00
|
|
|
typedef value_type* iterator;
|
|
|
|
typedef const value_type* const_iterator;
|
|
|
|
typedef value_type& reference;
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
*/
|
2008-03-21 14:51:28 +00:00
|
|
|
wxVector();
|
|
|
|
|
2008-11-29 22:28:44 +00: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 14:51:28 +00:00
|
|
|
/**
|
2011-04-03 20:31:32 +00:00
|
|
|
Copy constructor.
|
2008-03-21 14:51:28 +00:00
|
|
|
*/
|
|
|
|
wxVector(const wxVector<T>& c);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-03-21 14:51:28 +00:00
|
|
|
~wxVector();
|
|
|
|
|
|
|
|
/**
|
2008-04-28 08:26:04 +00:00
|
|
|
Returns item at position @a idx.
|
2008-03-21 14:51:28 +00:00
|
|
|
*/
|
|
|
|
const value_type& at(size_type idx) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-28 08:26:04 +00:00
|
|
|
Returns item at position @a idx.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-21 14:51:28 +00:00
|
|
|
value_type& at(size_type idx);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-21 14:51:28 +00:00
|
|
|
Return the last item.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-21 14:51:28 +00: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 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return iterator to beginning of the vector.
|
|
|
|
*/
|
2008-03-21 14:51:28 +00:00
|
|
|
iterator begin();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2008-09-16 12:43:11 +00:00
|
|
|
/**
|
|
|
|
Return reverse iterator to end of the vector.
|
|
|
|
*/
|
|
|
|
reverse_iterator rbegin();
|
2008-12-11 13:45:04 +00:00
|
|
|
|
2008-09-16 12:43:11 +00:00
|
|
|
/**
|
|
|
|
Return reverse iterator to beginning of the vector.
|
|
|
|
*/
|
|
|
|
reverse_iterator rend();
|
|
|
|
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
2008-03-21 14:51:28 +00:00
|
|
|
Returns vector's current capacity, i.e. how much memory is allocated.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-21 14:51:28 +00:00
|
|
|
@see reserve()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
size_type capacity() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Clears the vector.
|
|
|
|
*/
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the vector is empty.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool empty() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns iterator to the end of the vector.
|
|
|
|
*/
|
2008-03-21 14:51:28 +00:00
|
|
|
const_iterator end() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns iterator to the end of the vector.
|
|
|
|
*/
|
|
|
|
iterator end();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-21 14:51:28 +00:00
|
|
|
Erase item pointed to by iterator @a it.
|
|
|
|
|
|
|
|
@return Iterator pointing to the item immediately after the erased one.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
iterator erase(iterator it);
|
2008-03-21 14:51:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Erase items in the range @a first to @a last (@a last is not erased).
|
|
|
|
|
2008-04-28 08:26:04 +00:00
|
|
|
@return Iterator pointing to the item immediately after the erased
|
|
|
|
range.
|
2008-03-21 14:51:28 +00:00
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
iterator erase(iterator first, iterator last);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-21 14:51:28 +00:00
|
|
|
Returns the first item.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-21 14:51:28 +00:00
|
|
|
const value_type& front() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-21 14:51:28 +00:00
|
|
|
Returns the first item.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-21 14:51:28 +00: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 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Assignment operator.
|
|
|
|
*/
|
2008-04-28 08:26:04 +00:00
|
|
|
wxVector& operator=(const wxVector& vb);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-28 08:26:04 +00:00
|
|
|
Returns item at position @a idx.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-21 14:51:28 +00:00
|
|
|
const value_type& operator[](size_type idx) const;
|
|
|
|
|
|
|
|
/**
|
2008-04-28 08:26:04 +00:00
|
|
|
Returns item at position @a idx.
|
2008-03-21 14:51:28 +00:00
|
|
|
*/
|
|
|
|
value_type& operator[](size_type idx);
|
2008-03-08 13:52:38 +00: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 14:51:28 +00:00
|
|
|
Reserves memory for at least @a n items.
|
|
|
|
|
|
|
|
@see capacity()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void reserve(size_type n);
|
2008-04-28 08:26:04 +00:00
|
|
|
|
2008-12-11 13:45:04 +00: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 08:26:04 +00:00
|
|
|
/**
|
|
|
|
Returns the size of the vector.
|
|
|
|
*/
|
|
|
|
size_type size() const;
|
2010-07-22 12:09:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Efficiently exchanges contents of this vector with another one.
|
|
|
|
|
|
|
|
After the execution of this function the contents of this vector is
|
|
|
|
equal to the original contents of @a v and the contents of @a v becomes
|
|
|
|
the original contents of this vector without copying the data.
|
|
|
|
|
|
|
|
@since 2.9.1
|
|
|
|
*/
|
|
|
|
void swap(wxVector& v);
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2010-04-07 20:32:25 +00: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
|
2010-07-22 12:09:20 +00:00
|
|
|
|
2010-04-07 20:32:25 +00:00
|
|
|
@see wxVector<T>
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
void wxVectorSort(wxVector<T>& v);
|