Skip to content

Commit

Permalink
AURORA: Add GFF3Struct::setData()
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Mar 3, 2016
1 parent 404eab9 commit ae7a227
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/aurora/gff3file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,4 +1010,32 @@ void GFF3Struct::setOrientation(const Common::UString &field,
f->ownData = new Common::MemoryReadStream(extended, 16, true);
}

void GFF3Struct::setData(const Common::UString &field, Common::SeekableReadStream &value) {
Field *f = getField(field);
if (!f)
throw Common::Exception("GFF3: No such field");
if (f->type != kFieldTypeVoid)
throw Common::Exception("GFF3: Field is not a data type");

const size_t length = value.size() - value.pos();

if (length > 0xFFFFFFFB)
throw Common::Exception("GFF3: Value too long for a data field");

Common::MemoryWriteStreamDynamic writeStream(false, length + 4);

try {
writeStream.writeUint32LE((uint32) length);
writeStream.writeStream(value);

f->prepareSet();

f->ownData = new Common::MemoryReadStream(writeStream.getData(), writeStream.size(), true);

} catch (...) {
writeStream.dispose();
throw;
}
}

} // End of namespace Aurora
3 changes: 3 additions & 0 deletions src/aurora/gff3file.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ class GFF3Struct {
float x, float y, float z );
void setOrientation(const Common::UString &field,
float a, float b, float c, float d);

/** Set the data field and copy the stream. */
void setData(const Common::UString &field, Common::SeekableReadStream &value);
// '---

private:
Expand Down

0 comments on commit ae7a227

Please sign in to comment.