Counter Strike : Global Offensive Source Code
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.

190 lines
3.1 KiB

  1. //
  2. // mxToolKit (c) 1999 by Mete Ciragan
  3. //
  4. // file: mxLinkedList.h
  5. // implementation: all
  6. // last modified: Mar 19 1999, Mete Ciragan
  7. // copyright: The programs and associated files contained in this
  8. // distribution were developed by Mete Ciragan. The programs
  9. // are not in the public domain, but they are freely
  10. // distributable without licensing fees. These programs are
  11. // provided without guarantee or warrantee expressed or
  12. // implied.
  13. //
  14. #ifndef INCLUDED_MXLINKEDLIST
  15. #define INCLUDED_MXLINKEDLIST
  16. typedef struct mxListNode_s
  17. {
  18. void *d_data;
  19. struct mxListNode_s *d_next;
  20. struct mxListNode_s *d_prev;
  21. } mxListNode;
  22. class mxLinkedList
  23. {
  24. mxListNode *d_head;
  25. mxListNode *d_tail;
  26. int d_nodeCount;
  27. // NOT IMPLEMENTED
  28. mxLinkedList (const mxLinkedList&);
  29. mxLinkedList& operator= (const mxLinkedList&);
  30. public:
  31. //CREATORS
  32. mxLinkedList ()
  33. {
  34. d_head = new mxListNode;
  35. d_tail = new mxListNode;
  36. d_head->d_data = 0;
  37. d_head->d_next = d_tail;
  38. d_head->d_prev = 0;
  39. d_tail->d_data = 0;
  40. d_tail->d_next = 0;
  41. d_tail->d_prev = d_head;
  42. d_nodeCount = 0;
  43. }
  44. ~mxLinkedList ()
  45. {
  46. removeAll ();
  47. delete d_tail;
  48. delete d_head;
  49. }
  50. // MANIPULATORS
  51. void add (void *data)
  52. {
  53. mxListNode *node = new mxListNode;
  54. node->d_data = data;
  55. d_tail->d_prev->d_next = node;
  56. node->d_prev = d_tail->d_prev;
  57. node->d_next = d_tail;
  58. d_tail->d_prev = node;
  59. ++d_nodeCount;
  60. }
  61. void remove (void *data)
  62. {
  63. mxListNode *node = d_head->d_next;
  64. while (node != d_tail)
  65. {
  66. mxListNode *next = node->d_next;
  67. if (node->d_data == data)
  68. {
  69. node->d_prev->d_next = node->d_next;
  70. node->d_next->d_prev = node->d_prev;
  71. delete node;
  72. }
  73. node = next;
  74. }
  75. --d_nodeCount;
  76. }
  77. void removeAll ()
  78. {
  79. mxListNode *node = d_head->d_next;
  80. while (node != d_tail)
  81. {
  82. mxListNode *next = node->d_next;
  83. delete node;
  84. node = next;
  85. }
  86. d_head->d_next = d_tail;
  87. d_tail->d_prev = d_head;
  88. d_nodeCount = 0;
  89. }
  90. void setData (mxListNode *node, void *data)
  91. {
  92. if (node)
  93. node->d_data = data;
  94. }
  95. // ACCESSORS
  96. void *getData (mxListNode *node) const
  97. {
  98. if (node)
  99. return node->d_data;
  100. return 0;
  101. }
  102. mxListNode *getFirst () const
  103. {
  104. if (d_head->d_next != d_tail)
  105. return d_head->d_next;
  106. return 0;
  107. }
  108. mxListNode *getNext (mxListNode *node) const
  109. {
  110. if (node)
  111. {
  112. if (node->d_next != d_tail)
  113. return node->d_next;
  114. return 0;
  115. }
  116. return 0;
  117. }
  118. mxListNode *getLast () const
  119. {
  120. if (d_tail->d_prev != d_head)
  121. return d_tail->d_prev;
  122. return 0;
  123. }
  124. mxListNode *getPrev (mxListNode *node) const
  125. {
  126. if (node)
  127. {
  128. if (node->d_prev != d_head)
  129. return node->d_prev;
  130. return 0;
  131. }
  132. return 0;
  133. }
  134. mxListNode *at (int pos) const
  135. {
  136. mxListNode *node = d_head->d_next;
  137. while (pos > 0 && node != d_tail)
  138. {
  139. pos--;
  140. node = node->d_next;
  141. }
  142. if (node != d_tail)
  143. return node;
  144. return 0;
  145. }
  146. bool isEmpty () const
  147. {
  148. return (d_head->d_next == d_tail);
  149. }
  150. int getNodeCount () const
  151. {
  152. return d_nodeCount;
  153. }
  154. };
  155. #endif // INCLUDED_MXLINKEDLIST