ScummVM API documentation
coll_templ.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  * This file is based on WME Lite.
24  * http://dead-code.org/redir.php?target=wmelite
25  * Copyright (c) 2011 Jan Nedoma
26  */
27 
28 #ifndef WINTERMUTE_COLL_TEMPL_H
29 #define WINTERMUTE_COLL_TEMPL_H
30 
31 #include "common/array.h"
32 #include "engines/wintermute/base/base_persistence_manager.h"
33 
34 namespace Wintermute {
35 
36 // Basically Common::Array with peristence-support.
37 template<typename TYPE>
38 class BaseArrayBase : public Common::Array<TYPE> {
39 public:
40 // TODO: Might want to make sure that destructors are called when replacing/deleting/getting destructed
41  int add(TYPE newElement) {
43  return Common::Array<TYPE>::size() - 1;
44  }
45  void remove_at(uint32 idx) {
47  }
48  void remove_at(uint32 idx, uint32 num) {
49  while (num) {
50  if (idx >= Common::Array<TYPE>::size()) {
51  break;
52  }
54  }
55  }
56  template<typename T2>
57  void copy(const BaseArrayBase<T2> &src) {
59  }
60 };
61 
62 template <typename TYPE>
63 class BaseArray : public BaseArrayBase<TYPE> {
64  public:
65  bool persist(BasePersistenceManager *persistMgr) {
66  int32 j;
67  if (persistMgr->getIsSaving()) {
69  persistMgr->transferSint32("ArraySize", &j);
71  for (; it != Common::Array<TYPE>::end(); ++it) {
72  TYPE obj = *it;
73  persistMgr->transferPtr("", &obj);
74  }
75  } else {
77  persistMgr->transferSint32("ArraySize", &j);
78  for (int i = 0; i < j; i++) {
79  TYPE obj = nullptr;
80  persistMgr->transferPtr("", &obj);
81  this->add(obj);
82  }
83  }
84  return true;
85  }
86 };
87 
88 template <>
89 class BaseArray<char *> : public BaseArrayBase<char *> {
90  public:
91  bool persist(BasePersistenceManager *persistMgr) {
92  int32 j;
93  if (persistMgr->getIsSaving()) {
95  persistMgr->transferSint32("ArraySize", &j);
97  for (; it != Common::Array<char *>::end(); ++it) {
98  char * obj = *it;
99  persistMgr->transferCharPtr("", &obj);
100  }
101  } else {
103  persistMgr->transferSint32("ArraySize", &j);
104  for (int i = 0; i < j; i++) {
105  char * obj = nullptr;
106  persistMgr->transferCharPtr("", &obj);
107  add(obj);
108  }
109  }
110  return true;
111  }
112 };
113 
114 template <>
115 class BaseArray<const char *> : public BaseArrayBase<const char *> {
116 public:
117  bool persist(BasePersistenceManager *persistMgr) {
118  int32 j;
119  if (persistMgr->getIsSaving()) {
121  persistMgr->transferSint32("ArraySize", &j);
123  for (; it != Common::Array<const char *>::end(); ++it) {
124  const char * obj = *it;
125  persistMgr->transferConstChar("", &obj);
126  }
127  } else {
129  persistMgr->transferSint32("ArraySize", &j);
130  for (int i = 0; i < j; i++) {
131  const char * obj = nullptr;
132  persistMgr->transferConstChar("", &obj);
133  add(obj);
134  }
135  }
136  return true;
137  }
138 };
139 
140 } // End of namespace Wintermute
141 
142 #endif
void insert_at(size_type idx, const T &element)
Definition: array.h:241
Definition: base_persistence_manager.h:55
Definition: array.h:52
void clear()
Definition: array.h:320
iterator end()
Definition: array.h:379
iterator begin()
Definition: array.h:374
void push_back(const T &element)
Definition: array.h:180
const T * const_iterator
Definition: array.h:55
Definition: coll_templ.h:38
size_type size() const
Definition: array.h:315
Definition: coll_templ.h:63
T remove_at(size_type idx)
Definition: array.h:260
Definition: achievements_tables.h:27