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.

139 lines
1.8 KiB

  1. /*++
  2. Copyright (C) 2000 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. list.cxx
  6. Abstract:
  7. List template class.
  8. Author:
  9. Steve Kiraly (SteveKi) 03-Mar-2000
  10. Revision History:
  11. --*/
  12. #include "spllibp.hxx"
  13. #pragma hdrstop
  14. #include "CSRutility.hxx"
  15. #include "CSRlist.hxx"
  16. using namespace NCoreLibrary;
  17. TLink::
  18. TLink(
  19. VOID
  20. )
  21. {
  22. m_pNext = this;
  23. m_pPrev = this;
  24. }
  25. TLink::
  26. ~TLink(
  27. VOID
  28. )
  29. {
  30. if (SUCCEEDED(IsLinked()))
  31. {
  32. UnLink();
  33. }
  34. }
  35. HRESULT
  36. TLink::
  37. IsValid(
  38. VOID
  39. ) const
  40. {
  41. return m_pNext && m_pPrev ? S_OK : E_FAIL;
  42. }
  43. HRESULT
  44. TLink::
  45. IsLinked(
  46. VOID
  47. ) const
  48. {
  49. return m_pNext != this && m_pPrev != this ? S_OK : E_FAIL;
  50. }
  51. HRESULT
  52. TLink::
  53. Link(
  54. IN TLink *pNode
  55. )
  56. {
  57. HRESULT hRetval = E_FAIL;
  58. //
  59. // The caller must provide a valid node pointer.
  60. //
  61. if (pNode)
  62. {
  63. //
  64. // We cannot be linked twice.
  65. //
  66. if (SUCCEEDED(pNode->IsLinked()))
  67. {
  68. pNode->UnLink();
  69. }
  70. //
  71. // Link the specified node just after the this Node.
  72. //
  73. m_pNext->m_pPrev = pNode;
  74. pNode->m_pNext = m_pNext;
  75. pNode->m_pPrev = this;
  76. m_pNext = pNode;
  77. //
  78. // Indicate success.
  79. //
  80. hRetval = S_OK;
  81. }
  82. return hRetval;
  83. }
  84. VOID
  85. TLink::
  86. UnLink(
  87. VOID
  88. )
  89. {
  90. //
  91. // UnLink this node from the list.
  92. //
  93. m_pNext->m_pPrev = m_pPrev;
  94. m_pPrev->m_pNext = m_pNext;
  95. //
  96. // Fix yourself up now.
  97. //
  98. m_pPrev = m_pNext = this;
  99. }
  100. TLink *
  101. TLink::
  102. Next(
  103. VOID
  104. ) const
  105. {
  106. return m_pNext;
  107. }
  108. TLink *
  109. TLink::
  110. Prev(
  111. VOID
  112. ) const
  113. {
  114. return m_pPrev;
  115. }