1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: list.h
|
|
|
|
// Purpose: wxList, wxStringList classes
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 29/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998 Julian Smart
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-14 20:23:28 -04:00
|
|
|
#ifndef _WX_LISTH__
|
|
|
|
#define _WX_LISTH__
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
1998-07-03 12:36:10 -04:00
|
|
|
#pragma interface "list.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
#include "wx/object.h"
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxList;
|
|
|
|
|
|
|
|
#define wxKEY_NONE 0
|
|
|
|
#define wxKEY_INTEGER 1
|
|
|
|
#define wxKEY_STRING 2
|
|
|
|
class WXDLLEXPORT wxNode: public wxObject
|
|
|
|
{
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxNode)
|
|
|
|
private:
|
|
|
|
|
|
|
|
wxObject *data;
|
|
|
|
wxNode *next;
|
|
|
|
wxNode *previous;
|
|
|
|
|
|
|
|
public:
|
|
|
|
wxList *list;
|
|
|
|
|
|
|
|
// Optional key stuff
|
|
|
|
union
|
|
|
|
{
|
|
|
|
long integer;
|
|
|
|
char *string;
|
|
|
|
} key;
|
|
|
|
|
1998-08-22 23:22:56 -04:00
|
|
|
wxNode(wxList *the_list = (wxList *) NULL, wxNode *last_one = (wxNode *) NULL, wxNode *next_one = (wxNode *) NULL, wxObject *object = (wxObject *) NULL);
|
1998-05-20 10:01:55 -04:00
|
|
|
wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one,
|
|
|
|
wxObject *object, long the_key);
|
|
|
|
wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one,
|
|
|
|
wxObject *object, const char *the_key);
|
|
|
|
~wxNode(void);
|
|
|
|
|
|
|
|
inline wxNode *Next(void) const { return next; }
|
|
|
|
inline wxNode *Previous(void) const { return previous; }
|
|
|
|
inline wxObject *Data(void) const { return (wxObject *)data; }
|
|
|
|
inline void SetData(wxObject *the_data) { data = the_data; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// type of compare function for list sort operation (as in 'qsort')
|
|
|
|
typedef int (*wxSortCompareFunction)(const void *elem1, const void *elem2);
|
|
|
|
typedef int (*wxListIterateFunction)(wxObject *o);
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxList: public wxObject
|
|
|
|
{
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxList)
|
|
|
|
|
|
|
|
public:
|
|
|
|
int n;
|
|
|
|
int destroy_data;
|
|
|
|
wxNode *first_node;
|
|
|
|
wxNode *last_node;
|
|
|
|
unsigned int key_type;
|
|
|
|
|
|
|
|
wxList(void);
|
|
|
|
wxList(const unsigned int the_key_type);
|
1998-07-04 11:17:59 -04:00
|
|
|
wxList(int N, wxObject *Objects[]);
|
1998-05-20 10:01:55 -04:00
|
|
|
wxList(wxObject *object, ...);
|
|
|
|
|
|
|
|
~wxList(void);
|
|
|
|
|
|
|
|
inline int Number(void) const { return n; }
|
|
|
|
|
|
|
|
// Append to end of list
|
|
|
|
wxNode *Append(wxObject *object);
|
|
|
|
|
|
|
|
// Insert at front of list
|
|
|
|
wxNode *Insert(wxObject *object);
|
|
|
|
|
|
|
|
// Insert before given node
|
|
|
|
wxNode *Insert(wxNode *position, wxObject *object);
|
|
|
|
|
|
|
|
// Keyed append
|
1998-07-04 11:17:59 -04:00
|
|
|
wxNode *Append(long key, wxObject *object);
|
1998-05-20 10:01:55 -04:00
|
|
|
wxNode *Append(const char *key, wxObject *object);
|
|
|
|
|
|
|
|
bool DeleteNode(wxNode *node);
|
|
|
|
bool DeleteObject(wxObject *object); // Finds object pointer and
|
|
|
|
// deletes node (and object if
|
|
|
|
// DeleteContents is on)
|
|
|
|
void Clear(void); // Delete all nodes
|
|
|
|
|
|
|
|
inline wxNode *First(void) const { return first_node; }
|
|
|
|
inline wxNode *Last(void) const { return last_node; }
|
1998-07-04 11:17:59 -04:00
|
|
|
wxNode *Nth(int i) const; // nth node counting from 0
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Keyed search
|
1998-07-04 11:17:59 -04:00
|
|
|
wxNode *Find(long key) const;
|
1998-05-20 10:01:55 -04:00
|
|
|
wxNode *Find(const char *key) const;
|
|
|
|
|
|
|
|
wxNode *Member(wxObject *object) const;
|
|
|
|
|
1998-07-04 11:17:59 -04:00
|
|
|
inline void DeleteContents(int destroy) { destroy_data = destroy; }
|
1998-05-20 10:01:55 -04:00
|
|
|
// Instruct it to destroy user data
|
|
|
|
// when deleting nodes
|
|
|
|
// this function allows the sorting of arbitrary lists by giving
|
|
|
|
// a function to compare two list elements.
|
|
|
|
void Sort(const wxSortCompareFunction compfunc);
|
|
|
|
|
|
|
|
wxObject *FirstThat(wxListIterateFunction func);
|
|
|
|
void ForEach(wxListIterateFunction func);
|
|
|
|
wxObject *LastThat(wxListIterateFunction func);
|
|
|
|
};
|
|
|
|
|
|
|
|
// String list class. N.B. this always copies strings
|
|
|
|
// with Add and deletes them itself.
|
|
|
|
class WXDLLEXPORT wxStringList: public wxList
|
|
|
|
{
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxStringList)
|
|
|
|
|
|
|
|
public:
|
|
|
|
wxStringList(void);
|
|
|
|
wxStringList(const char *first ...);
|
|
|
|
~wxStringList(void);
|
|
|
|
|
|
|
|
virtual wxNode *Add(const char *s);
|
|
|
|
virtual void Delete(const char *s);
|
1998-07-04 11:17:59 -04:00
|
|
|
virtual char **ListToArray(bool new_copies = FALSE) const;
|
1998-05-20 10:01:55 -04:00
|
|
|
virtual void Sort(void);
|
|
|
|
virtual bool Member(const char *s) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
1998-08-14 20:23:28 -04:00
|
|
|
// _WX_LISTH__
|