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.

200 lines
4.6 KiB

  1. //--------------------------------------------------------------------------------------------------
  2. // qhList.inl
  3. //
  4. // Copyright(C) 2011 by D. Gregorius. All rights reserved.
  5. //--------------------------------------------------------------------------------------------------
  6. //--------------------------------------------------------------------------------------------------
  7. // qhListNode
  8. //--------------------------------------------------------------------------------------------------
  9. template < typename T > inline
  10. void qhInsert( T* Node, T* Where )
  11. {
  12. QH_ASSERT( !qhInList( Node ) && qhInList( Where ) );
  13. Node->Prev = Where->Prev;
  14. Node->Next = Where;
  15. Node->Prev->Next = Node;
  16. Node->Next->Prev = Node;
  17. }
  18. //--------------------------------------------------------------------------------------------------
  19. template < typename T > inline
  20. void qhRemove( T* Node )
  21. {
  22. QH_ASSERT( qhInList( Node ) );
  23. Node->Prev->Next = Node->Next;
  24. Node->Next->Prev = Node->Prev;
  25. Node->Prev = NULL;
  26. Node->Next = NULL;
  27. }
  28. //--------------------------------------------------------------------------------------------------
  29. template < typename T > inline
  30. bool qhInList( T* Node )
  31. {
  32. return Node->Prev != NULL && Node->Next != NULL;
  33. }
  34. //--------------------------------------------------------------------------------------------------
  35. // qhList
  36. //--------------------------------------------------------------------------------------------------
  37. template < typename T > inline
  38. qhList< T >::qhList( void )
  39. {
  40. mHead.Prev = &mHead;
  41. mHead.Next = &mHead;
  42. }
  43. //--------------------------------------------------------------------------------------------------
  44. template < typename T > inline
  45. int qhList< T >::Size( void ) const
  46. {
  47. int Count = 0;
  48. for ( const T* Node = Begin(); Node != End(); Node = Node->Next )
  49. {
  50. Count++;
  51. }
  52. return Count;
  53. }
  54. //--------------------------------------------------------------------------------------------------
  55. template < typename T > inline
  56. bool qhList< T >::Empty( void ) const
  57. {
  58. return mHead.Next == &mHead;
  59. }
  60. //--------------------------------------------------------------------------------------------------
  61. template < typename T > inline
  62. void qhList< T >::Clear( void )
  63. {
  64. mHead.Prev = &mHead;
  65. mHead.Next = &mHead;
  66. }
  67. //--------------------------------------------------------------------------------------------------
  68. template < typename T > inline
  69. void qhList< T >::PushFront( T* Node )
  70. {
  71. qhInsert( Node, mHead.Next );
  72. }
  73. //--------------------------------------------------------------------------------------------------
  74. template < typename T > inline
  75. void qhList< T >::PopFront( void )
  76. {
  77. QH_ASSERT( !Empty() );
  78. T* Node = mHead.Next;
  79. qhRemove( Node );
  80. }
  81. //--------------------------------------------------------------------------------------------------
  82. template < typename T > inline
  83. void qhList< T >::PushBack( T* Node )
  84. {
  85. qhInsert( Node, mHead.Prev );
  86. }
  87. //--------------------------------------------------------------------------------------------------
  88. template < typename T > inline
  89. void qhList< T >::PopBack( void )
  90. {
  91. QH_ASSERT( !Empty() );
  92. T* Node = mHead.Prev;
  93. qhRemove( Node );
  94. }
  95. //--------------------------------------------------------------------------------------------------
  96. template < typename T > inline
  97. void qhList< T >::Insert( T* Node, T* Where )
  98. {
  99. qhInsert( Node, Where );
  100. }
  101. //--------------------------------------------------------------------------------------------------
  102. template < typename T > inline
  103. void qhList< T >::Remove( T* Node )
  104. {
  105. qhRemove( Node );
  106. }
  107. //--------------------------------------------------------------------------------------------------
  108. template < typename T > inline
  109. int qhList< T >::IndexOf( const T* Node ) const
  110. {
  111. int Index = 0;
  112. for ( const T* First = Begin(); First != End(); First = First->Next )
  113. {
  114. if ( First == Node )
  115. {
  116. return Index;
  117. }
  118. Index++;
  119. }
  120. return -1;
  121. }
  122. //--------------------------------------------------------------------------------------------------
  123. template < typename T > inline
  124. T* qhList< T >::Begin( void )
  125. {
  126. return mHead.Next;
  127. }
  128. //--------------------------------------------------------------------------------------------------
  129. template < typename T > inline
  130. const T* qhList< T >::Begin( void ) const
  131. {
  132. return mHead.Next;
  133. }
  134. //--------------------------------------------------------------------------------------------------
  135. template < typename T > inline
  136. T* qhList< T >::End( void )
  137. {
  138. return &mHead;
  139. }
  140. //--------------------------------------------------------------------------------------------------
  141. template < typename T > inline
  142. const T* qhList< T >::End( void ) const
  143. {
  144. return &mHead;
  145. }