/home/ntakagi/work/STLport-5.1.5/stlport/stl/_queue.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_QUEUE_H
00031 #define _STLP_INTERNAL_QUEUE_H
00032 
00033 #ifndef _STLP_INTERNAL_DEQUE_H
00034 #  include <stl/_deque.h>
00035 #endif
00036 
00037 #ifndef _STLP_INTERNAL_VECTOR_H
00038 # include <stl/_vector.h>
00039 #endif
00040 
00041 #ifndef _STLP_INTERNAL_HEAP_H
00042 #  include <stl/_heap.h>
00043 #endif
00044 
00045 #ifndef _STLP_INTERNAL_FUNCTION_BASE_H
00046 #  include <stl/_function_base.h>
00047 #endif
00048 
00049 #if defined(__SC__) && !defined(__DMC__)    //*ty 12/07/2001 - since "comp" is a built-in type and reserved under SCpp
00050 #  define comp _Comp
00051 #endif
00052 
00053 _STLP_BEGIN_NAMESPACE
00054 
00055 # if ! defined ( _STLP_LIMITED_DEFAULT_TEMPLATES )
00056 template <class _Tp, class _Sequence = deque<_Tp> >
00057 # elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
00058 #  define _STLP_QUEUE_ARGS _Tp
00059 template <class _Tp>
00060 # else
00061 template <class _Tp, class _Sequence>
00062 # endif
00063 class queue
00064 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
00065 #  if defined (_STLP_QUEUE_ARGS)
00066             : public __stlport_class<queue<_Tp> >
00067 #  else
00068             : public __stlport_class<queue<_Tp, _Sequence> >
00069 #  endif
00070 #endif
00071 {
00072 # if defined ( _STLP_QUEUE_ARGS )
00073   typedef deque<_Tp> _Sequence;
00074   typedef queue<_Tp> _Self;
00075 # else
00076   typedef queue<_Tp, _Sequence> _Self;
00077 # endif
00078 public:
00079   typedef typename _Sequence::value_type      value_type;
00080   typedef typename _Sequence::size_type       size_type;
00081   typedef          _Sequence                  container_type;
00082 
00083   typedef typename _Sequence::reference       reference;
00084   typedef typename _Sequence::const_reference const_reference;
00085 
00086 protected:
00087   //c is a Standard name (23.2.3.1), do no make it STLport naming convention compliant.
00088   _Sequence c;
00089 public:
00090   queue() : c() {}
00091   explicit queue(const _Sequence& __c) : c(__c) {}
00092 
00093   queue(__move_source<_Self> src)
00094     : c(_STLP_PRIV _AsMoveSource(src.get().c)) {}
00095 
00096   bool empty() const { return c.empty(); }
00097   size_type size() const { return c.size(); }
00098   reference front() { return c.front(); }
00099   const_reference front() const { return c.front(); }
00100   reference back() { return c.back(); }
00101   const_reference back() const { return c.back(); }
00102   void push(const value_type& __x) { c.push_back(__x); }
00103   void pop() { c.pop_front(); }
00104   const _Sequence& _Get_s() const { return c; }
00105 };
00106 
00107 #ifndef _STLP_QUEUE_ARGS
00108 #  define _STLP_QUEUE_ARGS _Tp, _Sequence
00109 #  define _STLP_QUEUE_HEADER_ARGS class _Tp, class _Sequence
00110 #else
00111 #  define _STLP_QUEUE_HEADER_ARGS class _Tp
00112 #endif
00113 
00114 template < _STLP_QUEUE_HEADER_ARGS >
00115 inline bool _STLP_CALL
00116 operator==(const queue<_STLP_QUEUE_ARGS >& __x, const queue<_STLP_QUEUE_ARGS >& __y) {
00117   return __x._Get_s() == __y._Get_s();
00118 }
00119 
00120 template < _STLP_QUEUE_HEADER_ARGS >
00121 inline bool _STLP_CALL
00122 operator<(const queue<_STLP_QUEUE_ARGS >& __x, const queue<_STLP_QUEUE_ARGS >& __y) {
00123   return __x._Get_s() < __y._Get_s();
00124 }
00125 
00126 _STLP_RELOPS_OPERATORS( template < _STLP_QUEUE_HEADER_ARGS >, queue<_STLP_QUEUE_ARGS > )
00127 
00128 # if !(defined ( _STLP_LIMITED_DEFAULT_TEMPLATES ) || defined ( _STLP_TEMPLATE_PARAM_SUBTYPE_BUG ))
00129 template <class _Tp, class _Sequence = vector<_Tp>,
00130           class _Compare = less<_STLP_HEADER_TYPENAME _Sequence::value_type> >
00131 # elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
00132 template <class _Tp>
00133 # else
00134 template <class _Tp, class _Sequence, class _Compare>
00135 # endif
00136 class priority_queue
00137 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
00138 #  if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS)
00139             : public __stlport_class<priority_queue<_Tp> >
00140 #  else
00141             : public __stlport_class<priority_queue<_Tp, _Sequence> >
00142 #  endif
00143 #endif
00144 {
00145 # ifdef _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS
00146   typedef vector<_Tp> _Sequence;
00147   typedef less< typename vector<_Tp>::value_type> _Compare;
00148   typedef priority_queue<_Tp> _Self;
00149 # else
00150   typedef priority_queue<_Tp, _Sequence, _Compare> _Self;
00151 # endif
00152 public:
00153   typedef typename _Sequence::value_type      value_type;
00154   typedef typename _Sequence::size_type       size_type;
00155   typedef          _Sequence                  container_type;
00156 
00157   typedef typename _Sequence::reference       reference;
00158   typedef typename _Sequence::const_reference const_reference;
00159 protected:
00160   //c is a Standard name (23.2.3.2), do no make it STLport naming convention compliant.
00161   _Sequence c;
00162   _Compare comp;
00163 public:
00164   priority_queue() : c() {}
00165   explicit priority_queue(const _Compare& __x) :  c(), comp(__x) {}
00166   priority_queue(const _Compare& __x, const _Sequence& __s)
00167     : c(__s), comp(__x)
00168     { make_heap(c.begin(), c.end(), comp); }
00169 
00170   priority_queue(__move_source<_Self> src)
00171     : c(_STLP_PRIV _AsMoveSource(src.get().c)),
00172       comp(_STLP_PRIV _AsMoveSource(src.get().comp)) {}
00173 
00174 #ifdef _STLP_MEMBER_TEMPLATES
00175   template <class _InputIterator>
00176   priority_queue(_InputIterator __first, _InputIterator __last)
00177     : c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
00178 
00179   template <class _InputIterator>
00180   priority_queue(_InputIterator __first,
00181                  _InputIterator __last, const _Compare& __x)
00182     : c(__first, __last), comp(__x)
00183     { make_heap(c.begin(), c.end(), comp); }
00184 
00185   template <class _InputIterator>
00186   priority_queue(_InputIterator __first, _InputIterator __last,
00187                  const _Compare& __x, const _Sequence& __s)
00188   : c(__s), comp(__x)
00189   {
00190     c.insert(c.end(), __first, __last);
00191     make_heap(c.begin(), c.end(), comp);
00192   }
00193 
00194 #else /* _STLP_MEMBER_TEMPLATES */
00195   priority_queue(const value_type* __first, const value_type* __last)
00196     : c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
00197 
00198   priority_queue(const value_type* __first, const value_type* __last,
00199                  const _Compare& __x)
00200     : c(__first, __last), comp(__x)
00201     { make_heap(c.begin(), c.end(), comp); }
00202 
00203   priority_queue(const value_type* __first, const value_type* __last,
00204                  const _Compare& __x, const _Sequence& __c)
00205     : c(__c), comp(__x)
00206   {
00207     c.insert(c.end(), __first, __last);
00208     make_heap(c.begin(), c.end(), comp);
00209   }
00210 #endif /* _STLP_MEMBER_TEMPLATES */
00211 
00212   bool empty() const { return c.empty(); }
00213   size_type size() const { return c.size(); }
00214   const_reference top() const { return c.front(); }
00215   void push(const value_type& __x) {
00216     _STLP_TRY {
00217       c.push_back(__x);
00218       push_heap(c.begin(), c.end(), comp);
00219     }
00220     _STLP_UNWIND(c.clear())
00221   }
00222   void pop() {
00223     _STLP_TRY {
00224       pop_heap(c.begin(), c.end(), comp);
00225       c.pop_back();
00226     }
00227     _STLP_UNWIND(c.clear())
00228   }
00229 };
00230 
00231 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00232 template <class _Tp, class _Sequence>
00233 struct __move_traits<queue<_Tp, _Sequence> > :
00234   _STLP_PRIV __move_traits_aux<_Sequence>
00235 {};
00236 
00237 template <class _Tp, class _Sequence, class _Compare>
00238 struct __move_traits<priority_queue<_Tp, _Sequence, _Compare> > :
00239   _STLP_PRIV __move_traits_aux2<_Sequence, _Compare>
00240 {};
00241 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
00242 
00243 _STLP_END_NAMESPACE
00244 
00245 #undef _STLP_QUEUE_ARGS
00246 #undef _STLP_QUEUE_HEADER_ARGS
00247 #undef comp
00248 
00249 #endif /* _STLP_INTERNAL_QUEUE_H */
00250 
00251 // Local Variables:
00252 // mode:C++
00253 // End:



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