porymap/blockdata.cpp

56 lines
1.3 KiB
C++
Raw Normal View History

2016-09-07 04:50:47 +01:00
#include "blockdata.h"
2017-11-28 04:46:27 +00:00
#include <QDebug>
2016-09-07 04:50:47 +01:00
Blockdata::Blockdata(QObject *parent) : QObject(parent)
{
blocks = new QList<Block>;
}
void Blockdata::addBlock(uint16_t word) {
Block block(word);
blocks->append(block);
}
void Blockdata::addBlock(Block block) {
blocks->append(block);
}
QByteArray Blockdata::serialize() {
QByteArray data;
for (int i = 0; i < blocks->length(); i++) {
Block block = blocks->value(i);
uint16_t word = block.rawValue();
data.append(word & 0xff);
data.append((word >> 8) & 0xff);
}
return data;
}
void Blockdata::copyFrom(Blockdata* other) {
blocks->clear();
for (int i = 0; i < other->blocks->length(); i++) {
addBlock(other->blocks->value(i));
}
}
Blockdata* Blockdata::copy() {
Blockdata* blockdata = new Blockdata;
blockdata->copyFrom(this);
return blockdata;
}
2017-11-28 04:46:27 +00:00
bool Blockdata::equals(Blockdata *other) {
if (!other) {
return false;
}
if (blocks->length() != other->blocks->length()) {
return false;
}
for (int i = 0; i < blocks->length(); i++) {
if (blocks->value(i) != other->blocks->value(i)) {
return false;
}
}
return true;
}