diff options
author | Treeki <treeki@gmail.com> | 2010-10-14 20:17:20 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2010-10-14 20:17:20 +0200 |
commit | ebcc95da4c26369511caa90d89c5ed06e1e4853a (patch) | |
tree | 6ed445f0204a6e6615088d135c4b29c4309077a4 /lyt/binaryfilesection.cpp | |
parent | fdf8cfec2b795393d7ee901abaf747575067068b (diff) | |
download | LayoutStudio-ebcc95da4c26369511caa90d89c5ed06e1e4853a.tar.gz LayoutStudio-ebcc95da4c26369511caa90d89c5ed06e1e4853a.zip |
brlyt packing added, plus some changes in the existing API (mostly for const correctness). brlyt writing may still need some testing (especially for the material structs)
Diffstat (limited to '')
-rw-r--r-- | lyt/binaryfilesection.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/lyt/binaryfilesection.cpp b/lyt/binaryfilesection.cpp index a06810d..5115cda 100644 --- a/lyt/binaryfilesection.cpp +++ b/lyt/binaryfilesection.cpp @@ -17,14 +17,23 @@ #include "binaryfilesection.h" -LYTBinaryFileSection::LYTBinaryFileSection() { +LYTBinaryFileSection::LYTBinaryFileSection() : magic(0) { } +LYTBinaryFileSection::LYTBinaryFileSection(Magic m) : magic(m) { +} + +LYTBinaryFileSection::LYTBinaryFileSection(Magic m, QByteArray d) : magic(m), data(d) { +} -void LYTBinaryFileSection::writeToDataStream(QDataStream &out) { + +void LYTBinaryFileSection::writeToDataStream(QDataStream &out) const { out << (quint32)magic.value; - out << (quint32)data.length() + 8; + out << (quint32)AlignUp(data.length() + 8, 4); out.writeRawData(data.constData(), data.length()); + + int align = AlignUp(data.length(), 4) - data.length(); + WritePadding(align, out); } void LYTBinaryFileSection::readFromDataStream(QDataStream &in) { @@ -40,6 +49,20 @@ void LYTBinaryFileSection::readFromDataStream(QDataStream &in) { } -int LYTBinaryFileSection::writtenSize() { - return 8 + this->data.length(); +int LYTBinaryFileSection::writtenSize() const { + return 8 + AlignUp(this->data.length(), 4); +} + + +QDataStream *LYTBinaryFileSection::createReadStream() const { + QDataStream *stream = new QDataStream(this->data); + InitDataStream(*stream); + return stream; +} + + +QDataStream *LYTBinaryFileSection::createWriteStream() { + QDataStream *stream = new QDataStream(&this->data, QIODevice::ReadWrite); + InitDataStream(*stream); + return stream; } |