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.

336 lines
11 KiB

  1. // map standard header
  2. #ifndef _MAP_
  3. #define _MAP_
  4. #include <functional>
  5. #include <xtree>
  6. #ifdef _MSC_VER
  7. #pragma pack(push,8)
  8. #endif /* _MSC_VER */
  9. _STD_BEGIN
  10. // TEMPLATE CLASS map
  11. template<class _K, class _Ty, class _Pr = less<_K>,
  12. class _A = allocator<_Ty> >
  13. class map {
  14. public:
  15. typedef map<_K, _Ty, _Pr, _A> _Myt;
  16. typedef pair<const _K, _Ty> value_type;
  17. struct _Kfn : public unary_function<value_type, _K> {
  18. const _K& operator()(const value_type& _X) const
  19. {return (_X.first); }
  20. };
  21. class value_compare
  22. : public binary_function<value_type, value_type, bool> {
  23. friend class map<_K, _Ty, _Pr, _A>;
  24. public:
  25. bool operator()(const value_type& _X,
  26. const value_type& _Y) const
  27. {return (comp(_X.first, _Y.first)); }
  28. _PROTECTED:
  29. value_compare(_Pr _Pred)
  30. : comp(_Pred) {}
  31. _Pr comp;
  32. };
  33. typedef _K key_type;
  34. typedef _Ty referent_type;
  35. typedef _Pr key_compare;
  36. typedef _A allocator_type;
  37. typedef _A::reference _Tref;
  38. typedef _Tree<_K, value_type, _Kfn, _Pr, _A> _Imp;
  39. typedef _Imp::size_type size_type;
  40. typedef _Imp::difference_type difference_type;
  41. typedef _Imp::reference reference;
  42. typedef _Imp::const_reference const_reference;
  43. typedef _Imp::iterator iterator;
  44. typedef _Imp::const_iterator const_iterator;
  45. typedef _Imp::reverse_iterator reverse_iterator;
  46. typedef _Imp::const_reverse_iterator const_reverse_iterator;
  47. typedef pair<iterator, bool> _Pairib;
  48. typedef pair<iterator, iterator> _Pairii;
  49. typedef pair<const_iterator, const_iterator> _Paircc;
  50. explicit map(const _Pr& _Pred = _Pr(), const _A& _Al = _A())
  51. : _Tr(_Pred, false, _Al) {}
  52. typedef const value_type *_It;
  53. map(_It _F, _It _L, const _Pr& _Pred = _Pr(),
  54. const _A& _Al = _A())
  55. : _Tr(_Pred, false, _Al)
  56. {for (; _F != _L; ++_F)
  57. _Tr.insert(*_F); }
  58. _Myt& operator=(const _Myt& _X)
  59. {_Tr = _X._Tr;
  60. return (*this); }
  61. iterator begin()
  62. {return (_Tr.begin()); }
  63. const_iterator begin() const
  64. {return (_Tr.begin()); }
  65. iterator end()
  66. {return (_Tr.end()); }
  67. const_iterator end() const
  68. {return (_Tr.end()); }
  69. reverse_iterator rbegin()
  70. {return (_Tr.rbegin()); }
  71. const_reverse_iterator rbegin() const
  72. {return (_Tr.rbegin()); }
  73. reverse_iterator rend()
  74. {return (_Tr.rend()); }
  75. const_reverse_iterator rend() const
  76. {return (_Tr.rend()); }
  77. size_type size() const
  78. {return (_Tr.size()); }
  79. size_type max_size() const
  80. {return (_Tr.max_size()); }
  81. bool empty() const
  82. {return (_Tr.empty()); }
  83. _A get_allocator() const
  84. {return (_Tr.get_allocator()); }
  85. _Tref operator[](const key_type& _Kv)
  86. {iterator _P = insert(value_type(_Kv, _Ty())).first;
  87. return ((*_P).second); }
  88. _Pairib insert(const value_type& _X)
  89. {_Imp::_Pairib _Ans = _Tr.insert(_X);
  90. return (_Pairib(_Ans.first, _Ans.second)); }
  91. iterator insert(iterator _P, const value_type& _X)
  92. {return (_Tr.insert((_Imp::iterator&)_P, _X)); }
  93. void insert(_It _F, _It _L)
  94. {for (; _F != _L; ++_F)
  95. _Tr.insert(*_F); }
  96. iterator erase(iterator _P)
  97. {return (_Tr.erase((_Imp::iterator&)_P)); }
  98. iterator erase(iterator _F, iterator _L)
  99. {return (_Tr.erase((_Imp::iterator&)_F,
  100. (_Imp::iterator&)_L)); }
  101. size_type erase(const _K& _Kv)
  102. {return (_Tr.erase(_Kv)); }
  103. void clear()
  104. {_Tr.clear(); }
  105. void swap(_Myt& _X)
  106. {std::swap(_Tr, _X._Tr); }
  107. friend void swap(_Myt& _X, _Myt& _Y)
  108. {_X.swap(_Y); }
  109. key_compare key_comp() const
  110. {return (_Tr.key_comp()); }
  111. value_compare value_comp() const
  112. {return (value_compare(_Tr.key_comp())); }
  113. iterator find(const _K& _Kv)
  114. {return (_Tr.find(_Kv)); }
  115. const_iterator find(const _K& _Kv) const
  116. {return (_Tr.find(_Kv)); }
  117. size_type count(const _K& _Kv) const
  118. {return (_Tr.count(_Kv)); }
  119. iterator lower_bound(const _K& _Kv)
  120. {return (_Tr.lower_bound(_Kv)); }
  121. const_iterator lower_bound(const _K& _Kv) const
  122. {return (_Tr.lower_bound(_Kv)); }
  123. iterator upper_bound(const _K& _Kv)
  124. {return (_Tr.upper_bound(_Kv)); }
  125. const_iterator upper_bound(const _K& _Kv) const
  126. {return (_Tr.upper_bound(_Kv)); }
  127. _Pairii equal_range(const _K& _Kv)
  128. {return (_Tr.equal_range(_Kv)); }
  129. _Paircc equal_range(const _K& _Kv) const
  130. {return (_Tr.equal_range(_Kv)); }
  131. protected:
  132. _Imp _Tr;
  133. };
  134. // map TEMPLATE OPERATORS
  135. template<class _K, class _Ty, class _Pr, class _A> inline
  136. bool operator==(const map<_K, _Ty, _Pr, _A>& _X,
  137. const map<_K, _Ty, _Pr, _A>& _Y)
  138. {return (_X.size() == _Y.size()
  139. && equal(_X.begin(), _X.end(), _Y.begin())); }
  140. template<class _K, class _Ty, class _Pr, class _A> inline
  141. bool operator!=(const map<_K, _Ty, _Pr, _A>& _X,
  142. const map<_K, _Ty, _Pr, _A>& _Y)
  143. {return (!(_X == _Y)); }
  144. template<class _K, class _Ty, class _Pr, class _A> inline
  145. bool operator<(const map<_K, _Ty, _Pr, _A>& _X,
  146. const map<_K, _Ty, _Pr, _A>& _Y)
  147. {return (lexicographical_compare(_X.begin(), _X.end(),
  148. _Y.begin(), _Y.end())); }
  149. template<class _K, class _Ty, class _Pr, class _A> inline
  150. bool operator>(const map<_K, _Ty, _Pr, _A>& _X,
  151. const map<_K, _Ty, _Pr, _A>& _Y)
  152. {return (_Y < _X); }
  153. template<class _K, class _Ty, class _Pr, class _A> inline
  154. bool operator<=(const map<_K, _Ty, _Pr, _A>& _X,
  155. const map<_K, _Ty, _Pr, _A>& _Y)
  156. {return (!(_Y < _X)); }
  157. template<class _K, class _Ty, class _Pr, class _A> inline
  158. bool operator>=(const map<_K, _Ty, _Pr, _A>& _X,
  159. const map<_K, _Ty, _Pr, _A>& _Y)
  160. {return (!(_X < _Y)); }
  161. // TEMPLATE CLASS multimap
  162. template<class _K, class _Ty, class _Pr = less<_K>,
  163. class _A = allocator<_Ty> >
  164. class multimap {
  165. public:
  166. typedef multimap<_K, _Ty, _Pr, _A> _Myt;
  167. typedef pair<const _K, _Ty> value_type;
  168. struct _Kfn : public unary_function<value_type, _K> {
  169. const _K& operator()(const value_type& _X) const
  170. {return (_X.first); }
  171. };
  172. class value_compare
  173. : public binary_function<value_type, value_type, bool> {
  174. friend class map<_K, _Ty, _Pr, _A>;
  175. public:
  176. bool operator()(const value_type& _X,
  177. const value_type& _Y) const
  178. {return (comp(_X.first, _Y.first)); }
  179. _PROTECTED:
  180. value_compare(_Pr _Pred)
  181. : comp(_Pred) {}
  182. _Pr comp;
  183. };
  184. typedef _K key_type;
  185. typedef _Ty referent_type;
  186. typedef _Pr key_compare;
  187. typedef _A allocator_type;
  188. typedef _Tree<_K, value_type, _Kfn, _Pr, _A> _Imp;
  189. typedef _Imp::size_type size_type;
  190. typedef _Imp::difference_type difference_type;
  191. typedef _Imp::reference reference;
  192. typedef _Imp::const_reference const_reference;
  193. typedef _Imp::iterator iterator;
  194. typedef _Imp::const_iterator const_iterator;
  195. typedef _Imp::reverse_iterator reverse_iterator;
  196. typedef _Imp::const_reverse_iterator const_reverse_iterator;
  197. typedef pair<iterator, iterator> _Pairii;
  198. typedef pair<const_iterator, const_iterator> _Paircc;
  199. explicit multimap(const _Pr& _Pred = _Pr(),
  200. const _A& _Al = _A())
  201. : _Tr(_Pred, true, _Al) {}
  202. typedef const value_type *_It;
  203. multimap(_It _F, _It _L, const _Pr& _Pred = _Pr(),
  204. const _A& _Al = _A())
  205. : _Tr(_Pred, true, _Al)
  206. {for (; _F != _L; ++_F)
  207. _Tr.insert(*_F); }
  208. _Myt& operator=(const _Myt& _X)
  209. {_Tr = _X._Tr;
  210. return (*this); }
  211. iterator begin()
  212. {return (_Tr.begin()); }
  213. const_iterator begin() const
  214. {return (_Tr.begin()); }
  215. iterator end()
  216. {return (_Tr.end()); }
  217. const_iterator end() const
  218. {return (_Tr.end()); }
  219. reverse_iterator rbegin()
  220. {return (_Tr.rbegin()); }
  221. const_reverse_iterator rbegin() const
  222. {return (_Tr.rbegin()); }
  223. reverse_iterator rend()
  224. {return (_Tr.rend()); }
  225. const_reverse_iterator rend() const
  226. {return (_Tr.rend()); }
  227. size_type size() const
  228. {return (_Tr.size()); }
  229. size_type max_size() const
  230. {return (_Tr.max_size()); }
  231. bool empty() const
  232. {return (_Tr.empty()); }
  233. _A get_allocator() const
  234. {return (_Tr.get_allocator()); }
  235. iterator insert(const value_type& _X)
  236. {return (_Tr.insert(_X).first); }
  237. iterator insert(iterator _P, const value_type& _X)
  238. {return (_Tr.insert((_Imp::iterator&)_P, _X)); }
  239. void insert(_It _F, _It _L)
  240. {for (; _F != _L; ++_F)
  241. _Tr.insert(*_F); }
  242. iterator erase(iterator _P)
  243. {return (_Tr.erase((_Imp::iterator&)_P)); }
  244. iterator erase(iterator _F, iterator _L)
  245. {return (_Tr.erase((_Imp::iterator&)_F,
  246. (_Imp::iterator&)_L)); }
  247. size_type erase(const _K& _Kv = _K())
  248. {return (_Tr.erase(_Kv)); }
  249. void clear()
  250. {_Tr.clear(); }
  251. void swap(_Myt& _X)
  252. {std::swap(_Tr, _X._Tr); }
  253. friend void swap(_Myt& _X, _Myt& _Y)
  254. {_X.swap(_Y); }
  255. key_compare key_comp() const
  256. {return (_Tr.key_comp()); }
  257. value_compare value_comp() const
  258. {return (value_compare(_Tr.key_comp())); }
  259. iterator find(const _K& _Kv)
  260. {return (_Tr.find(_Kv)); }
  261. const_iterator find(const _K& _Kv) const
  262. {return (_Tr.find(_Kv)); }
  263. size_type count(const _K& _Kv) const
  264. {return (_Tr.count(_Kv)); }
  265. iterator lower_bound(const _K& _Kv)
  266. {return (_Tr.lower_bound(_Kv)); }
  267. const_iterator lower_bound(const _K& _Kv) const
  268. {return (_Tr.lower_bound(_Kv)); }
  269. iterator upper_bound(const _K& _Kv)
  270. {return (_Tr.upper_bound(_Kv)); }
  271. const_iterator upper_bound(const _K& _Kv) const
  272. {return (_Tr.upper_bound(_Kv)); }
  273. _Pairii equal_range(const _K& _Kv)
  274. {return (_Tr.equal_range(_Kv)); }
  275. _Paircc equal_range(const _K& _Kv) const
  276. {return (_Tr.equal_range(_Kv)); }
  277. protected:
  278. _Imp _Tr;
  279. };
  280. // multimap TEMPLATE OPERATORS
  281. template<class _K, class _Ty, class _Pr, class _A> inline
  282. bool operator==(const multimap<_K, _Ty, _Pr, _A>& _X,
  283. const multimap<_K, _Ty, _Pr, _A>& _Y)
  284. {return (_X.size() == _Y.size()
  285. && equal(_X.begin(), _X.end(), _Y.begin())); }
  286. template<class _K, class _Ty, class _Pr, class _A> inline
  287. bool operator!=(const multimap<_K, _Ty, _Pr, _A>& _X,
  288. const multimap<_K, _Ty, _Pr, _A>& _Y)
  289. {return (!(_X == _Y)); }
  290. template<class _K, class _Ty, class _Pr, class _A> inline
  291. bool operator<(const multimap<_K, _Ty, _Pr, _A>& _X,
  292. const multimap<_K, _Ty, _Pr, _A>& _Y)
  293. {return (lexicographical_compare(_X.begin(), _X.end(),
  294. _Y.begin(), _Y.end())); }
  295. template<class _K, class _Ty, class _Pr, class _A> inline
  296. bool operator>(const multimap<_K, _Ty, _Pr, _A>& _X,
  297. const multimap<_K, _Ty, _Pr, _A>& _Y)
  298. {return (_Y < _X); }
  299. template<class _K, class _Ty, class _Pr, class _A> inline
  300. bool operator<=(const multimap<_K, _Ty, _Pr, _A>& _X,
  301. const multimap<_K, _Ty, _Pr, _A>& _Y)
  302. {return (!(_Y < _X)); }
  303. template<class _K, class _Ty, class _Pr, class _A> inline
  304. bool operator>=(const multimap<_K, _Ty, _Pr, _A>& _X,
  305. const multimap<_K, _Ty, _Pr, _A>& _Y)
  306. {return (!(_X < _Y)); }
  307. _STD_END
  308. #ifdef _MSC_VER
  309. #pragma pack(pop)
  310. #endif /* _MSC_VER */
  311. #endif /* _MAP_ */
  312. /*
  313. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  314. * Consult your license regarding permissions and restrictions.
  315. */
  316. /*
  317. * This file is derived from software bearing the following
  318. * restrictions:
  319. *
  320. * Copyright (c) 1994
  321. * Hewlett-Packard Company
  322. *
  323. * Permission to use, copy, modify, distribute and sell this
  324. * software and its documentation for any purpose is hereby
  325. * granted without fee, provided that the above copyright notice
  326. * appear in all copies and that both that copyright notice and
  327. * this permission notice appear in supporting documentation.
  328. * Hewlett-Packard Company makes no representations about the
  329. * suitability of this software for any purpose. It is provided
  330. * "as is" without express or implied warranty.
  331. */