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.

83 lines
2.3 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1993-1995
  4. * TITLE: VEC.H
  5. * VERSION: 1.0
  6. * AUTHOR: jsenior
  7. * DATE: 10/28/1998
  8. *
  9. ********************************************************************************
  10. *
  11. * CHANGE LOG:
  12. *
  13. * DATE REV DESCRIPTION
  14. * ---------- ------- ----------------------------------------------------------
  15. * 10/28/1998 jsenior Original implementation.
  16. *
  17. *******************************************************************************/
  18. #ifndef _VEC_H
  19. #define _VEC_H
  20. //#include "debug.h"
  21. #include <assert.h>
  22. template<class T>
  23. class _VecElement {
  24. public:
  25. _VecElement() { data = NULL; next = NULL; prev = NULL; }
  26. _VecElement(T& newElement, _VecElement* oldElement) {
  27. data = new T;
  28. assert(data);
  29. *data = newElement;
  30. // CopyMemory(data, &newElement, sizeof(T));
  31. next = oldElement;
  32. prev = NULL;
  33. if (oldElement) { oldElement->prev = this; } }
  34. ~_VecElement() {
  35. if (prev) { prev->next = next; }
  36. if (next) { next->prev = prev; }
  37. delete data;
  38. data = NULL; }
  39. T* GetData() { return data; }
  40. _VecElement* GetNext() { return next; }
  41. private:
  42. T* data;
  43. _VecElement *next;
  44. _VecElement *prev;
  45. };
  46. template<class T>
  47. class _Vec {
  48. public:
  49. _Vec() { first = NULL; current = NULL; }
  50. ~_Vec() { clear(); }
  51. void clear() {
  52. if (first) {
  53. _VecElement<T> *temp = first->GetNext();
  54. for ( ; first; first = temp) {
  55. temp = first->GetNext();
  56. delete first; } }
  57. }
  58. void push_back(T &element) {
  59. first = new _VecElement<T>(element, first);
  60. assert(first); }
  61. T* begin() {
  62. current = first;
  63. return current ? current->GetData() : NULL; }
  64. T* next() {
  65. current = current->GetNext();
  66. return Current(); }
  67. T* Current() { return current ? current->GetData() : NULL; }
  68. void eraseCurrent() {
  69. if (current == first && first) { first = first->GetNext(); }
  70. delete current;
  71. current = first; }
  72. BOOL empty() { return first ? FALSE : TRUE; }
  73. private:
  74. _VecElement<T>* first;
  75. _VecElement<T>* current;
  76. };
  77. #endif // _VEC_H