27 #include <boost/make_shared.hpp> 37 _structs.push_back(boost::make_shared<GFF3WriterStruct>(
this));
51 uint32 fieldOffset = structOffset + structCount * 12;
54 uint32 labelOffset = fieldOffset + fieldCount * 12;
57 uint32 fieldDataOffset = labelOffset + labelCount * 16;
61 for (
size_t i = 0; i <
_fields.size(); ++i)
64 uint32 fieldIndicesOffset = fieldDataOffset + fieldDataCount;
65 uint32 fieldIndicesCount = 0;
68 for (
size_t i = 0; i <
_structs.size(); ++i) {
70 if (strct->getFieldCount() <= 1)
73 fieldIndicesCount += strct->getFieldCount() * 4;
76 uint32 listIndicesOffset = fieldIndicesOffset + fieldIndicesCount;
77 uint32 listIndicesCount = 0;
80 for (
size_t i = 0; i <
_lists.size(); ++i) {
81 listIndicesCount += (
_lists[i]->getSize() + 1) * 4;
99 size_t structFieldIndicesIndex = 0;
100 for (
size_t i = 0; i <
_structs.size(); ++i) {
107 if (strct->getFieldCount() > 1) {
109 structFieldIndicesIndex += strct->getFieldCount();
111 if (strct->getFieldCount() != 0)
122 size_t fieldDataIndex = 0;
123 size_t listDataIndex = 0;
124 for (
size_t i = 0; i <
_fields.size(); ++i) {
144 switch (field->type) {
153 listDataIndex += 1 +
_lists[field->uint32Value]->getSize();
174 for (
size_t i = 0; i <
_labels.size(); ++i) {
181 for (
size_t i = 0; i <
_fields.size(); ++i) {
183 switch (field->type) {
198 stream.
writeByte(MIN<byte>(16, field->stringValue.size()));
199 stream.
write(field->stringValue.c_str(), MIN<size_t>(field->stringValue.size(), 16));
202 stream.
writeUint32LE(static_cast<uint32>(field->stringValue.size()));
206 stream.
writeUint32LE(field->locStringValue.getWrittenSize() + 8);
209 field->locStringValue.writeLocString(stream);
213 stream.
write(field->voidData.get(), field->voidSize);
232 for (
size_t i = 0; i <
_structs.size(); ++i) {
234 if (strct->getFieldCount() <= 1)
237 for (
size_t j = 0; j < strct->getFieldCount(); ++j) {
243 for (
size_t i = 0; i <
_lists.size(); ++i) {
246 for (
size_t j = 0; j < list->_strcts.size(); ++j) {
253 std::vector<Common::UString>::iterator iter = std::find(
_labels.begin(),
_labels.end(), label);
255 return static_cast<uint32>(std::distance(
_labels.begin(), iter));
263 switch (field->type) {
270 return 4 + field->stringValue.size();
272 return 12 + field->locStringValue.getWrittenSize();
274 return 1 + field->stringValue.size();
280 return 4 + field->voidSize;
293 field->labelIndex =
addLabel(label);
436 field->voidData.reset(
new byte[size]);
437 field->voidSize = size;
438 memcpy(field->voidData.get(), data, size);
void addOrientation(const Common::UString &label, glm::vec4 value)
Add a new Orientation.
A class holding an UTF-8 string.
void writeString(const UString &str)
Write the given string to the stream, encoded as UTF-8.
GFF3WriterStruct(GFF3Writer *parent, uint32 id=0xFFFFFFFF)
boost::shared_ptr< Field > FieldPtr
GFF3WriterListPtr addList(const Common::UString &label)
Create a new list.
void addVoid(const Common::UString &label, const byte *data, uint32 size)
Add new void data.
String reference, index into a talk table.
Implementing the reading stream interfaces for plain memory blocks.
size_t createField(GFF3Struct::FieldType type, const Common::UString &label)
Writer for writing version V3.2/V3.3 of BioWare's GFFs (generic file format).
FORCEINLINE void writeSint32LE(int32 value)
void writeUint64LE(uint64 value)
boost::shared_ptr< GFF3WriterStruct > GFF3WriterStructPtr
void addFloat(const Common::UString &label, float value)
Add a new float.
GFF3WriterList(GFF3Writer *parent)
void addChar(const Common::UString &label, char value)
Add a new char.
FieldType
The type of a GFF3 field.
void addResRef(const Common::UString &label, const Common::UString &value)
Add a new Resource reference.
std::vector< Common::UString > _labels
void addStrRef(const Common::UString &label, uint32 value)
Add a new String reference.
void addLocString(const Common::UString &label, const LocString &value)
Add a new LocString.
FORCEINLINE void writeIEEEDoubleLE(double value)
GFF3WriterStructPtr addStruct(const Common::UString &label)
Create a new struct.
const char * c_str() const
Return the (utf8 encoded) string data.
GFF3WriterStructPtr addStruct(const Common::UString &label)
Add a new struct to the list.
void addExoString(const Common::UString &label, const Common::UString &value)
Add a new ExoString.
std::vector< size_t > _strcts
Random data of variable length.
void addSint16(const Common::UString &label, int16 value)
Add a new sint16.
FORCEINLINE void writeSint64LE(int64 value)
uint32 addLabel(const Common::UString &label)
Adds a label to the writer and returns the corresponding index.
void write(Common::WriteStream &stream)
Write the GFF3 to stream.
Basic writing stream interfaces.
void addUint64(const Common::UString &label, uint64 value)
Add a new uint64.
void addVector(const Common::UString &label, glm::vec3 value)
Add a new Vector.
virtual size_t write(const void *dataPtr, size_t dataSize)=0
Write data into the stream.
void writeByte(byte value)
std::vector< GFF3WriterListPtr > _lists
Generic interface for a writable data stream.
void addByte(const Common::UString &label, byte value)
Add a new byte.
std::vector< GFF3WriterStructPtr > _structs
size_t size() const
Return the size of the string, in characters.
FORCEINLINE void writeIEEEFloatLE(float value)
Resource reference, string.
void addUint32(const Common::UString &label, uint32 value)
Add a new uint32.
size_t getFieldCount() const
Get the count of fields.
std::vector< size_t > _fieldIndices
static uint32 getFieldDataSize(FieldPtr field)
Get the actual size of the field.
List containing a number of structs.
Struct containing a number of fields.
GFF3WriterStructPtr getTopLevel()
Get the top-level struct.
GFF3Writer::FieldPtr createField(GFF3Struct::FieldType type, const Common::UString &label)
void writeUint32BE(uint32 value)
FORCEINLINE void writeZeros(size_t n)
Write n zeros to the stream.
GFF3Writer(uint32 id, uint32 version=MKTAG('V', '3', '.', '2'))
boost::shared_ptr< GFF3WriterList > GFF3WriterListPtr
std::vector< FieldPtr > _fields
void addUint16(const Common::UString &label, uint16 value)
Add a new uint16.
void writeUint32LE(uint32 value)
uint32 getID() const
Get ID of the struct.
void addSint64(const Common::UString &label, int64 value)
Add a new sint64.
void addDouble(const Common::UString &label, double value)
Add a new double.
void addSint32(const Common::UString &label, int32 value)
Add a new sint32.