1 \section{\class{wxList
}}\label{wxlist
}
3 This class provides linked list functionality for wxWindows, and for an application
4 if it wishes. Depending on the form of constructor used, a list can be keyed on
5 integer or string keys to provide a primitive look-up ability. See
\helpref{wxHashTable
}{wxhashtable
}\rtfsp
6 for a faster method of storage when random access is required.
8 \wxheading{Derived from
}
10 \helpref{wxObject
}{wxobject
}
14 It is very common to iterate on a list as follows:
18 wxPoint *point1 = new wxPoint(
100,
100);
19 wxPoint *point2 = new wxPoint(
200,
200);
22 SomeList.Append(point1);
23 SomeList.Append(point2);
27 wxNode *node = SomeList.First();
30 wxPoint *point = (wxPoint *)node->Data();
36 To delete nodes in a list as the list is being traversed, replace
50 node = SomeList.First();
54 See
\helpref{wxNode
}{wxnode
} for members that retrieve the data associated with a node, and
55 members for getting to the next or previous node.
57 Note that a cast is required when retrieving the data from a node. Although a
58 node is defined to store objects of type
{\bf wxObject
} and derived types, other
59 types (such as char*) may be used with appropriate casting.
63 \helpref{wxNode
}{wxnode
},
\helpref{wxStringList
}{wxstringlist
}
65 \latexignore{\rtfignore{\wxheading{Members
}}}
68 \membersection{wxList::wxList
}
70 \func{}{wxList
}{\void}
72 \func{}{wxList
}{\param{unsigned int
}{ key
\_type}}
74 \func{}{wxList
}{\param{int
}{ n
},
\param{wxObject *
}{objects
[]}}
76 \func{}{wxList
}{\param{wxObject *
}{object
}, ...
}
78 Constructors.
{\it key
\_type} is one of wxKEY
\_NONE, wxKEY
\_INTEGER, or wxKEY
\_STRING,
79 and indicates what sort of keying is required (if any).
81 {\it objects
} is an array of
{\it n
} objects with which to initialize the list.
83 The variable-length argument list constructor must be supplied with a
86 \membersection{wxList::
\destruct{wxList
}}
88 \func{}{\destruct{wxList
}}{\void}
90 Destroys the list. Also destroys any remaining nodes, but does not destroy
91 client data held in the nodes.
93 \membersection{wxList::Append
}
95 \func{wxNode *
}{Append
}{\param{wxObject *
}{object
}}
97 \func{wxNode *
}{Append
}{\param{long
}{ key
},
\param{wxObject *
}{object
}}
99 \func{wxNode *
}{Append
}{\param{const wxString\&
}{key
},
\param{wxObject *
}{object
}}
101 Appends a new
{\bf wxNode
} to the end of the list and puts a pointer to the
102 \rtfsp{\it object
} in the node. The last two forms store a key with the object for
103 later retrieval using the key. The new node is returned in each case.
105 The key string is copied and stored by the list implementation.
107 \membersection{wxList::Clear
}
109 \func{void
}{Clear
}{\void}
111 Clears the list (but does not delete the client data stored with each node).
113 \membersection{wxList::DeleteContents
}
115 \func{void
}{DeleteContents
}{\param{bool
}{ destroy
}}
117 If
{\it destroy
} is TRUE, instructs the list to call
{\it delete
} on the client contents of
118 a node whenever the node is destroyed. The default is FALSE.
120 \membersection{wxList::DeleteNode
}
122 \func{bool
}{DeleteNode
}{\param{wxNode *
}{node
}}
124 Deletes the given node from the list, returning TRUE if successful.
126 \membersection{wxList::DeleteObject
}
128 \func{bool
}{DeleteObject
}{\param{wxObject *
}{object
}}
130 Finds the given client
{\it object
} and deletes the appropriate node from the list, returning
131 TRUE if successful. The application must delete the actual object separately.
133 \membersection{wxList::Find
}
135 \func{wxNode *
}{Find
}{\param{long
}{ key
}}
137 \func{wxNode *
}{Find
}{\param{const wxString\&
}{key
}}
139 Returns the node whose stored key matches
{\it key
}. Use on a keyed list only.
141 \membersection{wxList::First
}
143 \func{wxNode *
}{First
}{\void}
145 Returns the first node in the list (NULL if the list is empty).
147 \membersection{wxList::Insert
}
149 \func{wxNode *
}{Insert
}{\param{wxObject *
}{object
}}
151 Insert object at front of list.
153 \func{wxNode *
}{Insert
}{\param{wxNode *
}{position
},
\param{wxObject *
}{object
}}
155 Insert object before
{\it position
}.
158 \membersection{wxList::Last
}
160 \func{wxNode *
}{Last
}{\void}
162 Returns the last node in the list (NULL if the list is empty).
164 \membersection{wxList::Member
}
166 \func{wxNode *
}{Member
}{\param{wxObject *
}{object
}}
168 Returns the node associated with
{\it object
} if it is in the list, NULL otherwise.
170 \membersection{wxList::Nth
}
172 \func{wxNode *
}{Nth
}{\param{int
}{ n
}}
174 Returns the
{\it nth
} node in the list, indexing from zero (NULL if the list is empty
175 or the nth node could not be found).
177 \membersection{wxList::Number
}
179 \func{int
}{Number
}{\void}
181 Returns the number of elements in the list.
183 \membersection{wxList::Sort
}
185 \func{void
}{Sort
}{\param{wxSortCompareFunction
}{ compfunc
}}
188 // Type of compare function for list sort operation (as in 'qsort')
189 typedef int
(*wxSortCompareFunction)(const void *elem1, const void *elem2);
192 Allows the sorting of arbitrary lists by giving
193 a function to compare two list elements. We use the system {\bf qsort} function
194 for the actual sorting process. The sort function receives pointers to wxObject pointers (wxObject **),
195 so be careful to dereference appropriately.
200 int listcompare(const void *arg1, const void *arg2)
202 return(compare
(**(wxString **)arg1, // use the wxString 'compare'
203 **(wxString **)arg2)); // function
210 list.Append(new wxString("DEF"));
211 list.Append(new wxString("GHI"));
212 list.Append(new wxString("ABC"));
213 list.Sort(listcompare);