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.

381 lines
8.7 KiB

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