home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 1.ddi / OOPWLD.ZIP / SHAPES / SHLIST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-09  |  1.2 KB  |  37 lines

  1. // SHLIST.CPP : Methods for list to hold shapes
  2. #include "shlist.hpp"
  3.  
  4. void shape_list::drawlist() {
  5.   shape_holder * s = cursor;  // start at the current shape
  6.   do {
  7.     if(s) s = s->next; // find the next valid element
  8.     if(!s && cursor) s = head; // NULL == end of list; go to head
  9.     if(!s) return;  // still NULL -- must be empty list
  10.     s->shp->draw();
  11.   } while(s != cursor);  // draw cursor shape last, so it's on top
  12. }
  13.  
  14. void shape_list::remove() {  // delete current element
  15.   if(!cursor) return;  // nothing to remove (or at end of list)
  16.   shape_holder * cur, * drag;
  17.   cur = drag = head;
  18.   while(cur != cursor) {
  19.     drag = cur;
  20.     cur = cur->next;
  21.   }
  22.   // special case -- shape at the head of the list:
  23.   if (cur == head && head) head = head->next;
  24.   next();  // move cursor to next position
  25.   delete cur;
  26.   drag->next = cursor;  // thread past deleted node
  27. }
  28.  
  29. shape_list::~shape_list() {  // remove elements until the list is empty
  30.   cursor = head;  // move to top of list
  31.   while(head) { // while there are elements left at the top
  32.     cursor = head->next; // remember the next position
  33.     delete head; // delete the top
  34.     head = cursor; // move the head down to the new top
  35.   }
  36. }
  37.