1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 %% Author: wxWidgets Team
8 %% Copyright: (c) wxWidgets Team
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxList<T>
}}\label{wxlist
}
14 The wxList<T> class provides linked list functionality. It has been written
15 to be type safe and to provide the full API of the STL std::list container and
16 should be used like it. The exception is that wxList<T> actually stores
17 pointers and therefore its iterators return pointers and not references
18 to the actual objets in the list (see example below). Unfortunately, the
19 new wxList<T> class requires that you declare and define each wxList<T>
20 class in your program. This is done with
{\it WX
\_DECLARE\_LIST} and
21 {\it WX
\_DEFINE\_LIST} macros (see example). We hope that we'll be able
22 to provide a proper template class providing both the STL std::list
23 and the old wxList API in the future.
25 Please refer to the STL std::list documentation for further
26 information on how to use the class. Below we documented the legacy
27 API that originated from the old wxList class and which can still
28 be used alternatively for the the same class.
30 Note that if you compile wxWidgets in STL mode (wxUSE
\_STL defined as
1)
31 then wxList<T> will actually derive from std::list and just add a legacy
32 compatibility layer for the old wxList class.
37 // this part might be in a header or source (.cpp) file
43 // this macro declares and partly implements MyList class
44 WX_DECLARE_LIST(MyListElement, MyList);
48 // the only requirement for the rest is to be AFTER the full declaration of
49 // MyListElement (for WX_DECLARE_LIST forward declaration is enough), but
50 // usually it will be found in the source file and not in the header
52 #include <wx/listimpl.cpp>
53 WX_DEFINE_LIST(MyList);
57 MyListElement element;
58 list.Append(&element); // ok
59 list.Append(
17); // error: incorrect type
61 // let's iterate over the list in STL syntax
62 MyList::iterator iter;
63 for (iter = list.begin(); iter != list.end(); ++iter)
65 MyListElement *current = *iter;
67 ...process the current element...
70 // the same with the legacy API from the old wxList class
71 MyList::compatibility_iterator node = list.GetFirst();
74 MyListElement *current = node->GetData();
76 ...process the current element...
78 node = node->GetNext();
83 For compatibility with previous versions wxList and wxStringList classes are
84 still defined, but their usage is deprecated and they will disappear in the
85 future versions completely. The use of the latter is especially discouraged as
86 it is not only unsafe but is also much less efficient than
87 \helpref{wxArrayString
}{wxarraystring
} class.
89 \wxheading{Include files
}
95 \helpref{wxBase
}{librarieslist
}
99 \helpref{wxArray
}{wxarray
}
101 \latexignore{\rtfignore{\wxheading{Members
}}}
103 \membersection{wxList<T>::wxList<T>
}\label{wxlistctor
}
105 \func{}{wxList<T>
}{\void}
107 \func{}{wxList<T>
}{\param{size
\_t}{ count
},
\param{T *
}{elements
[]}}
111 \membersection{wxList<T>::
\destruct{wxList<T>
}}\label{wxlistdtor
}
113 \func{}{\destruct{wxList<T>
}}{\void}
115 Destroys the list, but does not delete the objects stored in the list
116 unless you called DeleteContents(
{\tt true
} ).
118 \membersection{wxList<T>::Append
}\label{wxlistappend
}
120 \func{wxList<T>::compatibility
\_iterator }{Append
}{\param{T *
}{object
}}
122 Appends the pointer to
\rtfsp{\it object
} to the list.
124 \membersection{wxList<T>::Clear
}\label{wxlistclear
}
126 \func{void
}{Clear
}{\void}
128 Clears the list, but does not delete the objects stored in the list
129 unless you called DeleteContents(
{\tt true
} ).
131 \membersection{wxList<T>::DeleteContents
}\label{wxlistdeletecontents
}
133 \func{void
}{DeleteContents
}{\param{bool
}{ destroy
}}
135 If
{\it destroy
} is
{\tt true
}, instructs the list to call
{\it delete
}
136 on objects stored in the list whenever they are removed.
137 The default is
{\tt false
}.
139 \membersection{wxList<T>::DeleteNode
}\label{wxlistdeletenode
}
141 \func{bool
}{DeleteNode
}{\param{const compatibility
\_iterator &
}{iter
}}
143 Deletes the given element refered to by
{\tt iter
} from the list,
144 returning
{\tt true
} if successful.
146 \membersection{wxList<T>::DeleteObject
}\label{wxlistdeleteobject
}
148 \func{bool
}{DeleteObject
}{\param{T *
}{object
}}
150 Finds the given
{\it object
} and removes it from the list, returning
151 {\tt true
} if successful. The application must delete the actual object
154 \membersection{wxList<T>::Erase
}\label{wxlisterase
}
156 \func{void
}{Erase
}{\param{const compatibility
\_iterator &
}{iter
}}
158 Removes element refered to be
{\tt iter
}.
160 \membersection{wxList<T>::Find
}\label{wxlistfind
}
162 \constfunc{wxList<T>::compatibility
\_iterator}{Find
}{\param{T *
}{ object
}}
164 Returns the iterator refering to
{\it object
} or NULL if none found.
166 \membersection{wxList<T>::GetCount
}\label{wxlistgetcount
}
168 \constfunc{size
\_t}{GetCount
}{\void}
170 Returns the number of elements in the list.
172 \membersection{wxList<T>::GetFirst
}\label{wxlistgetfirst
}
174 \constfunc{wxList<T>::compatibility
\_iterator}{GetFirst
}{\void}
176 Returns the first iterator in the list (NULL if the list is empty).
178 \membersection{wxList<T>::GetLast
}\label{wxlistgetlast
}
180 \constfunc{wxList<T>::compatibility
\_iterator}{GetLast
}{\void}
182 Returns the last iterator in the list (NULL if the list is empty).
184 \membersection{wxList<T>::IndexOf
}\label{wxlistindexof
}
186 \constfunc{int
}{IndexOf
}{\param{T*
}{ obj
}}
188 Returns the index of
{\it obj
} within the list or
{\tt wxNOT
\_FOUND} if
189 {\it obj
} is not found in the list.
191 \membersection{wxList<T>::Insert
}\label{wxlistinsert
}
193 \func{wxList<T>::compatibility
\_iterator}{Insert
}{\param{T *
}{object
}}
195 Insert object at the front of list.
197 \func{wxList<T>::compatibility
\_iterator}{Insert
}{\param{size
\_t }{position
},
\param{T *
}{object
}}
199 Insert object before
{\it position
}, i.e. the index of the new item in the
200 list will be equal to
{\it position
}.
{\it position
} should be less than or
201 equal to
\helpref{GetCount
}{wxlistgetcount
}; if it is equal to it, this is the
202 same as calling
\helpref{Append
}{wxlistappend
}.
204 \func{wxList<T>::compatibility
\_iterator}{Insert
}{\param{compatibility
\_iterator}{iter
},
\param{T *
}{object
}}
206 Inserts the object before the object refered to be
{\it iter
}.
208 \membersection{wxList<T>::IsEmpty
}\label{wxlistisempty
}
210 \constfunc{bool
}{IsEmpty
}{\void}
212 Returns
{\tt true
} if the list is empty,
{\tt false
} otherwise.
214 % Use different label name to avoid clashing with wxListItem label
215 \membersection{wxList<T>::Item
}\label{wxlistitemfunc
}
217 \constfunc{wxList<T>::compatibility
\_iterator}{Item
}{\param{size
\_t }{index
}}
219 Returns the iterator refering to the object at the given
220 {\tt index
} in the list.
222 \membersection{wxList<T>::Member
}\label{wxlistmember
}
224 \constfunc{wxList<T>::compatibility
\_iterator}{Member
}{\param{T *
}{ object
}}
226 {\bf NB:
} This function is deprecated, use
\helpref{Find
}{wxlistfind
} instead.
228 \membersection{wxList<T>::Nth
}\label{wxlistnth
}
230 \constfunc{wxList<T>::compatibility
\_iterator}{Nth
}{\param{int
}{n
}}
232 {\bf NB:
} This function is deprecated, use
\helpref{Item
}{wxlistitemfunc
} instead.
234 Returns the
{\it nth
} node in the list, indexing from zero (NULL if the list is empty
235 or the nth node could not be found).
237 \membersection{wxList<T>::Number
}\label{wxlistnumber
}
239 \constfunc{int
}{Number
}{\void}
241 {\bf NB:
} This function is deprecated, use
\helpref{GetCount
}{wxlistgetcount
} instead.
243 Returns the number of elements in the list.
245 \membersection{wxList<T>::Sort
}\label{wxlistsort
}
247 \func{void
}{Sort
}{\param{wxSortCompareFunction
}{ compfunc
}}
250 // Type of compare function for list sort operation (as in 'qsort')
251 typedef int
(*wxSortCompareFunction)(const void *elem1, const void *elem2);
254 Allows the sorting of arbitrary lists by giving a function to compare
255 two list elements. We use the system {\bf qsort} function for the actual