Add some comments on the stats loading.
parent
1d100e6c70
commit
6a99f44265
|
@ -133,6 +133,7 @@ BASE_STATS::BASE_STATS(unsigned ref, std::string const &str)
|
|||
{}
|
||||
|
||||
|
||||
// This constructor parses the file data in buffer, and stores a pointer to the buffer, along with a list of the starts and ends of each cell in the table.
|
||||
TableView::TableView(char const *buffer, unsigned size)
|
||||
: buffer(buffer)
|
||||
{
|
||||
|
@ -173,9 +174,9 @@ TableView::TableView(char const *buffer, unsigned size)
|
|||
char const *cellEnd = std::find(cellBegin, lineEnd, ',');
|
||||
cellNext = cellEnd + (cellEnd != lineEnd);
|
||||
|
||||
cells.push_back(cellBegin - buffer);
|
||||
cells.push_back(cellBegin - buffer); // Save the offset of the cell. The size of the cell is then the next offset minus 1 (the ',') minus this offset.
|
||||
}
|
||||
cells.push_back(lineEnd - buffer + 1);
|
||||
cells.push_back(lineEnd - buffer + 1); // Save the end of the last cell, must add 1 to skip a fake ',', because the code later assumes it's the start of a following cell.
|
||||
lines.push_back(std::make_pair(firstCell, cells.size() - firstCell));
|
||||
}
|
||||
}
|
||||
|
@ -192,12 +193,14 @@ void LineView::setError(unsigned index, char const *error)
|
|||
char const *cellBegin = table.buffer + cells[index];
|
||||
char const *cellEnd = table.buffer + (cells[index + 1] - 1);
|
||||
|
||||
// Print the location and contents of the cell along with the error message.
|
||||
char cellDesc[150];
|
||||
ssprintf(cellDesc, "Line %u, column %d \"%.*s\": ", lineNumber, index, std::min<unsigned>(100, cellEnd - cellBegin), cellBegin);
|
||||
table.parseError = QString::fromUtf8((std::string(cellDesc) + error).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// The cell does not exist. Print the location of where the cell would have been along with the error message.
|
||||
char cellDesc[50];
|
||||
ssprintf(cellDesc, "Line %u, column %d: ", lineNumber, index);
|
||||
table.parseError = QString::fromUtf8((std::string(cellDesc) + error).c_str());
|
||||
|
|
|
@ -91,8 +91,8 @@ class TableView
|
|||
public:
|
||||
TableView(char const *buffer, unsigned size);
|
||||
|
||||
bool isError() const { return !parseError.isEmpty(); }
|
||||
QString getError() const { return parseError; }
|
||||
bool isError() const { return !parseError.isEmpty(); } ///< If returning true, there was an error parsing the table.
|
||||
QString getError() const { return parseError; } ///< Returns an error message about what went wrong.
|
||||
|
||||
unsigned size() const { return lines.size(); }
|
||||
|
||||
|
@ -100,7 +100,7 @@ private:
|
|||
friend class LineView;
|
||||
char const * buffer;
|
||||
std::vector<uint32_t> cells;
|
||||
std::vector<std::pair<uint32_t, uint32_t> > lines;
|
||||
std::vector<std::pair<uint32_t, uint32_t> > lines; // List of pairs of offsets into the cells array and the number of cells in the line.
|
||||
QString parseError;
|
||||
std::string returnString;
|
||||
};
|
||||
|
@ -111,13 +111,16 @@ class LineView
|
|||
public:
|
||||
LineView(class TableView &table, unsigned lineNumber) : table(table), cells(&table.cells[table.lines.at(lineNumber).first]), numCells(table.lines.at(lineNumber).second), lineNumber(lineNumber) {} ///< This LineView is only valid for the lifetime of the TableView.
|
||||
|
||||
bool isError() const { return !table.parseError.isEmpty(); }
|
||||
bool isError() const { return !table.parseError.isEmpty(); } ///< If returning true, there was an error parsing the table.
|
||||
void setError(unsigned index, char const *error); ///< Only the first error is saved.
|
||||
|
||||
unsigned size() const { return numCells; }
|
||||
unsigned line() const { return lineNumber; }
|
||||
|
||||
/// Function for reading a bool (in the form of "0" or "1") in the line.
|
||||
bool b(unsigned index) { return i(index, 0, 1); }
|
||||
|
||||
/// Functions for reading integers in the line.
|
||||
int64_t i(unsigned index, int64_t min, int64_t max);
|
||||
uint32_t i8(unsigned index) { return i(index, INT8_MIN, INT8_MAX); }
|
||||
uint32_t u8(unsigned index) { return i(index, 0, UINT8_MAX); }
|
||||
|
@ -125,14 +128,23 @@ public:
|
|||
uint32_t u16(unsigned index) { return i(index, 0, UINT16_MAX); }
|
||||
uint32_t i32(unsigned index) { return i(index, INT32_MIN, INT32_MAX); }
|
||||
uint32_t u32(unsigned index) { return i(index, 0, UINT32_MAX); }
|
||||
|
||||
/// Function for reading a float in the line. (Should not use the result to affect game state.)
|
||||
float f(unsigned index, float min = -1.e30f, float max = 1.e30f);
|
||||
|
||||
/// Function for reading the raw contents of the cell as a string.
|
||||
std::string const &s(unsigned index);
|
||||
|
||||
// Function for reading enum values. The StringToEnum map should give a list of strings and corresponding enum values.
|
||||
template <typename Enum>
|
||||
Enum e(unsigned index, StringToEnumMap<Enum> const &map) { return (Enum)eu(index, map); }
|
||||
template <typename Enum, int N>
|
||||
Enum e(unsigned index, StringToEnum<Enum> const (&map)[N]) { return e(index, StringToEnumMap<Enum>::FromArray(map)); }
|
||||
|
||||
/// Returns the .pie file data referenced by the cell. May return NULL without error if the cell is "0" and accept0AsNULL is true.
|
||||
iIMDShape *imdShape(unsigned index, bool accept0AsNULL = false);
|
||||
|
||||
/// Returns the STATS * in the given list with the same name as this cell. May return NULL without error if the cell is "0" and accept0AsNULL is true.
|
||||
template <typename STATS>
|
||||
inline STATS *stats(unsigned index, STATS *asStats, unsigned numStats, bool accept0AsNULL = false)
|
||||
{
|
||||
|
@ -148,6 +160,7 @@ public:
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
/// Returns the STATS * in the given list with the same name as this cell. May return NULL without error if the cell is "0" and accept0AsNULL is true.
|
||||
template <typename STATS>
|
||||
inline STATS *stats(unsigned index, STATS **asStats, unsigned numStats, bool accept0AsNULL = false)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue