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.1 KiB

  1. //============================================================================
  2. //
  3. // File implements generic linked list class
  4. //
  5. //============================================================================
  6. #include "pch.hxx"
  7. #include "list.h"
  8. #include <BadStrFunctions.h>
  9. CItem::CItem(LPVOID lpObj, LPItem FAR * lppHeadItem, LPCSTR lpName)
  10. {
  11. this->lpObj = lpObj;
  12. this->lpName = lpName;
  13. this->iRefCnt = 1;
  14. lppListHead = lppHeadItem;
  15. lpPrevItem = NULL;
  16. lpNextItem = *lppHeadItem; // NULL at the beginning.
  17. if ( *lppHeadItem )
  18. (*lppHeadItem)->lpPrevItem = this;
  19. *lppHeadItem = this;
  20. }
  21. CItem::~CItem()
  22. {
  23. if ( lpPrevItem )
  24. lpPrevItem->lpNextItem = lpNextItem;
  25. else
  26. *lppListHead = lpNextItem;
  27. if ( lpNextItem )
  28. lpNextItem->lpPrevItem = lpPrevItem;
  29. if ( lpName )
  30. free ( (LPVOID)lpName );
  31. }
  32. CList::~CList()
  33. {
  34. LPItem lpItem;
  35. while ( lpListHead )
  36. {
  37. lpItem = lpListHead;
  38. delete lpItem; // item @ list head modifies lpListHead
  39. }
  40. }
  41. LPItem CList::FindItem(LPVOID lpObj)
  42. {
  43. LPItem lpItem = lpListHead;
  44. while ( lpItem )
  45. {
  46. if (lpItem->lpObj == lpObj)
  47. return lpItem;
  48. lpItem = lpItem->lpNextItem;
  49. }
  50. return NULL;
  51. }
  52. LPVOID CList::FindItemHandleWithName(LPCSTR lpName, LPVOID lpMem)
  53. {
  54. LPItem lpItem = lpListHead;
  55. while( lpItem )
  56. {
  57. if( lpName )
  58. {
  59. if( !strcmpi( lpName, lpItem->lpName ) )
  60. {
  61. lpItem->iRefCnt++;
  62. return lpItem->lpObj;
  63. }
  64. }
  65. else
  66. {
  67. if (lpItem->lpObj == lpMem)
  68. {
  69. lpItem->iRefCnt--;
  70. if( lpItem->iRefCnt == 0 )
  71. return lpItem->lpObj;
  72. else
  73. return NULL;
  74. }
  75. }
  76. lpItem = lpItem->lpNextItem;
  77. }
  78. return NULL;
  79. }