/project/jni/stlport/stlport/stl/_iterator_old.h

https://github.com/aichunyu/FFPlayer · C Header · 351 lines · 280 code · 36 blank · 35 comment · 15 complexity · 4393296946dc3d95d8696b6360e272bb MD5 · raw file

  1. /*
  2. *
  3. * Copyright (c) 1994
  4. * Hewlett-Packard Company
  5. *
  6. * Copyright (c) 1996-1998
  7. * Silicon Graphics Computer Systems, Inc.
  8. *
  9. * Copyright (c) 1997
  10. * Moscow Center for SPARC Technology
  11. *
  12. * Copyright (c) 1999
  13. * Boris Fomitchev
  14. *
  15. * This material is provided "as is", with absolutely no warranty expressed
  16. * or implied. Any use is at your own risk.
  17. *
  18. * Permission to use or copy this software for any purpose is hereby granted
  19. * without fee, provided the above notices are retained on all copies.
  20. * Permission to modify the code and to distribute modified code is granted,
  21. * provided the above notices are retained, and a notice that the code was
  22. * modified is included with the above copyright notice.
  23. *
  24. */
  25. /* NOTE: This is an internal header file, included by other STL headers.
  26. * You should not attempt to use it directly.
  27. */
  28. #ifndef _STLP_INTERNAL_ITERATOR_OLD_H
  29. #define _STLP_INTERNAL_ITERATOR_OLD_H
  30. #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
  31. # include <stl/_iterator_base.h>
  32. #endif
  33. _STLP_BEGIN_NAMESPACE
  34. # ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
  35. template <class _Container>
  36. inline output_iterator_tag _STLP_CALL
  37. iterator_category(const back_insert_iterator<_Container>&) { return output_iterator_tag(); }
  38. template <class _Container>
  39. inline output_iterator_tag _STLP_CALL
  40. iterator_category(const front_insert_iterator<_Container>&) { return output_iterator_tag(); }
  41. template <class _Container>
  42. inline output_iterator_tag _STLP_CALL
  43. iterator_category(const insert_iterator<_Container>&) { return output_iterator_tag(); }
  44. # endif
  45. # if defined (_STLP_MSVC50_COMPATIBILITY)
  46. # define __Reference _Reference, class _Pointer
  47. # define Reference__ _Reference, _Pointer
  48. template <class _BidirectionalIterator, class _Tp,
  49. _STLP_DFL_TMPL_PARAM(_Reference, _Tp& ),
  50. _STLP_DFL_TMPL_PARAM(_Pointer, _Tp*),
  51. _STLP_DFL_TYPE_PARAM(_Distance, ptrdiff_t)>
  52. # else
  53. # define __Reference _Reference
  54. # define Reference__ _Reference
  55. template <class _BidirectionalIterator, class _Tp, _STLP_DFL_TMPL_PARAM(_Reference, _Tp& ),
  56. _STLP_DFL_TYPE_PARAM(_Distance, ptrdiff_t)>
  57. # endif
  58. class reverse_bidirectional_iterator {
  59. typedef reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
  60. Reference__, _Distance> _Self;
  61. // friend inline bool operator== _STLP_NULL_TMPL_ARGS (const _Self& x, const _Self& y);
  62. protected:
  63. _BidirectionalIterator current;
  64. public:
  65. typedef bidirectional_iterator_tag iterator_category;
  66. typedef _Tp value_type;
  67. typedef _Distance difference_type;
  68. # if defined (_STLP_MSVC50_COMPATIBILITY)
  69. typedef _Pointer pointer;
  70. # else
  71. typedef _Tp* pointer;
  72. # endif
  73. typedef _Reference reference;
  74. reverse_bidirectional_iterator() {}
  75. explicit reverse_bidirectional_iterator(_BidirectionalIterator __x)
  76. : current(__x) {}
  77. _BidirectionalIterator base() const { return current; }
  78. _Reference operator*() const {
  79. _BidirectionalIterator __tmp = current;
  80. return *(--__tmp);
  81. }
  82. # if !(defined _STLP_NO_ARROW_OPERATOR)
  83. _STLP_DEFINE_ARROW_OPERATOR
  84. # endif
  85. _Self& operator++() {
  86. --current;
  87. return *this;
  88. }
  89. _Self operator++(int) {
  90. _Self __tmp = *this;
  91. --current;
  92. return __tmp;
  93. }
  94. _Self& operator--() {
  95. ++current;
  96. return *this;
  97. }
  98. _Self operator--(int) {
  99. _Self __tmp = *this;
  100. ++current;
  101. return __tmp;
  102. }
  103. };
  104. # ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
  105. template <class _BidirectionalIterator, class _Tp, class __Reference,
  106. class _Distance>
  107. inline bidirectional_iterator_tag _STLP_CALL
  108. iterator_category(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp, Reference__, _Distance>&)
  109. { return bidirectional_iterator_tag(); }
  110. template <class _BidirectionalIterator, class _Tp, class __Reference,
  111. class _Distance>
  112. inline _Tp* _STLP_CALL
  113. value_type(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp, Reference__, _Distance>&)
  114. { return (_Tp*) 0; }
  115. template <class _BidirectionalIterator, class _Tp, class __Reference,
  116. class _Distance>
  117. inline _Distance* _STLP_CALL
  118. distance_type(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp, Reference__, _Distance>&)
  119. { return (_Distance*) 0; }
  120. #endif
  121. template <class _BidirectionalIterator, class _Tp, class __Reference,
  122. class _Distance>
  123. inline bool _STLP_CALL operator==(
  124. const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
  125. Reference__, _Distance>& __x,
  126. const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
  127. Reference__, _Distance>& __y)
  128. {
  129. return __x.base() == __y.base();
  130. }
  131. #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
  132. template <class _BiIter, class _Tp, class __Reference, class _Distance>
  133. inline bool _STLP_CALL operator!=(
  134. const reverse_bidirectional_iterator<_BiIter, _Tp, Reference__, _Distance>& __x,
  135. const reverse_bidirectional_iterator<_BiIter, _Tp, Reference__, _Distance>& __y)
  136. {
  137. return !(__x == __y);
  138. }
  139. #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
  140. #if ! defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION )
  141. // This is the old version of reverse_iterator, as found in the original
  142. // HP STL. It does not use partial specialization.
  143. template <class _RandomAccessIterator,
  144. # if defined (__MSL__) && (__MSL__ >= 0x2405) \
  145. || defined(__MRC__) || (defined(__SC__) && !defined(__DMC__)) //*ty 03/22/2001 - give the default to the secont param under MPW.
  146. // I believe giving the default will cause any harm even though the 2nd type parameter
  147. // still have to be provided for T* type iterators.
  148. _STLP_DFL_TMPL_PARAM(_Tp,iterator_traits<_RandomAccessIterator>::value_type),
  149. # else
  150. class _Tp,
  151. #endif
  152. _STLP_DFL_TMPL_PARAM(_Reference,_Tp&),
  153. # if defined (_STLP_MSVC50_COMPATIBILITY)
  154. _STLP_DFL_TMPL_PARAM(_Pointer, _Tp*),
  155. # endif
  156. _STLP_DFL_TYPE_PARAM(_Distance,ptrdiff_t)>
  157. class reverse_iterator {
  158. typedef reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>
  159. _Self;
  160. protected:
  161. _RandomAccessIterator __current;
  162. public:
  163. typedef random_access_iterator_tag iterator_category;
  164. typedef _Tp value_type;
  165. typedef _Distance difference_type;
  166. # if defined (_STLP_MSVC50_COMPATIBILITY)
  167. typedef _Pointer pointer;
  168. # else
  169. typedef _Tp* pointer;
  170. # endif
  171. typedef _Reference reference;
  172. reverse_iterator() {}
  173. reverse_iterator(const _Self& __x) : __current(__x.base()) {}
  174. explicit reverse_iterator(_RandomAccessIterator __x) : __current(__x) {}
  175. _Self& operator=(const _Self& __x) {__current = __x.base(); return *this; }
  176. _RandomAccessIterator base() const { return __current; }
  177. _Reference operator*() const { return *(__current - (difference_type)1); }
  178. # if !(defined _STLP_NO_ARROW_OPERATOR)
  179. _STLP_DEFINE_ARROW_OPERATOR
  180. # endif
  181. _Self& operator++() {
  182. --__current;
  183. return *this;
  184. }
  185. _Self operator++(int) {
  186. _Self __tmp = *this;
  187. --__current;
  188. return __tmp;
  189. }
  190. _Self& operator--() {
  191. ++__current;
  192. return *this;
  193. }
  194. _Self operator--(int) {
  195. _Self __tmp = *this;
  196. ++__current;
  197. return __tmp;
  198. }
  199. _Self operator+(_Distance __n) const {
  200. return _Self(__current - __n);
  201. }
  202. _Self& operator+=(_Distance __n) {
  203. __current -= __n;
  204. return *this;
  205. }
  206. _Self operator-(_Distance __n) const {
  207. return _Self(__current + __n);
  208. }
  209. _Self& operator-=(_Distance __n) {
  210. __current += __n;
  211. return *this;
  212. }
  213. _Reference operator[](_Distance __n) const { return *(*this + __n); }
  214. };
  215. # ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
  216. template <class _RandomAccessIterator, class _Tp,
  217. class __Reference, class _Distance>
  218. inline random_access_iterator_tag _STLP_CALL
  219. iterator_category(const reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>&)
  220. { return random_access_iterator_tag(); }
  221. template <class _RandomAccessIterator, class _Tp,
  222. class __Reference, class _Distance>
  223. inline _Tp* _STLP_CALL value_type(const reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>&)
  224. { return (_Tp*) 0; }
  225. template <class _RandomAccessIterator, class _Tp,
  226. class __Reference, class _Distance>
  227. inline _Distance* _STLP_CALL
  228. distance_type(const reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>&)
  229. { return (_Distance*) 0; }
  230. #endif
  231. template <class _RandomAccessIterator, class _Tp,
  232. class __Reference, class _Distance>
  233. inline bool _STLP_CALL
  234. operator==(const reverse_iterator<_RandomAccessIterator, _Tp,
  235. Reference__, _Distance>& __x,
  236. const reverse_iterator<_RandomAccessIterator, _Tp,
  237. Reference__, _Distance>& __y)
  238. {
  239. return __x.base() == __y.base();
  240. }
  241. template <class _RandomAccessIterator, class _Tp,
  242. class __Reference, class _Distance>
  243. inline bool _STLP_CALL
  244. operator<(const reverse_iterator<_RandomAccessIterator, _Tp,
  245. Reference__, _Distance>& __x,
  246. const reverse_iterator<_RandomAccessIterator, _Tp,
  247. Reference__, _Distance>& __y)
  248. {
  249. return __y.base() < __x.base();
  250. }
  251. #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
  252. template <class _RandomAccessIterator, class _Tp,
  253. class __Reference, class _Distance>
  254. inline bool _STLP_CALL
  255. operator!=(const reverse_iterator<_RandomAccessIterator, _Tp,
  256. Reference__, _Distance>& __x,
  257. const reverse_iterator<_RandomAccessIterator, _Tp,
  258. Reference__, _Distance>& __y) {
  259. return !(__x == __y);
  260. }
  261. template <class _RandomAccessIterator, class _Tp,
  262. class __Reference, class _Distance>
  263. inline bool _STLP_CALL
  264. operator>(const reverse_iterator<_RandomAccessIterator, _Tp,
  265. Reference__, _Distance>& __x,
  266. const reverse_iterator<_RandomAccessIterator, _Tp,
  267. Reference__, _Distance>& __y) {
  268. return __y < __x;
  269. }
  270. template <class _RandomAccessIterator, class _Tp,
  271. class __Reference, class _Distance>
  272. inline bool _STLP_CALL
  273. operator<=(const reverse_iterator<_RandomAccessIterator, _Tp,
  274. Reference__, _Distance>& __x,
  275. const reverse_iterator<_RandomAccessIterator, _Tp,
  276. Reference__, _Distance>& __y) {
  277. return !(__y < __x);
  278. }
  279. template <class _RandomAccessIterator, class _Tp,
  280. class __Reference, class _Distance>
  281. inline bool _STLP_CALL
  282. operator>=(const reverse_iterator<_RandomAccessIterator, _Tp,
  283. Reference__, _Distance>& __x,
  284. const reverse_iterator<_RandomAccessIterator, _Tp,
  285. Reference__, _Distance>& __y) {
  286. return !(__x < __y);
  287. }
  288. #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
  289. template <class _RandomAccessIterator, class _Tp,
  290. class __Reference, class _Distance>
  291. inline _Distance _STLP_CALL
  292. operator-(const reverse_iterator<_RandomAccessIterator, _Tp,
  293. Reference__, _Distance>& __x,
  294. const reverse_iterator<_RandomAccessIterator, _Tp,
  295. Reference__, _Distance>& __y)
  296. {
  297. return __y.base() - __x.base();
  298. }
  299. template <class _RandomAccessIterator, class _Tp,
  300. class __Reference, class _Distance>
  301. inline reverse_iterator<_RandomAccessIterator, _Tp,
  302. Reference__, _Distance> _STLP_CALL
  303. operator+(_Distance __n,
  304. const reverse_iterator<_RandomAccessIterator, _Tp,
  305. Reference__, _Distance>& __x)
  306. {
  307. return reverse_iterator<_RandomAccessIterator, _Tp,
  308. Reference__, _Distance>(__x.base() - __n);
  309. }
  310. #endif /* ! defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION ) */
  311. _STLP_END_NAMESPACE
  312. #endif /* _STLP_INTERNAL_ITERATOR_H */
  313. // Local Variables:
  314. // mode:C++
  315. // End: