baselist.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /****************************************************************************
  2. ;
  3. ; MODULE: BASELIST (.H)
  4. ;
  5. ; PURPOSE:
  6. ;
  7. ; HISTORY: 05/29/95 [m]
  8. ;
  9. ; NOTICE: Copyright (c) 1995, MONOLITH, Inc.
  10. ;
  11. ****************************************************************************/
  12. #ifndef BASELIST_H
  13. #define BASELIST_H
  14. #include "lithtypes.h"
  15. // User must derive all list elements from this class.
  16. class CBaseListItem {
  17. public:
  18. CBaseListItem* Next() { return m_pNext; }; // Returns the next element in the list after this one
  19. CBaseListItem* Prev() { return m_pPrev; }; // Returns the previous element in the list before this one
  20. public:
  21. friend class CBaseList;
  22. protected:
  23. CBaseListItem* m_pNext;
  24. CBaseListItem* m_pPrev;
  25. };
  26. // User can derive new list classes from this class, or use it as is.
  27. class CBaseList {
  28. public:
  29. // Constructors and destructors
  30. CBaseList() { m_pFirst = NULL; m_pLast = NULL; };
  31. ~CBaseList() { };
  32. // member insert and delete functions
  33. void Insert(CBaseListItem* pItem) { InsertFirst(pItem); }; // Same as InsertFirst
  34. void InsertFirst(CBaseListItem* pItem); // Inserts item at the start of the list
  35. void InsertLast(CBaseListItem* pItem); // Inserts item at the end of the list
  36. void InsertAfter(CBaseListItem* pBeforeItem, CBaseListItem* pNewItem); // Inserts item after pBeforeItem in the list (if pBeforeItem is NULL puts at start of list)
  37. void InsertBefore(CBaseListItem* pAfterItem, CBaseListItem* pNewItem); // Inserts item before pAfterItem in the list (if pAfterItem is NULL puts at end of list)
  38. void Delete(CBaseListItem* pItem); // Removes the given item from the list
  39. // member access functions
  40. CBaseListItem* GetFirst() { return m_pFirst; }; // Returns the first element in the list (NULL if list is empty)
  41. CBaseListItem* GetLast() { return m_pLast; }; // Returns the last element in the list (NULL if list is empty)
  42. // this function will reinitialize the list first and last pointer making the list seem empty without deleting the items
  43. // this does not clean up the item pointers so this should only be used when the items in the list will never be used again
  44. void FastDeleteAll() { m_pFirst = NULL; m_pLast = NULL; };
  45. protected:
  46. // internal member variables
  47. CBaseListItem* m_pFirst;
  48. CBaseListItem* m_pLast;
  49. };
  50. #endif