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.

104 lines
2.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: list.cpp
  8. //
  9. // Contents: list helper functions.
  10. //
  11. // History: 27-Nov-96 kevinr created
  12. //
  13. //--------------------------------------------------------------------------
  14. #include "global.hxx"
  15. //--------------------------------------------------------------------------
  16. //
  17. //--------------------------------------------------------------------------
  18. BOOL CList::InsertHead( CNode *pn)
  19. {
  20. if (pn == NULL)
  21. return FALSE;
  22. pn->SetPrev( NULL);
  23. pn->SetNext( m_pnHead);
  24. if (m_pnHead)
  25. m_pnHead->SetPrev( pn);
  26. else
  27. m_pnTail = pn; // list was empty
  28. m_pnHead = pn;
  29. m_cNode++;
  30. return TRUE;
  31. };
  32. //--------------------------------------------------------------------------
  33. //
  34. //--------------------------------------------------------------------------
  35. BOOL CList::InsertTail( CNode *pn)
  36. {
  37. if (pn == NULL)
  38. return FALSE;
  39. pn->SetPrev( m_pnTail);
  40. pn->SetNext( NULL);
  41. if (m_pnTail)
  42. m_pnTail->SetNext( pn);
  43. else
  44. m_pnHead = pn; // list was empty
  45. m_pnTail = pn;
  46. m_cNode++;
  47. return TRUE;
  48. };
  49. //--------------------------------------------------------------------------
  50. // Remove node from the list. Do not delete the node.
  51. //--------------------------------------------------------------------------
  52. BOOL CList::Remove( CNode *pn)
  53. {
  54. if (pn == NULL)
  55. return FALSE;
  56. CNode *pnPrev = pn->Prev();
  57. CNode *pnNext = pn->Next();
  58. if (pnPrev)
  59. pnPrev->SetNext( pnNext);
  60. if (pnNext)
  61. pnNext->SetPrev( pnPrev);
  62. if (pn == m_pnHead)
  63. m_pnHead = pnNext;
  64. if (pn == m_pnTail)
  65. m_pnTail = pnPrev;
  66. m_cNode--;
  67. return TRUE;
  68. };
  69. //--------------------------------------------------------------------------
  70. //
  71. //--------------------------------------------------------------------------
  72. CNode * CList::Nth( DWORD i)
  73. {
  74. CNode *pn;
  75. if (i >= m_cNode)
  76. return NULL;
  77. for (pn = m_pnHead;
  78. (i>0) && pn;
  79. i--, pn=pn->Next())
  80. ;
  81. return pn;
  82. };