]> git.saurik.com Git - wxWidgets.git/blob - include/wx/list.h
fixed #pragma
[wxWidgets.git] / include / wx / list.h
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
12 #ifndef __LISTH__
13 #define __LISTH__
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "wx/defs.h"
20 #include "wx/object.h"
21
22 class WXDLLEXPORT wxList;
23
24 #define wxKEY_NONE 0
25 #define wxKEY_INTEGER 1
26 #define wxKEY_STRING 2
27 class 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
46 wxNode(wxList *the_list = NULL, wxNode *last_one = NULL, wxNode *next_one = NULL, wxObject *object = NULL);
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')
60 typedef int (*wxSortCompareFunction)(const void *elem1, const void *elem2);
61 typedef int (*wxListIterateFunction)(wxObject *o);
62
63 class 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);
76 wxList(const int N, wxObject *Objects[]);
77 wxList(wxObject *object, ...);
78
79 #ifdef USE_STORABLE_CLASSES
80 wxList( istream &stream, char *data );
81 virtual void StoreObject( ostream &stream );
82 #endif
83
84 ~wxList(void);
85
86 inline int Number(void) const { return n; }
87
88 // Append to end of list
89 wxNode *Append(wxObject *object);
90
91 // Insert at front of list
92 wxNode *Insert(wxObject *object);
93
94 // Insert before given node
95 wxNode *Insert(wxNode *position, wxObject *object);
96
97 // Keyed append
98 wxNode *Append(const long key, wxObject *object);
99 wxNode *Append(const char *key, wxObject *object);
100
101 bool DeleteNode(wxNode *node);
102 bool DeleteObject(wxObject *object); // Finds object pointer and
103 // deletes node (and object if
104 // DeleteContents is on)
105 void Clear(void); // Delete all nodes
106
107 inline wxNode *First(void) const { return first_node; }
108 inline wxNode *Last(void) const { return last_node; }
109 wxNode *Nth(const int i) const; // nth node counting from 0
110
111 // Keyed search
112 wxNode *Find(const long key) const;
113 wxNode *Find(const char *key) const;
114
115 wxNode *Member(wxObject *object) const;
116
117 inline void DeleteContents(const int destroy) { destroy_data = destroy; }
118 // Instruct it to destroy user data
119 // when deleting nodes
120 // this function allows the sorting of arbitrary lists by giving
121 // a function to compare two list elements.
122 void Sort(const wxSortCompareFunction compfunc);
123
124 wxObject *FirstThat(wxListIterateFunction func);
125 void ForEach(wxListIterateFunction func);
126 wxObject *LastThat(wxListIterateFunction func);
127 };
128
129 // String list class. N.B. this always copies strings
130 // with Add and deletes them itself.
131 class WXDLLEXPORT wxStringList: public wxList
132 {
133 DECLARE_DYNAMIC_CLASS(wxStringList)
134
135 public:
136 wxStringList(void);
137 wxStringList(const char *first ...);
138 ~wxStringList(void);
139
140 virtual wxNode *Add(const char *s);
141 virtual void Delete(const char *s);
142 virtual char **ListToArray(const bool new_copies = FALSE) const;
143 virtual void Sort(void);
144 virtual bool Member(const char *s) const;
145 };
146
147 #endif
148 // __LISTH__