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 
29 namespace QDEngine {
30 
31 template <class T>
33 public:
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 
58 private:
59 
60  object_list_t _object_list;
61 };
62 
63 template <class T>
65  if (get_object(p->name())) return false;
66  _object_list.push_back(p);
67 
68  return true;
69 }
70 
71 template <class T>
72 const 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 
83 template <class T>
84 T *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 
95 template <class T>
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 
107 template <class T>
108 bool 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 
115 template <class T>
116 bool qdObjectListContainer<T>::rename_object(T *p, const char *name) {
117  p->set_name(name);
118  return true;
119 }
120 
121 template <class T>
123 }
124 
125 template <class T>
127  clear();
128 }
129 
130 template <class T>
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
iterator end()
Definition: list.h:240
Базовый класс для игровых ресурсов.
Definition: console.h:28
iterator begin()
Definition: list.h:227
void clear()
Definition: list.h:206
Definition: list_intern.h:48
Definition: list_intern.h:51
iterator erase(iterator pos)
Definition: list.h:95
void push_back(const t_T &element)
Definition: list.h:140