ScummVM API documentation
SystemTypes.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 /*
23  * Copyright (C) 2006-2010 - Frictional Games
24  *
25  * This file is part of HPL1 Engine.
26  */
27 
28 #ifndef HPL_SYSTEM_TYPES_H
29 #define HPL_SYSTEM_TYPES_H
30 
31 #include "common/array.h"
32 #include "common/list.h"
33 #include "common/str.h"
34 #include "hpl1/algorithms.h"
35 #include "hpl1/engine/system/Container.h"
36 #include "hpl1/std/set.h"
37 
38 namespace hpl {
39 
43 
44 #define eFlagBit_None (0x00000000)
45 #define eFlagBit_All (0xFFFFFFFF)
46 
47 #define eFlagBit_0 (0x00000001)
48 #define eFlagBit_1 (0x00000002)
49 #define eFlagBit_2 (0x00000004)
50 #define eFlagBit_3 (0x00000008)
51 #define eFlagBit_4 (0x00000010)
52 #define eFlagBit_5 (0x00000020)
53 #define eFlagBit_6 (0x00000040)
54 #define eFlagBit_7 (0x00000080)
55 #define eFlagBit_8 (0x00000100)
56 #define eFlagBit_9 (0x00000200)
57 #define eFlagBit_10 (0x00000400)
58 #define eFlagBit_11 (0x00000800)
59 #define eFlagBit_12 (0x00001000)
60 #define eFlagBit_13 (0x00002000)
61 #define eFlagBit_14 (0x00004000)
62 #define eFlagBit_15 (0x00008000)
63 
64 #define _W(t) Common::U32String(t)
65 
66 //--------------------------------------------------------
67 
68 enum eSystemPath {
69  eSystemPath_Personal,
70  eSystemPath_LastEnum
71 };
72 
73 //--------------------------------------------------------
74 
75 typedef unsigned int tFlag;
76 
77 typedef Common::String tString;
78 
79 typedef Common::List<tString> tStringList;
80 typedef tStringList::iterator tStringListIt;
81 
82 typedef Common::Array<tString> tStringVec;
83 typedef tStringVec::iterator tStringVecIt;
84 
85 typedef Hpl1::Std::set<tString> tStringSet;
86 typedef tStringSet::iterator tStringSetIt;
87 
88 //--------------------------------------------------------
89 
90 typedef Common::U32String tWString;
91 typedef Common::List<tWString> tWStringList;
92 typedef tWStringList::iterator tWStringListIt;
93 
94 typedef Common::Array<tWString> tWStringVec;
95 typedef tWStringVec::iterator tWStringVecIt;
96 
97 typedef Hpl1::Std::set<tWString> tWStringSet;
98 typedef tWStringSet::iterator tWStringSetIt;
99 
100 //--------------------------------------------------------
101 
102 typedef Common::Array<unsigned char> tByteVec;
103 typedef tByteVec::iterator tByteVecIt;
104 
105 typedef Common::Array<unsigned int> tUIntVec;
106 typedef tUIntVec::iterator tUIntVecIt;
107 
108 typedef Common::Array<int> tIntVec;
109 typedef tIntVec::iterator tIntVecIt;
110 
111 typedef Common::Array<int> tIntList;
112 typedef tIntVec::iterator tIntListIt;
113 
114 typedef Common::Array<float> tFloatVec;
115 typedef tFloatVec::iterator tFloatVecIt;
116 
117 typedef Common::Array<float *> tFloatPtrVec;
118 typedef tFloatPtrVec::iterator tFloatPtrVecIt;
119 
120 typedef Common::List<float *> tFloatPtrList;
121 typedef tFloatPtrList::iterator tFloatPtrListIt;
122 
123 typedef Common::List<unsigned int> tUIntList;
124 typedef tUIntList::iterator tUIntListIt;
125 
126 typedef enum {
127  eMsgBoxType_Info,
128  eMsgBoxType_Error,
129  eMsgBoxType_Warning,
130  eMsgBoxType_Default
131 } eMsgBoxType;
132 
136 
137 //--------------------------------------------------------
138 
139 #define STLCallInAll(ContType, aCont, aFunc) \
140  { \
141  ##ContType## ::iterator it = ##aCont##.begin(); \
142  for (; it != ##aCont##.end(); ++it) \
143  (*it)->##aFunc##; \
144  }
145 
146 //--------------------------------------------------------
147 
151 
152 //--------------------------------------------------------
153 
154 class cDate {
155 public:
156  int seconds;
157  int minutes;
158  int hours;
159  int month_day;
160  int month;
161  int year;
162  int week_day;
163  int year_day;
164 
165  tString ToString() {
166  char buff[256];
167 
168  snprintf(buff, 256, "%d/%d-%d %d:%d:%d", month_day, month, 1900 + year, hours, minutes, seconds);
169 
170  return buff;
171  }
172 
173  bool operator==(const cDate &aDate) const {
174  if (seconds == aDate.seconds &&
175  minutes == aDate.minutes &&
176  hours == aDate.hours &&
177  month_day == aDate.month_day &&
178  month == aDate.month &&
179  year == aDate.year) {
180  return true;
181  }
182 
183  return false;
184  }
185 
186  bool operator!=(const cDate &aDate) const {
187  return !(*this == aDate);
188  }
189 
190  bool operator>(const cDate &aDate) const {
191  if (year > aDate.year)
192  return true;
193  else if (year < aDate.year)
194  return false;
195 
196  if (month > aDate.month)
197  return true;
198  else if (month < aDate.month)
199  return false;
200 
201  if (month_day > aDate.month_day)
202  return true;
203  else if (month_day < aDate.month_day)
204  return false;
205 
206  if (hours > aDate.hours)
207  return true;
208  else if (hours < aDate.hours)
209  return false;
210 
211  if (minutes > aDate.minutes)
212  return true;
213  else if (minutes < aDate.minutes)
214  return false;
215 
216  if (seconds > aDate.seconds)
217  return true;
218  else if (seconds < aDate.seconds)
219  return false;
220 
221  return false;
222  }
223 
224  bool operator<(const cDate &aDate) const {
225  if (year < aDate.year)
226  return true;
227  else if (year > aDate.year)
228  return false;
229 
230  if (month < aDate.month)
231  return true;
232  else if (month > aDate.month)
233  return false;
234 
235  if (month_day < aDate.month_day)
236  return true;
237  else if (month_day > aDate.month_day)
238  return false;
239 
240  if (hours < aDate.hours)
241  return true;
242  else if (hours > aDate.hours)
243  return false;
244 
245  if (minutes < aDate.minutes)
246  return true;
247  else if (minutes > aDate.minutes)
248  return false;
249 
250  if (seconds < aDate.seconds)
251  return true;
252  else if (seconds > aDate.seconds)
253  return false;
254 
255  return false;
256  }
257 };
258 
259 //--------------------------------------------------------
260 
261 template<class T>
262 class cMemoryPool {
263 public:
264  //---------------------------------
265 
266  cMemoryPool(size_t alSize, T *(*apCreateFunc)()) {
267  Hpl1::resizeAndFill(mvData, alSize, nullptr);
268  mlCurrentData = 0;
269 
270  mpCreateFunc = apCreateFunc;
271 
272  for (size_t i = 0; i < mvData.size(); ++i) {
273  if (mpCreateFunc)
274  mvData[i] = mpCreateFunc();
275  else
276  mvData[i] = hplNew(T, ());
277  }
278  }
279 
280  //---------------------------------
281 
282  ~cMemoryPool() {
283  for (size_t i = 0; i < mvData.size(); ++i)
284  hplDelete(mvData[i]);
285  }
286 
287  //---------------------------------
288 
289  T *Create() {
290  T *pData = mvData[mlCurrentData];
291 
292  if (mlCurrentData == mvData.size() - 1) {
293  size_t lNewSize = mvData.size() * 2;
294  size_t lStart = mvData.size();
295  mvData.resize(lNewSize);
296 
297  for (size_t i = lStart; i < mvData.size(); ++i) {
298  if (mpCreateFunc)
299  mvData[i] = mpCreateFunc();
300  else
301  mvData[i] = hplNew(T, ());
302  }
303 
304  ++mlCurrentData;
305  } else {
306  ++mlCurrentData;
307  }
308 
309  return pData;
310  }
311 
312  //---------------------------------
313 
314  void Release(T *apData) {
315  if (mlCurrentData == 0)
316  return;
317 
318  --mlCurrentData;
319  mvData[mlCurrentData] = apData;
320  }
321 
322  //---------------------------------
323 
324  void ClearUnused() {
325  for (size_t i = mlCurrentData + 1; i < mvData.size(); ++i) {
326  hplDelete(mvData[i]);
327  }
328  mvData.resize(mlCurrentData + 1);
329  }
330 
331  //---------------------------------
332 
333 private:
334  Common::Array<T *> mvData;
335 
336  size_t mlCurrentData;
337 
338  T *(*mpCreateFunc)();
339 };
340 
341 //----------------------------------------------------------
342 
346 
347 //--------------------------------------------------------
348 
349 template<class CONT, class T>
350 void STLFindAndRemove(CONT &aCont, T *pObject) {
351  typename CONT::iterator it = aCont.begin();
352  for (; it != aCont.end(); it++) {
353  if (*it == pObject) {
354  aCont.erase(it);
355  }
356  }
357 }
358 
359 //--------------------------------------------------------
360 
361 template<class CONT, class T>
362 void STLFindAndDelete(CONT &aCont, T *pObject) {
363  typename CONT::iterator it = aCont.begin();
364  for (; it != aCont.end(); it++) {
365  if (*it == pObject) {
366  aCont.erase(it);
367  break;
368  }
369  }
370  hplDelete(pObject);
371 }
372 
373 //--------------------------------------------------------
374 
375 template<class CONT>
376 void *STLFindByName(CONT &aCont, const tString &asName) {
377  typename CONT::iterator it = aCont.begin();
378  for (; it != aCont.end(); it++) {
379  if ((*it)->GetName() == asName) {
380  return *it;
381  }
382  }
383  return NULL;
384 }
385 
386 //--------------------------------------------------------
387 
388 template<class T>
389 void STLDeleteAll(T &aCont) {
390  typename T::iterator it = aCont.begin();
391  for (; it != aCont.end(); it++) {
392  hplDelete(*it);
393  }
394  aCont.clear();
395 }
396 
397 //--------------------------------------------------------
398 
399 template<class T>
400 void STLMapDeleteAll(T &aCont) {
401  typename T::iterator it = aCont.begin();
402  for (; it != aCont.end(); it++) {
403  hplDelete(it->second);
404  }
405  aCont.clear();
406 }
407 
408 //--------------------------------------------------------
409 
410 template<class T, class CONT, class IT>
412 public:
414  cSTLIterator(CONT *apCont) {
415  mpCont = apCont;
416  mIt = mpCont->begin();
417  }
418 
420 
421  bool HasNext() {
422  return mIt != mpCont->end();
423  }
424 
425  void *NextPtr() {
426  if (mIt == mpCont->end())
427  return NULL;
428  else {
429  T &temp = const_cast<T &>(*mIt);
430  mIt++;
431  return &temp;
432  }
433  }
434 
436 
437  T Next() {
438  if (mIt == mpCont->end())
439  return NULL;
440  else {
441  T &temp = const_cast<T &>(*mIt);
442  mIt++;
443  return temp;
444  }
445  }
446 
448 
449  T PeekNext() {
450  if (mIt == mpCont->end())
451  return NULL;
452  else {
453  return *mIt;
454  }
455  }
456 
458 
459 private:
460  IT mIt;
461  CONT *mpCont;
462 };
463 
464 //--------------------------------------------------------
465 
466 template<class T, class CONT, class IT>
468 public:
470  cSTLMapIterator(CONT *apCont) {
471  mpCont = apCont;
472  mIt = mpCont->begin();
473  }
474 
476 
477  bool HasNext() {
478  return mIt != mpCont->end();
479  }
480 
481  void *NextPtr() {
482  if (mIt == mpCont->end())
483  return NULL;
484  else {
485  T &temp = mIt->second;
486  mIt++;
487  return &temp;
488  }
489  }
490 
492 
493  T Next() {
494  if (mIt == mpCont->end())
495  return NULL;
496  else {
497  T temp = mIt->second;
498  mIt++;
499  return temp;
500  }
501  }
502 
504 
505  T PeekNext() {
506  if (mIt == mpCont->end())
507  return NULL;
508  else {
509  return mIt->second;
510  }
511  }
512 
514 
515 private:
516  IT mIt;
517  CONT *mpCont;
518 };
519 
520 } // namespace hpl
521 
522 #endif // HPL_SYSTEM_TYPES_H
Definition: AI.h:36
Definition: str.h:59
Definition: SystemTypes.h:262
Definition: Container.h:40
Definition: SystemTypes.h:467
Definition: SystemTypes.h:154
tString * iterator
Definition: array.h:54
Definition: SystemTypes.h:411
Definition: ustr.h:57
ListInternal::Iterator< tString > iterator
Definition: list.h:52