ScummVM API documentation
qd_object_list_container.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 QDENGINE_QDCORE_QD_OBJECT_LIST_CONTAINER_H
23#define QDENGINE_QDCORE_QD_OBJECT_LIST_CONTAINER_H
24
25#include "common/str.h"
26#include "common/std/list.h"
27
28
29namespace QDEngine {
30
31template <class T>
33public:
35
38
39 const object_list_t &get_list() const {
40 return _object_list;
41 }
42
43 T *get_object(const char *name);
44 const T *get_object(const char *name) const;
45
46 bool add_object(T *p);
47 bool remove_object(T *p);
48 bool rename_object(T *p, const char *name);
49 bool remove_object(const char *name);
50 bool is_in_list(const char *name) const {
51 return (get_object(name) != 0);
52 }
53 bool is_in_list(const T *p) const {
54 return (get_object(p->name()) != 0);
55 }
56 bool clear();
57
58private:
59
60 object_list_t _object_list;
61};
62
63template <class T>
65 if (get_object(p->name())) return false;
66 _object_list.push_back(p);
67
68 return true;
69}
70
71template <class T>
72const T *qdObjectListContainer<T>::get_object(const char *name) const {
73 if (!name) return NULL;
74
75 for (typename object_list_t::const_iterator it = _object_list.begin(); it != _object_list.end(); ++it) {
76 if (!scumm_stricmp(name, (*it)->name()))
77 return *it;
78 }
79
80 return NULL;
81}
82
83template <class T>
84T *qdObjectListContainer<T>::get_object(const char *name) {
85 if (!name) return NULL;
86
87 for (typename object_list_t::const_iterator it = _object_list.begin(); it != _object_list.end(); ++it) {
88 if (!scumm_stricmp(name, (*it)->name()))
89 return *it;
90 }
91
92 return NULL;
93}
94
95template <class T>
96bool qdObjectListContainer<T>::remove_object(T *p) {
97 for (typename object_list_t::iterator it = _object_list.begin(); it != _object_list.end(); ++it) {
98 if (*it == p) {
99 _object_list.erase(it);
100 return true;
101 }
102 }
103
104 return false;
105}
106
107template <class T>
108bool qdObjectListContainer<T>::remove_object(const char *name) {
109 T *p = get_object(name);
110 if (!p) return false;
111
112 return remove_object(p);
113}
114
115template <class T>
116bool qdObjectListContainer<T>::rename_object(T *p, const char *name) {
117 p->set_name(name);
118 return true;
119}
120
121template <class T>
122qdObjectListContainer<T>::qdObjectListContainer() {
123}
124
125template <class T>
126qdObjectListContainer<T>::~qdObjectListContainer() {
127 clear();
128}
129
130template <class T>
131bool qdObjectListContainer<T>::clear() {
132 for (typename object_list_t::iterator it = _object_list.begin(); it != _object_list.end(); ++it)
133 delete *it;
134
135 _object_list.clear();
136
137 return true;
138}
139
140} // namespace QDEngine
141
142#endif // QDENGINE_QDCORE_QD_OBJECT_LIST_CONTAINER_H
Definition: qd_object_list_container.h:32
Базовый класс для игровых ресурсов.
Definition: console.h:28