Пример #1
0
void TwoDAFile::load(const GDAFile &gda) {
	try {

		const GDAFile::Headers &headers = gda.getHeaders();
		assert(headers.size() == gda.getColumnCount());

		_headers.resize(gda.getColumnCount());
		for (size_t i = 0; i < gda.getColumnCount(); i++) {
			const char *headerString = findGDAHeader(headers[i].hash);

			_headers[i] = headerString ? headerString : Common::UString::format("[%u]", headers[i].hash);
		}

		_rows.resize(gda.getRowCount(), 0);
		for (size_t i = 0; i < gda.getRowCount(); i++) {
			const GFF4Struct *row = gda.getRow(i);

			_rows[i] = new TwoDARow(*this);
			_rows[i]->_data.resize(gda.getColumnCount());

			for (size_t j = 0; j < gda.getColumnCount(); j++) {
				if (row) {
					switch (headers[j].type) {
						case GDAFile::kTypeString:
						case GDAFile::kTypeResource:
							_rows[i]->_data[j] = row->getString(headers[j].field);
							break;

						case GDAFile::kTypeInt:
							_rows[i]->_data[j] = Common::UString::format("%d", (int) row->getSint(headers[j].field));
							break;

						case GDAFile::kTypeFloat:
							_rows[i]->_data[j] = Common::UString::format("%f", row->getDouble(headers[j].field));
							break;

						case GDAFile::kTypeBool:
							_rows[i]->_data[j] = Common::UString::format("%u", (uint) row->getUint(headers[j].field));
							break;

						default:
							break;
					}
				}

				if (_rows[i]->_data[j].empty())
					_rows[i]->_data[j] = "****";

			}
		}

	} catch (Common::Exception &e) {
		clear();

		e.add("Failed reading GDA file");
		throw;
	}

	createHeaderMap();
}
Пример #2
0
void TwoDAFile::load(Common::SeekableReadStream &twoda) {
	clear();

	readHeader(twoda);

	if ((_id != k2DAID) && (_id != k2DAIDTab))
		throw Common::Exception("Not a 2DA file");

	if ((_version != kVersion2a) && (_version != kVersion2b))
		throw Common::Exception("Unsupported 2DA file version %08X", _version);

	Common::UString lineRest = Common::readStringLine(twoda, Common::kEncodingASCII);

	try {

		if      (_version == kVersion2a)
			read2a(twoda);
		else if (_version == kVersion2b)
			read2b(twoda);

		// Create the map to quickly translate headers to column indices
		createHeaderMap();

		if (twoda.err())
			throw Common::Exception(Common::kReadError);

	} catch (Common::Exception &e) {
		e.add("Failed reading 2DA file");
		throw;
	}

}
Пример #3
0
void TwoDAFile::load(Common::SeekableReadStream &twoda) {
	readHeader(twoda);

	if ((_id != k2DAID) && (_id != k2DAIDTab))
		throw Common::Exception("Not a 2DA file (%s)", Common::debugTag(_id).c_str());

	if ((_version != kVersion2a) && (_version != kVersion2b))
		throw Common::Exception("Unsupported 2DA file version %s", Common::debugTag(_version).c_str());

	// Ignore the rest of the line; it's garbage
	Common::readStringLine(twoda, Common::kEncodingASCII);

	try {

		if      (_version == kVersion2a)
			read2a(twoda); // ASCII
		else if (_version == kVersion2b)
			read2b(twoda); // Binary

		// Create the map to quickly translate headers to column indices
		createHeaderMap();

	} catch (Common::Exception &e) {
		clear();

		e.add("Failed reading 2DA file");
		throw;
	}

}