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.

77 lines
1016 B

  1. #pragma once
  2. class elt
  3. {
  4. public:
  5. LPTSTR key;
  6. LPTSTR val;
  7. elt *next,
  8. *prev;
  9. elt()
  10. {
  11. next = NULL;
  12. prev = NULL;
  13. key = NULL;
  14. val = NULL;
  15. }
  16. virtual ~elt()
  17. {
  18. if (key)
  19. free (key);
  20. if (val)
  21. free (val);
  22. }
  23. };
  24. class CStrList
  25. {
  26. protected:
  27. elt *head;
  28. int count;
  29. HANDLE hmtxLock;
  30. elt *FindElement ( LPCTSTR key );
  31. void Lock ()
  32. {
  33. if ( hmtxLock )
  34. WaitForSingleObject ( hmtxLock, INFINITE );
  35. }
  36. void Unlock ()
  37. {
  38. if ( hmtxLock )
  39. ReleaseMutex ( hmtxLock );
  40. }
  41. public:
  42. CStrList()
  43. {
  44. head = NULL;
  45. count = 0;
  46. hmtxLock = CreateMutex ( NULL, FALSE, NULL );
  47. }
  48. virtual ~CStrList()
  49. {
  50. RemoveAll();
  51. CloseHandle ( hmtxLock );
  52. }
  53. bool AddValue ( LPCTSTR key, LPCTSTR val );
  54. LPTSTR Lookup ( LPCTSTR key, LPTSTR outBuf );
  55. void RemoveByKey ( LPCTSTR key );
  56. void RemoveAll ();
  57. LPTSTR ConcatKeyValues ( LPCTSTR separator, LPTSTR outBuf );
  58. int GetCount ()
  59. {
  60. return count;
  61. }
  62. };