wxList<T>The wxList<T> class provides linked list functionality. It has been written to be type safe and to provide the full API of the STL std::list container and should be used like it. The exception is that wxList<T> actually stores pointers and therefore its iterators return pointers and not references to the actual objets in the list (see example below). In other words value_type is defined as T*. Unfortunately, the new wxList<T> class requires that you declare and define each wxList<T> class in your program. This is done with WX_DECLARE_LIST and WX_DEFINE_LIST macros (see example). We hope that we'll be able to provide a proper template class providing both the STL std::list and the old wxList API in the future. Please refer to the STL std::list documentation for further information on how to use the class. Below we documented both the supported STL and the legacy API that originated from the old wxList class and which can still be used alternatively for the the same class. Note that if you compile wxWidgets in STL mode (wxUSE_STL defined as 1) then wxList<T> will actually derive from std::list and just add a legacy compatibility layer for the old wxList class. Example
// this part might be in a header or source (.cpp) file class MyListElement { ... // whatever }; // this macro declares and partly implements MyList class WX_DECLARE_LIST(MyListElement, MyList); ... // the only requirement for the rest is to be AFTER the full declaration of // MyListElement (for WX_DECLARE_LIST forward declaration is enough), but // usually it will be found in the source file and not in the header #include <wx/listimpl.cpp> WX_DEFINE_LIST(MyList); MyList list; MyListElement element; list.Append(&element); // ok list.Append(17); // error: incorrect type // let's iterate over the list in STL syntax MyList::iterator iter; for (iter = list.begin(); iter != list.end(); ++iter) { MyListElement *current = *iter; ...process the current element... } // the same with the legacy API from the old wxList class MyList::compatibility_iterator node = list.GetFirst(); while (node) { MyListElement *current = node->GetData(); ...process the current element... node = node->GetNext(); }For compatibility with previous versions wxList and wxStringList classes are still defined, but their usage is deprecated and they will disappear in the future versions completely. The use of the latter is especially discouraged as it is not only unsafe but is also much less efficient than wxArrayString class. Include files <wx/list.h> Library See also Members
wxList<T>::wxList<T>
wxList<T>::wxList<T>wxList<T>() wxList<T>(size_t count, T *elements[]) Constructors.
wxList<T>::~wxList<T>~wxList<T>() Destroys the list, but does not delete the objects stored in the list unless you called DeleteContents(true ).
wxList<T>::AppendwxList<T>::compatibility_iterator Append(T *object) Appends the pointer to object to the list.
wxList<T>::Clearvoid Clear() Clears the list, but does not delete the objects stored in the list unless you called DeleteContents(true ).
wxList<T>::DeleteContentsvoid DeleteContents(bool destroy) If destroy is true, instructs the list to call delete on objects stored in the list whenever they are removed. The default is false.
wxList<T>::DeleteNodebool DeleteNode(const compatibility_iterator&iter) Deletes the given element refered to by iter from the list, returning true if successful.
wxList<T>::DeleteObjectbool DeleteObject(T *object) Finds the given object and removes it from the list, returning true if successful. The application must delete the actual object separately.
wxList<T>::Erasevoid Erase(const compatibility_iterator&iter) Removes element refered to be iter.
wxList<T>::FindwxList<T>::compatibility_iterator Find(T * object) const Returns the iterator refering to object or NULL if none found.
wxList<T>::GetCountsize_t GetCount() const Returns the number of elements in the list.
wxList<T>::GetFirstwxList<T>::compatibility_iterator GetFirst() const Returns the first iterator in the list (NULL if the list is empty).
wxList<T>::GetLastwxList<T>::compatibility_iterator GetLast() const Returns the last iterator in the list (NULL if the list is empty).
wxList<T>::IndexOfint IndexOf(T* obj ) const Returns the index of obj within the list or wxNOT_FOUND if obj is not found in the list.
wxList<T>::InsertwxList<T>::compatibility_iterator Insert(T *object) Insert object at the front of list. wxList<T>::compatibility_iterator Insert(size_t position, T *object) Insert object before position, i.e. the index of the new item in the list will be equal to position. position should be less than or equal to GetCount; if it is equal to it, this is the same as calling Append. wxList<T>::compatibility_iterator Insert(compatibility_iteratoriter, T *object) Inserts the object before the object refered to be iter.
wxList<T>::IsEmptybool IsEmpty() const Returns true if the list is empty, false otherwise.
wxList<T>::ItemwxList<T>::compatibility_iterator Item(size_t index) const Returns the iterator refering to the object at the given index in the list.
wxList<T>::MemberwxList<T>::compatibility_iterator Member(T * object) const NB: This function is deprecated, use Find instead.
wxList<T>::NthwxList<T>::compatibility_iterator Nth(int n) const NB: This function is deprecated, use Item instead. Returns the nth node in the list, indexing from zero (NULL if the list is empty or the nth node could not be found).
wxList<T>::Numberint Number() const NB: This function is deprecated, use GetCount instead. Returns the number of elements in the list.
wxList<T>::Sortvoid Sort(wxSortCompareFunction compfunc)
// Type of compare function for list sort operation (as in 'qsort') typedef int (*wxSortCompareFunction)(const void *elem1, const void *elem2);Allows the sorting of arbitrary lists by giving a function to compare two list elements. We use the system qsort function for the actual sorting process.
wxList<T>::assignvoid assign(const_iterator first, const const_iterator& last) void assign(size_type n, const_reference v = value_type())
wxList<T>::backreference back() const_reference back() const Returns the last item of the list.
wxList<T>::beginiterator begin() const_iterator begin() const Returns a (const) iterator pointing to the beginning of the list.
wxList<T>::clearvoid clear() Removes all items from the list.
wxList<T>::emptybool empty() const Returns true if the list is empty.
wxList<T>::enditerator end() const_iterator end() const Returns a (const) iterator pointing at the end of the list.
wxList<T>::eraseiterator erase(const iterator& it) Erases the item pointed to by it. iterator erase(const iterator& first, const iterator& last) Erases the items from first to last.
wxList<T>::frontreference front() const_reference front() const Returns the first item in the list.
wxList<T>::insertiterator insert(const iterator& it, const_reference v = value_type()) void insert(const iterator& it, size_type n, const_reference v = value_type()) void insert(const iterator& it, const_iterator first, const const_iterator& last) Inserts an item (or several) at the given position.
wxList<T>::max_sizesize_type max_size() const Returns the largest possible size of the list.
wxList<T>::pop_backvoid pop_back() Removes the list item.
wxList<T>::pop_frontvoid pop_front() Removes the first item.
wxList<T>::push_backvoid push_back(const_reference v = value_type()) Adds an item to end of the list.
wxList<T>::push_frontvoid push_front(const_reference v = value_type()) Adds an item to the front of the list.
wxList<T>::rbeginreverse_iterator rbegin() const_reverse_iterator rbegin() const Returns a (const) reverse iterator pointer to the beginning of the reversed list.
wxList<T>::removevoid remove(const_reference v) Removes an item from the list.
wxList<T>::rendreverse_iterator rend() const_reverse_iterator rend() const Returns a (const) reverse iterator pointer to the end of the reversed list.
wxList<T>::resizevoid resize(size_type n, value_type v = value_type()) Resizes the list. If the the list is enlarges items with the value v are appended to the list.
wxList<T>::reversevoid reverse() Reverses the list.
wxList<T>::sizesize_type size() const Returns the size of the list.
wxList<T>::splicevoid splice(const iterator& it, wxList<T>& l) void splice(const iterator& it, wxList<T>& l, const iterator& first) void splice(const iterator& it, wxList<T>& l, const iterator& first, const iterator& last) Moves part of the list into another list, starting from first and ending at last if specified.
|