home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / include / list2.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-24  |  2.4 KB  |  119 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1987, 1988, 1989 Stanford University
  5.    Copyright (c) 1989, Tera Computer Company
  6.  **/
  7.  
  8. #ifndef list2_h
  9. #define list2_h
  10.  
  11. #include <InterViews/defs.h>
  12.  
  13. // A BaseNode contains links to its previous and next BaseNodes.
  14. // BaseLists can link BaseNodes to each other to form lists of
  15. // BaseNodes.
  16.  
  17. class BaseNode 
  18. {
  19.     friend class BaseList;
  20. public:
  21.     BaseNode();
  22.     virtual ~BaseNode();
  23.     virtual boolean SameValueAs(void*);
  24. private:
  25.     BaseNode* prev;        // points to previous BaseNode in list
  26.     BaseNode* next;        // points to next BaseNode in list
  27. };
  28.  
  29. // A BaseList maintains and iterates through a list of BaseNodes.
  30.  
  31. class BaseList 
  32. {
  33. public:
  34.     BaseList();
  35.     ~BaseList();
  36.  
  37.     int Size();
  38.     boolean AtEnd();
  39.     BaseNode* First();
  40.     BaseNode* Last();
  41.     BaseNode* Prev();
  42.     BaseNode* Next();
  43.     BaseNode* GetCur();
  44.     BaseNode* Index(int);
  45.     boolean Find(void*);
  46.  
  47.     void Append(BaseNode*);
  48.     void Prepend(BaseNode*);
  49.     void InsertAfterCur(BaseNode*);
  50.     void InsertBeforeCur(BaseNode*);
  51.  
  52.     void RemoveCur();
  53.     void DeleteCur();
  54.     void DeleteAll();
  55. private:
  56.     BaseNode* head;        // points to dummy head of circular list
  57.     BaseNode* cur;        // points to current node of circular list
  58.     int size;            // stores number of non-dummy nodes in list
  59. };
  60.  
  61. // Size returns the number of non-dummy nodes in a list.
  62.  
  63. inline int BaseList::Size () 
  64. {
  65.     return size;
  66. }
  67.  
  68. // AtEnd returns true if the current node is the dummy node.
  69.  
  70. inline boolean BaseList::AtEnd () 
  71. {
  72.     return cur == head;
  73. }
  74.  
  75. // First returns the first node in a list (or the head if it's empty)
  76. // and sets the current node to that node.
  77.  
  78. inline BaseNode* BaseList::First () 
  79. {
  80.     cur = head->next;
  81.     return cur;
  82. }
  83.  
  84. // Last returns the last node in a list (or the head if it's empty)
  85. // and sets the current node to that node.
  86.  
  87. inline BaseNode* BaseList::Last () 
  88. {
  89.     cur = head->prev;
  90.     return cur;
  91. }
  92.  
  93. // Prev returns the node before the current node and sets the current
  94. // node to that node.
  95.  
  96. inline BaseNode* BaseList::Prev () 
  97. {
  98.     cur = cur->prev;
  99.     return cur;
  100. }
  101.  
  102. // Next returns the node after the current node and sets the current
  103. // node to that node.
  104.  
  105. inline BaseNode* BaseList::Next () 
  106. {
  107.     cur = cur->next;
  108.     return cur;
  109. }
  110.  
  111. // GetCur returns the current node in a list.
  112.  
  113. inline BaseNode* BaseList::GetCur () 
  114. {
  115.     return cur;
  116. }
  117.  
  118. #endif
  119.