williamr@4
|
1 |
/*
|
williamr@4
|
2 |
*
|
williamr@4
|
3 |
* Copyright (c) 1994
|
williamr@4
|
4 |
* Hewlett-Packard Company
|
williamr@4
|
5 |
*
|
williamr@4
|
6 |
* Copyright (c) 1996,1997
|
williamr@4
|
7 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@4
|
8 |
*
|
williamr@4
|
9 |
* Copyright (c) 1997
|
williamr@4
|
10 |
* Moscow Center for SPARC Technology
|
williamr@4
|
11 |
*
|
williamr@4
|
12 |
* Copyright (c) 1999
|
williamr@4
|
13 |
* Boris Fomitchev
|
williamr@4
|
14 |
*
|
williamr@4
|
15 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@4
|
16 |
* or implied. Any use is at your own risk.
|
williamr@4
|
17 |
*
|
williamr@4
|
18 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@4
|
19 |
* without fee, provided the above notices are retained on all copies.
|
williamr@4
|
20 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@4
|
21 |
* provided the above notices are retained, and a notice that the code was
|
williamr@4
|
22 |
* modified is included with the above copyright notice.
|
williamr@4
|
23 |
*
|
williamr@4
|
24 |
*/
|
williamr@4
|
25 |
|
williamr@4
|
26 |
/* NOTE: This is an internal header file, included by other STL headers.
|
williamr@4
|
27 |
* You should not attempt to use it directly.
|
williamr@4
|
28 |
*/
|
williamr@4
|
29 |
|
williamr@4
|
30 |
#ifndef _STLP_INTERNAL_QUEUE_H
|
williamr@4
|
31 |
#define _STLP_INTERNAL_QUEUE_H
|
williamr@4
|
32 |
|
williamr@4
|
33 |
#ifndef _STLP_INTERNAL_DEQUE_H
|
williamr@4
|
34 |
# include <stl/_deque.h>
|
williamr@4
|
35 |
#endif
|
williamr@4
|
36 |
|
williamr@4
|
37 |
#ifndef _STLP_INTERNAL_VECTOR_H
|
williamr@4
|
38 |
# include <stl/_vector.h>
|
williamr@4
|
39 |
#endif
|
williamr@4
|
40 |
|
williamr@4
|
41 |
#ifndef _STLP_INTERNAL_HEAP_H
|
williamr@4
|
42 |
# include <stl/_heap.h>
|
williamr@4
|
43 |
#endif
|
williamr@4
|
44 |
|
williamr@4
|
45 |
#ifndef _STLP_INTERNAL_FUNCTION_BASE_H
|
williamr@4
|
46 |
# include <stl/_function_base.h>
|
williamr@4
|
47 |
#endif
|
williamr@4
|
48 |
|
williamr@4
|
49 |
#if defined(__SC__) && !defined(__DMC__) //*ty 12/07/2001 - since "comp" is a built-in type and reserved under SCpp
|
williamr@4
|
50 |
# define comp _Comp
|
williamr@4
|
51 |
#endif
|
williamr@4
|
52 |
|
williamr@4
|
53 |
_STLP_BEGIN_NAMESPACE
|
williamr@4
|
54 |
|
williamr@4
|
55 |
# if ! defined ( _STLP_LIMITED_DEFAULT_TEMPLATES )
|
williamr@4
|
56 |
template <class _Tp, class _Sequence = deque<_Tp> >
|
williamr@4
|
57 |
# elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
|
williamr@4
|
58 |
# define _STLP_QUEUE_ARGS _Tp
|
williamr@4
|
59 |
template <class _Tp>
|
williamr@4
|
60 |
# else
|
williamr@4
|
61 |
template <class _Tp, class _Sequence>
|
williamr@4
|
62 |
# endif
|
williamr@4
|
63 |
class queue
|
williamr@4
|
64 |
#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
|
williamr@4
|
65 |
# if defined (_STLP_QUEUE_ARGS)
|
williamr@4
|
66 |
: public __stlport_class<queue<_Tp> >
|
williamr@4
|
67 |
# else
|
williamr@4
|
68 |
: public __stlport_class<queue<_Tp, _Sequence> >
|
williamr@4
|
69 |
# endif
|
williamr@4
|
70 |
#endif
|
williamr@4
|
71 |
{
|
williamr@4
|
72 |
# if defined ( _STLP_QUEUE_ARGS )
|
williamr@4
|
73 |
typedef deque<_Tp> _Sequence;
|
williamr@4
|
74 |
typedef queue<_Tp> _Self;
|
williamr@4
|
75 |
# else
|
williamr@4
|
76 |
typedef queue<_Tp, _Sequence> _Self;
|
williamr@4
|
77 |
# endif
|
williamr@4
|
78 |
public:
|
williamr@4
|
79 |
typedef typename _Sequence::value_type value_type;
|
williamr@4
|
80 |
typedef typename _Sequence::size_type size_type;
|
williamr@4
|
81 |
typedef _Sequence container_type;
|
williamr@4
|
82 |
|
williamr@4
|
83 |
typedef typename _Sequence::reference reference;
|
williamr@4
|
84 |
typedef typename _Sequence::const_reference const_reference;
|
williamr@4
|
85 |
|
williamr@4
|
86 |
protected:
|
williamr@4
|
87 |
//c is a Standard name (23.2.3.1), do no make it STLport naming convention compliant.
|
williamr@4
|
88 |
_Sequence c;
|
williamr@4
|
89 |
public:
|
williamr@4
|
90 |
queue() : c() {}
|
williamr@4
|
91 |
explicit queue(const _Sequence& __c) : c(__c) {}
|
williamr@4
|
92 |
|
williamr@4
|
93 |
queue(__move_source<_Self> src)
|
williamr@4
|
94 |
: c(_STLP_PRIV _AsMoveSource(src.get().c)) {}
|
williamr@4
|
95 |
|
williamr@4
|
96 |
bool empty() const { return c.empty(); }
|
williamr@4
|
97 |
size_type size() const { return c.size(); }
|
williamr@4
|
98 |
reference front() { return c.front(); }
|
williamr@4
|
99 |
const_reference front() const { return c.front(); }
|
williamr@4
|
100 |
reference back() { return c.back(); }
|
williamr@4
|
101 |
const_reference back() const { return c.back(); }
|
williamr@4
|
102 |
void push(const value_type& __x) { c.push_back(__x); }
|
williamr@4
|
103 |
void pop() { c.pop_front(); }
|
williamr@4
|
104 |
const _Sequence& _Get_s() const { return c; }
|
williamr@4
|
105 |
};
|
williamr@4
|
106 |
|
williamr@4
|
107 |
#ifndef _STLP_QUEUE_ARGS
|
williamr@4
|
108 |
# define _STLP_QUEUE_ARGS _Tp, _Sequence
|
williamr@4
|
109 |
# define _STLP_QUEUE_HEADER_ARGS class _Tp, class _Sequence
|
williamr@4
|
110 |
#else
|
williamr@4
|
111 |
# define _STLP_QUEUE_HEADER_ARGS class _Tp
|
williamr@4
|
112 |
#endif
|
williamr@4
|
113 |
|
williamr@4
|
114 |
template < _STLP_QUEUE_HEADER_ARGS >
|
williamr@4
|
115 |
inline bool _STLP_CALL
|
williamr@4
|
116 |
operator==(const queue<_STLP_QUEUE_ARGS >& __x, const queue<_STLP_QUEUE_ARGS >& __y) {
|
williamr@4
|
117 |
return __x._Get_s() == __y._Get_s();
|
williamr@4
|
118 |
}
|
williamr@4
|
119 |
|
williamr@4
|
120 |
template < _STLP_QUEUE_HEADER_ARGS >
|
williamr@4
|
121 |
inline bool _STLP_CALL
|
williamr@4
|
122 |
operator<(const queue<_STLP_QUEUE_ARGS >& __x, const queue<_STLP_QUEUE_ARGS >& __y) {
|
williamr@4
|
123 |
return __x._Get_s() < __y._Get_s();
|
williamr@4
|
124 |
}
|
williamr@4
|
125 |
|
williamr@4
|
126 |
_STLP_RELOPS_OPERATORS( template < _STLP_QUEUE_HEADER_ARGS >, queue<_STLP_QUEUE_ARGS > )
|
williamr@4
|
127 |
|
williamr@4
|
128 |
# if !(defined ( _STLP_LIMITED_DEFAULT_TEMPLATES ) || defined ( _STLP_TEMPLATE_PARAM_SUBTYPE_BUG ))
|
williamr@4
|
129 |
template <class _Tp, class _Sequence = vector<_Tp>,
|
williamr@4
|
130 |
class _Compare = less<_STLP_HEADER_TYPENAME _Sequence::value_type> >
|
williamr@4
|
131 |
# elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
|
williamr@4
|
132 |
template <class _Tp>
|
williamr@4
|
133 |
# else
|
williamr@4
|
134 |
template <class _Tp, class _Sequence, class _Compare>
|
williamr@4
|
135 |
# endif
|
williamr@4
|
136 |
class priority_queue
|
williamr@4
|
137 |
#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
|
williamr@4
|
138 |
# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS)
|
williamr@4
|
139 |
: public __stlport_class<priority_queue<_Tp> >
|
williamr@4
|
140 |
# else
|
williamr@4
|
141 |
: public __stlport_class<priority_queue<_Tp, _Sequence> >
|
williamr@4
|
142 |
# endif
|
williamr@4
|
143 |
#endif
|
williamr@4
|
144 |
{
|
williamr@4
|
145 |
# ifdef _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS
|
williamr@4
|
146 |
typedef vector<_Tp> _Sequence;
|
williamr@4
|
147 |
typedef less< typename vector<_Tp>::value_type> _Compare;
|
williamr@4
|
148 |
typedef priority_queue<_Tp> _Self;
|
williamr@4
|
149 |
# else
|
williamr@4
|
150 |
typedef priority_queue<_Tp, _Sequence, _Compare> _Self;
|
williamr@4
|
151 |
# endif
|
williamr@4
|
152 |
public:
|
williamr@4
|
153 |
typedef typename _Sequence::value_type value_type;
|
williamr@4
|
154 |
typedef typename _Sequence::size_type size_type;
|
williamr@4
|
155 |
typedef _Sequence container_type;
|
williamr@4
|
156 |
|
williamr@4
|
157 |
typedef typename _Sequence::reference reference;
|
williamr@4
|
158 |
typedef typename _Sequence::const_reference const_reference;
|
williamr@4
|
159 |
protected:
|
williamr@4
|
160 |
//c is a Standard name (23.2.3.2), do no make it STLport naming convention compliant.
|
williamr@4
|
161 |
_Sequence c;
|
williamr@4
|
162 |
_Compare comp;
|
williamr@4
|
163 |
public:
|
williamr@4
|
164 |
priority_queue() : c() {}
|
williamr@4
|
165 |
explicit priority_queue(const _Compare& __x) : c(), comp(__x) {}
|
williamr@4
|
166 |
priority_queue(const _Compare& __x, const _Sequence& __s)
|
williamr@4
|
167 |
: c(__s), comp(__x)
|
williamr@4
|
168 |
{ make_heap(c.begin(), c.end(), comp); }
|
williamr@4
|
169 |
|
williamr@4
|
170 |
priority_queue(__move_source<_Self> src)
|
williamr@4
|
171 |
: c(_STLP_PRIV _AsMoveSource(src.get().c)),
|
williamr@4
|
172 |
comp(_STLP_PRIV _AsMoveSource(src.get().comp)) {}
|
williamr@4
|
173 |
|
williamr@4
|
174 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@4
|
175 |
template <class _InputIterator>
|
williamr@4
|
176 |
priority_queue(_InputIterator __first, _InputIterator __last)
|
williamr@4
|
177 |
: c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
|
williamr@4
|
178 |
|
williamr@4
|
179 |
template <class _InputIterator>
|
williamr@4
|
180 |
priority_queue(_InputIterator __first,
|
williamr@4
|
181 |
_InputIterator __last, const _Compare& __x)
|
williamr@4
|
182 |
: c(__first, __last), comp(__x)
|
williamr@4
|
183 |
{ make_heap(c.begin(), c.end(), comp); }
|
williamr@4
|
184 |
|
williamr@4
|
185 |
template <class _InputIterator>
|
williamr@4
|
186 |
priority_queue(_InputIterator __first, _InputIterator __last,
|
williamr@4
|
187 |
const _Compare& __x, const _Sequence& __s)
|
williamr@4
|
188 |
: c(__s), comp(__x)
|
williamr@4
|
189 |
{
|
williamr@4
|
190 |
c.insert(c.end(), __first, __last);
|
williamr@4
|
191 |
make_heap(c.begin(), c.end(), comp);
|
williamr@4
|
192 |
}
|
williamr@4
|
193 |
|
williamr@4
|
194 |
#else /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
195 |
priority_queue(const value_type* __first, const value_type* __last)
|
williamr@4
|
196 |
: c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
|
williamr@4
|
197 |
|
williamr@4
|
198 |
priority_queue(const value_type* __first, const value_type* __last,
|
williamr@4
|
199 |
const _Compare& __x)
|
williamr@4
|
200 |
: c(__first, __last), comp(__x)
|
williamr@4
|
201 |
{ make_heap(c.begin(), c.end(), comp); }
|
williamr@4
|
202 |
|
williamr@4
|
203 |
priority_queue(const value_type* __first, const value_type* __last,
|
williamr@4
|
204 |
const _Compare& __x, const _Sequence& __c)
|
williamr@4
|
205 |
: c(__c), comp(__x)
|
williamr@4
|
206 |
{
|
williamr@4
|
207 |
c.insert(c.end(), __first, __last);
|
williamr@4
|
208 |
make_heap(c.begin(), c.end(), comp);
|
williamr@4
|
209 |
}
|
williamr@4
|
210 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
211 |
|
williamr@4
|
212 |
bool empty() const { return c.empty(); }
|
williamr@4
|
213 |
size_type size() const { return c.size(); }
|
williamr@4
|
214 |
const_reference top() const { return c.front(); }
|
williamr@4
|
215 |
void push(const value_type& __x) {
|
williamr@4
|
216 |
_STLP_TRY {
|
williamr@4
|
217 |
c.push_back(__x);
|
williamr@4
|
218 |
push_heap(c.begin(), c.end(), comp);
|
williamr@4
|
219 |
}
|
williamr@4
|
220 |
_STLP_UNWIND(c.clear())
|
williamr@4
|
221 |
}
|
williamr@4
|
222 |
void pop() {
|
williamr@4
|
223 |
_STLP_TRY {
|
williamr@4
|
224 |
pop_heap(c.begin(), c.end(), comp);
|
williamr@4
|
225 |
c.pop_back();
|
williamr@4
|
226 |
}
|
williamr@4
|
227 |
_STLP_UNWIND(c.clear())
|
williamr@4
|
228 |
}
|
williamr@4
|
229 |
};
|
williamr@4
|
230 |
|
williamr@4
|
231 |
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
williamr@4
|
232 |
template <class _Tp, class _Sequence>
|
williamr@4
|
233 |
struct __move_traits<queue<_Tp, _Sequence> > :
|
williamr@4
|
234 |
_STLP_PRIV __move_traits_aux<_Sequence>
|
williamr@4
|
235 |
{};
|
williamr@4
|
236 |
|
williamr@4
|
237 |
template <class _Tp, class _Sequence, class _Compare>
|
williamr@4
|
238 |
struct __move_traits<priority_queue<_Tp, _Sequence, _Compare> > :
|
williamr@4
|
239 |
_STLP_PRIV __move_traits_aux2<_Sequence, _Compare>
|
williamr@4
|
240 |
{};
|
williamr@4
|
241 |
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
|
williamr@4
|
242 |
|
williamr@4
|
243 |
_STLP_END_NAMESPACE
|
williamr@4
|
244 |
|
williamr@4
|
245 |
#undef _STLP_QUEUE_ARGS
|
williamr@4
|
246 |
#undef _STLP_QUEUE_HEADER_ARGS
|
williamr@4
|
247 |
#undef comp
|
williamr@4
|
248 |
|
williamr@4
|
249 |
#endif /* _STLP_INTERNAL_QUEUE_H */
|
williamr@4
|
250 |
|
williamr@4
|
251 |
// Local Variables:
|
williamr@4
|
252 |
// mode:C++
|
williamr@4
|
253 |
// End:
|