home *** CD-ROM | disk | FTP | other *** search
- #include "abslist.h"
-
- link_node::link_node(containable *arg)
- {
- next = NULL;
- data = arg;
- }
-
- link_node::~link_node()
- {
- if (data != NULL)
- delete data;
- }
-
- abstract_index::abstract_index(abstract_list & base)
- {
- attach(base);
- }
-
- void abstract_index::attach(abstract_list &base)
- {
- list = &base;
- rewind();
- }
-
- void abstract_index::rewind()
- {
- if (list == NULL)
- data = NULL;
- else
- data = list->head;
- }
-
- int abstract_index::has(containable *arg, int exact)
- {
- rewind();
- if (exact) {
- while (data != NULL) {
- if (data->item() == arg) return 1;
- (*this)++;
- }
- } else {
- while (data != NULL) {
- if (*data->item() == *arg) return 1;
- (*this)++;
- }
- }
- return 0;
- }
-
- void abstract_index::put(link_node *arg)
- {
- list->object_count++;
- if (data == NULL)
- list->head = arg;
- else {
- arg->next = data->next;
- data->next = arg;
- }
- data = arg;
- }
-
- containable *abstract_index::remove()
- {
- containable *result;
-
- if (data == NULL) return NULL;
- result = item(); // preserve value for this index
- data->empty();
- destroy();
- return result;
- }
-
- void abstract_index::destroy() {};
- void abstract_index::operator -- ( int ) {};
-
- abstract_list::abstract_list()
- {
- head = NULL;
- }
-
- abstract_list::~abstract_list()
- {
- empty(1);
- }
-
- void abstract_list::empty(char kill)
- {
- if (kill) {
- while (object_count)
- destroy();
- } else {
- while (object_count)
- remove();
- }
- }
-
- void abstract_list::destroy()
- {
- link_node *old_node = head;
- if (head == NULL) return;
- head = head->next;
- delete old_node;
- object_count--;
- }
-
- containable *abstract_list::remove()
- {
- containable *result;
-
- if (head == NULL) return NULL;
- result = head->item();
- head->empty();
- destroy();
- return result;
- }
-
- int abstract_list::has(containable *arg, int exact)
- {
- abstract_index i(*this);
-
- return i.has(arg, exact);
- }
-
-