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 
38 namespace Std {
39 
40 template<class T>
41 using queue = Common::Queue<T>;
42 
48 template<class T, class Container = vector<T>, class Comparitor = typename Common::Less<T> >
50 private:
51  Container _container;
52  Comparitor _comparitor;
53 public:
54  priority_queue() {}
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 
74 template<class T>
75 class deque {
76 private:
77  vector<T> _intern;
78 public:
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
Definition: vector.h:39
void clear()
Definition: array.h:320
T & front()
Definition: array.h:217
Definition: queue.h:42
Definition: queue.h:49
void push_back(const T &element)
Definition: array.h:180
Definition: queue.h:75
void pop_back()
Definition: array.h:199
size_type size() const
Definition: array.h:315
void resize(size_type newSize)
Definition: array.h:411
T remove_at(size_type idx)
Definition: array.h:260
Definition: vector.h:41
void sort(T first, T last, StrictWeakOrdering comp)
Definition: algorithm.h:349
Definition: algorithm.h:37
T & back()
Definition: array.h:229