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.

274 lines
7.9 KiB

  1. // iterator standard header
  2. #ifndef _ITERATOR_
  3. #define _ITERATOR_
  4. #include <utility>
  5. #ifdef _MSC_VER
  6. #pragma pack(push,8)
  7. #endif /* _MSC_VER */
  8. _STD_BEGIN
  9. // TEMPLATE CLASS reverse_bidirectional_iterator
  10. template<class _BI,
  11. class _Ty,
  12. class _Rt = _Ty&,
  13. class _Pt = _Ty *,
  14. class _D = ptrdiff_t>
  15. class reverse_bidirectional_iterator
  16. : public _Bidit<_Ty, _D> {
  17. public:
  18. typedef reverse_bidirectional_iterator<_BI,
  19. _Ty, _Rt, _Pt, _D> _Myt;
  20. typedef _BI iter_type;
  21. typedef _Rt reference_type;
  22. typedef _Pt pointer_type;
  23. reverse_bidirectional_iterator()
  24. {}
  25. explicit reverse_bidirectional_iterator(_BI _X)
  26. : current(_X) {}
  27. _BI base() const
  28. {return (current); }
  29. _Rt operator*() const
  30. {_BI _Tmp = current;
  31. return (*--_Tmp); }
  32. _Pt operator->() const
  33. {return (&**this); }
  34. _Myt& operator++()
  35. {--current;
  36. return (*this); }
  37. _Myt operator++(int)
  38. {_Myt _Tmp = *this;
  39. --current;
  40. return (_Tmp); }
  41. _Myt& operator--()
  42. {++current;
  43. return (*this); }
  44. _Myt operator--(int)
  45. {_Myt _Tmp = *this;
  46. ++current;
  47. return (_Tmp); }
  48. protected:
  49. _BI current;
  50. };
  51. template<class _BI, class _Ty, class _Rt, class _Pt,
  52. class _D> inline
  53. bool operator==(const reverse_bidirectional_iterator<_BI,
  54. _Ty, _Rt, _Pt, _D>& _X,
  55. const reverse_bidirectional_iterator<_BI,
  56. _Ty, _Rt, _Pt, _D>& _Y)
  57. {return (_X.base() == _Y.base()); }
  58. template<class _BI, class _Ty, class _Rt, class _Pt,
  59. class _D> inline
  60. bool operator!=(const reverse_bidirectional_iterator<_BI,
  61. _Ty, _Rt, _Pt, _D>& _X,
  62. const reverse_bidirectional_iterator<_BI,
  63. _Ty, _Rt, _Pt, _D>& _Y)
  64. {return (!(_X == _Y)); }
  65. // TEMPLATE CLASS back_insert_iterator
  66. template<class _C>
  67. class back_insert_iterator
  68. : public iterator<output_iterator_tag, void, void> {
  69. public:
  70. typedef _C container_type;
  71. typedef typename _C::value_type value_type;
  72. explicit back_insert_iterator(_C& _X)
  73. : container(_X) {}
  74. back_insert_iterator<_C>& operator=(
  75. const value_type& _V)
  76. {container.push_back(_V);
  77. return (*this); }
  78. back_insert_iterator<_C>& operator*()
  79. {return (*this); }
  80. back_insert_iterator<_C>& operator++()
  81. {return (*this); }
  82. back_insert_iterator<_C> operator++(int)
  83. {return (*this); }
  84. protected:
  85. _C& container;
  86. };
  87. template<class _C> inline
  88. back_insert_iterator<_C> back_inserter(_C& _X)
  89. {return (back_insert_iterator<_C>(_X)); }
  90. // TEMPLATE CLASS front_insert_iterator
  91. template<class _C>
  92. class front_insert_iterator
  93. : public iterator<output_iterator_tag, void, void> {
  94. public:
  95. typedef _C container_type;
  96. typedef typename _C::value_type value_type;
  97. explicit front_insert_iterator(_C& _X)
  98. : container(_X) {}
  99. front_insert_iterator<_C>& operator=(
  100. const value_type& _V)
  101. {container.push_front(_V);
  102. return (*this); }
  103. front_insert_iterator<_C>& operator*()
  104. {return (*this); }
  105. front_insert_iterator<_C>& operator++()
  106. {return (*this); }
  107. front_insert_iterator<_C> operator++(int)
  108. {return (*this); }
  109. protected:
  110. _C& container;
  111. };
  112. template<class _C> inline
  113. front_insert_iterator<_C> front_inserter(_C& _X)
  114. {return (front_insert_iterator<_C>(_X)); }
  115. // TEMPLATE CLASS insert_iterator
  116. template<class _C>
  117. class insert_iterator
  118. : public iterator<output_iterator_tag, void, void> {
  119. public:
  120. typedef _C container_type;
  121. typedef typename _C::value_type value_type;
  122. insert_iterator(_C& _X, typename _C::iterator _I)
  123. : container(_X), iter(_I) {}
  124. insert_iterator<_C>& operator=(
  125. const value_type& _V)
  126. {iter = container.insert(iter, _V);
  127. ++iter;
  128. return (*this); }
  129. insert_iterator<_C>& operator*()
  130. {return (*this); }
  131. insert_iterator<_C>& operator++()
  132. {return (*this); }
  133. insert_iterator<_C>& operator++(int)
  134. {return (*this); }
  135. protected:
  136. _C& container;
  137. typename _C::iterator iter;
  138. };
  139. template<class _C, class _XI> inline
  140. insert_iterator<_C> inserter(_C& _X, _XI _I)
  141. {return (insert_iterator<_C>(_X, _C::iterator(_I))); }
  142. // TEMPLATE CLASS istream_iterator
  143. template<class _U, class _E = char,
  144. class _Tr = char_traits<_E> >
  145. class istream_iterator
  146. : public iterator<input_iterator_tag, _U, ptrdiff_t> {
  147. public:
  148. typedef _E char_type;
  149. typedef _Tr traits_type;
  150. typedef basic_istream<_E, _Tr> istream_type;
  151. istream_iterator()
  152. : _Istr(0) {}
  153. istream_iterator(istream_type& _I)
  154. : _Istr(&_I) {_Getval(); }
  155. const _U& operator*() const
  156. {return (_Val); }
  157. const _U *operator->() const
  158. {return (&**this); }
  159. istream_iterator<_U, _E, _Tr>& operator++()
  160. {_Getval();
  161. return (*this); }
  162. istream_iterator<_U, _E, _Tr> operator++(int)
  163. {istream_iterator<_U, _E, _Tr> _Tmp = *this;
  164. _Getval();
  165. return (_Tmp); }
  166. bool _Equal(const istream_iterator<_U, _E, _Tr>& _X) const
  167. {return (_Istr == _X._Istr); }
  168. protected:
  169. void _Getval()
  170. {if (_Istr != 0 && !(*_Istr >> _Val))
  171. _Istr = 0; }
  172. istream_type *_Istr;
  173. _U _Val;
  174. };
  175. template<class _U, class _E, class _Tr> inline
  176. bool operator==(const istream_iterator<_U, _E, _Tr>& _X,
  177. const istream_iterator<_U, _E, _Tr>& _Y)
  178. {return (_X._Equal(_Y)); }
  179. template<class _U, class _E, class _Tr> inline
  180. bool operator!=(const istream_iterator<_U, _E, _Tr>& _X,
  181. const istream_iterator<_U, _E, _Tr>& _Y)
  182. {return (!(_X == _Y)); }
  183. // TEMPLATE CLASS ostream_iterator
  184. template<class _U, class _E = char,
  185. class _Tr = char_traits<_E> >
  186. class ostream_iterator
  187. : public iterator<output_iterator_tag, void, void> {
  188. public:
  189. typedef _U value_type;
  190. typedef _E char_type;
  191. typedef _Tr traits_type;
  192. typedef basic_ostream<_E, _Tr> ostream_type;
  193. ostream_iterator(ostream_type& _O,
  194. const _E *_D = 0)
  195. : _Ostr(&_O), _Delim(_D) {}
  196. ostream_iterator<_U, _E, _Tr>& operator=(const _U& _X)
  197. {*_Ostr << _X;
  198. if (_Delim != 0)
  199. *_Ostr << _Delim;
  200. return (*this); }
  201. ostream_iterator<_U, _E, _Tr>& operator*()
  202. {return (*this); }
  203. ostream_iterator<_U, _E, _Tr>& operator++()
  204. {return (*this); }
  205. ostream_iterator<_U, _E, _Tr> operator++(int)
  206. {return (*this); }
  207. protected:
  208. const _E *_Delim;
  209. ostream_type *_Ostr;
  210. };
  211. // TEMPLATE FUNCTION _Val_type
  212. template<class _C, class _Ty, class _D> inline
  213. _Ty *_Val_type(const iterator<_C, _Ty, _D>&)
  214. {return ((_Ty *)0); }
  215. template<class _Ty> inline
  216. _Ty *_Val_type(const _Ty *)
  217. {return ((_Ty *)0); }
  218. // TEMPLATE FUNCTION advance
  219. template<class _II, class _D> inline
  220. void advance(_II& _I, _D _N)
  221. {_Advance(_I, _N, _Iter_cat(_I)); }
  222. template<class _II, class _D> inline
  223. void _Advance(_II& _I, _D _N, input_iterator_tag)
  224. {for (; 0 < _N; --_N)
  225. ++_I; }
  226. template<class _FI, class _D> inline
  227. void _Advance(_FI& _I, _D _N, forward_iterator_tag)
  228. {for (; 0 < _N; --_N)
  229. ++_I; }
  230. template<class _BI, class _D> inline
  231. void _Advance(_BI& _I, _D _N, bidirectional_iterator_tag)
  232. {for (; 0 < _N; --_N)
  233. ++_I;
  234. for (; _N < 0; ++_N)
  235. --_I; }
  236. template<class _RI, class _D> inline
  237. void _Advance(_RI& _I, _D _N, random_access_iterator_tag)
  238. {_I += _N; }
  239. // TEMPLATE FUNCTION _Dist_type
  240. template<class _C, class _Ty, class _D> inline
  241. _D *_Dist_type(const iterator<_C, _Ty, _D>&)
  242. {return ((_D *)0); }
  243. template<class _Ty> inline
  244. ptrdiff_t *_Dist_type(const _Ty *)
  245. {return ((ptrdiff_t *)0); }
  246. _STD_END
  247. #ifdef _MSC_VER
  248. #pragma pack(pop)
  249. #endif /* _MSC_VER */
  250. #endif /* _ITERATOR_ */
  251. /*
  252. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  253. * Consult your license regarding permissions and restrictions.
  254. */
  255. /*
  256. * This file is derived from software bearing the following
  257. * restrictions:
  258. *
  259. * Copyright (c) 1994
  260. * Hewlett-Packard Company
  261. *
  262. * Permission to use, copy, modify, distribute and sell this
  263. * software and its documentation for any purpose is hereby
  264. * granted without fee, provided that the above copyright notice
  265. * appear in all copies and that both that copyright notice and
  266. * this permission notice appear in supporting documentation.
  267. * Hewlett-Packard Company makes no representations about the
  268. * suitability of this software for any purpose. It is provided
  269. * "as is" without express or implied warranty.
  270. */