Source code of Windows XP (NT5)
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.

157 lines
4.5 KiB

  1. #if _MSC_VER > 1000
  2. #pragma once
  3. #endif // _MSC_VER > 1000
  4. ////////////////////////////////////////////////////////////////////////////////
  5. //
  6. // block
  7. //
  8. // There should be a block or c_array type in STL, but MSVC might not have one,
  9. // so here it is:
  10. //
  11. ////////////////////////////////////////////////////////////////////////////////
  12. template< class T, const size_t N>
  13. struct block
  14. {
  15. typedef T value_type;
  16. typedef value_type* pointer;
  17. typedef const value_type* const_pointer;
  18. typedef value_type& reference;
  19. typedef const value_type& const_reference;
  20. typedef ptrdiff_t difference_type;
  21. typedef size_t size_type;
  22. typedef pointer iterator;
  23. typedef const_pointer const_iterator;
  24. struct reverse_iterator
  25. {
  26. typedef random_access_iterator_tag iterator_category;
  27. typedef value_type value_type;
  28. typedef difference_type difference_type;
  29. typedef pointer pointer;
  30. typedef reference reference;
  31. pointer m_pCur;
  32. reverse_iterator() throw()
  33. { }
  34. reverse_iterator( const iterator& x) throw(): m_pCur( x)
  35. { }
  36. operator iterator() const throw()
  37. { return m_pCur; }
  38. reference operator*() const throw()
  39. { return *m_pCur; }
  40. pointer operator->() const throw()
  41. { return &(*()); }
  42. reverse_iterator& operator++() throw()
  43. {
  44. --m_pCur;
  45. return (*this);
  46. }
  47. reverse_iterator operator++(int)
  48. {
  49. reverse_iterator Tmp( m_pCur);
  50. ++(*this);
  51. return Tmp;
  52. }
  53. reverse_iterator& operator--()
  54. {
  55. ++m_pCur;
  56. return (*this);
  57. }
  58. reverse_iterator operator--(int)
  59. {
  60. reverse_iterator Tmp( m_pCur);
  61. --(*this);
  62. return Tmp;
  63. }
  64. bool operator==( const reverse_iterator& Other) const
  65. { return (m_pCur== Other.m_pCur); }
  66. bool operator!=( const reverse_iterator& Other) const
  67. { return (m_pCur!= Other.m_pCur); }
  68. };
  69. struct const_reverse_iterator
  70. {
  71. typedef random_access_iterator_tag iterator_category;
  72. typedef value_type value_type;
  73. typedef difference_type difference_type;
  74. typedef const_pointer pointer;
  75. typedef const_reference reference;
  76. const_pointer m_pCur;
  77. const_reverse_iterator() throw()
  78. { }
  79. const_reverse_iterator( const const_iterator& x) throw(): m_pCur( x)
  80. { }
  81. const_reverse_iterator( const reverse_iterator& x) throw(): m_pCur( x)
  82. { }
  83. operator const_iterator() const throw()
  84. { return m_pCur; }
  85. reference operator*() const throw()
  86. { return *m_pCur; }
  87. pointer operator->() const throw()
  88. { return &(*()); }
  89. const_reverse_iterator& operator++() throw()
  90. {
  91. --m_pCur;
  92. return (*this);
  93. }
  94. const_reverse_iterator operator++(int)
  95. {
  96. const_reverse_iterator Tmp( m_pCur);
  97. ++(*this);
  98. return Tmp;
  99. }
  100. const_reverse_iterator& operator--()
  101. {
  102. ++m_pCur;
  103. return (*this);
  104. }
  105. const_reverse_iterator operator--(int)
  106. {
  107. reverse_iterator Tmp( m_pCur);
  108. --(*this);
  109. return Tmp;
  110. }
  111. bool operator==( const const_reverse_iterator& Other) const
  112. { return (m_pCur== Other.m_pCur); }
  113. bool operator!=( const const_reverse_iterator& Other) const
  114. { return (m_pCur!= Other.m_pCur); }
  115. };
  116. iterator begin() throw() { return data; }
  117. iterator end() throw() { return data+ N; }
  118. const_iterator begin() const throw() { return data; }
  119. const_iterator end() const throw() { return data+ N; }
  120. reverse_iterator rbegin() throw() { return data+ N- 1; }
  121. reverse_iterator rend() throw() { return data- 1; }
  122. const_reverse_iterator rbegin() const throw() { return data+ N- 1; }
  123. const_reverse_iterator rend() const throw() { return data- 1; }
  124. reference operator[]( size_type n) throw() {
  125. return data[n];
  126. }
  127. const_reference operator[]( size_type n) const throw() {
  128. return data[n];
  129. }
  130. size_type size() const throw() { return N; }
  131. size_type max_size() const throw() { return N; }
  132. bool empty() const throw() { return (0==N); }
  133. void swap( block<T,N>& x) throw() {
  134. size_type n(N);
  135. if( n!= 0) do {
  136. --n;
  137. swap( data[n], x.data[n]);
  138. } while( n!= 0);
  139. }
  140. T data[N];
  141. };