1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxList, wxStringList classes
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "list.h"
20 #include "wx/object.h"
22 class WXDLLEXPORT wxList
;
25 #define wxKEY_INTEGER 1
26 #define wxKEY_STRING 2
27 class WXDLLEXPORT wxNode
: public wxObject
29 DECLARE_DYNAMIC_CLASS(wxNode
)
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
);
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
; }
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
);
63 class WXDLLEXPORT wxList
: public wxObject
65 DECLARE_DYNAMIC_CLASS(wxList
)
72 unsigned int key_type
;
75 wxList(const unsigned int the_key_type
);
76 wxList(int N
, wxObject
*Objects
[]);
77 wxList(wxObject
*object
, ...);
81 inline int Number(void) const { return n
; }
83 // Append to end of list
84 wxNode
*Append(wxObject
*object
);
86 // Insert at front of list
87 wxNode
*Insert(wxObject
*object
);
89 // Insert before given node
90 wxNode
*Insert(wxNode
*position
, wxObject
*object
);
93 wxNode
*Append(long key
, wxObject
*object
);
94 wxNode
*Append(const char *key
, wxObject
*object
);
96 bool DeleteNode(wxNode
*node
);
97 bool DeleteObject(wxObject
*object
); // Finds object pointer and
98 // deletes node (and object if
99 // DeleteContents is on)
100 void Clear(void); // Delete all nodes
102 inline wxNode
*First(void) const { return first_node
; }
103 inline wxNode
*Last(void) const { return last_node
; }
104 wxNode
*Nth(int i
) const; // nth node counting from 0
107 wxNode
*Find(long key
) const;
108 wxNode
*Find(const char *key
) const;
110 wxNode
*Member(wxObject
*object
) const;
112 inline void DeleteContents(int destroy
) { destroy_data
= destroy
; }
113 // Instruct it to destroy user data
114 // when deleting nodes
115 // this function allows the sorting of arbitrary lists by giving
116 // a function to compare two list elements.
117 void Sort(const wxSortCompareFunction compfunc
);
119 wxObject
*FirstThat(wxListIterateFunction func
);
120 void ForEach(wxListIterateFunction func
);
121 wxObject
*LastThat(wxListIterateFunction func
);
124 // String list class. N.B. this always copies strings
125 // with Add and deletes them itself.
126 class WXDLLEXPORT wxStringList
: public wxList
128 DECLARE_DYNAMIC_CLASS(wxStringList
)
132 wxStringList(const char *first
...);
135 virtual wxNode
*Add(const char *s
);
136 virtual void Delete(const char *s
);
137 virtual char **ListToArray(bool new_copies
= FALSE
) const;
138 virtual void Sort(void);
139 virtual bool Member(const char *s
) const;