wxList: wxObject

This class provides linked list functionality for wxWindows, and for an application if it wishes. Depending on the form of constructor used, a list can be keyed on integer or string keys to provide a primitive look-up ability. See wxHashTable for a faster method of storage when random access is required. It is very common to iterate on a list as follows:

  ...
  wxPoint *point1 = new wxPoint(100, 100);
  wxPoint *point2 = new wxPoint(200, 200);

  wxList SomeList;
  SomeList.Append(point1);
  SomeList.Append(point2);

  ...

  wxNode *node = SomeList.First();
  while (node)
 {
    wxPoint *point = (wxPoint *)node->Data();
    ...
    node = node->Next();
  }

To delete nodes in a list as the list is being traversed, replace

    ...
    node = node->Next();
    ...

with

    ...
    delete point;
    delete node;
    node = SomeList.First();
    ...

See wxNode for members that retrieve the data associated with a node, and members for getting to the next or previous node.

Note that a cast is required when retrieving the data from a node. Although a node is defined to store objects of type wxObject and derived types, other types (such as char *) may be used with appropriate casting.

wxList::wxList

voidwxList

voidwxListunsigned int key_type

voidwxListint n, wxObject *objects[]

voidwxListwxObject *object, ...

Constructors. key_type is one of wxKEY_NONE, wxKEY_INTEGER, or wxKEY_STRING, and indicates what sort of keying is required (if any).

objects is an array of n objects with which to initialize the list.

The variable-length argument list constructor must be supplied with a terminating NULL.

wxList::wxList

voidwxList

Destroys list. Also destroys any remaining nodes, but does not destroy client data held in the nodes.

wxList::Append

wxNode *AppendwxObject *object

wxNode *Appendlong key, wxObject *object

wxNode *Appendchar *key, wxObject *object

Appends a new wxNode to the end of the list and puts a pointer to the object in the node. The last two forms store a key with the object for later retrieval using the key. The new node is returned in each case.

wxList::Clear

voidClear

Clears the list (but does not delete the client data stored with each node).

wxList::DeleteContents

voidDeleteContentsBool destroy

If destroy is TRUE, instructs the list to call delete on the client contents of a node whenever the node is destroyed. The default is FALSE.

wxList::DeleteNode

BoolDeleteNodewxNode *node

Deletes the given node from the list, returning TRUE if successful.

wxList::DeleteObject

BoolDeleteObjectwxObject *object

Finds the given client object and deletes the appropriate node from the list, returning TRUE if successful. The application must delete the actual object separately.

wxList::Find

wxNode *Findlong key

wxNode *Findchar *key

Returns the node whose stored key matches key. Use on a keyed list only.

wxList::First

wxNode *First

Returns the first node in the list (NULL if the list is empty).

wxList::Insert

wxNode *InsertwxObject *object

Insert object at front of list.

wxNode *InsertwxNode *position, wxObject *object

Insert object before position.

wxList::Last

wxNode *Last

Returns the last node in the list (NULL if the list is empty).

wxList::Member

BoolMemberwxObject *object

Returns TRUE if the client data object is in the list.

wxList::Nth

wxNode *Nthint n

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::Number

intNumber

Returns the number of elements in the list.