Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

stl_queue.h

Go to the documentation of this file.
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 <bits/concept_check.h>
00035 
00036 namespace std
00037 {
00038 
00039 // Forward declarations of operators < and ==, needed for friend declaration.
00040 
00041 template <class _Tp, 
00042           class _Sequence = deque<_Tp> >
00043 class queue;
00044 
00045 template <class _Tp, class _Seq>
00046 inline bool operator==(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&);
00047 
00048 template <class _Tp, class _Seq>
00049 inline bool operator<(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&);
00050 
00051 
00052 template <class _Tp, class _Sequence>
00053 class queue
00054 {
00055   // concept requirements
00056   __glibcpp_class_requires(_Tp, _SGIAssignableConcept);
00057   __glibcpp_class_requires(_Sequence, _FrontInsertionSequenceConcept);
00058   __glibcpp_class_requires(_Sequence, _BackInsertionSequenceConcept);
00059   typedef typename _Sequence::value_type _Sequence_value_type;
00060   __glibcpp_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept);
00061 
00062   template <class _Tp1, class _Seq1>
00063   friend bool operator== (const queue<_Tp1, _Seq1>&,
00064                           const queue<_Tp1, _Seq1>&);
00065   template <class _Tp1, class _Seq1>
00066   friend bool operator< (const queue<_Tp1, _Seq1>&,
00067                          const queue<_Tp1, _Seq1>&);
00068 public:
00069   typedef typename _Sequence::value_type      value_type;
00070   typedef typename _Sequence::size_type       size_type;
00071   typedef          _Sequence                  container_type;
00072 
00073   typedef typename _Sequence::reference       reference;
00074   typedef typename _Sequence::const_reference const_reference;
00075 protected:
00076   _Sequence c;
00077 public:
00078   queue() : c() {}
00079   explicit queue(const _Sequence& __c) : c(__c) {}
00080 
00081   bool empty() const { return c.empty(); }
00082   size_type size() const { return c.size(); }
00083   reference front() { return c.front(); }
00084   const_reference front() const { return c.front(); }
00085   reference back() { return c.back(); }
00086   const_reference back() const { return c.back(); }
00087   void push(const value_type& __x) { c.push_back(__x); }
00088   void pop() { c.pop_front(); }
00089 };
00090 
00091 template <class _Tp, class _Sequence>
00092 bool 
00093 operator==(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
00094 {
00095   return __x.c == __y.c;
00096 }
00097 
00098 template <class _Tp, class _Sequence>
00099 bool
00100 operator<(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
00101 {
00102   return __x.c < __y.c;
00103 }
00104 
00105 template <class _Tp, class _Sequence>
00106 bool
00107 operator!=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
00108 {
00109   return !(__x == __y);
00110 }
00111 
00112 template <class _Tp, class _Sequence>
00113 bool 
00114 operator>(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
00115 {
00116   return __y < __x;
00117 }
00118 
00119 template <class _Tp, class _Sequence>
00120 bool 
00121 operator<=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
00122 {
00123   return !(__y < __x);
00124 }
00125 
00126 template <class _Tp, class _Sequence>
00127 bool 
00128 operator>=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
00129 {
00130   return !(__x < __y);
00131 }
00132 
00133 template <class _Tp, 
00134           class _Sequence = vector<_Tp>,
00135           class _Compare  = less<typename _Sequence::value_type> >
00136 class priority_queue
00137 {
00138   // concept requirements
00139   __glibcpp_class_requires(_Tp, _SGIAssignableConcept);
00140   __glibcpp_class_requires(_Sequence, _SequenceConcept);
00141   __glibcpp_class_requires(_Sequence, _RandomAccessContainerConcept);
00142   typedef typename _Sequence::value_type _Sequence_value_type;
00143   __glibcpp_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept);
00144   __glibcpp_class_requires4(_Compare, bool, _Tp, _Tp, _BinaryFunctionConcept);
00145 
00146 public:
00147   typedef typename _Sequence::value_type      value_type;
00148   typedef typename _Sequence::size_type       size_type;
00149   typedef          _Sequence                  container_type;
00150 
00151   typedef typename _Sequence::reference       reference;
00152   typedef typename _Sequence::const_reference const_reference;
00153 protected:
00154   _Sequence c;
00155   _Compare comp;
00156 public:
00157   priority_queue() : c() {}
00158   explicit priority_queue(const _Compare& __x) :  c(), comp(__x) {}
00159   priority_queue(const _Compare& __x, const _Sequence& __s) 
00160     : c(__s), comp(__x) 
00161     { make_heap(c.begin(), c.end(), comp); }
00162 
00163   template <class _InputIterator>
00164   priority_queue(_InputIterator __first, _InputIterator __last) 
00165     : c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
00166 
00167   template <class _InputIterator>
00168   priority_queue(_InputIterator __first, 
00169                  _InputIterator __last, const _Compare& __x)
00170     : c(__first, __last), comp(__x) 
00171     { make_heap(c.begin(), c.end(), comp); }
00172 
00173   template <class _InputIterator>
00174   priority_queue(_InputIterator __first, _InputIterator __last,
00175                  const _Compare& __x, const _Sequence& __s)
00176   : c(__s), comp(__x)
00177   { 
00178     c.insert(c.end(), __first, __last);
00179     make_heap(c.begin(), c.end(), comp);
00180   }
00181 
00182   bool empty() const { return c.empty(); }
00183   size_type size() const { return c.size(); }
00184   const_reference top() const { return c.front(); }
00185   void push(const value_type& __x) {
00186     __STL_TRY {
00187       c.push_back(__x); 
00188       push_heap(c.begin(), c.end(), comp);
00189     }
00190     __STL_UNWIND(c.clear());
00191   }
00192   void pop() {
00193     __STL_TRY {
00194       pop_heap(c.begin(), c.end(), comp);
00195       c.pop_back();
00196     }
00197     __STL_UNWIND(c.clear());
00198   }
00199 };
00200 
00201 // no equality is provided
00202 
00203 } // namespace std
00204 
00205 #endif /* __SGI_STL_INTERNAL_QUEUE_H */
00206 
00207 // Local Variables:
00208 // mode:C++
00209 // End:

Generated at Tue May 1 16:28:39 2001 for libstdc++-v3 by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001