scummvm/engines/pink/utils.h

75 lines
2.1 KiB
C
Raw Normal View History

2018-05-21 18:38:02 +00:00
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
2018-05-21 18:38:02 +00:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2018-05-21 18:38:02 +00:00
*
*/
#ifndef PINK_UTILS_H
#define PINK_UTILS_H
2018-06-10 07:54:08 +00:00
#include "pink/objects/object.h"
2018-05-21 18:38:02 +00:00
namespace Pink {
template <typename T>
class Array : public Common::Array<T>, public Object {
public:
2020-02-09 11:05:31 +00:00
void deserialize(Archive &archive) override {
2018-06-29 07:37:44 +00:00
uint size_ = archive.readWORD();
this->resize(size_);
for (uint i = 0; i < size_; ++i) {
2018-05-21 18:38:02 +00:00
this->data()[i] = reinterpret_cast<T>(archive.readObject()); // dynamic_cast needs to know complete type
}
}
};
class StringArray : public Common::StringArray {
public:
2018-05-25 14:41:45 +00:00
void deserialize(Archive &archive) {
2018-06-29 07:37:44 +00:00
uint32 size_ = archive.readWORD();
this->resize(size_);
for (uint i = 0; i < size_; ++i) {
2018-05-21 18:38:02 +00:00
this->data()[i] = archive.readString();
}
}
};
2018-05-25 14:41:45 +00:00
class StringMap : public Common::StringMap {
public:
void serialize(Archive &archive) {
archive.writeWORD(size());
for (Common::StringMap::const_iterator it = begin(); it != end(); ++it) {
archive.writeString(it->_key);
archive.writeString(it->_value);
}
}
void deserialize(Archive &archive) {
2018-06-29 07:37:44 +00:00
uint size_ = archive.readWORD();
for (uint i = 0; i < size_; ++i) {
2018-05-25 14:41:45 +00:00
Common::String key = archive.readString();
Common::String val = archive.readString();
setVal(key, val);
}
}
};
2018-05-21 18:38:02 +00:00
} // End of namespace Pink
2018-05-22 03:04:44 +00:00
#endif