$szTitle = "wxlist<t>"; include "./_header.inc"; ?>
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>::append
wxlist<t>::clear
wxlist<t>::deletecontents
wxlist<t>::deletenode
wxlist<t>::deleteobject
wxlist<t>::erase
wxlist<t>::find
wxlist<t>::getcount
wxlist<t>::getfirst
wxlist<t>::getlast
wxlist<t>::indexof
wxlist<t>::insert
wxlist<t>::isempty
wxlist<t>::item
wxlist<t>::member
wxlist<t>::nth
wxlist<t>::number
wxlist<t>::sort
wxlist<t>::assign
wxlist<t>::back
wxlist<t>::begin
wxlist<t>::clear
wxlist<t>::empty
wxlist<t>::end
wxlist<t>::erase
wxlist<t>::front
wxlist<t>::insert
wxlist<t>::max_size
wxlist<t>::pop_back
wxlist<t>::pop_front
wxlist<t>::push_back
wxlist<t>::push_front
wxlist<t>::rbegin
wxlist<t>::remove
wxlist<t>::rend
wxlist<t>::resize
wxlist<t>::reverse
wxlist<t>::size
wxlist<t>::splice
wxlist<t>()
wxlist<t>(size_t count, t *elements[])
constructors.
~wxlist<t>()
destroys the list, but does not delete the objects stored in the list unless you called deletecontents(true ).
wxlist<t>::compatibility_iterator append(t *object)
appends the pointer to object to the list.
void clear()
clears the list, but does not delete the objects stored in the list unless you called deletecontents(true ).
void 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.
bool deletenode(const compatibility_iterator&iter)
deletes the given element refered to by iter from the list, returning true if successful.
bool 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.
void erase(const compatibility_iterator&iter)
removes element refered to be iter.
wxlist<t>::compatibility_iterator find(t * object) const
returns the iterator refering to object or null if none found.
size_t getcount() const
returns the number of elements in the list.
wxlist<t>::compatibility_iterator getfirst() const
returns the first iterator in the list (null if the list is empty).
wxlist<t>::compatibility_iterator getlast() const
returns the last iterator in the list (null if the list is empty).
int 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>::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.
bool isempty() const
returns true if the list is empty, false otherwise.
wxlist<t>::compatibility_iterator item(size_t index) const
returns the iterator refering to the object at the given index in the list.
wxlist<t>::compatibility_iterator member(t * object) const
nb: this function is deprecated, use find instead.
wxlist<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).
int number() const
nb: this function is deprecated, use getcount instead.
returns the number of elements in the list.
void 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.
void assign(const_iterator first, const const_iterator& last)
void assign(size_type n, const_reference v = value_type())
reference back()
const_reference back() const
returns the last item of the list.
iterator begin()
const_iterator begin() const
returns a (const) iterator pointing to the beginning of the list.
void clear()
removes all items from the list.
bool empty() const
returns true if the list is empty.
iterator end()
const_iterator end() const
returns a (const) iterator pointing at the end of the list.
iterator 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.
reference front()
const_reference front() const
returns the first item in the list.
iterator 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.
size_type max_size() const
returns the largest possible size of the list.
void pop_back()
removes the list item.
void pop_front()
removes the first item.
void push_back(const_reference v = value_type())
adds an item to end of the list.
void push_front(const_reference v = value_type())
adds an item to the front of the list.
reverse_iterator rbegin()
const_reverse_iterator rbegin() const
returns a (const) reverse iterator pointer to the beginning of the reversed list.
void remove(const_reference v)
removes an item from the list.
reverse_iterator rend()
const_reverse_iterator rend() const
returns a (const) reverse iterator pointer to the end of the reversed list.
void 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.
void reverse()
reverses the list.
size_type size() const
returns the size of the list.
void 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.
include "./_footer.inc"; ?>