home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / doom_i / program / dmreject.exe / SOURCE.ZIP / LIST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-31  |  3.0 KB  |  102 lines

  1. //**********************************************************************************
  2. //    REJECT.EXE - Reject data table builder for DOOM
  3. //    Copyright (C) 1994 L.M.WITEK 
  4. //
  5. //    This program is free software; you can redistribute it and/or modify
  6. //    it under the terms of the GNU General Public License as published by
  7. //    the Free Software Foundation; either version 1, or (at your option)
  8. //    any later version.
  9. //
  10. //    This program is distributed in the hope that it will be useful,
  11. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. //    GNU General Public License for more details.
  14. //
  15. //    You should have received a copy of the GNU General Public License
  16. //    along with this program; if not, write to the Free Software
  17. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. //**********************************************************************************
  19.  
  20. /*********************************************************************************
  21. **
  22. **  MODULE: LIST - Implemetation of a Doubly linked list
  23. **
  24. *********************************************************************************/
  25.  
  26. #include "list.hpp"
  27.  
  28. /*********************************************************************************
  29. **
  30. **  FUNCTION: Add an CLink Object to the start of the linked list.
  31. **
  32. **  ENTRY: Pointer to a Clink
  33. **
  34. *********************************************************************************/
  35.  
  36. void CList::AddItem (CLink *link)
  37. {
  38.      link->next = base;
  39.      if (base)
  40.           base->prev = link;
  41.      base = link;
  42. }
  43.    
  44. /*********************************************************************************
  45. **
  46. **  FUNCTION: Remove an item from the list and delete it.
  47. **
  48. **  ENTRY:   link = pointer to the link to delete.
  49. **
  50. *********************************************************************************/
  51.    
  52. void CList::DeleteItem (CLink *link)
  53. {
  54.      CLink *prev;
  55.      CLink *next;
  56.      
  57.      if (link)
  58.      {
  59.           prev = link->prev;          
  60.           next = link->next;
  61.      
  62.           delete link;
  63.      
  64.           if (prev) 
  65.                prev->next = next;
  66.           else
  67.                base = next;
  68.                
  69.           if (next) next->prev = prev;
  70.      }
  71. }                
  72.  
  73.  
  74. /*********************************************************************************
  75. **
  76. **  FUNCTION: Walks the list of CLinks and deletes each link.
  77. **
  78. *********************************************************************************/
  79.  
  80. void CList::DeleteAll ()
  81. {
  82.      CLink *temp;
  83.  
  84.      while (base)
  85.      {
  86.           temp   = base->next;        
  87.           delete base;
  88.           base  = temp;
  89.      }
  90. }
  91.  
  92. /*********************************************************************************
  93. **
  94. **  FUNCTION:  Clist Destructor. Walks the list of CLinks and deletes each link.
  95. **
  96. *********************************************************************************/
  97.  
  98. CList::~CList ()
  99. {
  100.      DeleteAll ();
  101. }
  102.