ScummVM API documentation
utils.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 PINK_UTILS_H
23 #define PINK_UTILS_H
24 
25 #include "pink/objects/object.h"
26 
27 namespace Pink {
28 
29 template <typename T>
30 class Array : public Common::Array<T>, public Object {
31 public:
32  void deserialize(Archive &archive) override {
33  uint size_ = archive.readWORD();
34  this->resize(size_);
35  for (uint i = 0; i < size_; ++i) {
36  this->data()[i] = reinterpret_cast<T>(archive.readObject()); // dynamic_cast needs to know complete type
37  }
38  }
39 };
40 
42 public:
43  void deserialize(Archive &archive) {
44  uint32 size_ = archive.readWORD();
45  this->resize(size_);
46  for (uint i = 0; i < size_; ++i) {
47  this->data()[i] = archive.readString();
48  }
49  }
50 };
51 
52 class StringMap : public Common::StringMap {
53 public:
54  void serialize(Archive &archive) {
55  archive.writeWORD(size());
56  for (Common::StringMap::const_iterator it = begin(); it != end(); ++it) {
57  archive.writeString(it->_key);
58  archive.writeString(it->_value);
59  }
60  }
61 
62  void deserialize(Archive &archive) {
63  uint size_ = archive.readWORD();
64  for (uint i = 0; i < size_; ++i) {
65  Common::String key = archive.readString();
66  Common::String val = archive.readString();
67  setVal(key, val);
68  }
69  }
70 };
71 
72 } // End of namespace Pink
73 
74 #endif
Definition: archive.h:39
Definition: str.h:59
const T * data() const
Definition: array.h:207
Definition: array.h:52
iterator end()
Definition: array.h:379
iterator begin()
Definition: array.h:374
Definition: object.h:31
Definition: archive.h:35
size_type size() const
Definition: array.h:315
void resize(size_type newSize)
Definition: array.h:411
Definition: utils.h:52
Definition: utils.h:30
Definition: utils.h:41