home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_07 / 8n07121a < prev    next >
Text File  |  1990-06-19  |  3KB  |  109 lines

  1. /* Listing 6*/
  2. /*----------------- PINLIST.H--------------------*/
  3. #include "pinnacle.h"
  4. #include "list.h"
  5.  
  6. #define PINNACLE_LIST_CLASS       LIST_CLASS \
  7. /* Pinnacle Database Object */        DB db; \
  8. /*Pinnacle Database Table */    DBTAB table; \
  9. /* Boolean flags*/     unsigned is_at_top, is_at_bottom;
  10.  
  11. typedef struct pinnacle_list {
  12.     PINNACLE_LIST_CLASS
  13. } PINNACLE_LIST;
  14.  
  15. PINNACLE_LIST *new_pinnacle_list(char *database,
  16. char *table);
  17.  
  18. /*------------------- PINLIST.C ------------------*/
  19. #include "pinlist.h"
  20.  
  21. static long total_members(PINNACLE_LIST *this) {
  22.     return((long) DB_CountRows(this->table));
  23. }
  24.  
  25. static unsigned at_top(PINNACLE_LIST *this) {
  26.     return(this->is_at_top);
  27. }
  28.  
  29. static unsigned at_end(PINNACLE_LIST *this) {
  30.     return(this->is_at_bottom);
  31. }
  32.  
  33. static void prev(PINNACLE_LIST *this) {
  34.     if (DB_NextRow(this->table, DBPREVIOUS))
  35.         this->is_at_top = FALSE;
  36.     else
  37.         this->is_at_top = TRUE;
  38.     if (this->total_members(this) > 1)
  39.         this->is_at_bottom = FALSE;
  40. }
  41.  
  42. static void next(PINNACLE_LIST *this) {
  43.     if (DB_NextRow(this->table, DBNEXT))
  44.        this->is_at_bottom = FALSE;
  45.     else
  46.        this->is_at_bottom = TRUE;
  47.     if (this->total_members(this) > 1)
  48.         this->is_at_top = FALSE;
  49. }
  50.  
  51.  
  52. static void top(PINNACLE_LIST *this) {
  53.     DB_FirstRow(this->table);
  54.     DB_NextRow(this->table,DBNEXT);
  55.     this->is_at_top = TRUE;
  56.     if (this->total_members(this) > 1)
  57.         this->is_at_bottom = FALSE;
  58. }
  59.  
  60. static void end(PINNACLE_LIST *this) {
  61.     DB_ForAllRows(this->table);
  62.     this->is_at_bottom = TRUE;
  63.     if (this->total_members(this) > 1)
  64.     this->is_at_top = FALSE;
  65. }
  66.  
  67. static long tell(PINNACLE_LIST *this) {
  68.     DBROWID thisrow, checkrow;
  69.     long position = 0L;
  70.  
  71.     thisrow = DB_CurrentRow(this->table);
  72.     this->top(this);
  73.     checkrow = DB_CurrentRow(this->table);
  74.     while(checkrow != thisrow) {
  75.         ++position;
  76.         DB_NextRow(this->table,DBNEXT);
  77.         checkrow = DB_CurrentRow(this->table);
  78.     }
  79.     return(position);
  80. }
  81.  
  82. PINNACLE_LIST *new_pinnacle_list(char *datab,char *table) {
  83. PINNACLE_LIST *this;
  84. LIST *l;
  85.  
  86. l = new_list();
  87. if (l == NULL)
  88.    return(NULL);
  89.  
  90. this = calloc(1,sizeof(PINNACLE_LIST));
  91. if (this == NULL) {
  92.     destroy_list(l);  return(NULL);
  93. }
  94. memmove(this,l,sizeof(LIST)); free(l);
  95.  
  96. this->db = DB_Open(datab,"rw",0);
  97. this->table = DB_Table(this->db,table);
  98. this->total_members = total_members;
  99. this->at_top = at_top; this->at_end = at_end;
  100. this->prev = prev; this->next = next;
  101. this->top = top; this->end = end; this->tell = tell;
  102.  
  103. return(this);
  104. }
  105.  
  106. destroy_pinnacle_list(PINNACLE_LIST *this) {
  107. DB_Close(this->db); destroy_list(this);
  108. }
  109.