home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / windows / c / wxwin140 / include / wx_list.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-18  |  4.1 KB  |  145 lines

  1. /*
  2.  * File:     wx_list.h
  3.  * Purpose:  wxList implementation much used in wxWindows
  4.  *
  5.  *                       wxWindows 1.40
  6.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  7.  *                   The University of Edinburgh
  8.  *
  9.  *                     Author: Julian Smart
  10.  *                       Date: 18-4-93
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose is hereby granted without fee, provided
  14.  * that the above copyright notice, author statement and this permission
  15.  * notice appear in all copies of this software and related documentation.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  18.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  19.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  22.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  23.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  24.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  25.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  26.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  */
  28.  
  29. #ifndef wx_listh
  30. #define wx_listh
  31.  
  32. #include "common.h"
  33. #include "wx_obj.h"
  34.  
  35. class wxList;
  36.  
  37. #define wxKEY_NONE    0
  38. #define wxKEY_INTEGER 1
  39. #define wxKEY_STRING  2
  40. class wxNode: public wxObject
  41. {
  42.   wxObject *data;
  43.   wxNode *next;
  44.   wxNode *previous;
  45.  
  46.  public:
  47.   wxList *list;
  48.  
  49.   // Optional key stuff
  50.   union
  51.   {
  52.     long integer;
  53.     char *string;
  54.   } key;
  55.  
  56.   wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one, wxObject *object);
  57.   wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one,
  58.          wxObject *object, long the_key);
  59.   wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one,
  60.          wxObject *object, char *the_key);
  61.   ~wxNode(void);
  62.  
  63.   inline wxNode *Next(void) { return next; }
  64.   inline wxNode *Previous(void) { return previous; }
  65.   inline wxObject *Data(void) { return data; }
  66.   inline void SetData(wxObject *the_data) { data = the_data; }
  67. };
  68.  
  69. class wxList: public wxObject
  70. {
  71.  public:
  72.   int n;
  73.   int destroy_data;
  74.   wxNode *first_node;
  75.   wxNode *last_node;
  76.   unsigned int key_type;
  77.  
  78.   wxList(void);
  79.   wxList(unsigned int the_key_type);
  80.   wxList(int N, wxObject *Objects[]);
  81.   wxList(wxObject *object, ...);
  82.   ~wxList(void);
  83.  
  84.   inline int Number(void) { return n; }
  85.  
  86.   // Append to end of list
  87.   inline wxNode *Append(wxObject *object)
  88.   {
  89.     wxNode *node = new wxNode(this, last_node, NULL, object);
  90.     if (!first_node)
  91.       first_node = node;
  92.     last_node = node;
  93.     n ++;
  94.     return node;
  95.   }
  96.  
  97.   // Insert at front of list
  98.   wxNode *Insert(wxObject *object);
  99.  
  100.   // Insert before given node
  101.   wxNode *Insert(wxNode *position, wxObject *object);
  102.  
  103.   // Keyed append
  104.   wxNode *Append(long key, wxObject *object);
  105.   wxNode *Append(char *key, wxObject *object);
  106.  
  107.   Bool DeleteNode(wxNode *node);
  108.   Bool DeleteObject(wxObject *object);  // Finds object pointer and
  109.                                         // deletes node (and object if
  110.                                         // DeleteContents is on)
  111.   void Clear(void);                     // Delete all nodes
  112.  
  113.   inline wxNode *First(void) { return first_node; }
  114.   inline wxNode *Last(void) { return last_node; }
  115.   wxNode *Nth(int i);                  // nth node counting from 0
  116.  
  117.   // Keyed search
  118.   wxNode *Find(long key);
  119.   wxNode *Find(char *key);
  120.  
  121.   wxNode *Member(wxObject *object);
  122.  
  123.   inline void DeleteContents(int destroy) { destroy_data = destroy; }
  124.                                              // Instruct it to destroy user data
  125.                                              // when deleting nodes
  126. };
  127.  
  128. // String list class. N.B. this always copies strings
  129. // with Add and deletes them itself.
  130. class wxStringList: public wxList
  131. {
  132.  public:
  133.   wxStringList(void);
  134.   wxStringList(char *first ...);
  135.   ~wxStringList(void);
  136.  
  137.   virtual wxNode *Add(char *s);
  138.   virtual void Delete(char *s);
  139.   virtual char **ListToArray(Bool new_copies = FALSE);
  140.   virtual void Sort(void);
  141.   virtual Bool Member(char *s);
  142. };
  143.  
  144. #endif // wx_listh
  145.