xoreos
0.0.5
|
Class to hold the two-dimensional array of a 2DA file. More...
#include <2dafile.h>
Public Member Functions | |
TwoDAFile (Common::SeekableReadStream &twoda) | |
TwoDAFile (const GDAFile &gda) | |
~TwoDAFile () | |
size_t | getRowCount () const |
Return the number of rows in the array. More... | |
size_t | getColumnCount () const |
Return the number of columns in the array. More... | |
const std::vector< Common::UString > & | getHeaders () const |
Return the columns' headers. More... | |
size_t | headerToColumn (const Common::UString &header) const |
Translate a column header to a column index. More... | |
const TwoDARow & | getRow (size_t row) const |
Get a row. More... | |
const TwoDARow & | getRow (const Common::UString &header, const Common::UString &value) const |
Get a row whose value in the column named header is the given string value. More... | |
void | writeASCII (Common::WriteStream &out) const |
Write the 2DA data into an V2.0 ASCII 2DA. More... | |
bool | writeASCII (const Common::UString &fileName) const |
Write the 2DA data into an V2.0 ASCII 2DA. More... | |
void | writeBinary (Common::WriteStream &out) const |
Write the 2DA data into an V2.b binary 2DA. More... | |
bool | writeBinary (const Common::UString &fileName) const |
Write the 2DA data into an V2.b binary 2DA. More... | |
void | writeCSV (Common::WriteStream &out) const |
Write the 2DA data into a CSV stream. More... | |
bool | writeCSV (const Common::UString &fileName) const |
Write the 2DA data into a CSV file. More... | |
Public Member Functions inherited from Aurora::AuroraFile | |
AuroraFile () | |
void | clear () |
uint32 | getID () const |
Return the file's ID. More... | |
uint32 | getVersion () const |
Return the file's version. More... | |
bool | isUTF16LE () const |
Were the ID and version encoded in little-endian UTF-16 in the file? More... | |
Private Types | |
typedef std::map< Common::UString, size_t, Common::UString::iless > | HeaderMap |
Private Member Functions | |
void | load (Common::SeekableReadStream &twoda) |
void | read2a (Common::SeekableReadStream &twoda) |
void | read2b (Common::SeekableReadStream &twoda) |
void | readDefault2a (Common::SeekableReadStream &twoda, Common::StreamTokenizer &tokenize) |
void | readHeaders2a (Common::SeekableReadStream &twoda, Common::StreamTokenizer &tokenize) |
void | readRows2a (Common::SeekableReadStream &twoda, Common::StreamTokenizer &tokenize) |
void | readHeaders2b (Common::SeekableReadStream &twoda) |
void | skipRowNames2b (Common::SeekableReadStream &twoda) |
void | readRows2b (Common::SeekableReadStream &twoda) |
void | load (const GDAFile &gda) |
void | createHeaderMap () |
Static Private Member Functions | |
static int32 | parseInt (const Common::UString &str) |
static float | parseFloat (const Common::UString &str) |
Private Attributes | |
Common::UString | _defaultString |
The default string to return should a cell not exist. More... | |
int32 | _defaultInt |
The default int to return should a cell not exist. More... | |
float | _defaultFloat |
The default float to return should a cell not exist. More... | |
std::vector< Common::UString > | _headers |
HeaderMap | _headerMap |
TwoDARow | _emptyRow |
Common::PtrVector< TwoDARow > | _rows |
Friends | |
class | TwoDARow |
Additional Inherited Members | |
Static Public Member Functions inherited from Aurora::AuroraFile | |
static void | readHeader (Common::ReadStream &stream, uint32 &id, uint32 &version, bool &utf16le) |
Read the header out of a stream. More... | |
static void | readHeader (Common::ReadStream &stream, uint32 &id, uint32 &version) |
Read the ID and version out of a stream. More... | |
static uint32 | readHeaderID (Common::ReadStream &stream) |
Read the ID out of a stream. More... | |
Protected Member Functions inherited from Aurora::AuroraFile | |
void | readHeader (Common::ReadStream &stream) |
Static Protected Member Functions inherited from Aurora::AuroraFile | |
static uint32 | convertUTF16LE (uint32 x1, uint32 x2) |
Protected Attributes inherited from Aurora::AuroraFile | |
uint32 | _id |
The file's ID. More... | |
uint32 | _version |
The file's version. More... | |
bool | _utf16le |
The file's ID and version are in little-endian UTF-16. More... | |
Class to hold the two-dimensional array of a 2DA file.
A 2DA contains a two-dimensional array of string data, where each cell can be identified by the numerical index of its row and column. Moreover, each column has a textual "header", a string uniquely identifying the column by what it's used for.
The usual use-case is to first identify which row to use for a certain object, item, feat, etc., read this row out of the 2DA, and then read each column cell in that row.
For example: the data file defining an item specifies a "Type" of 23, which is an index into the row 23 of the 2DA "items.2da". This 2DA contains the column "Model", "Icon" and "Price", so the cells in the row 23 contain the model, icon and price of the item we are looking for.
2DA files exist in two variants: ASCII and binary. The ASCII version is just a simple text file, formatted to represent a grid of data, with whitespace separating the cells. It can be read and modified with a simple text editor. The binary version cannot.
See also classes TwoDARow and TwoDARegistry.
|
private |
Aurora::TwoDAFile::TwoDAFile | ( | Common::SeekableReadStream & | twoda | ) |
Definition at line 128 of file 2dafile.cpp.
References load().
Aurora::TwoDAFile::TwoDAFile | ( | const GDAFile & | gda | ) |
Definition at line 134 of file 2dafile.cpp.
References load().
Aurora::TwoDAFile::~TwoDAFile | ( | ) |
Definition at line 140 of file 2dafile.cpp.
|
private |
Definition at line 336 of file 2dafile.cpp.
References _headerMap, and _headers.
Referenced by load().
size_t Aurora::TwoDAFile::getColumnCount | ( | ) | const |
Return the number of columns in the array.
Definition at line 404 of file 2dafile.cpp.
References _headers.
Referenced by Engines::NWN::CharSpells::computeRemainingSpells(), Engines::Jade::Functions::get2DANumColumn(), Engines::NWN::CharSpells::makeSpellsList(), and Graphics::CBGT::readPaletteIndices().
const std::vector< Common::UString > & Aurora::TwoDAFile::getHeaders | ( | ) | const |
const TwoDARow & Aurora::TwoDAFile::getRow | ( | size_t | row | ) | const |
Get a row.
Definition at line 421 of file 2dafile.cpp.
References _emptyRow, and _rows.
Referenced by Engines::Jade::MainMenu::addBackground(), Engines::NWN::CharPackage::callbackActive(), Engines::NWN::CharGenChoices::computeAvailSkillRank(), Engines::NWN::CharSpells::computeRemainingSpells(), Engines::NWN::CharClass::createClassList(), Engines::NWN::CharDomain::createDomainList(), Engines::NWN::CharPackage::createPackageList(), Engines::Jade::Functions::findTable(), Engines::Jade::Functions::get2DAEntryFloat(), Engines::Jade::Functions::get2DAEntryFloatByString(), Engines::Jade::Functions::get2DAEntryInt(), Engines::Jade::Functions::get2DAEntryIntByString(), Engines::Jade::Functions::get2DAEntryString(), Engines::Jade::Functions::get2DAEntryStringByString(), Engines::NWN2::Functions::get2DAString(), Engines::NWN::Functions::get2DAString(), Engines::Witcher::Functions::get2DAString(), Engines::NWN::CharGenChoices::getFeatItems(), Engines::KotOR2::Creature::getPartModels(), Engines::KotOR::Creature::getPartModels(), Engines::NWN::Creature::getPartModels(), Engines::KotOR::PartySelectionGUI::getPortrait(), Engines::NWN::CharGenChoices::getPrefDomains(), Engines::NWN::CharGenChoices::getPrefFeats(), Engines::NWN::CharGenChoices::getPrefSkills(), Engines::NWN::CharGenChoices::getPrefSpells(), Engines::NWN::CharGenChoices::getPrefSpellSchool(), Engines::NWN::CharGenChoices::getSkillItems(), Engines::NWN::CharGenChoices::hasPrereqFeat(), Engines::NWN::CharPortrait::initPortraitList(), Engines::NWN::CharInfoVoice::initVoicesList(), Engines::KotOR2::Placeable::loadAppearance(), Engines::NWN2::Placeable::loadAppearance(), Engines::KotOR::Placeable::loadAppearance(), Engines::NWN::Placeable::loadAppearance(), Engines::KotOR2::Door::loadAppearance(), Engines::KotOR::Door::loadAppearance(), Engines::NWN2::Door::loadAppearance(), Engines::NWN::Door::loadAppearance(), Engines::KotOR2::Area::loadCameraStyle(), Engines::KotOR::Area::loadCameraStyle(), Engines::NWN::Situated::loadPortrait(), Engines::NWN::Item::loadPortrait(), Engines::KotOR2::Situated::loadPortrait(), Engines::KotOR::Situated::loadPortrait(), Engines::KotOR2::Creature::loadPortrait(), Engines::KotOR::Creature::loadPortrait(), Engines::NWN::Creature::loadPortrait(), Engines::NWN2::Area::loadProperties(), Engines::NWN::Area::loadProperties(), Engines::KotOR2::Area::loadProperties(), Engines::KotOR::Area::loadProperties(), Engines::Witcher::Situated::loadSounds(), Engines::NWN::Situated::loadSounds(), Engines::NWN2::Situated::loadSounds(), Engines::KotOR2::Situated::loadSounds(), Engines::KotOR::Situated::loadSounds(), Engines::NWN2::Object::loadSSF(), Engines::NWN::Object::loadSSF(), Engines::NWN2::Area::loadTile(), Engines::NWN::CharFeats::makeAvailList(), Engines::NWN::CharFeats::makeKnownList(), Engines::NWN::CharSpells::makeSpellsList(), Graphics::CBGT::readPaletteIndices(), Engines::NWN::CharGenChoices::setClass(), Engines::KotOR2::Area::setMusicBattleTrack(), Engines::NWN2::Area::setMusicBattleTrack(), Engines::NWN::Area::setMusicBattleTrack(), Engines::KotOR::Area::setMusicBattleTrack(), Engines::NWN::CharGenChoices::setPackage(), Engines::NWN::CharGenChoices::setRace(), Engines::NWN::CharAttributes::setRecommend(), Engines::NWN::CharAlignment::setRestrict(), and Engines::NWN::CharAttributes::show().
const TwoDARow & Aurora::TwoDAFile::getRow | ( | const Common::UString & | header, |
const Common::UString & | value | ||
) | const |
Get a row whose value in the column named header is the given string value.
Definition at line 429 of file 2dafile.cpp.
References _emptyRow, _rows, headerToColumn(), and Aurora::kFieldIDInvalid.
size_t Aurora::TwoDAFile::getRowCount | ( | ) | const |
Return the number of rows in the array.
Definition at line 400 of file 2dafile.cpp.
References _rows.
Referenced by Engines::NWN::CharClass::createClassList(), Engines::NWN::CharDomain::createDomainList(), Engines::NWN::CharPackage::createPackageList(), Engines::Jade::Functions::get2DANumRows(), Engines::NWN::CharGenChoices::getFeatItems(), Engines::NWN::CharGenChoices::getPrefFeats(), Engines::NWN::CharGenChoices::getPrefSkills(), Engines::NWN::CharGenChoices::getPrefSpells(), Engines::NWN::CharGenChoices::getSkillItems(), Engines::NWN::CharPortrait::initPortraitList(), Engines::NWN::CharInfoVoice::initVoicesList(), Engines::NWN::CharSpells::makeSpellsList(), Graphics::CBGT::readPaletteIndices(), Engines::NWN::CharGenChoices::setClass(), and Engines::NWN::CharGenChoices::setRace().
size_t Aurora::TwoDAFile::headerToColumn | ( | const Common::UString & | header | ) | const |
Translate a column header to a column index.
Definition at line 412 of file 2dafile.cpp.
References _headerMap, and Aurora::kFieldIDInvalid.
Referenced by Aurora::TwoDARow::empty(), Engines::NWN::CharGenChoices::getFeatItems(), Aurora::TwoDARow::getFloat(), Aurora::TwoDARow::getInt(), getRow(), Aurora::TwoDARow::getString(), Engines::KotOR::Door::loadAppearance(), Engines::KotOR2::Door::loadAppearance(), and Engines::NWN::Door::loadAppearance().
|
private |
Definition at line 143 of file 2dafile.cpp.
References Aurora::AuroraFile::_id, Aurora::AuroraFile::_version, Common::StackException::add(), createHeaderMap(), Common::debugTag(), k2DAID, k2DAIDTab, Common::kEncodingASCII, kVersion2a, kVersion2b, read2a(), read2b(), Aurora::AuroraFile::readHeader(), and Common::readStringLine().
Referenced by TwoDAFile().
|
private |
Definition at line 341 of file 2dafile.cpp.
References _headers, _rows, Common::StackException::add(), createHeaderMap(), Aurora::findGDAHeader(), Common::UString::format(), Aurora::GDAFile::getColumnCount(), Aurora::GFF4Struct::getDouble(), Aurora::GDAFile::getHeaders(), Aurora::GDAFile::getRow(), Aurora::GDAFile::getRowCount(), Aurora::GFF4Struct::getSint(), Aurora::GFF4Struct::getString(), Aurora::GFF4Struct::getUint(), Aurora::GDAFile::kTypeBool, Aurora::GDAFile::kTypeFloat, Aurora::GDAFile::kTypeInt, Aurora::GDAFile::kTypeResource, Aurora::GDAFile::kTypeString, and TwoDARow.
|
staticprivate |
Definition at line 691 of file 2dafile.cpp.
References Common::UString::empty(), and Common::parseString().
Referenced by Aurora::TwoDARow::getFloat(), and readDefault2a().
|
staticprivate |
Definition at line 677 of file 2dafile.cpp.
References Common::UString::empty(), and Common::parseString().
Referenced by Aurora::TwoDARow::getInt(), and readDefault2a().
|
private |
Definition at line 172 of file 2dafile.cpp.
References Common::StreamTokenizer::addChunkEnd(), Common::StreamTokenizer::addIgnore(), Common::StreamTokenizer::addQuote(), Common::StreamTokenizer::addSeparator(), Common::StreamTokenizer::kRuleIgnoreAll, readDefault2a(), readHeaders2a(), and readRows2a().
Referenced by load().
|
private |
Definition at line 190 of file 2dafile.cpp.
References readHeaders2b(), readRows2b(), and skipRowNames2b().
Referenced by load().
|
private |
Definition at line 196 of file 2dafile.cpp.
References _defaultFloat, _defaultInt, _defaultString, Common::StreamTokenizer::getTokens(), Common::StreamTokenizer::nextChunk(), parseFloat(), and parseInt().
Referenced by read2a().
|
private |
Definition at line 216 of file 2dafile.cpp.
References _headers, Common::ReadStream::eos(), Common::StreamTokenizer::getTokens(), and Common::StreamTokenizer::nextChunk().
Referenced by read2a().
|
private |
Definition at line 258 of file 2dafile.cpp.
References _headers, Common::StreamTokenizer::addSeparator(), Common::UString::empty(), Common::StreamTokenizer::getToken(), and Common::StreamTokenizer::kRuleHeed.
Referenced by read2b().
|
private |
Definition at line 227 of file 2dafile.cpp.
References _headers, _rows, Common::ReadStream::eos(), Common::StreamTokenizer::findFirstToken(), Common::StreamTokenizer::getTokens(), Common::StreamTokenizer::nextChunk(), Common::ScopedPtrBase< T, Deallocator >::release(), Common::StreamTokenizer::skipToken(), and TwoDARow.
Referenced by read2a().
|
private |
Definition at line 294 of file 2dafile.cpp.
References _headers, _rows, Common::StreamTokenizer::addSeparator(), Common::StreamTokenizer::getToken(), Common::StreamTokenizer::kRuleHeed, Common::SeekableReadStream::pos(), Common::ReadStream::readUint16LE(), Common::SeekableReadStream::seek(), Common::SeekableReadStream::skip(), and TwoDARow.
Referenced by read2b().
|
private |
Definition at line 275 of file 2dafile.cpp.
References _rows, Common::StreamTokenizer::addSeparator(), Common::StreamTokenizer::kRuleHeed, Common::ReadStream::readUint32LE(), and Common::StreamTokenizer::skipToken().
Referenced by read2b().
void Aurora::TwoDAFile::writeASCII | ( | Common::WriteStream & | out | ) | const |
Write the 2DA data into an V2.0 ASCII 2DA.
Definition at line 443 of file 2dafile.cpp.
References _defaultString, _headers, _rows, Common::UString::c_str(), Common::UString::empty(), Common::WriteStream::flush(), Common::UString::format(), Common::UString::size(), Common::WriteStream::writeByte(), and Common::WriteStream::writeString().
Referenced by Engines::dump2DA(), and writeASCII().
bool Aurora::TwoDAFile::writeASCII | ( | const Common::UString & | fileName | ) | const |
Write the 2DA data into an V2.0 ASCII 2DA.
Definition at line 504 of file 2dafile.cpp.
References Common::WriteFile::close(), Common::WriteFile::open(), and writeASCII().
void Aurora::TwoDAFile::writeBinary | ( | Common::WriteStream & | out | ) | const |
Write the 2DA data into an V2.b binary 2DA.
Definition at line 515 of file 2dafile.cpp.
References _headers, _rows, Common::composeString(), SIZE_MAX, Common::WriteStream::writeByte(), Common::WriteStream::writeString(), Common::WriteStream::writeUint16LE(), and Common::WriteStream::writeUint32LE().
Referenced by writeBinary().
bool Aurora::TwoDAFile::writeBinary | ( | const Common::UString & | fileName | ) | const |
Write the 2DA data into an V2.b binary 2DA.
Definition at line 611 of file 2dafile.cpp.
References Common::WriteFile::close(), Common::WriteFile::open(), and writeBinary().
void Aurora::TwoDAFile::writeCSV | ( | Common::WriteStream & | out | ) | const |
Write the 2DA data into a CSV stream.
Definition at line 622 of file 2dafile.cpp.
References _headers, _rows, Common::WriteStream::flush(), Common::WriteStream::writeByte(), and Common::WriteStream::writeString().
Referenced by writeCSV().
bool Aurora::TwoDAFile::writeCSV | ( | const Common::UString & | fileName | ) | const |
Write the 2DA data into a CSV file.
Definition at line 666 of file 2dafile.cpp.
References Common::WriteFile::close(), Common::WriteFile::open(), and writeCSV().
|
friend |
Definition at line 201 of file 2dafile.h.
Referenced by load(), readRows2a(), and readRows2b().
|
private |
The default float to return should a cell not exist.
Definition at line 170 of file 2dafile.h.
Referenced by Aurora::TwoDARow::getFloat(), and readDefault2a().
|
private |
The default int to return should a cell not exist.
Definition at line 169 of file 2dafile.h.
Referenced by Aurora::TwoDARow::getInt(), and readDefault2a().
|
private |
The default string to return should a cell not exist.
Definition at line 168 of file 2dafile.h.
Referenced by Aurora::TwoDARow::getString(), readDefault2a(), and writeASCII().
|
private |
|
private |
Definition at line 173 of file 2dafile.h.
Referenced by createHeaderMap(), and headerToColumn().
|
private |
Definition at line 172 of file 2dafile.h.
Referenced by createHeaderMap(), getColumnCount(), getHeaders(), load(), readHeaders2a(), readHeaders2b(), readRows2a(), readRows2b(), writeASCII(), writeBinary(), and writeCSV().
|
private |
Definition at line 176 of file 2dafile.h.
Referenced by getRow(), getRowCount(), load(), readRows2a(), readRows2b(), skipRowNames2b(), writeASCII(), writeBinary(), and writeCSV().