]> git.saurik.com Git - wxWidgets.git/blame - include/wx/list.h
Changes related to stream includes
[wxWidgets.git] / include / wx / list.h
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: list.h
3// Purpose: wxList, wxStringList classes
4// Author: Julian Smart
5// Modified by:
6// Created: 29/01/98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Julian Smart
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_LISTH__
13#define _WX_LISTH__
c801d85f
KB
14
15#ifdef __GNUG__
0d3820b3 16#pragma interface "list.h"
c801d85f
KB
17#endif
18
19#include "wx/defs.h"
20#include "wx/object.h"
21
22class WXDLLEXPORT wxList;
23
24#define wxKEY_NONE 0
25#define wxKEY_INTEGER 1
26#define wxKEY_STRING 2
27class WXDLLEXPORT wxNode: public wxObject
28{
29 DECLARE_DYNAMIC_CLASS(wxNode)
30 private:
31
32 wxObject *data;
33 wxNode *next;
34 wxNode *previous;
35
36 public:
37 wxList *list;
38
39 // Optional key stuff
40 union
41 {
42 long integer;
43 char *string;
44 } key;
45
c67daf87 46 wxNode(wxList *the_list = (wxList *) NULL, wxNode *last_one = (wxNode *) NULL, wxNode *next_one = (wxNode *) NULL, wxObject *object = (wxObject *) NULL);
c801d85f
KB
47 wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one,
48 wxObject *object, long the_key);
49 wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one,
50 wxObject *object, const char *the_key);
51 ~wxNode(void);
52
53 inline wxNode *Next(void) const { return next; }
54 inline wxNode *Previous(void) const { return previous; }
55 inline wxObject *Data(void) const { return (wxObject *)data; }
56 inline void SetData(wxObject *the_data) { data = the_data; }
57};
58
59// type of compare function for list sort operation (as in 'qsort')
60typedef int (*wxSortCompareFunction)(const void *elem1, const void *elem2);
61typedef int (*wxListIterateFunction)(wxObject *o);
62
63class WXDLLEXPORT wxList: public wxObject
64{
65 DECLARE_DYNAMIC_CLASS(wxList)
66
67 public:
68 int n;
69 int destroy_data;
70 wxNode *first_node;
71 wxNode *last_node;
72 unsigned int key_type;
73
74 wxList(void);
75 wxList(const unsigned int the_key_type);
debe6624 76 wxList(int N, wxObject *Objects[]);
c801d85f
KB
77 wxList(wxObject *object, ...);
78
c801d85f
KB
79 ~wxList(void);
80
81 inline int Number(void) const { return n; }
8fdca65c 82 inline int GetCount(void) const { return n; }
c801d85f
KB
83
84 // Append to end of list
85 wxNode *Append(wxObject *object);
86
87 // Insert at front of list
88 wxNode *Insert(wxObject *object);
89
90 // Insert before given node
91 wxNode *Insert(wxNode *position, wxObject *object);
92
93 // Keyed append
debe6624 94 wxNode *Append(long key, wxObject *object);
c801d85f
KB
95 wxNode *Append(const char *key, wxObject *object);
96
97 bool DeleteNode(wxNode *node);
98 bool DeleteObject(wxObject *object); // Finds object pointer and
99 // deletes node (and object if
100 // DeleteContents is on)
8cb50e4b 101 virtual void Clear(void); // Delete all nodes
c801d85f
KB
102
103 inline wxNode *First(void) const { return first_node; }
104 inline wxNode *Last(void) const { return last_node; }
debe6624 105 wxNode *Nth(int i) const; // nth node counting from 0
c801d85f
KB
106
107 // Keyed search
8cb50e4b
JS
108 virtual wxNode *Find(long key) const;
109 virtual wxNode *Find(const char *key) const;
c801d85f 110
8cb50e4b 111 virtual wxNode *Member(wxObject *object) const;
c801d85f 112
debe6624 113 inline void DeleteContents(int destroy) { destroy_data = destroy; }
c801d85f
KB
114 // Instruct it to destroy user data
115 // when deleting nodes
116 // this function allows the sorting of arbitrary lists by giving
117 // a function to compare two list elements.
118 void Sort(const wxSortCompareFunction compfunc);
119
120 wxObject *FirstThat(wxListIterateFunction func);
121 void ForEach(wxListIterateFunction func);
122 wxObject *LastThat(wxListIterateFunction func);
123};
124
125// String list class. N.B. this always copies strings
126// with Add and deletes them itself.
127class WXDLLEXPORT wxStringList: public wxList
128{
129 DECLARE_DYNAMIC_CLASS(wxStringList)
130
131 public:
132 wxStringList(void);
8cb50e4b 133 wxStringList(const wxStringList& list);
c801d85f
KB
134 wxStringList(const char *first ...);
135 ~wxStringList(void);
136
137 virtual wxNode *Add(const char *s);
138 virtual void Delete(const char *s);
debe6624 139 virtual char **ListToArray(bool new_copies = FALSE) const;
c801d85f
KB
140 virtual void Sort(void);
141 virtual bool Member(const char *s) const;
8cb50e4b
JS
142 virtual void Clear(void);
143 void operator= (const wxStringList& list);
144 char* operator[] (int i) const;
c801d85f
KB
145};
146
147#endif
34138703 148 // _WX_LISTH__