home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Compilers / digital marsC compier / dm / stl / stl_multiset.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-08  |  9.4 KB  |  275 lines

  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
  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_MULTISET_H
  32. #define __SGI_STL_INTERNAL_MULTISET_H
  33.  
  34. #include <concept_checks.h>
  35.  
  36. __STL_BEGIN_NAMESPACE
  37.  
  38. #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
  39. #pragma set woff 1174
  40. #pragma set woff 1375
  41. #endif
  42.  
  43. // Forward declaration of operators < and ==, needed for friend declaration.
  44.  
  45. template <class _Key, class _Compare __STL_DEPENDENT_DEFAULT_TMPL(less<_Key>),
  46.           class _Alloc = __STL_DEFAULT_ALLOCATOR(_Key) >
  47. class multiset;
  48.  
  49. template <class _Key, class _Compare, class _Alloc>
  50. inline bool operator==(const multiset<_Key,_Compare,_Alloc>& __x, 
  51.                        const multiset<_Key,_Compare,_Alloc>& __y);
  52.  
  53. template <class _Key, class _Compare, class _Alloc>
  54. inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x, 
  55.                       const multiset<_Key,_Compare,_Alloc>& __y);
  56.  
  57. template <class _Key, class _Compare, class _Alloc>
  58. class multiset {
  59.   // requirements:
  60.   
  61.   __STL_CLASS_REQUIRES(_Key, _Assignable);
  62.   __STL_CLASS_BINARY_FUNCTION_CHECK(_Compare, bool, _Key, _Key);
  63.  
  64. public:
  65.  
  66.   // typedefs:
  67.  
  68.   typedef _Key     key_type;
  69.   typedef _Key     value_type;
  70.   typedef _Compare key_compare;
  71.   typedef _Compare value_compare;
  72. private:
  73.   typedef _Rb_tree<key_type, value_type, 
  74.                   _Identity<value_type>, key_compare, _Alloc> _Rep_type;
  75.   _Rep_type _M_t;  // red-black tree representing multiset
  76. public:
  77.   typedef typename _Rep_type::const_pointer pointer;
  78.   typedef typename _Rep_type::const_pointer const_pointer;
  79.   typedef typename _Rep_type::const_reference reference;
  80.   typedef typename _Rep_type::const_reference const_reference;
  81.   typedef typename _Rep_type::const_iterator iterator;
  82.   typedef typename _Rep_type::const_iterator const_iterator;
  83.   typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
  84.   typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
  85.   typedef typename _Rep_type::size_type size_type;
  86.   typedef typename _Rep_type::difference_type difference_type;
  87.   typedef typename _Rep_type::allocator_type allocator_type;
  88.  
  89.   // allocation/deallocation
  90.  
  91.   multiset() : _M_t(_Compare(), allocator_type()) {}
  92.   explicit multiset(const _Compare& __comp,
  93.                     const allocator_type& __a = allocator_type())
  94.     : _M_t(__comp, __a) {}
  95.  
  96. #ifdef __STL_MEMBER_TEMPLATES
  97.  
  98.   template <class _InputIterator>
  99.   multiset(_InputIterator __first, _InputIterator __last)
  100.     : _M_t(_Compare(), allocator_type())
  101.     { _M_t.insert_equal(__first, __last); }
  102.  
  103.   template <class _InputIterator>
  104.   multiset(_InputIterator __first, _InputIterator __last,
  105.            const _Compare& __comp,
  106.            const allocator_type& __a = allocator_type())
  107.     : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
  108.  
  109. #else
  110.  
  111.   multiset(const value_type* __first, const value_type* __last)
  112.     : _M_t(_Compare(), allocator_type())
  113.     { _M_t.insert_equal(__first, __last); }
  114.  
  115.   multiset(const value_type* __first, const value_type* __last,
  116.            const _Compare& __comp,
  117.            const allocator_type& __a = allocator_type())
  118.     : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
  119.  
  120.   multiset(const_iterator __first, const_iterator __last)
  121.     : _M_t(_Compare(), allocator_type())
  122.     { _M_t.insert_equal(__first, __last); }
  123.  
  124.   multiset(const_iterator __first, const_iterator __last,
  125.            const _Compare& __comp,
  126.            const allocator_type& __a = allocator_type())
  127.     : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
  128.    
  129. #endif /* __STL_MEMBER_TEMPLATES */
  130.  
  131.   multiset(const multiset<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
  132.   multiset<_Key,_Compare,_Alloc>&
  133.   operator=(const multiset<_Key,_Compare,_Alloc>& __x) {
  134.     _M_t = __x._M_t; 
  135.     return *this;
  136.   }
  137.  
  138.   // accessors:
  139.  
  140.   key_compare key_comp() const { return _M_t.key_comp(); }
  141.   value_compare value_comp() const { return _M_t.key_comp(); }
  142.   allocator_type get_allocator() const { return _M_t.get_allocator(); }
  143.  
  144.   iterator begin() const { return _M_t.begin(); }
  145.   iterator end() const { return _M_t.end(); }
  146.   reverse_iterator rbegin() const { return _M_t.rbegin(); } 
  147.   reverse_iterator rend() const { return _M_t.rend(); }
  148.   bool empty() const { return _M_t.empty(); }
  149.   size_type size() const { return _M_t.size(); }
  150.   size_type max_size() const { return _M_t.max_size(); }
  151.   void swap(multiset<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
  152.  
  153.   // insert/erase
  154.   iterator insert(const value_type& __x) { 
  155.     return _M_t.insert_equal(__x);
  156.   }
  157.   iterator insert(iterator __position, const value_type& __x) {
  158.     typedef typename _Rep_type::iterator _Rep_iterator;
  159.     return _M_t.insert_equal((_Rep_iterator&)__position, __x);
  160.   }
  161.  
  162. #ifdef __STL_MEMBER_TEMPLATES  
  163.   template <class _InputIterator>
  164.   void insert(_InputIterator __first, _InputIterator __last) {
  165.     _M_t.insert_equal(__first, __last);
  166.   }
  167. #else
  168.   void insert(const value_type* __first, const value_type* __last) {
  169.     _M_t.insert_equal(__first, __last);
  170.   }
  171.   void insert(const_iterator __first, const_iterator __last) {
  172.     _M_t.insert_equal(__first, __last);
  173.   }
  174. #endif /* __STL_MEMBER_TEMPLATES */
  175.   void erase(iterator __position) { 
  176.     typedef typename _Rep_type::iterator _Rep_iterator;
  177.     _M_t.erase((_Rep_iterator&)__position); 
  178.   }
  179.   size_type erase(const key_type& __x) { 
  180.     return _M_t.erase(__x); 
  181.   }
  182.   void erase(iterator __first, iterator __last) { 
  183.     typedef typename _Rep_type::iterator _Rep_iterator;
  184.     _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last); 
  185.   }
  186.   void clear() { _M_t.clear(); }
  187.  
  188.   // multiset operations:
  189.  
  190.   iterator find(const key_type& __x) const { return _M_t.find(__x); }
  191.   size_type count(const key_type& __x) const { return _M_t.count(__x); }
  192.   iterator lower_bound(const key_type& __x) const {
  193.     return _M_t.lower_bound(__x);
  194.   }
  195.   iterator upper_bound(const key_type& __x) const {
  196.     return _M_t.upper_bound(__x); 
  197.   }
  198.   pair<iterator,iterator> equal_range(const key_type& __x) const {
  199.     return _M_t.equal_range(__x);
  200.   }
  201.  
  202. #ifdef __STL_TEMPLATE_FRIENDS
  203.   template <class _K1, class _C1, class _A1>
  204.   friend bool operator== (const multiset<_K1,_C1,_A1>&,
  205.                           const multiset<_K1,_C1,_A1>&);
  206.   template <class _K1, class _C1, class _A1>
  207.   friend bool operator< (const multiset<_K1,_C1,_A1>&,
  208.                          const multiset<_K1,_C1,_A1>&);
  209. #else /* __STL_TEMPLATE_FRIENDS */
  210.   friend bool __STD_QUALIFIER
  211.   operator== __STL_NULL_TMPL_ARGS (const multiset&, const multiset&);
  212.   friend bool __STD_QUALIFIER
  213.   operator< __STL_NULL_TMPL_ARGS (const multiset&, const multiset&);
  214. #endif /* __STL_TEMPLATE_FRIENDS */
  215. };
  216.  
  217. template <class _Key, class _Compare, class _Alloc>
  218. inline bool operator==(const multiset<_Key,_Compare,_Alloc>& __x, 
  219.                        const multiset<_Key,_Compare,_Alloc>& __y) {
  220.   return __x._M_t == __y._M_t;
  221. }
  222.  
  223. template <class _Key, class _Compare, class _Alloc>
  224. inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x, 
  225.                       const multiset<_Key,_Compare,_Alloc>& __y) {
  226.   return __x._M_t < __y._M_t;
  227. }
  228.  
  229. #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
  230.  
  231. template <class _Key, class _Compare, class _Alloc>
  232. inline bool operator!=(const multiset<_Key,_Compare,_Alloc>& __x, 
  233.                        const multiset<_Key,_Compare,_Alloc>& __y) {
  234.   return !(__x == __y);
  235. }
  236.  
  237. template <class _Key, class _Compare, class _Alloc>
  238. inline bool operator>(const multiset<_Key,_Compare,_Alloc>& __x, 
  239.                       const multiset<_Key,_Compare,_Alloc>& __y) {
  240.   return __y < __x;
  241. }
  242.  
  243. template <class _Key, class _Compare, class _Alloc>
  244. inline bool operator<=(const multiset<_Key,_Compare,_Alloc>& __x, 
  245.                        const multiset<_Key,_Compare,_Alloc>& __y) {
  246.   return !(__y < __x);
  247. }
  248.  
  249. template <class _Key, class _Compare, class _Alloc>
  250. inline bool operator>=(const multiset<_Key,_Compare,_Alloc>& __x, 
  251.                        const multiset<_Key,_Compare,_Alloc>& __y) {
  252.   return !(__x < __y);
  253. }
  254.  
  255. template <class _Key, class _Compare, class _Alloc>
  256. inline void swap(multiset<_Key,_Compare,_Alloc>& __x, 
  257.                  multiset<_Key,_Compare,_Alloc>& __y) {
  258.   __x.swap(__y);
  259. }
  260.  
  261. #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
  262.  
  263. #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
  264. #pragma reset woff 1174
  265. #pragma reset woff 1375
  266. #endif
  267.  
  268. __STL_END_NAMESPACE
  269.  
  270. #endif /* __SGI_STL_INTERNAL_MULTISET_H */
  271.  
  272. // Local Variables:
  273. // mode:C++
  274. // End:
  275.