/home/ntakagi/work/STLport-5.1.5/stlport/stl/_set.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Copyright (c) 1996,1997
00007  * Silicon Graphics Computer Systems, Inc.
00008  *
00009  * Copyright (c) 1997
00010  * Moscow Center for SPARC Technology
00011  *
00012  * Copyright (c) 1999
00013  * Boris Fomitchev
00014  *
00015  * This material is provided "as is", with absolutely no warranty expressed
00016  * or implied. Any use is at your own risk.
00017  *
00018  * Permission to use or copy this software for any purpose is hereby granted
00019  * without fee, provided the above notices are retained on all copies.
00020  * Permission to modify the code and to distribute modified code is granted,
00021  * provided the above notices are retained, and a notice that the code was
00022  * modified is included with the above copyright notice.
00023  *
00024  */
00025 
00026 /* NOTE: This is an internal header file, included by other STL headers.
00027  *   You should not attempt to use it directly.
00028  */
00029 
00030 #ifndef _STLP_INTERNAL_SET_H
00031 #define _STLP_INTERNAL_SET_H
00032 
00033 #ifndef _STLP_INTERNAL_TREE_H
00034 #  include <stl/_tree.h>
00035 #endif
00036 
00037 #if !defined (_STLP_USE_PTR_SPECIALIZATIONS)
00038 
00039 _STLP_BEGIN_NAMESPACE
00040 
00041 //Specific iterator traits creation
00042 _STLP_CREATE_ITERATOR_TRAITS(SetTraitsT, Const_traits)
00043 
00044 template <class _Key, _STLP_DFL_TMPL_PARAM(_Compare, less<_Key>),
00045                      _STLP_DEFAULT_ALLOCATOR_SELECT(_Key) >
00046 class set
00047 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
00048           : public __stlport_class<set<_Key, _Compare, _Alloc> >
00049 #endif
00050 {
00051   typedef set<_Key, _Compare, _Alloc> _Self;
00052 public:
00053 // typedefs:
00054   typedef _Key     key_type;
00055   typedef _Key     value_type;
00056   typedef _Compare key_compare;
00057   typedef _Compare value_compare;
00058 
00059 private:
00060   //Specific iterator traits creation
00061   typedef _STLP_PRIV _SetTraitsT<value_type> _SetTraits;
00062 
00063 public:
00064   //Following typedef have to be public for __move_traits specialization.
00065   typedef _STLP_PRIV _Rb_tree<key_type, key_compare,
00066                               value_type, _STLP_PRIV _Identity<value_type>,
00067                               _SetTraits, _Alloc> _Rep_type;
00068 
00069   typedef typename _Rep_type::pointer pointer;
00070   typedef typename _Rep_type::const_pointer const_pointer;
00071   typedef typename _Rep_type::reference reference;
00072   typedef typename _Rep_type::const_reference const_reference;
00073   typedef typename _Rep_type::iterator iterator;
00074   typedef typename _Rep_type::const_iterator const_iterator;
00075   typedef typename _Rep_type::reverse_iterator reverse_iterator;
00076   typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00077   typedef typename _Rep_type::size_type size_type;
00078   typedef typename _Rep_type::difference_type difference_type;
00079   typedef typename _Rep_type::allocator_type allocator_type;
00080 
00081 private:
00082   _Rep_type _M_t;  // red-black tree representing set
00083   _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
00084 
00085 public:
00086 
00087   // allocation/deallocation
00088 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
00089   explicit set(const _Compare& __comp = _Compare(),
00090                const allocator_type& __a = allocator_type())
00091 #else
00092   set()
00093     : _M_t(_Compare(), allocator_type()) {}
00094   explicit set(const _Compare& __comp)
00095     : _M_t(__comp, allocator_type()) {}
00096   set(const _Compare& __comp, const allocator_type& __a)
00097 #endif
00098     : _M_t(__comp, __a) {}
00099 
00100 #if defined (_STLP_MEMBER_TEMPLATES)
00101   template <class _InputIterator>
00102   set(_InputIterator __first, _InputIterator __last)
00103     : _M_t(_Compare(), allocator_type())
00104     { _M_t.insert_unique(__first, __last); }
00105 
00106 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
00107   template <class _InputIterator>
00108   set(_InputIterator __first, _InputIterator __last, const _Compare& __comp)
00109     : _M_t(__comp, allocator_type()) { _M_t.insert_unique(__first, __last); }
00110 #  endif
00111   template <class _InputIterator>
00112   set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
00113       const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
00114     : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
00115 #else
00116   set(const value_type* __first, const value_type* __last)
00117     : _M_t(_Compare(), allocator_type())
00118     { _M_t.insert_unique(__first, __last); }
00119 
00120   set(const value_type* __first,
00121       const value_type* __last, const _Compare& __comp,
00122       const allocator_type& __a = allocator_type())
00123     : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
00124 
00125   set(const_iterator __first, const_iterator __last)
00126     : _M_t(_Compare(), allocator_type())
00127     { _M_t.insert_unique(__first, __last); }
00128 
00129   set(const_iterator __first, const_iterator __last, const _Compare& __comp,
00130       const allocator_type& __a = allocator_type())
00131     : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
00132 #endif /* _STLP_MEMBER_TEMPLATES */
00133 
00134   set(const _Self& __x) : _M_t(__x._M_t) {}
00135 
00136   set(__move_source<_Self> src)
00137     : _M_t(__move_source<_Rep_type>(src.get()._M_t)) {}
00138 
00139   _Self& operator=(const _Self& __x) {
00140     _M_t = __x._M_t;
00141     return *this;
00142   }
00143 
00144   // accessors:
00145   key_compare key_comp() const { return _M_t.key_comp(); }
00146   value_compare value_comp() const { return _M_t.key_comp(); }
00147   allocator_type get_allocator() const { return _M_t.get_allocator(); }
00148 
00149   iterator begin() { return _M_t.begin(); }
00150   iterator end() { return _M_t.end(); }
00151   const_iterator begin() const { return _M_t.begin(); }
00152   const_iterator end() const { return _M_t.end(); }
00153   reverse_iterator rbegin() { return _M_t.rbegin(); }
00154   reverse_iterator rend() { return _M_t.rend(); }
00155   const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
00156   const_reverse_iterator rend() const { return _M_t.rend(); }
00157   bool empty() const { return _M_t.empty(); }
00158   size_type size() const { return _M_t.size(); }
00159   size_type max_size() const { return _M_t.max_size(); }
00160   void swap(_Self& __x) { _M_t.swap(__x._M_t); }
00161 
00162   // insert/erase
00163   pair<iterator,bool> insert(const value_type& __x)
00164   { return _M_t.insert_unique(__x); }
00165   iterator insert(iterator __pos, const value_type& __x)
00166   { return _M_t.insert_unique( __pos , __x); }
00167 #if defined (_STLP_MEMBER_TEMPLATES)
00168   template <class _InputIterator>
00169   void insert(_InputIterator __first, _InputIterator __last)
00170   { _M_t.insert_unique(__first, __last); }
00171 #else
00172   void insert(const_iterator __first, const_iterator __last)
00173   { _M_t.insert_unique(__first, __last); }
00174   void insert(const value_type* __first, const value_type* __last)
00175   { _M_t.insert_unique(__first, __last); }
00176 #endif /* _STLP_MEMBER_TEMPLATES */
00177   void erase(iterator __pos) { _M_t.erase( __pos ); }
00178   size_type erase(const key_type& __x) { return _M_t.erase_unique(__x); }
00179   void erase(iterator __first, iterator __last) { _M_t.erase(__first, __last ); }
00180   void clear() { _M_t.clear(); }
00181 
00182   // set operations:
00183   _STLP_TEMPLATE_FOR_CONT_EXT
00184   const_iterator find(const _KT& __x) const { return _M_t.find(__x); }
00185   _STLP_TEMPLATE_FOR_CONT_EXT
00186   iterator find(const _KT& __x) { return _M_t.find(__x); }
00187   _STLP_TEMPLATE_FOR_CONT_EXT
00188   size_type count(const _KT& __x) const
00189   { return _M_t.find(__x) == _M_t.end() ? 0 : 1 ; }
00190   _STLP_TEMPLATE_FOR_CONT_EXT
00191   iterator lower_bound(const _KT& __x) { return _M_t.lower_bound(__x); }
00192   _STLP_TEMPLATE_FOR_CONT_EXT
00193   const_iterator lower_bound(const _KT& __x) const { return _M_t.lower_bound(__x); }
00194   _STLP_TEMPLATE_FOR_CONT_EXT
00195   iterator upper_bound(const _KT& __x) { return _M_t.upper_bound(__x); }
00196   _STLP_TEMPLATE_FOR_CONT_EXT
00197   const_iterator upper_bound(const _KT& __x) const { return _M_t.upper_bound(__x); }
00198   _STLP_TEMPLATE_FOR_CONT_EXT
00199   pair<iterator, iterator> equal_range(const _KT& __x)
00200   { return _M_t.equal_range_unique(__x); }
00201   _STLP_TEMPLATE_FOR_CONT_EXT
00202   pair<const_iterator, const_iterator> equal_range(const _KT& __x) const
00203   { return _M_t.equal_range_unique(__x); }
00204 };
00205 
00206 //Specific iterator traits creation
00207 _STLP_CREATE_ITERATOR_TRAITS(MultisetTraitsT, Const_traits)
00208 
00209 template <class _Key, _STLP_DFL_TMPL_PARAM(_Compare, less<_Key>),
00210           _STLP_DEFAULT_ALLOCATOR_SELECT(_Key) >
00211 class multiset
00212 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
00213                : public __stlport_class<multiset<_Key, _Compare, _Alloc> >
00214 #endif
00215 {
00216   typedef multiset<_Key, _Compare, _Alloc> _Self;
00217 public:
00218   // typedefs:
00219 
00220   typedef _Key     key_type;
00221   typedef _Key     value_type;
00222   typedef _Compare key_compare;
00223   typedef _Compare value_compare;
00224 
00225 private:
00226   //Specific iterator traits creation
00227   typedef _STLP_PRIV _MultisetTraitsT<value_type> _MultisetTraits;
00228 
00229 public:
00230   //Following typedef have to be public for __move_traits specialization.
00231   typedef _STLP_PRIV _Rb_tree<key_type, key_compare,
00232                               value_type, _STLP_PRIV _Identity<value_type>,
00233                               _MultisetTraits, _Alloc> _Rep_type;
00234 
00235   typedef typename _Rep_type::pointer pointer;
00236   typedef typename _Rep_type::const_pointer const_pointer;
00237   typedef typename _Rep_type::reference reference;
00238   typedef typename _Rep_type::const_reference const_reference;
00239   typedef typename _Rep_type::iterator iterator;
00240   typedef typename _Rep_type::const_iterator const_iterator;
00241   typedef typename _Rep_type::reverse_iterator reverse_iterator;
00242   typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00243   typedef typename _Rep_type::size_type size_type;
00244   typedef typename _Rep_type::difference_type difference_type;
00245   typedef typename _Rep_type::allocator_type allocator_type;
00246 
00247 private:
00248   _Rep_type _M_t;  // red-black tree representing multiset
00249   _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
00250 
00251 public:
00252 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
00253   explicit multiset(const _Compare& __comp = _Compare(),
00254                     const allocator_type& __a = allocator_type())
00255 #else
00256   multiset()
00257     : _M_t(_Compare(), allocator_type()) {}
00258   explicit multiset(const _Compare& __comp)
00259     : _M_t(__comp, allocator_type()) {}
00260   multiset(const _Compare& __comp, const allocator_type& __a)
00261 #endif
00262     : _M_t(__comp, __a) {}
00263 
00264 #if defined (_STLP_MEMBER_TEMPLATES)
00265   template <class _InputIterator>
00266   multiset(_InputIterator __first, _InputIterator __last)
00267     : _M_t(_Compare(), allocator_type())
00268     { _M_t.insert_equal(__first, __last); }
00269 
00270   template <class _InputIterator>
00271   multiset(_InputIterator __first, _InputIterator __last,
00272            const _Compare& __comp,
00273            const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
00274     : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
00275 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
00276   template <class _InputIterator>
00277   multiset(_InputIterator __first, _InputIterator __last,
00278            const _Compare& __comp)
00279     : _M_t(__comp, allocator_type()) { _M_t.insert_equal(__first, __last); }
00280 #  endif
00281 #else
00282   multiset(const value_type* __first, const value_type* __last)
00283     : _M_t(_Compare(), allocator_type())
00284     { _M_t.insert_equal(__first, __last); }
00285 
00286   multiset(const value_type* __first, const value_type* __last,
00287            const _Compare& __comp,
00288            const allocator_type& __a = allocator_type())
00289     : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
00290 
00291   multiset(const_iterator __first, const_iterator __last)
00292     : _M_t(_Compare(), allocator_type())
00293     { _M_t.insert_equal(__first, __last); }
00294 
00295   multiset(const_iterator __first, const_iterator __last,
00296            const _Compare& __comp,
00297            const allocator_type& __a = allocator_type())
00298     : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
00299 #endif /* _STLP_MEMBER_TEMPLATES */
00300 
00301   multiset(const _Self& __x) : _M_t(__x._M_t) {}
00302   _Self& operator=(const _Self& __x) {
00303     _M_t = __x._M_t;
00304     return *this;
00305   }
00306 
00307   multiset(__move_source<_Self> src)
00308     : _M_t(__move_source<_Rep_type>(src.get()._M_t)) {}
00309 
00310   // accessors:
00311   key_compare key_comp() const { return _M_t.key_comp(); }
00312   value_compare value_comp() const { return _M_t.key_comp(); }
00313   allocator_type get_allocator() const { return _M_t.get_allocator(); }
00314 
00315   iterator begin() { return _M_t.begin(); }
00316   iterator end() { return _M_t.end(); }
00317   const_iterator begin() const { return _M_t.begin(); }
00318   const_iterator end() const { return _M_t.end(); }
00319   reverse_iterator rbegin() { return _M_t.rbegin(); }
00320   reverse_iterator rend() { return _M_t.rend(); }
00321   const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
00322   const_reverse_iterator rend() const { return _M_t.rend(); }
00323   bool empty() const { return _M_t.empty(); }
00324   size_type size() const { return _M_t.size(); }
00325   size_type max_size() const { return _M_t.max_size(); }
00326   void swap(_Self& __x) { _M_t.swap(__x._M_t); }
00327 
00328   // insert/erase
00329   iterator insert(const value_type& __x)
00330   { return _M_t.insert_equal(__x); }
00331   iterator insert(iterator __pos, const value_type& __x)
00332   { return _M_t.insert_equal(__pos, __x); }
00333 
00334 #if defined (_STLP_MEMBER_TEMPLATES)
00335   template <class _InputIterator>
00336   void insert(_InputIterator __first, _InputIterator __last)
00337   { _M_t.insert_equal(__first, __last); }
00338 #else
00339   void insert(const value_type* __first, const value_type* __last)
00340   { _M_t.insert_equal(__first, __last); }
00341   void insert(const_iterator __first, const_iterator __last)
00342   { _M_t.insert_equal(__first, __last); }
00343 #endif /* _STLP_MEMBER_TEMPLATES */
00344   void erase(iterator __pos) { _M_t.erase( __pos ); }
00345   size_type erase(const key_type& __x) { return _M_t.erase(__x); }
00346   void erase(iterator __first, iterator __last) { _M_t.erase( __first, __last ); }
00347   void clear() { _M_t.clear(); }
00348 
00349   // multiset operations:
00350   _STLP_TEMPLATE_FOR_CONT_EXT
00351   iterator find(const _KT& __x) { return _M_t.find(__x); }
00352   _STLP_TEMPLATE_FOR_CONT_EXT
00353   const_iterator find(const _KT& __x) const { return _M_t.find(__x); }
00354   _STLP_TEMPLATE_FOR_CONT_EXT
00355   size_type count(const _KT& __x) const { return _M_t.count(__x); }
00356   _STLP_TEMPLATE_FOR_CONT_EXT
00357   iterator lower_bound(const _KT& __x) { return _M_t.lower_bound(__x); }
00358   _STLP_TEMPLATE_FOR_CONT_EXT
00359   const_iterator lower_bound(const _KT& __x) const { return _M_t.lower_bound(__x); }
00360   _STLP_TEMPLATE_FOR_CONT_EXT
00361   iterator upper_bound(const _KT& __x) { return _M_t.upper_bound(__x); }
00362   _STLP_TEMPLATE_FOR_CONT_EXT
00363   const_iterator upper_bound(const _KT& __x) const { return _M_t.upper_bound(__x); }
00364   _STLP_TEMPLATE_FOR_CONT_EXT
00365   pair<iterator, iterator> equal_range(const _KT& __x) { return _M_t.equal_range(__x); }
00366   _STLP_TEMPLATE_FOR_CONT_EXT
00367   pair<const_iterator, const_iterator> equal_range(const _KT& __x) const { return _M_t.equal_range(__x); }
00368 };
00369 
00370 #else
00371 #  include <stl/pointers/_set.h>
00372 _STLP_BEGIN_NAMESPACE
00373 #endif /* _STLP_USE_PTR_SPECIALIZATIONS */
00374 
00375 #define _STLP_TEMPLATE_HEADER template <class _Key, class _Compare, class _Alloc>
00376 #define _STLP_TEMPLATE_CONTAINER set<_Key,_Compare,_Alloc>
00377 #include <stl/_relops_cont.h>
00378 #undef  _STLP_TEMPLATE_CONTAINER
00379 #define _STLP_TEMPLATE_CONTAINER multiset<_Key,_Compare,_Alloc>
00380 #include <stl/_relops_cont.h>
00381 #undef  _STLP_TEMPLATE_CONTAINER
00382 #undef  _STLP_TEMPLATE_HEADER
00383 
00384 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00385 template <class _Key, class _Compare, class _Alloc>
00386 struct __move_traits<set<_Key,_Compare,_Alloc> > :
00387   _STLP_PRIV __move_traits_aux<typename set<_Key,_Compare,_Alloc>::_Rep_type>
00388 {};
00389 
00390 template <class _Key, class _Compare, class _Alloc>
00391 struct __move_traits<multiset<_Key,_Compare,_Alloc> > :
00392   _STLP_PRIV __move_traits_aux<typename multiset<_Key,_Compare,_Alloc>::_Rep_type>
00393 {};
00394 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
00395 
00396 _STLP_END_NAMESPACE
00397 
00398 #endif /* _STLP_INTERNAL_SET_H */
00399 
00400 // Local Variables:
00401 // mode:C++
00402 // End:



Generated on Mon Mar 10 15:32:34 2008 by  doxygen 1.5.1