/project/jni/stlport/stlport/stl/_iterator.h

https://github.com/aichunyu/FFPlayer · C Header · 266 lines · 198 code · 30 blank · 38 comment · 6 complexity · ad4cf8391f69050f8b27c3f27a1887de 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_H
  29. #define _STLP_INTERNAL_ITERATOR_H
  30. #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
  31. # include <stl/_iterator_base.h>
  32. #endif
  33. _STLP_BEGIN_NAMESPACE
  34. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  35. // This is the new version of reverse_iterator, as defined in the
  36. // draft C++ standard. It relies on the iterator_traits template,
  37. // which in turn relies on partial specialization. The class
  38. // reverse_bidirectional_iterator is no longer part of the draft
  39. // standard, but it is retained for backward compatibility.
  40. template <class _Iterator>
  41. class reverse_iterator :
  42. public iterator<typename iterator_traits<_Iterator>::iterator_category,
  43. typename iterator_traits<_Iterator>::value_type,
  44. typename iterator_traits<_Iterator>::difference_type,
  45. typename iterator_traits<_Iterator>::pointer,
  46. typename iterator_traits<_Iterator>::reference> {
  47. protected:
  48. _Iterator current;
  49. typedef reverse_iterator<_Iterator> _Self;
  50. public:
  51. typedef typename iterator_traits<_Iterator>::iterator_category iterator_category;
  52. typedef typename iterator_traits<_Iterator>::value_type value_type;
  53. typedef typename iterator_traits<_Iterator>::difference_type difference_type;
  54. typedef typename iterator_traits<_Iterator>::pointer pointer;
  55. typedef typename iterator_traits<_Iterator>::reference reference;
  56. typedef _Iterator iterator_type;
  57. public:
  58. reverse_iterator() {}
  59. explicit reverse_iterator(iterator_type __x) : current(__x) {}
  60. reverse_iterator(const _Self& __x) : current(__x.current) {}
  61. _Self& operator = (const _Self& __x) { current = __x.base(); return *this; }
  62. # if defined (_STLP_MEMBER_TEMPLATES)
  63. template <class _Iter>
  64. reverse_iterator(const reverse_iterator<_Iter>& __x) : current(__x.base()) {}
  65. template <class _Iter>
  66. _Self& operator = (const reverse_iterator<_Iter>& __x) { current = __x.base(); return *this; }
  67. # endif /* _STLP_MEMBER_TEMPLATES */
  68. iterator_type base() const { return current; }
  69. reference operator*() const {
  70. _Iterator __tmp = current;
  71. return *--__tmp;
  72. }
  73. _STLP_DEFINE_ARROW_OPERATOR
  74. _Self& operator++() {
  75. --current;
  76. return *this;
  77. }
  78. _Self operator++(int) {
  79. _Self __tmp = *this;
  80. --current;
  81. return __tmp;
  82. }
  83. _Self& operator--() {
  84. ++current;
  85. return *this;
  86. }
  87. _Self operator--(int) {
  88. _Self __tmp = *this;
  89. ++current;
  90. return __tmp;
  91. }
  92. _Self operator+(difference_type __n) const { return _Self(current - __n); }
  93. _Self& operator+=(difference_type __n) {
  94. current -= __n;
  95. return *this;
  96. }
  97. _Self operator-(difference_type __n) const { return _Self(current + __n); }
  98. _Self& operator-=(difference_type __n) {
  99. current += __n;
  100. return *this;
  101. }
  102. reference operator[](difference_type __n) const { return *(*this + __n); }
  103. };
  104. template <class _Iterator>
  105. inline bool _STLP_CALL operator==(const reverse_iterator<_Iterator>& __x,
  106. const reverse_iterator<_Iterator>& __y)
  107. { return __x.base() == __y.base(); }
  108. template <class _Iterator>
  109. inline bool _STLP_CALL operator<(const reverse_iterator<_Iterator>& __x,
  110. const reverse_iterator<_Iterator>& __y)
  111. { return __y.base() < __x.base(); }
  112. # if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
  113. template <class _Iterator>
  114. inline bool _STLP_CALL operator!=(const reverse_iterator<_Iterator>& __x,
  115. const reverse_iterator<_Iterator>& __y)
  116. { return !(__x == __y); }
  117. template <class _Iterator>
  118. inline bool _STLP_CALL operator>(const reverse_iterator<_Iterator>& __x,
  119. const reverse_iterator<_Iterator>& __y)
  120. { return __y < __x; }
  121. template <class _Iterator>
  122. inline bool _STLP_CALL operator<=(const reverse_iterator<_Iterator>& __x,
  123. const reverse_iterator<_Iterator>& __y)
  124. { return !(__y < __x); }
  125. template <class _Iterator>
  126. inline bool _STLP_CALL operator>=(const reverse_iterator<_Iterator>& __x,
  127. const reverse_iterator<_Iterator>& __y)
  128. { return !(__x < __y); }
  129. # endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
  130. template <class _Iterator>
  131. # if defined (__SUNPRO_CC)
  132. inline ptrdiff_t _STLP_CALL
  133. # else
  134. inline typename reverse_iterator<_Iterator>::difference_type _STLP_CALL
  135. # endif
  136. operator-(const reverse_iterator<_Iterator>& __x,
  137. const reverse_iterator<_Iterator>& __y)
  138. { return __y.base() - __x.base(); }
  139. template <class _Iterator, class _DifferenceType>
  140. inline reverse_iterator<_Iterator> _STLP_CALL
  141. operator+(_DifferenceType n,const reverse_iterator<_Iterator>& x)
  142. { return x.operator+(n); }
  143. #endif
  144. template <class _Container>
  145. class back_insert_iterator
  146. : public iterator<output_iterator_tag, void, void, void, void> {
  147. typedef back_insert_iterator<_Container> _Self;
  148. protected:
  149. //c is a Standard name (24.4.2.1), do no make it STLport naming convention compliant.
  150. _Container *container;
  151. public:
  152. typedef _Container container_type;
  153. typedef output_iterator_tag iterator_category;
  154. explicit back_insert_iterator(_Container& __x) : container(&__x) {}
  155. _Self& operator=(const _Self& __other) {
  156. container = __other.container;
  157. return *this;
  158. }
  159. _Self& operator=(const typename _Container::value_type& __val) {
  160. container->push_back(__val);
  161. return *this;
  162. }
  163. _Self& operator*() { return *this; }
  164. _Self& operator++() { return *this; }
  165. _Self operator++(int) { return *this; }
  166. };
  167. template <class _Container>
  168. inline back_insert_iterator<_Container> _STLP_CALL back_inserter(_Container& __x)
  169. { return back_insert_iterator<_Container>(__x); }
  170. template <class _Container>
  171. class front_insert_iterator
  172. : public iterator<output_iterator_tag, void, void, void, void> {
  173. typedef front_insert_iterator<_Container> _Self;
  174. protected:
  175. //c is a Standard name (24.4.2.3), do no make it STLport naming convention compliant.
  176. _Container *container;
  177. public:
  178. typedef _Container container_type;
  179. typedef output_iterator_tag iterator_category;
  180. explicit front_insert_iterator(_Container& __x) : container(&__x) {}
  181. _Self& operator=(const _Self& __other) {
  182. container = __other.container;
  183. return *this;
  184. }
  185. _Self& operator=(const typename _Container::value_type& __val) {
  186. container->push_front(__val);
  187. return *this;
  188. }
  189. _Self& operator*() { return *this; }
  190. _Self& operator++() { return *this; }
  191. _Self operator++(int) { return *this; }
  192. };
  193. template <class _Container>
  194. inline front_insert_iterator<_Container> _STLP_CALL front_inserter(_Container& __x)
  195. { return front_insert_iterator<_Container>(__x); }
  196. template <class _Container>
  197. class insert_iterator
  198. : public iterator<output_iterator_tag, void, void, void, void> {
  199. typedef insert_iterator<_Container> _Self;
  200. protected:
  201. //container is a Standard name (24.4.2.5), do no make it STLport naming convention compliant.
  202. _Container *container;
  203. typename _Container::iterator _M_iter;
  204. public:
  205. typedef _Container container_type;
  206. typedef output_iterator_tag iterator_category;
  207. insert_iterator(_Container& __x, typename _Container::iterator __i)
  208. : container(&__x), _M_iter(__i) {}
  209. _Self& operator=(_Self const& __other) {
  210. container = __other.container;
  211. _M_iter = __other._M_iter;
  212. return *this;
  213. }
  214. _Self& operator=(const typename _Container::value_type& __val) {
  215. _M_iter = container->insert(_M_iter, __val);
  216. ++_M_iter;
  217. return *this;
  218. }
  219. _Self& operator*() { return *this; }
  220. _Self& operator++() { return *this; }
  221. _Self& operator++(int) { return *this; }
  222. };
  223. template <class _Container, class _Iterator>
  224. inline insert_iterator<_Container> _STLP_CALL
  225. inserter(_Container& __x, _Iterator __i) {
  226. typedef typename _Container::iterator __iter;
  227. return insert_iterator<_Container>(__x, __iter(__i));
  228. }
  229. _STLP_END_NAMESPACE
  230. #if ! defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) || defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
  231. # include <stl/_iterator_old.h>
  232. #endif
  233. #endif /* _STLP_INTERNAL_ITERATOR_H */
  234. // Local Variables:
  235. // mode:C++
  236. // End: