xoreos  0.0.5
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
Aurora::TwoDAFile Class Reference

Class to hold the two-dimensional array of a 2DA file. More...

#include <2dafile.h>

Inheritance diagram for Aurora::TwoDAFile:
Inheritance graph
[legend]
Collaboration diagram for Aurora::TwoDAFile:
Collaboration graph
[legend]

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 TwoDARowgetRow (size_t row) const
 Get a row. More...
 
const TwoDARowgetRow (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::ilessHeaderMap
 

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...
 

Detailed Description

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.

Definition at line 124 of file 2dafile.h.

Member Typedef Documentation

◆ HeaderMap

Definition at line 166 of file 2dafile.h.

Constructor & Destructor Documentation

◆ TwoDAFile() [1/2]

Aurora::TwoDAFile::TwoDAFile ( Common::SeekableReadStream twoda)

Definition at line 128 of file 2dafile.cpp.

References load().

Here is the call graph for this function:

◆ TwoDAFile() [2/2]

Aurora::TwoDAFile::TwoDAFile ( const GDAFile gda)

Definition at line 134 of file 2dafile.cpp.

References load().

Here is the call graph for this function:

◆ ~TwoDAFile()

Aurora::TwoDAFile::~TwoDAFile ( )

Definition at line 140 of file 2dafile.cpp.

Member Function Documentation

◆ createHeaderMap()

void Aurora::TwoDAFile::createHeaderMap ( )
private

Definition at line 336 of file 2dafile.cpp.

References _headerMap, and _headers.

Referenced by load().

Here is the caller graph for this function:

◆ getColumnCount()

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().

Here is the caller graph for this function:

◆ getHeaders()

const std::vector< Common::UString > & Aurora::TwoDAFile::getHeaders ( ) const

Return the columns' headers.

Definition at line 408 of file 2dafile.cpp.

References _headers.

◆ getRow() [1/2]

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().

◆ getRow() [2/2]

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.

Here is the call graph for this function:

◆ getRowCount()

size_t Aurora::TwoDAFile::getRowCount ( ) const

◆ headerToColumn()

size_t Aurora::TwoDAFile::headerToColumn ( const Common::UString header) const

◆ load() [1/2]

void Aurora::TwoDAFile::load ( Common::SeekableReadStream twoda)
private

◆ load() [2/2]

void Aurora::TwoDAFile::load ( const GDAFile gda)
private

◆ parseFloat()

float Aurora::TwoDAFile::parseFloat ( const Common::UString str)
staticprivate

Definition at line 691 of file 2dafile.cpp.

References Common::UString::empty(), and Common::parseString().

Referenced by Aurora::TwoDARow::getFloat(), and readDefault2a().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseInt()

int32 Aurora::TwoDAFile::parseInt ( const Common::UString str)
staticprivate

Definition at line 677 of file 2dafile.cpp.

References Common::UString::empty(), and Common::parseString().

Referenced by Aurora::TwoDARow::getInt(), and readDefault2a().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read2a()

void Aurora::TwoDAFile::read2a ( Common::SeekableReadStream twoda)
private

◆ read2b()

void Aurora::TwoDAFile::read2b ( Common::SeekableReadStream twoda)
private

Definition at line 190 of file 2dafile.cpp.

References readHeaders2b(), readRows2b(), and skipRowNames2b().

Referenced by load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readDefault2a()

void Aurora::TwoDAFile::readDefault2a ( Common::SeekableReadStream twoda,
Common::StreamTokenizer tokenize 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readHeaders2a()

void Aurora::TwoDAFile::readHeaders2a ( Common::SeekableReadStream twoda,
Common::StreamTokenizer tokenize 
)
private

Definition at line 216 of file 2dafile.cpp.

References _headers, Common::ReadStream::eos(), Common::StreamTokenizer::getTokens(), and Common::StreamTokenizer::nextChunk().

Referenced by read2a().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readHeaders2b()

void Aurora::TwoDAFile::readHeaders2b ( Common::SeekableReadStream twoda)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readRows2a()

void Aurora::TwoDAFile::readRows2a ( Common::SeekableReadStream twoda,
Common::StreamTokenizer tokenize 
)
private

◆ readRows2b()

void Aurora::TwoDAFile::readRows2b ( Common::SeekableReadStream twoda)
private

◆ skipRowNames2b()

void Aurora::TwoDAFile::skipRowNames2b ( Common::SeekableReadStream twoda)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeASCII() [1/2]

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeASCII() [2/2]

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().

Here is the call graph for this function:

◆ writeBinary() [1/2]

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeBinary() [2/2]

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().

Here is the call graph for this function:

◆ writeCSV() [1/2]

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeCSV() [2/2]

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().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ TwoDARow

friend class TwoDARow
friend

Definition at line 201 of file 2dafile.h.

Referenced by load(), readRows2a(), and readRows2b().

Member Data Documentation

◆ _defaultFloat

float Aurora::TwoDAFile::_defaultFloat
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().

◆ _defaultInt

int32 Aurora::TwoDAFile::_defaultInt
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().

◆ _defaultString

Common::UString Aurora::TwoDAFile::_defaultString
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().

◆ _emptyRow

TwoDARow Aurora::TwoDAFile::_emptyRow
private

Definition at line 175 of file 2dafile.h.

Referenced by getRow().

◆ _headerMap

HeaderMap Aurora::TwoDAFile::_headerMap
private

Definition at line 173 of file 2dafile.h.

Referenced by createHeaderMap(), and headerToColumn().

◆ _headers

std::vector<Common::UString> Aurora::TwoDAFile::_headers
private

◆ _rows

Common::PtrVector<TwoDARow> Aurora::TwoDAFile::_rows
private

The documentation for this class was generated from the following files: