home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WW3DKit / list.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-22  |  1.8 KB  |  75 lines

  1. #ifndef LIST_ALREADY_INCLUDED
  2.  
  3. #ifndef FIFO
  4. #define    FIFO    0
  5. #define    LIFO    1
  6. #endif
  7.  
  8. /* use macros for list_size and list_get_nth if LIST_MACROS is defined */
  9. #define LIST_MACROS  
  10.  
  11. typedef    int    list_data_type;
  12.  
  13. typedef struct list_descriptor
  14. {
  15.     int        listdiscipline;
  16.     list_data_type    **list;
  17.     list_data_type     **listlast;
  18.     list_data_type     **listhead;
  19.     list_data_type     **listtail;
  20. } LIST;
  21.  
  22. extern list_data_type     *list_delete_nth();
  23. extern LIST         *list_open();
  24. extern void          list_close();
  25. extern int           list_empty();
  26. extern list_data_type     **list_next();
  27. extern list_data_type    **list_prev();
  28. extern int        list_full();
  29. extern list_data_type    **list_push();
  30. extern list_data_type    *list_pop();
  31. extern list_data_type    *list_top();
  32. extern list_data_type    **list_enqueue();
  33. extern list_data_type    *list_dequeue();
  34. extern int        list_discipline();
  35. extern list_data_type    **list_put();
  36. extern list_data_type    **list_put_nth();
  37. extern list_data_type    *list_get();
  38. extern int        list_copy();
  39.  
  40. #ifndef LIST_MACROS
  41. extern list_data_type    *list_get_nth(); 
  42. extern int        list_size(); 
  43. #else
  44.  
  45. /* list_size:
  46.     returns the number of elements in the list
  47. */
  48. #define list_size(_ld)    \
  49.     ( \
  50.     /* if */ ( (_ld) == NULL ) ? \
  51.         (0) : \
  52.     /* else if */ ( ((_ld)->listhead > (_ld)->listtail) ? \
  53.             ( ((_ld)->listlast - (_ld)->listhead) + \
  54.             ((_ld)->listtail - (_ld)->list) + 1 ) : \
  55.         /* else    */ ((_ld)->listtail - (_ld)->listhead) ) \
  56.     )
  57.  
  58. /* list_get_nth:
  59.     returns the nth element in the list (doesn't delete it)
  60. */
  61. #define list_get_nth(_ld,_n) \
  62.     (\
  63.     /* if */ ((_n) >= list_size(_ld)) ? \
  64.             ( (list_data_type *) NULL) : \
  65.     /* else if */ ( (1 + (_ld)->listhead + (_n) - (_ld)->listlast <= 0) ? \
  66.             (*(1 + (_n) + (_ld)->listhead)) : \
  67.     /* else */    (*((_ld)->list + (1 + (_n) + (_ld)->listhead - (_ld)->listlast) - 1)) )\
  68.     )
  69. #endif
  70.  
  71. #define LIST_ALREADY_INCLUDED
  72.  
  73.  
  74. #endif
  75.