_queue.h

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_H
00046 # include <stl/_function.h>
00047 #endif
00048 
00049 _STLP_BEGIN_NAMESPACE
00050 
00051 # if ! defined ( _STLP_LIMITED_DEFAULT_TEMPLATES )
00052 template <class _Tp, class _Sequence = deque<_Tp> >
00053 # elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
00054 #  define _STLP_QUEUE_ARGS _Tp
00055 template <class _Tp>
00056 # else
00057 template <class _Tp, class _Sequence>
00058 # endif
00059 
00060 class queue {
00061 # if defined ( _STLP_QUEUE_ARGS )
00062   typedef deque<_Tp> _Sequence;
00063 # endif
00064 public:
00065   typedef typename _Sequence::value_type      value_type;
00066   typedef typename _Sequence::size_type       size_type;
00067   typedef          _Sequence                  container_type;
00068 
00069   typedef typename _Sequence::reference       reference;
00070   typedef typename _Sequence::const_reference const_reference;
00071 
00072 protected:
00073   _Sequence c;
00074 public:
00075   queue() : c() {}
00076   explicit queue(const _Sequence& __c) : c(__c) {}
00077 
00078   bool empty() const { return c.empty(); }
00079   size_type size() const { return c.size(); }
00080   reference front() { return c.front(); }
00081   const_reference front() const { return c.front(); }
00082   reference back() { return c.back(); }
00083   const_reference back() const { return c.back(); }
00084   void push(const value_type& __x) { c.push_back(__x); }
00085   void pop() { c.pop_front(); }
00086   const _Sequence& _Get_c() const { return c; }
00087 };
00088 
00089 # ifndef _STLP_QUEUE_ARGS
00090 #  define _STLP_QUEUE_ARGS _Tp, _Sequence
00091 #  define _STLP_QUEUE_HEADER_ARGS class _Tp, class _Sequence
00092 # else
00093 #  define _STLP_QUEUE_HEADER_ARGS class _Tp
00094 # endif
00095 
00096 template < _STLP_QUEUE_HEADER_ARGS >
00097 inline bool _STLP_CALL 
00098 operator==(const queue<_STLP_QUEUE_ARGS >& __x, const queue<_STLP_QUEUE_ARGS >& __y)
00099 {
00100   return __x._Get_c() == __y._Get_c();
00101 }
00102 
00103 template < _STLP_QUEUE_HEADER_ARGS >
00104 inline bool _STLP_CALL
00105 operator<(const queue<_STLP_QUEUE_ARGS >& __x, const queue<_STLP_QUEUE_ARGS >& __y)
00106 {
00107   return __x._Get_c() < __y._Get_c();
00108 }
00109 
00110 _STLP_RELOPS_OPERATORS( template < _STLP_QUEUE_HEADER_ARGS >, queue<_STLP_QUEUE_ARGS > )
00111 
00112 # if !(defined ( _STLP_LIMITED_DEFAULT_TEMPLATES ) || defined ( _STLP_TEMPLATE_PARAM_SUBTYPE_BUG ))
00113 template <class _Tp, class _Sequence = vector<_Tp>, 
00114           class _Compare = less<_STLP_HEADER_TYPENAME _Sequence::value_type> >
00115 # elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
00116 template <class _Tp>
00117 # else
00118 template <class _Tp, class _Sequence, class _Compare>
00119 # endif
00120 class  priority_queue {
00121 # ifdef _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS
00122   typedef vector<_Tp> _Sequence;
00123   typedef less< typename vector<_Tp>::value_type> _Compare; 
00124 # endif
00125 public:
00126   typedef typename _Sequence::value_type      value_type;
00127   typedef typename _Sequence::size_type       size_type;
00128   typedef          _Sequence                  container_type;
00129 
00130   typedef typename _Sequence::reference       reference;
00131   typedef typename _Sequence::const_reference const_reference;
00132 protected:
00133   _Sequence c;
00134   _Compare comp;
00135 public:
00136   priority_queue() : c() {}
00137   explicit priority_queue(const _Compare& __x) :  c(), comp(__x) {}
00138   priority_queue(const _Compare& __x, const _Sequence& __s) 
00139     : c(__s), comp(__x)
00140     { make_heap(c.begin(), c.end(), comp); }
00141 
00142 #ifdef _STLP_MEMBER_TEMPLATES
00143   template <class _InputIterator>
00144   priority_queue(_InputIterator __first, _InputIterator __last) 
00145     : c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
00146 
00147   template <class _InputIterator>
00148   priority_queue(_InputIterator __first, 
00149                  _InputIterator __last, const _Compare& __x)
00150     : c(__first, __last), comp(__x)
00151     { make_heap(c.begin(), c.end(), comp); }
00152 
00153   template <class _InputIterator>
00154   priority_queue(_InputIterator __first, _InputIterator __last,
00155                  const _Compare& __x, const _Sequence& __s)
00156   : c(__s), comp(__x)
00157   { 
00158     c.insert(c.end(), __first, __last);
00159     make_heap(c.begin(), c.end(), comp);
00160   }
00161 
00162 #else /* _STLP_MEMBER_TEMPLATES */
00163   priority_queue(const value_type* __first, const value_type* __last) 
00164     : c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
00165 
00166   priority_queue(const value_type* __first, const value_type* __last, 
00167                  const _Compare& __x) 
00168     : c(__first, __last), comp(__x)
00169     { make_heap(c.begin(), c.end(), comp); }
00170 
00171   priority_queue(const value_type* __first, const value_type* __last, 
00172                  const _Compare& __x, const _Sequence& __c)
00173     : c(__c), comp(__x)
00174   { 
00175     c.insert(c.end(), __first, __last);
00176     make_heap(c.begin(), c.end(), comp);
00177   }
00178 #endif /* _STLP_MEMBER_TEMPLATES */
00179 
00180   bool empty() const { return c.empty(); }
00181   size_type size() const { return c.size(); }
00182   const_reference top() const { return c.front(); }
00183   void push(const value_type& __x) {
00184     _STLP_TRY {
00185       c.push_back(__x); 
00186       push_heap(c.begin(), c.end(), comp);
00187     }
00188     _STLP_UNWIND(c.clear());
00189   }
00190   void pop() {
00191     _STLP_TRY {
00192       pop_heap(c.begin(), c.end(), comp);
00193       c.pop_back();
00194     }
00195     _STLP_UNWIND(c.clear());
00196   }
00197 };
00198 
00199 _STLP_END_NAMESPACE
00200 
00201 #  undef _STLP_QUEUE_ARGS
00202 #  undef _STLP_QUEUE_HEADER_ARGS
00203 
00204 #endif /* _STLP_INTERNAL_QUEUE_H */
00205 
00206 // Local Variables:
00207 // mode:C++
00208 // End:

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