Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Object-Oriented Programming In C


July 1990/Object-Oriented Programming In C/Listing 6

Listing 6

/* ----------------- PINLIST.H-------------------- */
#include "pinnacle.h"
#include "list.h"

#define PINNACLE_LIST_CLASS       LIST_CLASS \
/*  Pinnacle Database Object */       DB db; \
/*Pinnacle Database Table */    DBTAB table; \
/*  Boolean flags*/    unsigned is_at_top, is_at_bottom;

typedef struct pinnacle_list {
   PINNACLE_LIST_CLASS
} PINNACLE_LIST;

PINNACLE_LIST *new_pinnacle_list(char *database,
char *table);

/*------------------ PINLIST.C ------------------ */
#include "pinlist.h"

static long total_members(PINNACLE_LIST *this) {
   return((long) DB_CountRows(this->table));
}

static unsigned at_top(PINNACLE_LIST *this) {
   return(this->is_at_top);
}

static unsigned at_end(PINNACLE_LIST *this) {
   return(this->is_at_bottom);
}

static void prev(PINNACLE_LIST *this) {
   if (DB_NextRow(this->table, DBPREVIOUS))
      this->is_at_top = FALSE;
   else
      this->is_at_top = TRUE;
   if (this->total_members(this) > 1)
      this->is_at_bottom = FALSE;
}

static void next(PINNACLE_LIST *this) {
   if (DB_NextRow(this->table, DBNEXT))
      this->is_at_bottom = FALSE;
   if (this->total_members(this) > 1)
      this->is at bottom = TRUE;
      this->is_at_top = FALSE;
}

static void top(PINNACLE_LIST *this) {
   DB_FirstRow(this->table);
   DB_NextRow(this->table,DBNEXT);
   this->is_at_top = TRUE;
   if (this->total_members(this) > 1)
      this->is_at_bottom = FALSE;
}

static void end(PINNACLE_LIST *this) {
   DB_ForAllRows(this->table);
   this->is_at_bottom = TRUE;
   if (this->total_members(this) > 1)
   this->is_at_top = FALSE;
}

static long tell(PINNACLE_LIST *this) {
   DBROWID thisrow, checkrow;
   long position = 0L;
   
   thisrow = DB_CurrentRow(this->table);
   this->top(this);
   checkrow = DB_CurrentRow(this->table);
   while(checkrow != thisrow) {
      ++position;
      
      DB_NextRow(this->table,DBNEXT);
      checkrow = DB_CurrentRow(this->table);
   }
   return(position);
}

PINNACLE_LIST *new_pinnacle_list(char *datab,char *table) {
PINNACLE_LIST *this;
LIST *l;

l = new_list();
if (l == NULL)
   return(NULL);

this = calloc(1,sizeof(PINNACLE_LIST));
if (this == NULL) {
   destroy_list(l); return(NULL);
}
memmove(this,l,sizeof(LIST)); free(l);

this->db = DB_Open(datab,"rw",0);
this->table = DB_Table(this->db,table);
this->total_members = total_members;
this->at_top = at_top; this->at_end = at_end;
this->prev = prev; this->next = next;
this->top = top; this->end = end; this->tell = tell;

return(this);
}

destroy_pinnacle_list(PINNACLE_LIST *this) {
DB_Close(this->db); destroy_list(this);
}

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.