Common::UString GFF3Struct::getString(const Common::UString &field, const Common::UString &def) const { const Field *f = getField(field); if (!f) return def; if (f->type == kFieldTypeExoString) { Common::SeekableReadStream &data = getData(*f); const uint32 length = data.readUint32LE(); return Common::readStringFixed(data, Common::kEncodingASCII, length); } if (f->type == kFieldTypeResRef) { Common::SeekableReadStream &data = getData(*f); const uint32 length = data.readByte(); return Common::readStringFixed(data, Common::kEncodingASCII, length); } if ((f->type == kFieldTypeByte ) || (f->type == kFieldTypeUint16) || (f->type == kFieldTypeUint32) || (f->type == kFieldTypeUint64) || (f->type == kFieldTypeStrRef)) { return Common::UString::format("%lu", getUint(field)); } if ((f->type == kFieldTypeChar ) || (f->type == kFieldTypeSint16) || (f->type == kFieldTypeSint32) || (f->type == kFieldTypeSint64)) { return Common::UString::format("%ld", getSint(field)); } if ((f->type == kFieldTypeFloat) || (f->type == kFieldTypeDouble)) { return Common::UString::format("%lf", getDouble(field)); } if (f->type == kFieldTypeVector) { float x, y, z; getVector(field, x, y, z); return Common::UString::format("%f/%f/%f", x, y, z); } if (f->type == kFieldTypeOrientation) { float a, b, c, d; getOrientation(field, a, b, c, d); return Common::UString::format("%f/%f/%f/%f", a, b, c, d); } throw Common::Exception("GFF3: Field is not a string(able) type"); }
int64 GFF4Struct::getSint(uint32 field, int64 def) const { const Field *f; Common::SeekableReadStream *data = getField(field, f); if (!data) return def; if (f->isList) throw Common::Exception("GFF4: Tried reading list as singular value"); return getSint(*data, f->type); }
bool GFF4Struct::getSint(uint32 field, std::vector<int64> &list) const { const Field *f; Common::SeekableReadStream *data = getField(field, f); if (!data) return false; const uint32 count = getListCount(*data, *f); list.resize(count); for (uint32 i = 0; i < count; i++) list[i] = getSint(*data, f->type); return true; }
Common::UString GFF3Struct::getString(const Common::UString &field, const Common::UString &def) const { const Field *f = getField(field); if (!f) return def; // Direct string if (f->type == kFieldTypeExoString) { Common::SeekableReadStream &data = getData(*f); const uint32 length = data.readUint32LE(); return Common::readStringFixed(data, Common::kEncodingASCII, length); } // ResRef, resource reference, a shorter string if (f->type == kFieldTypeResRef) { Common::SeekableReadStream &data = getData(*f); const uint32 length = data.readByte(); return Common::readStringFixed(data, Common::kEncodingASCII, length); } // LocString, a localized string if (f->type == kFieldTypeLocString) { LocString locString; getLocString(field, locString); return locString.getString(); } // Unsigned integer type, compose a string representation if ((f->type == kFieldTypeByte ) || (f->type == kFieldTypeUint16) || (f->type == kFieldTypeUint32) || (f->type == kFieldTypeUint64) || (f->type == kFieldTypeStrRef)) { return Common::composeString(getUint(field)); } // Signed integer type, compose a string representation if ((f->type == kFieldTypeChar ) || (f->type == kFieldTypeSint16) || (f->type == kFieldTypeSint32) || (f->type == kFieldTypeSint64)) { return Common::composeString(getSint(field)); } // Floating point type, compose a string representation if ((f->type == kFieldTypeFloat) || (f->type == kFieldTypeDouble)) { return Common::composeString(getDouble(field)); } // Vector, consisting of 3 floats if (f->type == kFieldTypeVector) { float x = 0.0, y = 0.0, z = 0.0; getVector(field, x, y, z); return Common::composeString(x) + "/" + Common::composeString(y) + "/" + Common::composeString(z); } // Orientation, consisting of 4 floats if (f->type == kFieldTypeOrientation) { float a = 0.0, b = 0.0, c = 0.0, d = 0.0; getOrientation(field, a, b, c, d); return Common::composeString(a) + "/" + Common::composeString(b) + "/" + Common::composeString(c) + "/" + Common::composeString(d); } throw Common::Exception("GFF3: Field is not a string(able) type"); }
Common::UString GFF3Struct::getString(const Common::UString &field, const Common::UString &def) const { const Field *f = getField(field); if (!f) return def; if (f->type == kFieldTypeExoString) { Common::SeekableReadStream &data = getData(*f); const uint32 length = data.readUint32LE(); return Common::readStringFixed(data, Common::kEncodingASCII, length); } if (f->type == kFieldTypeResRef) { Common::SeekableReadStream &data = getData(*f); const uint32 length = data.readByte(); return Common::readStringFixed(data, Common::kEncodingASCII, length); } if (f->type == kFieldTypeLocString) { LocString locString; getLocString(field, locString); return locString.getString(); } if ((f->type == kFieldTypeByte ) || (f->type == kFieldTypeUint16) || (f->type == kFieldTypeUint32) || (f->type == kFieldTypeUint64) || (f->type == kFieldTypeStrRef)) { return Common::composeString(getUint(field)); } if ((f->type == kFieldTypeChar ) || (f->type == kFieldTypeSint16) || (f->type == kFieldTypeSint32) || (f->type == kFieldTypeSint64)) { return Common::composeString(getSint(field)); } if ((f->type == kFieldTypeFloat) || (f->type == kFieldTypeDouble)) { return Common::composeString(getDouble(field)); } if (f->type == kFieldTypeVector) { float x = 0.0, y = 0.0, z = 0.0; getVector(field, x, y, z); return Common::composeString(x) + "/" + Common::composeString(y) + "/" + Common::composeString(z); } if (f->type == kFieldTypeOrientation) { float a = 0.0, b = 0.0, c = 0.0, d = 0.0; getOrientation(field, a, b, c, d); return Common::composeString(a) + "/" + Common::composeString(b) + "/" + Common::composeString(c) + "/" + Common::composeString(d); } throw Common::Exception("GFF3: Field is not a string(able) type"); }