/project/jni/stlport/stlport/stl/_set.h

https://github.com/aichunyu/FFPlayer · C Header · 402 lines · 305 code · 52 blank · 45 comment · 3 complexity · 676e3ccdb8e9b8dc1eda4c6f67225a96 MD5 · raw file

  1. /*
  2. *
  3. * Copyright (c) 1994
  4. * Hewlett-Packard Company
  5. *
  6. * Copyright (c) 1996,1997
  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_SET_H
  29. #define _STLP_INTERNAL_SET_H
  30. #ifndef _STLP_INTERNAL_TREE_H
  31. # include <stl/_tree.h>
  32. #endif
  33. #if !defined (_STLP_USE_PTR_SPECIALIZATIONS)
  34. _STLP_BEGIN_NAMESPACE
  35. //Specific iterator traits creation
  36. _STLP_CREATE_ITERATOR_TRAITS(SetTraitsT, Const_traits)
  37. template <class _Key, _STLP_DFL_TMPL_PARAM(_Compare, less<_Key>),
  38. _STLP_DEFAULT_ALLOCATOR_SELECT(_Key) >
  39. class set
  40. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
  41. : public __stlport_class<set<_Key, _Compare, _Alloc> >
  42. #endif
  43. {
  44. typedef set<_Key, _Compare, _Alloc> _Self;
  45. public:
  46. // typedefs:
  47. typedef _Key key_type;
  48. typedef _Key value_type;
  49. typedef _Compare key_compare;
  50. typedef _Compare value_compare;
  51. private:
  52. //Specific iterator traits creation
  53. typedef _STLP_PRIV _SetTraitsT<value_type> _SetTraits;
  54. public:
  55. //Following typedef have to be public for __move_traits specialization.
  56. typedef _STLP_PRIV _Rb_tree<key_type, key_compare,
  57. value_type, _STLP_PRIV _Identity<value_type>,
  58. _SetTraits, _Alloc> _Rep_type;
  59. typedef typename _Rep_type::pointer pointer;
  60. typedef typename _Rep_type::const_pointer const_pointer;
  61. typedef typename _Rep_type::reference reference;
  62. typedef typename _Rep_type::const_reference const_reference;
  63. typedef typename _Rep_type::iterator iterator;
  64. typedef typename _Rep_type::const_iterator const_iterator;
  65. typedef typename _Rep_type::reverse_iterator reverse_iterator;
  66. typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
  67. typedef typename _Rep_type::size_type size_type;
  68. typedef typename _Rep_type::difference_type difference_type;
  69. typedef typename _Rep_type::allocator_type allocator_type;
  70. private:
  71. _Rep_type _M_t; // red-black tree representing set
  72. _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
  73. public:
  74. // allocation/deallocation
  75. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  76. explicit set(const _Compare& __comp = _Compare(),
  77. const allocator_type& __a = allocator_type())
  78. #else
  79. set()
  80. : _M_t(_Compare(), allocator_type()) {}
  81. explicit set(const _Compare& __comp)
  82. : _M_t(__comp, allocator_type()) {}
  83. set(const _Compare& __comp, const allocator_type& __a)
  84. #endif
  85. : _M_t(__comp, __a) {}
  86. #if defined (_STLP_MEMBER_TEMPLATES)
  87. template <class _InputIterator>
  88. set(_InputIterator __first, _InputIterator __last)
  89. : _M_t(_Compare(), allocator_type())
  90. { _M_t.insert_unique(__first, __last); }
  91. # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
  92. template <class _InputIterator>
  93. set(_InputIterator __first, _InputIterator __last, const _Compare& __comp)
  94. : _M_t(__comp, allocator_type()) { _M_t.insert_unique(__first, __last); }
  95. # endif
  96. template <class _InputIterator>
  97. set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
  98. const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
  99. : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
  100. #else
  101. set(const value_type* __first, const value_type* __last)
  102. : _M_t(_Compare(), allocator_type())
  103. { _M_t.insert_unique(__first, __last); }
  104. set(const value_type* __first,
  105. const value_type* __last, const _Compare& __comp,
  106. const allocator_type& __a = allocator_type())
  107. : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
  108. set(const_iterator __first, const_iterator __last)
  109. : _M_t(_Compare(), allocator_type())
  110. { _M_t.insert_unique(__first, __last); }
  111. set(const_iterator __first, const_iterator __last, const _Compare& __comp,
  112. const allocator_type& __a = allocator_type())
  113. : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
  114. #endif /* _STLP_MEMBER_TEMPLATES */
  115. set(const _Self& __x) : _M_t(__x._M_t) {}
  116. set(__move_source<_Self> src)
  117. : _M_t(__move_source<_Rep_type>(src.get()._M_t)) {}
  118. _Self& operator=(const _Self& __x) {
  119. _M_t = __x._M_t;
  120. return *this;
  121. }
  122. // accessors:
  123. key_compare key_comp() const { return _M_t.key_comp(); }
  124. value_compare value_comp() const { return _M_t.key_comp(); }
  125. allocator_type get_allocator() const { return _M_t.get_allocator(); }
  126. iterator begin() { return _M_t.begin(); }
  127. iterator end() { return _M_t.end(); }
  128. const_iterator begin() const { return _M_t.begin(); }
  129. const_iterator end() const { return _M_t.end(); }
  130. reverse_iterator rbegin() { return _M_t.rbegin(); }
  131. reverse_iterator rend() { return _M_t.rend(); }
  132. const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
  133. const_reverse_iterator rend() const { return _M_t.rend(); }
  134. bool empty() const { return _M_t.empty(); }
  135. size_type size() const { return _M_t.size(); }
  136. size_type max_size() const { return _M_t.max_size(); }
  137. void swap(_Self& __x) { _M_t.swap(__x._M_t); }
  138. // insert/erase
  139. pair<iterator,bool> insert(const value_type& __x)
  140. { return _M_t.insert_unique(__x); }
  141. iterator insert(iterator __pos, const value_type& __x)
  142. { return _M_t.insert_unique( __pos , __x); }
  143. #if defined (_STLP_MEMBER_TEMPLATES)
  144. template <class _InputIterator>
  145. void insert(_InputIterator __first, _InputIterator __last)
  146. { _M_t.insert_unique(__first, __last); }
  147. #else
  148. void insert(const_iterator __first, const_iterator __last)
  149. { _M_t.insert_unique(__first, __last); }
  150. void insert(const value_type* __first, const value_type* __last)
  151. { _M_t.insert_unique(__first, __last); }
  152. #endif /* _STLP_MEMBER_TEMPLATES */
  153. void erase(iterator __pos) { _M_t.erase( __pos ); }
  154. size_type erase(const key_type& __x) { return _M_t.erase_unique(__x); }
  155. void erase(iterator __first, iterator __last) { _M_t.erase(__first, __last ); }
  156. void clear() { _M_t.clear(); }
  157. // set operations:
  158. _STLP_TEMPLATE_FOR_CONT_EXT
  159. const_iterator find(const _KT& __x) const { return _M_t.find(__x); }
  160. _STLP_TEMPLATE_FOR_CONT_EXT
  161. iterator find(const _KT& __x) { return _M_t.find(__x); }
  162. _STLP_TEMPLATE_FOR_CONT_EXT
  163. size_type count(const _KT& __x) const
  164. { return _M_t.find(__x) == _M_t.end() ? 0 : 1 ; }
  165. _STLP_TEMPLATE_FOR_CONT_EXT
  166. iterator lower_bound(const _KT& __x) { return _M_t.lower_bound(__x); }
  167. _STLP_TEMPLATE_FOR_CONT_EXT
  168. const_iterator lower_bound(const _KT& __x) const { return _M_t.lower_bound(__x); }
  169. _STLP_TEMPLATE_FOR_CONT_EXT
  170. iterator upper_bound(const _KT& __x) { return _M_t.upper_bound(__x); }
  171. _STLP_TEMPLATE_FOR_CONT_EXT
  172. const_iterator upper_bound(const _KT& __x) const { return _M_t.upper_bound(__x); }
  173. _STLP_TEMPLATE_FOR_CONT_EXT
  174. pair<iterator, iterator> equal_range(const _KT& __x)
  175. { return _M_t.equal_range_unique(__x); }
  176. _STLP_TEMPLATE_FOR_CONT_EXT
  177. pair<const_iterator, const_iterator> equal_range(const _KT& __x) const
  178. { return _M_t.equal_range_unique(__x); }
  179. };
  180. //Specific iterator traits creation
  181. _STLP_CREATE_ITERATOR_TRAITS(MultisetTraitsT, Const_traits)
  182. template <class _Key, _STLP_DFL_TMPL_PARAM(_Compare, less<_Key>),
  183. _STLP_DEFAULT_ALLOCATOR_SELECT(_Key) >
  184. class multiset
  185. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
  186. : public __stlport_class<multiset<_Key, _Compare, _Alloc> >
  187. #endif
  188. {
  189. typedef multiset<_Key, _Compare, _Alloc> _Self;
  190. public:
  191. // typedefs:
  192. typedef _Key key_type;
  193. typedef _Key value_type;
  194. typedef _Compare key_compare;
  195. typedef _Compare value_compare;
  196. private:
  197. //Specific iterator traits creation
  198. typedef _STLP_PRIV _MultisetTraitsT<value_type> _MultisetTraits;
  199. public:
  200. //Following typedef have to be public for __move_traits specialization.
  201. typedef _STLP_PRIV _Rb_tree<key_type, key_compare,
  202. value_type, _STLP_PRIV _Identity<value_type>,
  203. _MultisetTraits, _Alloc> _Rep_type;
  204. typedef typename _Rep_type::pointer pointer;
  205. typedef typename _Rep_type::const_pointer const_pointer;
  206. typedef typename _Rep_type::reference reference;
  207. typedef typename _Rep_type::const_reference const_reference;
  208. typedef typename _Rep_type::iterator iterator;
  209. typedef typename _Rep_type::const_iterator const_iterator;
  210. typedef typename _Rep_type::reverse_iterator reverse_iterator;
  211. typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
  212. typedef typename _Rep_type::size_type size_type;
  213. typedef typename _Rep_type::difference_type difference_type;
  214. typedef typename _Rep_type::allocator_type allocator_type;
  215. private:
  216. _Rep_type _M_t; // red-black tree representing multiset
  217. _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
  218. public:
  219. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  220. explicit multiset(const _Compare& __comp = _Compare(),
  221. const allocator_type& __a = allocator_type())
  222. #else
  223. multiset()
  224. : _M_t(_Compare(), allocator_type()) {}
  225. explicit multiset(const _Compare& __comp)
  226. : _M_t(__comp, allocator_type()) {}
  227. multiset(const _Compare& __comp, const allocator_type& __a)
  228. #endif
  229. : _M_t(__comp, __a) {}
  230. #if defined (_STLP_MEMBER_TEMPLATES)
  231. template <class _InputIterator>
  232. multiset(_InputIterator __first, _InputIterator __last)
  233. : _M_t(_Compare(), allocator_type())
  234. { _M_t.insert_equal(__first, __last); }
  235. template <class _InputIterator>
  236. multiset(_InputIterator __first, _InputIterator __last,
  237. const _Compare& __comp,
  238. const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
  239. : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
  240. # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
  241. template <class _InputIterator>
  242. multiset(_InputIterator __first, _InputIterator __last,
  243. const _Compare& __comp)
  244. : _M_t(__comp, allocator_type()) { _M_t.insert_equal(__first, __last); }
  245. # endif
  246. #else
  247. multiset(const value_type* __first, const value_type* __last)
  248. : _M_t(_Compare(), allocator_type())
  249. { _M_t.insert_equal(__first, __last); }
  250. multiset(const value_type* __first, const value_type* __last,
  251. const _Compare& __comp,
  252. const allocator_type& __a = allocator_type())
  253. : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
  254. multiset(const_iterator __first, const_iterator __last)
  255. : _M_t(_Compare(), allocator_type())
  256. { _M_t.insert_equal(__first, __last); }
  257. multiset(const_iterator __first, const_iterator __last,
  258. const _Compare& __comp,
  259. const allocator_type& __a = allocator_type())
  260. : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
  261. #endif /* _STLP_MEMBER_TEMPLATES */
  262. multiset(const _Self& __x) : _M_t(__x._M_t) {}
  263. _Self& operator=(const _Self& __x) {
  264. _M_t = __x._M_t;
  265. return *this;
  266. }
  267. multiset(__move_source<_Self> src)
  268. : _M_t(__move_source<_Rep_type>(src.get()._M_t)) {}
  269. // accessors:
  270. key_compare key_comp() const { return _M_t.key_comp(); }
  271. value_compare value_comp() const { return _M_t.key_comp(); }
  272. allocator_type get_allocator() const { return _M_t.get_allocator(); }
  273. iterator begin() { return _M_t.begin(); }
  274. iterator end() { return _M_t.end(); }
  275. const_iterator begin() const { return _M_t.begin(); }
  276. const_iterator end() const { return _M_t.end(); }
  277. reverse_iterator rbegin() { return _M_t.rbegin(); }
  278. reverse_iterator rend() { return _M_t.rend(); }
  279. const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
  280. const_reverse_iterator rend() const { return _M_t.rend(); }
  281. bool empty() const { return _M_t.empty(); }
  282. size_type size() const { return _M_t.size(); }
  283. size_type max_size() const { return _M_t.max_size(); }
  284. void swap(_Self& __x) { _M_t.swap(__x._M_t); }
  285. // insert/erase
  286. iterator insert(const value_type& __x)
  287. { return _M_t.insert_equal(__x); }
  288. iterator insert(iterator __pos, const value_type& __x)
  289. { return _M_t.insert_equal(__pos, __x); }
  290. #if defined (_STLP_MEMBER_TEMPLATES)
  291. template <class _InputIterator>
  292. void insert(_InputIterator __first, _InputIterator __last)
  293. { _M_t.insert_equal(__first, __last); }
  294. #else
  295. void insert(const value_type* __first, const value_type* __last)
  296. { _M_t.insert_equal(__first, __last); }
  297. void insert(const_iterator __first, const_iterator __last)
  298. { _M_t.insert_equal(__first, __last); }
  299. #endif /* _STLP_MEMBER_TEMPLATES */
  300. void erase(iterator __pos) { _M_t.erase( __pos ); }
  301. size_type erase(const key_type& __x) { return _M_t.erase(__x); }
  302. void erase(iterator __first, iterator __last) { _M_t.erase( __first, __last ); }
  303. void clear() { _M_t.clear(); }
  304. // multiset operations:
  305. _STLP_TEMPLATE_FOR_CONT_EXT
  306. iterator find(const _KT& __x) { return _M_t.find(__x); }
  307. _STLP_TEMPLATE_FOR_CONT_EXT
  308. const_iterator find(const _KT& __x) const { return _M_t.find(__x); }
  309. _STLP_TEMPLATE_FOR_CONT_EXT
  310. size_type count(const _KT& __x) const { return _M_t.count(__x); }
  311. _STLP_TEMPLATE_FOR_CONT_EXT
  312. iterator lower_bound(const _KT& __x) { return _M_t.lower_bound(__x); }
  313. _STLP_TEMPLATE_FOR_CONT_EXT
  314. const_iterator lower_bound(const _KT& __x) const { return _M_t.lower_bound(__x); }
  315. _STLP_TEMPLATE_FOR_CONT_EXT
  316. iterator upper_bound(const _KT& __x) { return _M_t.upper_bound(__x); }
  317. _STLP_TEMPLATE_FOR_CONT_EXT
  318. const_iterator upper_bound(const _KT& __x) const { return _M_t.upper_bound(__x); }
  319. _STLP_TEMPLATE_FOR_CONT_EXT
  320. pair<iterator, iterator> equal_range(const _KT& __x) { return _M_t.equal_range(__x); }
  321. _STLP_TEMPLATE_FOR_CONT_EXT
  322. pair<const_iterator, const_iterator> equal_range(const _KT& __x) const { return _M_t.equal_range(__x); }
  323. };
  324. #else
  325. # include <stl/pointers/_set.h>
  326. _STLP_BEGIN_NAMESPACE
  327. #endif /* _STLP_USE_PTR_SPECIALIZATIONS */
  328. #define _STLP_TEMPLATE_HEADER template <class _Key, class _Compare, class _Alloc>
  329. #define _STLP_TEMPLATE_CONTAINER set<_Key,_Compare,_Alloc>
  330. #include <stl/_relops_cont.h>
  331. #undef _STLP_TEMPLATE_CONTAINER
  332. #define _STLP_TEMPLATE_CONTAINER multiset<_Key,_Compare,_Alloc>
  333. #include <stl/_relops_cont.h>
  334. #undef _STLP_TEMPLATE_CONTAINER
  335. #undef _STLP_TEMPLATE_HEADER
  336. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  337. template <class _Key, class _Compare, class _Alloc>
  338. struct __move_traits<set<_Key,_Compare,_Alloc> > :
  339. _STLP_PRIV __move_traits_aux<typename set<_Key,_Compare,_Alloc>::_Rep_type>
  340. {};
  341. template <class _Key, class _Compare, class _Alloc>
  342. struct __move_traits<multiset<_Key,_Compare,_Alloc> > :
  343. _STLP_PRIV __move_traits_aux<typename multiset<_Key,_Compare,_Alloc>::_Rep_type>
  344. {};
  345. #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
  346. _STLP_END_NAMESPACE
  347. #endif /* _STLP_INTERNAL_SET_H */
  348. // Local Variables:
  349. // mode:C++
  350. // End: