stl_queue.h

00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Permission to use, copy, modify, distribute and sell this software
00007  * and its documentation for any purpose is hereby granted without fee,
00008  * provided that the above copyright notice appear in all copies and
00009  * that both that copyright notice and this permission notice appear
00010  * in supporting documentation.  Hewlett-Packard Company makes no
00011  * representations about the suitability of this software for any
00012  * purpose.  It is provided "as is" without express or implied warranty.
00013  *
00014  *
00015  * Copyright (c) 1996,1997
00016  * Silicon Graphics Computer Systems, Inc.
00017  *
00018  * Permission to use, copy, modify, distribute and sell this software
00019  * and its documentation for any purpose is hereby granted without fee,
00020  * provided that the above copyright notice appear in all copies and
00021  * that both that copyright notice and this permission notice appear
00022  * in supporting documentation.  Silicon Graphics makes no
00023  * representations about the suitability of this software for any
00024  * purpose.  It is provided "as is" without express or implied warranty.
00025  */
00026 
00027 /* NOTE: This is an internal header file, included by other STL headers.
00028  *   You should not attempt to use it directly.
00029  */
00030 
00031 #ifndef __SGI_STL_INTERNAL_QUEUE_H
00032 #define __SGI_STL_INTERNAL_QUEUE_H
00033 
00034 #include <sequence_concepts.h>
00035 
00036 __STL_BEGIN_NAMESPACE
00037 
00038 // Forward declarations of operators < and ==, needed for friend declaration.
00039 
00040 template <class _Tp, 
00041           class _Sequence __STL_DEPENDENT_DEFAULT_TMPL(deque<_Tp>) >
00042 class queue;
00043 
00044 template <class _Tp, class _Seq>
00045 inline bool operator==(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&);
00046 
00047 template <class _Tp, class _Seq>
00048 inline bool operator<(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&);
00049 
00050 
00051 template <class _Tp, class _Sequence>
00052 class queue {
00053 
00054   // requirements:
00055 
00056   __STL_CLASS_REQUIRES(_Tp, _Assignable);
00057   __STL_CLASS_REQUIRES(_Sequence, _FrontInsertionSequence);
00058   __STL_CLASS_REQUIRES(_Sequence, _BackInsertionSequence);
00059   typedef typename _Sequence::value_type _Sequence_value_type;
00060   __STL_CLASS_REQUIRES_SAME_TYPE(_Tp, _Sequence_value_type);
00061 
00062 
00063 #ifdef __STL_MEMBER_TEMPLATES 
00064   template <class _Tp1, class _Seq1>
00065   friend bool operator== (const queue<_Tp1, _Seq1>&,
00066                           const queue<_Tp1, _Seq1>&);
00067   template <class _Tp1, class _Seq1>
00068   friend bool operator< (const queue<_Tp1, _Seq1>&,
00069                          const queue<_Tp1, _Seq1>&);
00070 #else /* __STL_MEMBER_TEMPLATES */
00071   friend bool __STD_QUALIFIER
00072   operator== __STL_NULL_TMPL_ARGS (const queue&, const queue&);
00073   friend bool __STD_QUALIFIER
00074   operator<  __STL_NULL_TMPL_ARGS (const queue&, const queue&);
00075 #endif /* __STL_MEMBER_TEMPLATES */
00076 
00077 public:
00078   typedef typename _Sequence::value_type      value_type;
00079   typedef typename _Sequence::size_type       size_type;
00080   typedef          _Sequence                  container_type;
00081 
00082   typedef typename _Sequence::reference       reference;
00083   typedef typename _Sequence::const_reference const_reference;
00084 protected:
00085   _Sequence c;
00086 public:
00087   queue() : c() {}
00088   explicit queue(const _Sequence& __c) : c(__c) {}
00089 
00090   bool empty() const { return c.empty(); }
00091   size_type size() const { return c.size(); }
00092   reference front() { return c.front(); }
00093   const_reference front() const { return c.front(); }
00094   reference back() { return c.back(); }
00095   const_reference back() const { return c.back(); }
00096   void push(const value_type& __x) { c.push_back(__x); }
00097   void pop() { c.pop_front(); }
00098 };
00099 
00100 template <class _Tp, class _Sequence>
00101 bool 
00102 operator==(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
00103 {
00104   return __x.c == __y.c;
00105 }
00106 
00107 template <class _Tp, class _Sequence>
00108 bool
00109 operator<(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
00110 {
00111   return __x.c < __y.c;
00112 }
00113 
00114 #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
00115 
00116 template <class _Tp, class _Sequence>
00117 bool
00118 operator!=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
00119 {
00120   return !(__x == __y);
00121 }
00122 
00123 template <class _Tp, class _Sequence>
00124 bool 
00125 operator>(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
00126 {
00127   return __y < __x;
00128 }
00129 
00130 template <class _Tp, class _Sequence>
00131 bool 
00132 operator<=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
00133 {
00134   return !(__y < __x);
00135 }
00136 
00137 template <class _Tp, class _Sequence>
00138 bool 
00139 operator>=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
00140 {
00141   return !(__x < __y);
00142 }
00143 
00144 #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
00145 
00146 template <class _Tp, 
00147           class _Sequence __STL_DEPENDENT_DEFAULT_TMPL(vector<_Tp>),
00148           class _Compare
00149           __STL_DEPENDENT_DEFAULT_TMPL(less<typename _Sequence::value_type>) >
00150 class priority_queue {
00151 
00152   // requirements:
00153 
00154   __STL_CLASS_REQUIRES(_Tp, _Assignable);
00155   __STL_CLASS_REQUIRES(_Sequence, _Sequence);
00156   __STL_CLASS_REQUIRES(_Sequence, _RandomAccessContainer);
00157   typedef typename _Sequence::value_type _Sequence_value_type;
00158   __STL_CLASS_REQUIRES_SAME_TYPE(_Tp, _Sequence_value_type);
00159   __STL_CLASS_BINARY_FUNCTION_CHECK(_Compare, bool, _Tp, _Tp);
00160 
00161 public:
00162   typedef typename _Sequence::value_type      value_type;
00163   typedef typename _Sequence::size_type       size_type;
00164   typedef          _Sequence                  container_type;
00165 
00166   typedef typename _Sequence::reference       reference;
00167   typedef typename _Sequence::const_reference const_reference;
00168 protected:
00169   _Sequence c;
00170   _Compare comp;
00171 public:
00172   priority_queue() : c() {}
00173   explicit priority_queue(const _Compare& __x) :  c(), comp(__x) {}
00174   priority_queue(const _Compare& __x, const _Sequence& __s) 
00175     : c(__s), comp(__x) 
00176     { make_heap(c.begin(), c.end(), comp); }
00177 
00178 #ifdef __STL_MEMBER_TEMPLATES
00179   template <class _InputIterator>
00180   priority_queue(_InputIterator __first, _InputIterator __last) 
00181     : c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
00182 
00183   template <class _InputIterator>
00184   priority_queue(_InputIterator __first, 
00185                  _InputIterator __last, const _Compare& __x)
00186     : c(__first, __last), comp(__x) 
00187     { make_heap(c.begin(), c.end(), comp); }
00188 
00189   template <class _InputIterator>
00190   priority_queue(_InputIterator __first, _InputIterator __last,
00191                  const _Compare& __x, const _Sequence& __s)
00192   : c(__s), comp(__x)
00193   { 
00194     c.insert(c.end(), __first, __last);
00195     make_heap(c.begin(), c.end(), comp);
00196   }
00197 
00198 #else /* __STL_MEMBER_TEMPLATES */
00199   priority_queue(const value_type* __first, const value_type* __last) 
00200     : c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
00201 
00202   priority_queue(const value_type* __first, const value_type* __last, 
00203                  const _Compare& __x) 
00204     : c(__first, __last), comp(__x)
00205     { make_heap(c.begin(), c.end(), comp); }
00206 
00207   priority_queue(const value_type* __first, const value_type* __last, 
00208                  const _Compare& __x, const _Sequence& __c)
00209     : c(__c), comp(__x) 
00210   { 
00211     c.insert(c.end(), __first, __last);
00212     make_heap(c.begin(), c.end(), comp);
00213   }
00214 #endif /* __STL_MEMBER_TEMPLATES */
00215 
00216   bool empty() const { return c.empty(); }
00217   size_type size() const { return c.size(); }
00218   const_reference top() const { return c.front(); }
00219   void push(const value_type& __x) {
00220     __STL_TRY {
00221       c.push_back(__x); 
00222       push_heap(c.begin(), c.end(), comp);
00223     }
00224     __STL_UNWIND(c.clear());
00225   }
00226   void pop() {
00227     __STL_TRY {
00228       pop_heap(c.begin(), c.end(), comp);
00229       c.pop_back();
00230     }
00231     __STL_UNWIND(c.clear());
00232   }
00233 };
00234 
00235 // no equality is provided
00236 
00237 __STL_END_NAMESPACE
00238 
00239 #endif /* __SGI_STL_INTERNAL_QUEUE_H */
00240 
00241 // Local Variables:
00242 // mode:C++
00243 // End:

Generated on Mon Jun 5 10:20:44 2006 for Intelligence.kdevelop by  doxygen 1.4.6