Back to index

plt-scheme  4.2.1
wx_list.h
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  * File:             wx_list.h
00003  * Purpose:   wxList implementation much used in wxWindows
00004  * Author:           Julian Smart
00005  * Created:   1993
00006  * Updated:   
00007  * Copyright: (c) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (c) 1993, AIAI, University of Edinburgh
00009  */
00010 
00011 #ifndef wxb_listh
00012 #define wxb_listh
00013 
00014 #ifdef __GNUG__
00015 # ifndef wx_mac
00016 #  pragma interface
00017 # endif
00018 #endif
00019 
00020 #ifndef wx_xt
00021     // wxWindows standard include mechanism
00022     /* sccsid[] = "@(#)wx_list.h   1.2 5/9/94" */
00023 #   include "common.h"
00024 #   include "wx_obj.h"
00025 #endif
00026 
00027 #ifdef IN_CPROTO
00028 typedef       void    *wxList ;
00029 typedef       void    *wxNode;
00030 typedef       void    *wxStringList;
00031 #else
00032 
00033 class wxList;
00034 
00035 enum KeyType {wxKEY_NONE = 0, wxKEY_INTEGER, wxKEY_STRING};
00036 
00037 class wxNode
00038 #ifndef MZ_PRECISE_GC
00039 : public gc
00040 #endif
00041 {
00042  private:
00043  
00044   wxObject *data;
00045   wxNode *next;
00046   wxNode *previous;
00047 
00048   void Setup(wxNode *last_one, wxNode *next_one, 
00049             wxObject *object);
00050 
00051  public:
00052   // Optional key stuff
00053   long integer_key;
00054   char *string_key;
00055 
00056   wxNode(wxNode *last_one = NULL, wxNode *next_one = NULL,
00057         wxObject *object = NULL);
00058   wxNode(wxNode *last_one, wxNode *next_one,
00059          wxObject *object, long the_key);
00060   wxNode(wxNode *last_one, wxNode *next_one,
00061          wxObject *object, const char *the_key);
00062   wxNode(wxNode *last_one, wxNode *next_one,
00063          wxObject *object, void *the_key);
00064 
00065   void Kill(wxList *list);
00066 
00067   inline wxNode *Next(void) { return next; }
00068   inline wxNode *Previous(void) { return previous; }
00069   inline wxObject *Data(void) { return data; }
00070   inline void SetData(wxObject *the_data) { data = the_data; }
00071 
00072   inline void     DataGCIgnored(void)         { WXGC_IGNORE(this, data); }
00073 };
00074 
00075 class wxList: public wxObject
00076 {
00077 
00078  public:
00079 #ifdef wx_mac
00080    enum DestroyDataCode {kNoDestroyData = 0, kDestroyData = 1};
00081 #endif
00082   int n;
00083   int destroy_data;
00084   wxNode *first_node;
00085   wxNode *last_node;
00086   unsigned int key_type;
00087 
00088 #ifdef wx_mac
00089   wxList(DestroyDataCode destroyData = kNoDestroyData, Bool clean_up = TRUE);
00090 #else
00091   wxList(void);
00092 #endif
00093   wxList(KeyType the_key_type, Bool clean_up = TRUE);
00094   wxList(int N, wxObject *Objects[]);
00095   ~wxList(void);
00096 
00097   inline int Number(void) { return n; }
00098 
00099   // Append to end of list
00100   wxNode *Append(wxObject *object);
00101 
00102   // Insert at front of list
00103   wxNode *Insert(wxObject *object);
00104 
00105   // Insert before given node
00106   wxNode *Insert(wxNode *position, wxObject *object);
00107 
00108   // Keyed append
00109   wxNode *Append(long key, wxObject *object);
00110   wxNode *Append(const char *key, wxObject *object);
00111   wxNode *Append(void *key, wxObject *object);
00112 
00113   Bool DeleteNode(wxNode *node);
00114   Bool DeleteObject(wxObject *object);  // Finds object pointer and
00115                                         // deletes node (and object if
00116                                         // DeleteContents is on)
00117   void Clear(void);                     // Delete all nodes
00118 
00119 #ifdef wx_mac
00120   Bool OnDeleteObject(wxObject *object); // mac platform only
00121   long MemberIndex(wxObject *object); // WCH wx_mac added 8/12/94
00122 #endif
00123 
00124   inline wxNode *First(void) { return first_node; }
00125   inline wxNode *Last(void) { return last_node; }
00126   wxNode *Nth(int i);                  // nth node counting from 0
00127 
00128   // Keyed search
00129   wxNode *Find(long key);
00130   wxNode *Find(const char *key);
00131   wxNode *FindPtr(void *key);
00132 
00133   wxNode *Member(wxObject *object);
00134 
00135   inline void DeleteContents(int destroy) { destroy_data = destroy; }
00136                                              // Instruct it to destroy user data
00137                                              // when deleting nodes
00138 
00139 #ifdef MEMORY_USE_METHOD
00140   long MemoryUse(void);
00141 #endif
00142 
00143  private:
00144    wxNode *DoAppend(wxNode *node);
00145 };
00146 
00147 // String list class. N.B. this always copies strings
00148 // with Add and deletes them itself.
00149 class wxStringList: public wxList
00150 {
00151 
00152  public:
00153   wxStringList(void);
00154   ~wxStringList(void);
00155 
00156   wxNode *Add(const char *s);
00157   void Delete(const char *s);
00158   char **ListToArray(Bool new_copies = FALSE);
00159   Bool Member(const char *s);
00160 };
00161 
00162 class wxChildList;
00163 
00164 class wxChildNode
00165 #ifndef MZ_PRECISE_GC
00166 : public gc
00167 #endif
00168 {
00169 public:
00170   wxChildList *owner;
00171   wxObject *strong;
00172 #ifdef MZ_PRECISE_GC
00173   void *weak;
00174 # define cnGET_WEAK(weak) ((wxObject *)gcPTR_TO_OBJ(GC_weak_box_val(weak)))
00175 #else
00176   wxObject **weak; /* atomic-allocated disappearing ptr */
00177 # define cnGET_WEAK(weak) (*weak)
00178 #endif
00179 
00180   wxChildNode *Next();
00181   wxObject *Data();
00182   Bool IsShown();
00183 };
00184 
00185 class wxChildList
00186 #ifndef MZ_PRECISE_GC
00187 : public gc
00188 #endif
00189 {
00190  public:
00191   int n;
00192   int size;
00193   wxChildNode **nodes;
00194 
00195   wxChildList(void);
00196   ~wxChildList(void);
00197 
00198   inline int Number(void) { return n; }
00199 
00200   // Append to end of list
00201   void Append(wxObject *object);
00202 
00203   Bool DeleteObject(wxObject *object);
00204   Bool DeleteNode(wxChildNode *node);
00205 
00206   inline wxChildNode *First(void) { return FindNode(NULL); }
00207   
00208   wxChildNode *FindNode(wxChildNode *after);
00209   wxChildNode *NextNode(int &pos);
00210 
00211   void Show(wxObject *object, Bool show);
00212 
00213   Bool IsShown(wxObject *object);
00214 };
00215 
00216 #endif // IN_CPROTO
00217 #endif // wxb_listh