This repository has been archived on 2024-03-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
ContactBook/CExpr/Wx_list.h
2024-03-20 09:28:18 -05:00

155 lines
4 KiB
C++

/*
* File: wx_list.h
* Purpose: wxList implementation much used in wxWindows
* Author: Julian Smart
* Created: 1993
* Updated:
* Copyright:
*/
/* sccsid[] = "@(#)wx_list.h 1.2 5/9/94" */
#ifndef wxb_listh
#define wxb_listh
#ifdef __GNUG__
#pragma interface
#endif
#ifdef IN_CPROTO
typedef void *wxList ;
typedef void *wxNode;
typedef void *wxStringList;
#else
class wxList;
#define wxKEY_NONE 0
#define wxKEY_INTEGER 1
#define wxKEY_STRING 2
class wxNode: public CObject
{
DECLARE_DYNAMIC(wxNode)
private:
CObject *data;
wxNode *next;
wxNode *previous;
public:
wxList *list;
// Optional key stuff
union
{
long integer;
char *string;
} key;
wxNode(wxList *the_list = NULL, wxNode *last_one = NULL, wxNode *next_one = NULL, CObject *object = NULL);
wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one,
CObject *object, long the_key);
wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one,
CObject *object, const char *the_key);
~wxNode(void);
inline wxNode *Next(void) { return next; }
inline wxNode *Previous(void) { return previous; }
inline CObject *Data(void) { return data; }
inline void SetData(CObject *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);
class wxList: public CObject
{
DECLARE_DYNAMIC(wxList)
public:
int n;
int destroy_data;
wxNode *first_node;
wxNode *last_node;
unsigned int key_type;
wxList(void);
wxList(unsigned int the_key_type);
wxList(int N, CObject *Objects[]);
wxList(CObject *object, ...);
~wxList(void);
inline int Number(void) { return n; }
// Append to end of list
inline wxNode *Append(CObject *object)
{
wxNode *node = new wxNode(this, last_node, NULL, object);
if (!first_node)
first_node = node;
last_node = node;
n ++;
return node;
}
// Insert at front of list
wxNode *Insert(CObject *object);
// Insert before given node
wxNode *Insert(wxNode *position, CObject *object);
// Keyed append
wxNode *Append(long key, CObject *object);
wxNode *Append(const char *key, CObject *object);
BOOL DeleteNode(wxNode *node);
BOOL DeleteObject(CObject *object); // Finds object pointer and
// deletes node (and object if
// DeleteContents is on)
void Clear(void); // Delete all nodes
inline wxNode *First(void) { return first_node; }
inline wxNode *Last(void) { return last_node; }
wxNode *Nth(int i); // nth node counting from 0
// Keyed search
wxNode *Find(long key);
wxNode *Find(const char *key);
wxNode *Member(CObject *object);
inline void DeleteContents(int destroy) { destroy_data = destroy; }
// 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(wxSortCompareFunction compfunc);
CObject *FirstThat(int (*F)(CObject *O));
void ForEach(void (*F)(CObject *O));
//CObject *LastThat(int (*F)(CObject *O));
};
// String list class. N.B. this always copies strings
// with Add and deletes them itself.
class wxStringList: public wxList
{
DECLARE_DYNAMIC(wxStringList)
public:
wxStringList(void);
wxStringList(char *first ...);
~wxStringList(void);
virtual wxNode *Add(const char *s);
virtual void Delete(const char *s);
virtual char **ListToArray(BOOL new_copies = FALSE);
virtual void Sort(void);
virtual BOOL Member(const char *s);
};
// Make a copy of this string using 'new'
extern char *copystring(const char *s);
#endif // IN_CPROTO
#endif // wxb_listh