Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
2.2 KiB

  1. /*++
  2. Microsoft Windows NT RPC Name Service
  3. Copyright (C) Microsoft Corporation, 1995 - 1999
  4. Module Name:
  5. simpleLL.hxx
  6. Abstract:
  7. This module contains the definition a simple linklist class
  8. which avoids reference counting, and stored pointers of any kind.
  9. Author:
  10. Satish Thatte (SatishT) 11/20/95 Created all the code below except where
  11. otherwise indicated.
  12. --*/
  13. #ifndef _SimpleListType_
  14. #define _SimpleListType_
  15. #define NULL 0
  16. /*++
  17. Class Definition:
  18. CSimpleLinkList
  19. Abstract:
  20. This is a minimal linked list class, used when a link list is required
  21. for short term use and the data could be pointers of any kind, not
  22. necessarily pointers to types derived from IDataItem, as required
  23. for the CLinkList class.
  24. --*/
  25. class CSimpleLinkList
  26. {
  27. friend class CSimpleLinkListIterator;
  28. protected:
  29. struct Link
  30. {
  31. Link* next;
  32. void* data;
  33. Link(void* a, Link* n) {
  34. data = a;
  35. next = n;
  36. }
  37. ~Link() {
  38. }
  39. };
  40. Link * pLnkLast, * pLnkFirst;
  41. long lCount;
  42. public:
  43. CSimpleLinkList() {
  44. pLnkFirst = pLnkLast = NULL;
  45. lCount = 0;
  46. }
  47. void clear();
  48. ~CSimpleLinkList() {
  49. clear();
  50. }
  51. void enque(void* x)
  52. {
  53. if (pLnkLast) pLnkLast = pLnkLast->next = new Link(x, NULL);
  54. else pLnkFirst = pLnkLast = new Link(x,NULL);
  55. lCount++;
  56. }
  57. void push(void* x)
  58. {
  59. pLnkFirst = new Link(x, pLnkFirst);
  60. if (!pLnkLast) pLnkLast = pLnkFirst;
  61. lCount++;
  62. }
  63. void insert(void* x) // at the end in this class
  64. { enque(x); }
  65. void* pop(); // remove first item and return it
  66. void* nth(long lOrdinal);
  67. long size() { return lCount; }
  68. void rotate(long lDegree);
  69. };
  70. /*++
  71. Class Definition:
  72. CSimpleLinkListIterator
  73. Abstract:
  74. An iterator class for traversing a CSimpleLinkList.
  75. --*/
  76. class CSimpleLinkListIterator {
  77. CSimpleLinkList::Link* ptr; // the current link
  78. public:
  79. CSimpleLinkListIterator(CSimpleLinkList& source) {
  80. ptr = source.pLnkFirst;
  81. }
  82. ~CSimpleLinkListIterator();
  83. void* next(); // advance the iterator and return next void
  84. int finished() { return ptr == NULL; }
  85. };
  86. #endif // _SimpleListType_