home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES4.ZIP / UUTRAF / dlst.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-16  |  5.6 KB  |  188 lines

  1. /*
  2.  *    dlst.h - dynamic list classes
  3.  */
  4.  
  5. #define SID_H    "@(#)dlst:dlst.h    1.5    92/07/12 14:59:15 (woods)"
  6. #define SID_NM    dlst_sccsid
  7. #include <sccsid.h>
  8.  
  9. /* WARNING: these are bound to cause trouble for someone! */
  10. #ifndef DLST_HAVE_BOOL
  11. typedef int    bool;        /* boolean result */
  12. #endif
  13. #ifndef DLST_HAVE_CMP_T
  14. typedef int    cmp_t;        /* comparison result */
  15. #endif
  16.  
  17. #ifndef TRUE
  18. # define TRUE    1
  19. #endif
  20. #ifndef FALSE
  21. # define FALSE    0
  22. #endif
  23.  
  24. /*
  25.  * generic list base class methods definition
  26.  *
  27.  * NOTE:  The proper way to do this is to define the arguments to the
  28.  * methods with prototyping, but since that's not available we'll do it
  29.  * below with a set of macros for "sending" the messages.
  30.  */
  31. #define LIST_CLASS    \
  32.         bool    (*attop)(), \
  33.             (*atbottom)(), \
  34.             (*isempty)(), \
  35.             (*add)(), \
  36.             (*prev)(), \
  37.             (*next)(), \
  38.             (*seek)(), \
  39.             (*find)(); \
  40.         cmp_t    (*cmp)(); \
  41.         VOID    (*top)(), \
  42.             (*bottom)(), \
  43.             (*replace)(), \
  44.             (*delete)(), \
  45.             (*display)(); \
  46.         UnivPtr    (*current)(), \
  47.             (*cdr)(), \
  48.             (*car)(); \
  49.         size_t    (*total)(), \
  50.             (*ltell)();
  51.  
  52. typedef struct list {
  53.     LIST_CLASS
  54. } lst_t;
  55.  
  56. /*
  57.  * constructor and destructor
  58.  */
  59. extern lst_t    *new_list();
  60. extern void    destroy_list();
  61.  
  62. /*
  63.  * method "messages"
  64.  *
  65.  * NOTE:  make sure we don't de-reference NULL!
  66.  */
  67. #define lst_new            new_list
  68. #define lst_destroy(list)    destroy_list(list)
  69. #define lst_attop(list)        ((list) ? ((*((list)->attop))(list)) : 0)
  70. #define lst_atbottom(list)    ((list) ? ((*((list)->atbottom))(list)) : 0)
  71. #define lst_isempty(list)    ((list) ? ((*((list)->isempty))(list)) : 0)
  72. #define lst_add(list, el)    ((list) ? ((*((list)->add))(list, el)) : 0)
  73. #define lst_find(list, el, fn)    ((list) ? ((*((list)->find))(list, el, fn)) : 0)
  74. #define lst_cmp(list, a, b)    ((list) ? ((*((list)->cmp))(list, a, b)) : (cmp_t) 0)
  75. #define lst_prev(list)        ((list) ? ((*((list)->prev))(list)) : 0)
  76. #define lst_next(list)        ((list) ? ((*((list)->next))(list)) : 0)
  77. #define lst_top(list)        ((list) ? ((*((list)->top))(list)) : (VOID) 0)
  78. #define lst_bottom(list)    ((list) ? ((*((list)->bottom))(list)) : (VOID) 0)
  79. #define lst_seek(list, w, s)    ((list) ? ((*((list)->seek))(list, w, s)) : 0)
  80. #define lst_replace(list, el)    ((list) ? ((*((list)->replace))(list, el)) : (VOID) 0)
  81. #define lst_delete(list)    ((list) ? ((*((list)->delete))(list)) : (VOID) 0)
  82. #define lst_display(list, f)    ((list) ? ((*((list)->display))(list, f)) : (VOID) 0)
  83. #define lst_current(list)    ((list) ? ((*((list)->current))(list)) : (UnivPtr) 0)
  84. #define lst_car(list)        ((list) ? ((*((list)->car))(list)) : (UnivPtr) 0)
  85. #define lst_cdr(list)        ((list) ? ((*((list)->cdr))(list)) : (UnivPtr) 0)
  86. #define lst_total(list)        ((list) ? ((*((list)->total))(list)) : (size_t) 0)
  87. #define lst_ltell(list)        ((list) ? ((*((list)->ltell))(list)) : (size_t) 0)
  88.  
  89. /*
  90.  * a doubly linked list sub-class methods definition.
  91.  *
  92.  * NOTE:  data elements are also defined.
  93.  */
  94. typedef struct llist_element {
  95.     struct llist_element    *nxt;
  96.     struct llist_element    *prv;
  97.     UnivPtr            d;
  98. } llel_t;
  99.  
  100. #define LINKED_LIST_CLASS \
  101.         LIST_CLASS \
  102.         VOID    (*sort)(); \
  103.         llel_t    *first_el; \
  104.         llel_t    *last_el; \
  105.         llel_t    *curr_el; \
  106.         size_t    num_el;
  107.  
  108. typedef struct llist {
  109.     LINKED_LIST_CLASS
  110. } llst_t;
  111.  
  112. /*
  113.  * constructor and destructor
  114.  */
  115. extern llst_t    *new_llist();
  116. extern void    destroy_llist();
  117.  
  118. /*
  119.  * method "messages"
  120.  */
  121. #define llst_new        new_llist
  122. #define llst_destroy(list)    destroy_llist(list)
  123. #define llst_attop(list)    lst_attop(list)
  124. #define llst_atbottom(list)    lst_atbottom(list)
  125. #define llst_isempty(list)    lst_isempty(list)
  126. #define llst_add(list, el)    lst_add(list, el)
  127. #define llst_find(list, el, fn)    lst_find(list, el, fn)
  128. #define llst_cmp(list, a, b)    lst_cmp(list, a, b)
  129. #define llst_prev(list)        lst_prev(list)
  130. #define llst_next(list)        lst_next(list)
  131. #define llst_top(list)        lst_top(list)
  132. #define llst_seek(list, w, s)    lst_seek(list, w, s)
  133. #define llst_bottom(list)    lst_bottom(list)
  134. #define llst_replace(list, el)    lst_replace(list, el)
  135. #define llst_delete(list)    lst_delete(list)
  136. #define llst_display(list, f)    lst_display(list, f)
  137. #define llst_current(list)    lst_current(list)
  138. #define llst_car(list)        lst_car(list)
  139. #define llst_cdr(list)        lst_cdr(list)
  140. #define llst_total(list)    lst_total(list)
  141. #define llst_ltell(list)    lst_ltell(list)
  142. #define llst_sort(list, f)    ((list) ? ((*((list)->sort))(list, f)) : (VOID) 0)
  143.  
  144. /*
  145.  * an array list sub-class methods definition
  146.  *
  147.  * NOTE:  data elements are also defined.
  148.  */
  149. #define ARRAY_LIST_CLASS \
  150.         LIST_CLASS \
  151.         size_t    curr_el; \
  152.         size_t    num_el;
  153.  
  154. typedef struct alist {
  155.     ARRAY_LIST_CLASS
  156. } alst_t;
  157.  
  158. /*
  159.  * constructor and destructor
  160.  */
  161. extern alst_t    *new_alist();
  162. extern void    destroy_alist();
  163.  
  164. /*
  165.  * method "messages"
  166.  */
  167. #define alst_new        new_alist
  168. #define alst_destroy(list)    destroy_alist(list)
  169. #define alst_attop(list)    lst_attop(list)
  170. #define alst_atbottom(list)    lst_atbottom(list)
  171. #define alst_isempty(list)    lst_isempty(list)
  172. #define alst_add(list, el)    lst_add(list, el)
  173. #define alst_find(list, el, fn)    lst_find(list, el, fn)
  174. #define alst_cmp(list, a, b)    lst_cmp(list, a, b)
  175. #define alst_prev(list)        lst_prev(list)
  176. #define alst_next(list)        lst_next(list)
  177. #define alst_top(list)        lst_top(list)
  178. #define alst_seek(list, w, s)    lst_seek(list, w, s)
  179. #define alst_bottom(list)    lst_bottom(list)
  180. #define alst_replace(list, el)    lst_replace(list, el)
  181. #define alst_delete(list)    lst_delete(list)
  182. #define alst_display(list, f)    lst_display(list, f)
  183. #define alst_current(list)    lst_current(list)
  184. #define alst_car(list)        lst_car(list)
  185. #define alst_cdr(list)        lst_cdr(list)
  186. #define alst_total(list)    lst_total(list)
  187. #define alst_ltell(list)    lst_ltell(list)
  188.