ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 #ifndef COMMON_QUEUE_H
23 #define COMMON_QUEUE_H
24 
25 #include "common/scummsys.h"
26 #include "common/list.h"
27 
28 namespace Common {
29 
41 template<class T>
42 class Queue {
43 //public:
44 // typedef T value_type;
45 
46 public:
47  bool empty() const {
48  return _impl.empty();
49  }
50 
51  void clear() {
52  _impl.clear();
53  }
54 
55  template<class... TArgs>
56  void emplace(TArgs&&... args) {
57  _impl.emplace_back(Common::forward<TArgs>(args)...);
58  }
59 
60  void push(const T &x) {
61  _impl.push_back(x);
62  }
63 
64  void push(T &&x) {
65  _impl.push_back(Common::move(x));
66  }
67 
68  T &front() {
69  return _impl.front();
70  }
71 
72  const T &front() const {
73  return _impl.front();
74  }
75 
76  T &back() {
77  return _impl.back();
78  }
79 
80  const T &back() const {
81  return _impl.back();
82  }
83 
84  T pop() {
85  T tmp = Common::move(front());
86  _impl.pop_front();
87  return tmp;
88  }
89 
90  int size() const {
91  return _impl.size();
92  }
93 
94 private:
95  List<T> _impl;
96 };
97 
100 } // End of namespace Common
101 
102 #endif
void pop_front()
Definition: list.h:184
size_type size() const
Definition: list.h:237
Definition: queue.h:42
t_T & back()
Definition: list.h:206
Definition: algorithm.h:29
void clear()
Definition: list.h:245
void emplace_back(TArgs &&...args)
Definition: list.h:169
Out move(In first, In last, Out dst)
Definition: algorithm.h:109
t_T & front()
Definition: list.h:196
void push_back(const t_T &element)
Definition: list.h:174
bool empty() const
Definition: list.h:258