Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  *
  3.  * Copyright (c) 1994
  4.  * Hewlett-Packard Company
  5.  *
  6.  * Permission to use, copy, modify, distribute and sell this software
  7.  * and its documentation for any purpose is hereby granted without fee,
  8.  * provided that the above copyright notice appear in all copies and
  9.  * that both that copyright notice and this permission notice appear
  10.  * in supporting documentation.  Hewlett-Packard Company makes no
  11.  * representations about the suitability of this software for any
  12.  * purpose.  It is provided "as is" without express or implied warranty.
  13.  *
  14.  *
  15.  * Copyright (c) 1996,1997
  16.  * Silicon Graphics Computer Systems, Inc.
  17.  *
  18.  * Permission to use, copy, modify, distribute and sell this software
  19.  * and its documentation for any purpose is hereby granted without fee,
  20.  * provided that the above copyright notice appear in all copies and
  21.  * that both that copyright notice and this permission notice appear
  22.  * in supporting documentation.  Silicon Graphics makes no
  23.  * representations about the suitability of this software for any
  24.  * purpose.  It is provided "as is" without express or implied warranty.
  25.  */
  26.  
  27. /* NOTE: This is an internal header file, included by other STL headers.
  28.  *   You should not attempt to use it directly.
  29.  */
  30.  
  31. #ifndef __SGI_STL_INTERNAL_SET_H
  32. #define __SGI_STL_INTERNAL_SET_H
  33.  
  34. #include <bits/concept_check.h>
  35.  
  36. namespace std
  37. {
  38.  
  39. // Forward declarations of operators < and ==, needed for friend declaration.
  40.  
  41. template <class _Key, class _Compare = less<_Key>,
  42.           class _Alloc = allocator<_Key> >
  43. class set;
  44.  
  45. template <class _Key, class _Compare, class _Alloc>
  46. inline bool operator==(const set<_Key,_Compare,_Alloc>& __x,
  47.                        const set<_Key,_Compare,_Alloc>& __y);
  48.  
  49. template <class _Key, class _Compare, class _Alloc>
  50. inline bool operator<(const set<_Key,_Compare,_Alloc>& __x,
  51.                       const set<_Key,_Compare,_Alloc>& __y);
  52.  
  53.  
  54. template <class _Key, class _Compare, class _Alloc>
  55. class set
  56. {
  57.   // concept requirements
  58.   __glibcpp_class_requires(_Key, _SGIAssignableConcept);
  59.   __glibcpp_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept);
  60.  
  61. public:
  62.   // typedefs:
  63.   typedef _Key     key_type;
  64.   typedef _Key     value_type;
  65.   typedef _Compare key_compare;
  66.   typedef _Compare value_compare;
  67. private:
  68.   typedef _Rb_tree<key_type, value_type,
  69.                   _Identity<value_type>, key_compare, _Alloc> _Rep_type;
  70.   _Rep_type _M_t;  // red-black tree representing set
  71. public:
  72.   typedef typename _Rep_type::const_pointer pointer;
  73.   typedef typename _Rep_type::const_pointer const_pointer;
  74.   typedef typename _Rep_type::const_reference reference;
  75.   typedef typename _Rep_type::const_reference const_reference;
  76.   typedef typename _Rep_type::const_iterator iterator;
  77.   typedef typename _Rep_type::const_iterator const_iterator;
  78.   typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
  79.   typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
  80.   typedef typename _Rep_type::size_type size_type;
  81.   typedef typename _Rep_type::difference_type difference_type;
  82.   typedef typename _Rep_type::allocator_type allocator_type;
  83.  
  84.   // allocation/deallocation
  85.  
  86.   set() : _M_t(_Compare(), allocator_type()) {}
  87.   explicit set(const _Compare& __comp,
  88.                const allocator_type& __a = allocator_type())
  89.     : _M_t(__comp, __a) {}
  90.  
  91.   template <class _InputIterator>
  92.   set(_InputIterator __first, _InputIterator __last)
  93.     : _M_t(_Compare(), allocator_type())
  94.     { _M_t.insert_unique(__first, __last); }
  95.  
  96.   template <class _InputIterator>
  97.   set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
  98.       const allocator_type& __a = allocator_type())
  99.     : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
  100.  
  101.   set(const set<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
  102.   set<_Key,_Compare,_Alloc>& operator=(const set<_Key, _Compare, _Alloc>& __x)
  103.   {
  104.     _M_t = __x._M_t;
  105.     return *this;
  106.   }
  107.  
  108.   // accessors:
  109.  
  110.   key_compare key_comp() const { return _M_t.key_comp(); }
  111.   value_compare value_comp() const { return _M_t.key_comp(); }
  112.   allocator_type get_allocator() const { return _M_t.get_allocator(); }
  113.  
  114.   iterator begin() const { return _M_t.begin(); }
  115.   iterator end() const { return _M_t.end(); }
  116.   reverse_iterator rbegin() const { return _M_t.rbegin(); }
  117.   reverse_iterator rend() const { return _M_t.rend(); }
  118.   bool empty() const { return _M_t.empty(); }
  119.   size_type size() const { return _M_t.size(); }
  120.   size_type max_size() const { return _M_t.max_size(); }
  121.   void swap(set<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
  122.  
  123.   // insert/erase
  124.   pair<iterator,bool> insert(const value_type& __x) {
  125.     pair<typename _Rep_type::iterator, bool> __p = _M_t.insert_unique(__x);
  126.     return pair<iterator, bool>(__p.first, __p.second);
  127.   }
  128.   iterator insert(iterator __position, const value_type& __x) {
  129.     typedef typename _Rep_type::iterator _Rep_iterator;
  130.     return _M_t.insert_unique((_Rep_iterator&)__position, __x);
  131.   }
  132.   template <class _InputIterator>
  133.   void insert(_InputIterator __first, _InputIterator __last) {
  134.     _M_t.insert_unique(__first, __last);
  135.   }
  136.   void erase(iterator __position) {
  137.     typedef typename _Rep_type::iterator _Rep_iterator;
  138.     _M_t.erase((_Rep_iterator&)__position);
  139.   }
  140.   size_type erase(const key_type& __x) {
  141.     return _M_t.erase(__x);
  142.   }
  143.   void erase(iterator __first, iterator __last) {
  144.     typedef typename _Rep_type::iterator _Rep_iterator;
  145.     _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
  146.   }
  147.   void clear() { _M_t.clear(); }
  148.  
  149.   // set operations:
  150.  
  151.   size_type count(const key_type& __x) const {
  152.     return _M_t.find(__x) == _M_t.end() ? 0 : 1;
  153.   }
  154.  
  155. #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
  156. //214.  set::find() missing const overload
  157.   iterator find(const key_type& __x) { return _M_t.find(__x); }
  158.   const_iterator find(const key_type& __x) const { return _M_t.find(__x); }
  159.   iterator lower_bound(const key_type& __x) {
  160.     return _M_t.lower_bound(__x);
  161.   }
  162.   const_iterator lower_bound(const key_type& __x) const {
  163.     return _M_t.lower_bound(__x);
  164.   }
  165.   iterator upper_bound(const key_type& __x) {
  166.     return _M_t.upper_bound(__x);
  167.   }
  168.   const_iterator upper_bound(const key_type& __x) const {
  169.     return _M_t.upper_bound(__x);
  170.   }
  171.   pair<iterator,iterator> equal_range(const key_type& __x) {
  172.     return _M_t.equal_range(__x);
  173.   }
  174.   pair<const_iterator,const_iterator> equal_range(const key_type& __x) const {
  175.     return _M_t.equal_range(__x);
  176.   }
  177. #else
  178.   iterator find(const key_type& __x) const { return _M_t.find(__x); }
  179.   iterator lower_bound(const key_type& __x) const {
  180.     return _M_t.lower_bound(__x);
  181.   }
  182.   iterator upper_bound(const key_type& __x) const {
  183.     return _M_t.upper_bound(__x);
  184.   }
  185.   pair<iterator,iterator> equal_range(const key_type& __x) const {
  186.     return _M_t.equal_range(__x);
  187.   }
  188. #endif
  189.  
  190.   template <class _K1, class _C1, class _A1>
  191.   friend bool operator== (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
  192.   template <class _K1, class _C1, class _A1>
  193.   friend bool operator< (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
  194. };
  195.  
  196. template <class _Key, class _Compare, class _Alloc>
  197. inline bool operator==(const set<_Key,_Compare,_Alloc>& __x,
  198.                        const set<_Key,_Compare,_Alloc>& __y) {
  199.   return __x._M_t == __y._M_t;
  200. }
  201.  
  202. template <class _Key, class _Compare, class _Alloc>
  203. inline bool operator<(const set<_Key,_Compare,_Alloc>& __x,
  204.                       const set<_Key,_Compare,_Alloc>& __y) {
  205.   return __x._M_t < __y._M_t;
  206. }
  207.  
  208. template <class _Key, class _Compare, class _Alloc>
  209. inline bool operator!=(const set<_Key,_Compare,_Alloc>& __x,
  210.                        const set<_Key,_Compare,_Alloc>& __y) {
  211.   return !(__x == __y);
  212. }
  213.  
  214. template <class _Key, class _Compare, class _Alloc>
  215. inline bool operator>(const set<_Key,_Compare,_Alloc>& __x,
  216.                       const set<_Key,_Compare,_Alloc>& __y) {
  217.   return __y < __x;
  218. }
  219.  
  220. template <class _Key, class _Compare, class _Alloc>
  221. inline bool operator<=(const set<_Key,_Compare,_Alloc>& __x,
  222.                        const set<_Key,_Compare,_Alloc>& __y) {
  223.   return !(__y < __x);
  224. }
  225.  
  226. template <class _Key, class _Compare, class _Alloc>
  227. inline bool operator>=(const set<_Key,_Compare,_Alloc>& __x,
  228.                        const set<_Key,_Compare,_Alloc>& __y) {
  229.   return !(__x < __y);
  230. }
  231.  
  232. template <class _Key, class _Compare, class _Alloc>
  233. inline void swap(set<_Key,_Compare,_Alloc>& __x,
  234.                  set<_Key,_Compare,_Alloc>& __y) {
  235.   __x.swap(__y);
  236. }
  237.  
  238. } // namespace std
  239.  
  240. #endif /* __SGI_STL_INTERNAL_SET_H */
  241.  
  242. // Local Variables:
  243. // mode:C++
  244. // End:
  245.