1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * |
---|
4 | * |
---|
5 | * License notice: |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU General Public License |
---|
9 | * as published by the Free Software Foundation; either version 2 |
---|
10 | * of the License, or (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, write to the Free Software |
---|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
20 | * |
---|
21 | * Author: |
---|
22 | * Fabian 'x3n' Landau |
---|
23 | * Co-authors: |
---|
24 | * ... |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | #include "Loader.h" |
---|
29 | #include "Identifier.h" |
---|
30 | #include "Iterator.h" |
---|
31 | #include "BaseObject.h" |
---|
32 | #include "util/tinyxml/tinyxml.h" |
---|
33 | |
---|
34 | namespace orxonox |
---|
35 | { |
---|
36 | std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > > Loader::files_s; |
---|
37 | |
---|
38 | // ############################### |
---|
39 | // ### open ### |
---|
40 | // ############################### |
---|
41 | // Single file |
---|
42 | bool Loader::open(const std::string& file) |
---|
43 | { |
---|
44 | return Loader::open(file, ClassIdentifier<BaseObject>::getIdentifier()); |
---|
45 | } |
---|
46 | |
---|
47 | bool Loader::open(const std::string& file, const Identifier* subclassInclude) |
---|
48 | { |
---|
49 | return Loader::open(file, subclassInclude, 0); |
---|
50 | } |
---|
51 | |
---|
52 | bool Loader::open(const std::string& file, const Identifier* subclassInclude, const Identifier* subclassExclude) |
---|
53 | { |
---|
54 | return Loader::open(file, subclassInclude, std::vector<const Identifier*>(1, subclassExclude)); |
---|
55 | } |
---|
56 | |
---|
57 | bool Loader::open(const std::string& file, const Identifier* subclassInclude, std::vector<const Identifier*> subclassesExclude) |
---|
58 | { |
---|
59 | return Loader::open(file, std::vector<const Identifier*>(1, subclassInclude), subclassesExclude); |
---|
60 | } |
---|
61 | |
---|
62 | bool Loader::open(const std::string& file, const std::vector<const Identifier*>& subclassesInclude) |
---|
63 | { |
---|
64 | return Loader::open(file, subclassesInclude, 0); |
---|
65 | } |
---|
66 | |
---|
67 | bool Loader::open(const std::string& file, const std::vector<const Identifier*>& subclassesInclude, const Identifier* subclassExclude) |
---|
68 | { |
---|
69 | return Loader::open(file, subclassesInclude, std::vector<const Identifier*>(1, subclassExclude)); |
---|
70 | } |
---|
71 | |
---|
72 | bool Loader::open(const std::string& file, const std::vector<const Identifier*>& subclassesInclude, std::vector<const Identifier*> subclassesExclude) |
---|
73 | { |
---|
74 | return Loader::open(std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > >(1, std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > >(file, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> >(subclassesInclude, subclassesExclude)))); |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | // Multiple files with common conditions |
---|
79 | bool Loader::open(const std::vector<std::string>& files) |
---|
80 | { |
---|
81 | return Loader::open(files, ClassIdentifier<BaseObject>::getIdentifier()); |
---|
82 | } |
---|
83 | |
---|
84 | bool Loader::open(const std::vector<std::string>& files, const Identifier* subclassInclude) |
---|
85 | { |
---|
86 | return Loader::open(files, subclassInclude, 0); |
---|
87 | } |
---|
88 | |
---|
89 | bool Loader::open(const std::vector<std::string>& files, const Identifier* subclassInclude, const Identifier* subclassExclude) |
---|
90 | { |
---|
91 | return Loader::open(files, subclassInclude, std::vector<const Identifier*>(1, subclassExclude)); |
---|
92 | } |
---|
93 | |
---|
94 | bool Loader::open(const std::vector<std::string>& files, const Identifier* subclassInclude, std::vector<const Identifier*> subclassesExclude) |
---|
95 | { |
---|
96 | return Loader::open(files, std::vector<const Identifier*>(1, subclassInclude), subclassesExclude); |
---|
97 | } |
---|
98 | |
---|
99 | bool Loader::open(const std::vector<std::string>& files, const std::vector<const Identifier*>& subclassesInclude) |
---|
100 | { |
---|
101 | return Loader::open(files, subclassesInclude, 0); |
---|
102 | } |
---|
103 | |
---|
104 | bool Loader::open(const std::vector<std::string>& files, const std::vector<const Identifier*>& subclassesInclude, const Identifier* subclassExclude) |
---|
105 | { |
---|
106 | return Loader::open(files, subclassesInclude, std::vector<const Identifier*>(1, subclassExclude)); |
---|
107 | } |
---|
108 | |
---|
109 | bool Loader::open(const std::vector<std::string>& files, const std::vector<const Identifier*>& subclassesInclude, std::vector<const Identifier*> subclassesExclude) |
---|
110 | { |
---|
111 | std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > > temp; |
---|
112 | for (std::vector<std::string>::const_iterator it = files.begin(); it < files.end(); ++it) |
---|
113 | temp.insert(temp.end(), std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > >(*it, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> >(subclassesInclude, subclassesExclude))); |
---|
114 | |
---|
115 | return Loader::open(temp); |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | // Multiple files with individual conditions |
---|
120 | bool Loader::open(const std::vector<std::pair<std::string, const Identifier*> >& files) |
---|
121 | { |
---|
122 | std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > > temp; |
---|
123 | for (std::vector<std::pair<std::string, const Identifier*> >::const_iterator it = files.begin(); it < files.end(); ++it) |
---|
124 | temp.insert(temp.end(), std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > >(it->first, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> >(std::vector<const Identifier*>(1, it->second), std::vector<const Identifier*>(1, (const Identifier*)0)))); |
---|
125 | |
---|
126 | return Loader::open(temp); |
---|
127 | } |
---|
128 | |
---|
129 | bool Loader::open(const std::vector<std::pair<std::string, std::pair<const Identifier*, const Identifier*> > >& files) |
---|
130 | { |
---|
131 | std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > > temp; |
---|
132 | for (std::vector<std::pair<std::string, std::pair<const Identifier*, const Identifier*> > >::const_iterator it = files.begin(); it < files.end(); ++it) |
---|
133 | temp.insert(temp.end(), std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > >(it->first, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> >(std::vector<const Identifier*>(1, it->second.first), std::vector<const Identifier*>(1, it->second.second)))); |
---|
134 | |
---|
135 | return Loader::open(temp); |
---|
136 | } |
---|
137 | |
---|
138 | bool Loader::open(const std::vector<std::pair<std::string, std::pair<const Identifier*, std::vector<const Identifier*> > > >& files) |
---|
139 | { |
---|
140 | std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > > temp; |
---|
141 | for (std::vector<std::pair<std::string, std::pair<const Identifier*, std::vector<const Identifier*> > > >::const_iterator it = files.begin(); it < files.end(); ++it) |
---|
142 | temp.insert(temp.end(), std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > >(it->first, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> >(std::vector<const Identifier*>(1, it->second.first), it->second.second))); |
---|
143 | |
---|
144 | return Loader::open(temp); |
---|
145 | } |
---|
146 | |
---|
147 | bool Loader::open(const std::vector<std::pair<std::string, std::vector<const Identifier*> > >& files) |
---|
148 | { |
---|
149 | std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > > temp; |
---|
150 | for (std::vector<std::pair<std::string, std::vector<const Identifier*> > >::const_iterator it = files.begin(); it < files.end(); ++it) |
---|
151 | temp.insert(temp.end(), std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > >(it->first, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> >(it->second, std::vector<const Identifier*>(1, (const Identifier*)0)))); |
---|
152 | |
---|
153 | return Loader::open(temp); |
---|
154 | } |
---|
155 | |
---|
156 | bool Loader::open(const std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, const Identifier*> > >& files) |
---|
157 | { |
---|
158 | std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > > temp; |
---|
159 | for (std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, const Identifier*> > >::const_iterator it = files.begin(); it < files.end(); ++it) |
---|
160 | temp.insert(temp.end(), std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > >(it->first, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> >(it->second.first, std::vector<const Identifier*>(1, it->second.second)))); |
---|
161 | |
---|
162 | return Loader::open(temp); |
---|
163 | } |
---|
164 | |
---|
165 | bool Loader::open(const std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > >& files) |
---|
166 | { |
---|
167 | Loader::files_s = files; |
---|
168 | Loader::unload(); |
---|
169 | return Loader::load(Loader::files_s); |
---|
170 | } |
---|
171 | |
---|
172 | // ############################### |
---|
173 | // ### add ### |
---|
174 | // ############################### |
---|
175 | bool Loader::add(const std::string& file) |
---|
176 | { |
---|
177 | return Loader::add(file, ClassIdentifier<BaseObject>::getIdentifier()); |
---|
178 | } |
---|
179 | |
---|
180 | bool Loader::add(const std::string& file, const Identifier* subclassInclude) |
---|
181 | { |
---|
182 | return Loader::add(file, subclassInclude, 0); |
---|
183 | } |
---|
184 | |
---|
185 | bool Loader::add(const std::string& file, const Identifier* subclassInclude, const Identifier* subclassExclude) |
---|
186 | { |
---|
187 | return Loader::add(file, std::vector<const Identifier*>(1, subclassInclude), std::vector<const Identifier*>(1, subclassExclude)); |
---|
188 | } |
---|
189 | |
---|
190 | bool Loader::add(const std::string& file, const Identifier* subclassInclude, std::vector<const Identifier*> subclassesExclude) |
---|
191 | { |
---|
192 | return Loader::add(file, std::vector<const Identifier*>(1, subclassInclude), subclassesExclude); |
---|
193 | } |
---|
194 | |
---|
195 | bool Loader::add(const std::string& file, const std::vector<const Identifier*>& subclassesInclude) |
---|
196 | { |
---|
197 | return Loader::add(file, subclassesInclude, 0); |
---|
198 | } |
---|
199 | |
---|
200 | bool Loader::add(const std::string& file, const std::vector<const Identifier*>& subclassesInclude, const Identifier* subclassExclude) |
---|
201 | { |
---|
202 | return Loader::add(file, subclassesInclude, std::vector<const Identifier*>(1, subclassExclude)); |
---|
203 | } |
---|
204 | |
---|
205 | bool Loader::add(const std::string& file, const std::vector<const Identifier*>& subclassesInclude, std::vector<const Identifier*> subclassesExclude) |
---|
206 | { |
---|
207 | Loader::files_s.insert(Loader::files_s.end(), std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > >(file, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> >(subclassesInclude, subclassesExclude))); |
---|
208 | return Loader::load(file, subclassesInclude, subclassesExclude); |
---|
209 | } |
---|
210 | |
---|
211 | // ############################### |
---|
212 | // ### remove ### |
---|
213 | // ############################### |
---|
214 | void Loader::remove() |
---|
215 | { |
---|
216 | Loader::files_s.clear(); |
---|
217 | } |
---|
218 | |
---|
219 | void Loader::remove(const std::vector<std::string>& files) |
---|
220 | { |
---|
221 | for (std::vector<std::string>::const_iterator it = files.begin(); it < files.end(); ++it) |
---|
222 | Loader::remove(*it); |
---|
223 | } |
---|
224 | |
---|
225 | void Loader::remove(const std::string& file) |
---|
226 | { |
---|
227 | for (std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > >::iterator it = Loader::files_s.begin(); it < Loader::files_s.end(); ++it) |
---|
228 | if (it->first.compare(file) == 0) |
---|
229 | Loader::files_s.erase(it); |
---|
230 | } |
---|
231 | |
---|
232 | // ############################### |
---|
233 | // ### reload ### |
---|
234 | // ############################### |
---|
235 | bool Loader::reload() |
---|
236 | { |
---|
237 | return Loader::reload(ClassIdentifier<BaseObject>::getIdentifier()); |
---|
238 | } |
---|
239 | |
---|
240 | bool Loader::reload(const Identifier* subclassInclude) |
---|
241 | { |
---|
242 | return Loader::reload(subclassInclude, 0); |
---|
243 | } |
---|
244 | |
---|
245 | bool Loader::reload(const Identifier* subclassInclude, const Identifier* subclassExclude) |
---|
246 | { |
---|
247 | return Loader::reload(std::vector<const Identifier*>(1, subclassInclude), std::vector<const Identifier*>(1, subclassExclude)); |
---|
248 | } |
---|
249 | |
---|
250 | bool Loader::reload(const Identifier* subclassInclude, const std::vector<const Identifier*>& subclassesExclude) |
---|
251 | { |
---|
252 | return Loader::reload(std::vector<const Identifier*>(1, subclassInclude), subclassesExclude); |
---|
253 | } |
---|
254 | |
---|
255 | bool Loader::reload(const std::vector<const Identifier*>& subclassesInclude) |
---|
256 | { |
---|
257 | return Loader::reload(subclassesInclude, 0); |
---|
258 | } |
---|
259 | |
---|
260 | bool Loader::reload(const std::vector<const Identifier*>& subclassesInclude, const Identifier* subclassExclude) |
---|
261 | { |
---|
262 | return Loader::reload(subclassesInclude, std::vector<const Identifier*>(1, subclassExclude)); |
---|
263 | } |
---|
264 | |
---|
265 | bool Loader::reload(const std::vector<const Identifier*>& subclassesInclude, const std::vector<const Identifier*>& subclassesExclude) |
---|
266 | { |
---|
267 | Loader::unload(subclassesInclude, subclassesExclude); |
---|
268 | return Loader::load(Loader::files_s, subclassesInclude, subclassesExclude); |
---|
269 | } |
---|
270 | |
---|
271 | // ############################### |
---|
272 | // ### unload ### |
---|
273 | // ############################### |
---|
274 | void Loader::unload() |
---|
275 | { |
---|
276 | Loader::unload(ClassIdentifier<BaseObject>::getIdentifier()); |
---|
277 | } |
---|
278 | |
---|
279 | void Loader::unload(const Identifier* subclassInclude) |
---|
280 | { |
---|
281 | Loader::unload(subclassInclude, 0); |
---|
282 | } |
---|
283 | |
---|
284 | void Loader::unload(const Identifier* subclassInclude, const Identifier* subclassExclude) |
---|
285 | { |
---|
286 | Loader::unload(std::vector<const Identifier*>(1, subclassInclude), std::vector<const Identifier*>(1, subclassExclude)); |
---|
287 | } |
---|
288 | |
---|
289 | void Loader::unload(const Identifier* subclassInclude, const std::vector<const Identifier*>& subclassesExclude) |
---|
290 | { |
---|
291 | Loader::unload(std::vector<const Identifier*>(1, subclassInclude), subclassesExclude); |
---|
292 | } |
---|
293 | |
---|
294 | void Loader::unload(const std::vector<const Identifier*>& subclassesInclude) |
---|
295 | { |
---|
296 | Loader::unload(subclassesInclude, 0); |
---|
297 | } |
---|
298 | |
---|
299 | void Loader::unload(const std::vector<const Identifier*>& subclassesInclude, const Identifier* subclassExclude) |
---|
300 | { |
---|
301 | Loader::unload(subclassesInclude, std::vector<const Identifier*>(1, subclassExclude)); |
---|
302 | } |
---|
303 | |
---|
304 | void Loader::unload(const std::vector<const Identifier*>& subclassesInclude, const std::vector<const Identifier*>& subclassesExclude) |
---|
305 | { |
---|
306 | for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it; ) |
---|
307 | { |
---|
308 | bool isIncluded = false; |
---|
309 | for (std::vector<const Identifier*>::const_iterator it_in = subclassesInclude.begin(); it_in < subclassesInclude.end(); ++it_in) |
---|
310 | { |
---|
311 | if (it->isA(*it_in)) |
---|
312 | { |
---|
313 | isIncluded = true; |
---|
314 | break; |
---|
315 | } |
---|
316 | } |
---|
317 | |
---|
318 | if (isIncluded) |
---|
319 | { |
---|
320 | bool isExcluded = false; |
---|
321 | for (std::vector<const Identifier*>::const_iterator it_ex = subclassesInclude.begin(); it_ex < subclassesInclude.end(); ++it_ex) |
---|
322 | { |
---|
323 | if (it->isA(*it_ex)) |
---|
324 | { |
---|
325 | isExcluded = true; |
---|
326 | break; |
---|
327 | } |
---|
328 | } |
---|
329 | |
---|
330 | if (!isExcluded) |
---|
331 | { |
---|
332 | delete *(it++); |
---|
333 | continue; |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | ++it; |
---|
338 | } |
---|
339 | } |
---|
340 | |
---|
341 | // ############################### |
---|
342 | // ### load ### |
---|
343 | // ############################### |
---|
344 | bool Loader::load(const std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > >& files) |
---|
345 | { |
---|
346 | bool success = true; |
---|
347 | for (std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > >::const_iterator it = files.begin(); it < files.end(); ++it) |
---|
348 | if (!Loader::load(it->first, it->second.first, it->second.second)) |
---|
349 | success = false; |
---|
350 | |
---|
351 | return success; |
---|
352 | } |
---|
353 | |
---|
354 | bool Loader::load(const std::vector<std::string>& files, const std::vector<const Identifier*>& subclassesInclude, const std::vector<const Identifier*>& subclassesExclude) |
---|
355 | { |
---|
356 | bool success = true; |
---|
357 | for (std::vector<std::string>::const_iterator it = files.begin(); it < files.end(); ++it) |
---|
358 | if (!Loader::load(*it, subclassesInclude, subclassesExclude)) |
---|
359 | success = false; |
---|
360 | |
---|
361 | return success; |
---|
362 | } |
---|
363 | |
---|
364 | bool Loader::load(const std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > >& files, const std::vector<const Identifier*>& subclassesInclude, const std::vector<const Identifier*>& subclassesExclude) |
---|
365 | { |
---|
366 | bool success = true; |
---|
367 | for (std::vector<std::pair<std::string, std::pair<std::vector<const Identifier*>, std::vector<const Identifier*> > > >::const_iterator it = files.begin(); it < files.end(); ++it) |
---|
368 | if (!Loader::load(it->first, subclassesInclude, subclassesExclude)) |
---|
369 | success = false; |
---|
370 | |
---|
371 | return success; |
---|
372 | } |
---|
373 | |
---|
374 | bool Loader::load(const std::string& file, const std::vector<const Identifier*>& subclassesInclude, const std::vector<const Identifier*>& subclassesExclude) |
---|
375 | { |
---|
376 | // ...load... // |
---|
377 | } |
---|
378 | } |
---|