ScummVM API documentation
queue.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22/********************************************
23 DISCLAIMER:
24
25 This is a wrapper code to mimic the relevant std:: class
26 Please use it ONLY when porting an existing code e.g. from the original sources
27
28 For all new development please use classes from Common::
29 *********************************************/
30
31#ifndef COMMON_STD_QUEUE_H
32#define COMMON_STD_QUEUE_H
33
34#include "common/std/algorithm.h"
35#include "common/std/vector.h"
36#include "common/queue.h"
37
38namespace Std {
39
40template<class T>
41using queue = Common::Queue<T>;
42
48template<class T, class Container = vector<T>, class Comparitor = typename Common::Less<T> >
50private:
51 Container _container;
52 Comparitor _comparitor;
53public:
55
56 bool empty() const {
57 return _container.empty();
58 }
59
60 const T &top() const {
61 return _container.front();
62 }
63
64 void push(const T &item) {
65 _container.push_back(item);
66 Common::sort(_container.begin(), _container.end(), _comparitor);
67 }
68
69 void pop() {
70 _container.remove_at(0);
71 }
72};
73
74template<class T>
75class deque {
76private:
77 vector<T> _intern;
78public:
79 deque() = default;
80 typedef typename vector<T>::iterator iterator;
81 typedef const typename vector<T>::const_iterator const_iterator;
84
85 void clear() {
86 _intern.clear();
87 }
88 void insert(const T &item) {
89 _intern.push_back(item);
90 }
91 void push_back(const T &item) {
92 _intern.push_back(item);
93 }
94 void push_front(const T &item) {
95 _intern.push_front(item);
96 }
97 void pop_back() {
98 _intern.pop_back();
99 }
100 void pop_front() {
101 _intern.remove_at(0);
102 }
103 const T &front() const {
104 return _intern.front();
105 }
106 const T &back() const {
107 return _intern.back();
108 }
109
110 void resize(size_t newSize) {
111 _intern.resize(newSize);
112 }
113
114 size_t size() const {
115 return _intern.size();
116 }
117
118 T at(size_t idx) {
119 return _intern[idx];
120 }
121
122 const_iterator cbegin() {
123 return _intern.cbegin();
124 }
125 const_iterator cend() {
126 return _intern.cend();
127 }
128 reverse_iterator rbegin() {
129 return _intern.rbegin();
130 }
131 reverse_iterator rend() {
132 return _intern.rend();
133 }
134 const_reverse_iterator rbegin() const {
135 return _intern.rbegin();
136 }
137 const_reverse_iterator rend() const {
138 return _intern.rend();
139 }
140 const_reverse_iterator crbegin() const {
141 return _intern.crbegin();
142 }
143 const_reverse_iterator crend() const {
144 return _intern.crend();
145 }
146};
147
148} // namespace Std
149
150#endif
T & front()
Definition: array.h:218
T remove_at(size_type idx)
Definition: array.h:261
size_type size() const
Definition: array.h:316
T & back()
Definition: array.h:230
void clear()
Definition: array.h:321
void push_back(const T &element)
Definition: array.h:181
void resize(size_type newSize)
Definition: array.h:412
void pop_back()
Definition: array.h:200
Definition: queue.h:42
Definition: queue.h:75
Definition: queue.h:49
Definition: vector.h:39
void sort(T first, T last, StrictWeakOrdering comp)
Definition: algorithm.h:349
Definition: vector.h:41