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.

86 lines
1.4 KiB

  1. // List.cpp: implementation of the List class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "List.h"
  5. #include "Object.h"
  6. #include <string.h>
  7. //////////////////////////////////////////////////////////////////////
  8. // Construction/Destruction
  9. //////////////////////////////////////////////////////////////////////
  10. List::List()
  11. {
  12. head = tail = 0;
  13. length = 0;
  14. }
  15. List::~List()
  16. {
  17. Object* o,*p;
  18. o = head;
  19. if (o) p = o->next;
  20. while (o) {
  21. delete o;
  22. o = p;
  23. if (o) p = o->next;
  24. }
  25. }
  26. void List::Add(Object* o) {
  27. if (o==0) return;
  28. if (head==0) {
  29. head = tail = o;
  30. length = 1;
  31. return;
  32. }
  33. o->next = head;
  34. head->prev = o;
  35. head = o;
  36. length++;
  37. }
  38. void List::Remove(TCHAR* s) {
  39. if (s==0) return;
  40. Object* ptr = head;
  41. while(ptr) {
  42. if (!wcscmp(s,ptr->Data())) {
  43. if (ptr->prev) ptr->prev->next = ptr->next;
  44. if (ptr->next) ptr->next->prev = ptr->prev;
  45. length--;
  46. if (ptr==head) head = ptr->next;
  47. }
  48. ptr = ptr->next;
  49. }
  50. }
  51. Object* List::Find(TCHAR* s) {
  52. Object* ptr = head;
  53. if (s==0) return 0;
  54. while (ptr!=0) {
  55. if (wcscmp(ptr->Data(),s)==0) return ptr;
  56. ptr = ptr->next;
  57. }
  58. return 0;
  59. }
  60. Object* List::Find(Object* o) {
  61. Object* ptr = head;
  62. if (o==0) return 0;
  63. while (ptr!=0) {
  64. if (wcscmp(ptr->Data(),o->Data())==0) return ptr;
  65. ptr = ptr->next;
  66. }
  67. return 0;
  68. }