ScummVM API documentation
focus_list.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 ZVISION_FOCUS_LIST_H
23#define ZVISION_FOCUS_LIST_H
24
25#include "common/array.h"
26
27namespace ZVision {
28
40template<class T>
41class FocusList : public Common::Array<T> {
42private:
43 typedef uint size_type;
44public:
49 void set(const T currentFocus) {
50 if (!this->size())
51 this->push_back(currentFocus);
52 else {
53 if (this->front() != currentFocus) {
54 Common::Array<T> buffer;
55 while (this->size() > 0) {
56 if (this->back() != currentFocus)
57 buffer.push_back(this->back());
58 this->pop_back();
59 }
60 this->push_back(currentFocus);
61 while (buffer.size() > 0) {
62 this->push_back(buffer.back());
63 buffer.pop_back();
64 }
65 }
66 }
67 }
68
73 void remove(const T value) {
74 if (this->size()) {
75 Common::Array<T> buffer;
76 while (this->size() > 0) {
77 if (this->back() != value)
78 buffer.push_back(this->back());
79 this->pop_back();
80 }
81 while (buffer.size() > 0) {
82 this->push_back(buffer.back());
83 buffer.pop_back();
84 }
85 }
86 }
87
88};
89
90} // End of namespace ZVision
91
92#endif
Definition: array.h:52
T & front()
Definition: array.h:218
uint size_type
Definition: array.h:62
size_type size() const
Definition: array.h:316
T & back()
Definition: array.h:230
void push_back(const T &element)
Definition: array.h:181
void pop_back()
Definition: array.h:200
Definition: focus_list.h:41
void remove(const T value)
Definition: focus_list.h:73
void set(const T currentFocus)
Definition: focus_list.h:49
Definition: focus_list.h:27