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.

100 lines
2.8 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1997 Microsoft Corporation. All Rights Reserved.
  5. Component: misc
  6. File: vector.h
  7. Owner: DGottner
  8. This file contains a dynamic array
  9. ===================================================================*
  10. /*
  11. * This file is derived from software bearing the following
  12. * restrictions:
  13. *
  14. * Copyright 1994, David Gottner
  15. *
  16. * All Rights Reserved
  17. *
  18. * Permission to use, copy, modify, and distribute this software and its
  19. * documentation for any purpose and without fee is hereby granted,
  20. * provided that the above copyright notice, this permission notice and
  21. * the following disclaimer notice appear unmodified in all copies.
  22. *
  23. * I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL I
  25. * BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
  26. * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER
  27. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  28. * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  29. *
  30. */
  31. #ifndef VECTOR_H
  32. #define VECTOR_H
  33. /*---------------------------------------------------------------------------*
  34. ** The vector class is a thin encapsulation of a C style array, which
  35. ** allows dynamic sizing of the array and bounds checking; you can also use
  36. ** this array as a stack. This is a value-based collection.
  37. */
  38. template <class TYPE>
  39. class vector {
  40. TYPE * m_rgData;
  41. size_t m_cItems;
  42. size_t m_cCells;
  43. public:
  44. vector<TYPE>();
  45. ~vector();
  46. HRESULT Init(const TYPE *, size_t);
  47. HRESULT Init(size_t n);
  48. vector<TYPE> &operator= (const vector<TYPE> &);
  49. size_t length() const { return m_cItems; }
  50. const TYPE *vec() const { return m_rgData; }
  51. // STL iterators (const)
  52. const TYPE *begin() const { return &m_rgData[0]; }
  53. const TYPE *end() const { return &m_rgData[m_cItems]; }
  54. // STL iterators (non-const)
  55. TYPE *begin() { return &m_rgData[0]; }
  56. TYPE *end() { return &m_rgData[m_cItems]; }
  57. TYPE operator[](unsigned i) const
  58. {
  59. Assert (i < m_cItems);
  60. return m_rgData[i];
  61. }
  62. TYPE &operator[](unsigned i)
  63. {
  64. Assert (i < m_cItems);
  65. return m_rgData[i];
  66. }
  67. HRESULT resize(size_t);
  68. HRESULT reshape(size_t);
  69. HRESULT append(const TYPE &a) { return insertAt(m_cItems, a); }
  70. HRESULT prepend(const TYPE &a) { return insertAt(0, a); }
  71. HRESULT insertAt(size_t, const TYPE &);
  72. TYPE removeAt(size_t);
  73. HRESULT push(const TYPE &a) { return append(a); }
  74. TYPE pop() { return m_rgData[--m_cItems]; }
  75. int find(const TYPE &) const;
  76. };
  77. #endif /* VECTOR */