Class StringTable

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class StringTable

Summary
Public Methods
StringTable(text, rowSeparator, columnSeparator)
inline bool valid() const
inline bool empty() const
void clear()
const string& get(row, column) const
inline const string& get(column) const
const string& getById(id, column) const
inline const string& getById(id, column) const
const int findId(rowId) const
IntList getIds() const
inline bool idExists(rowId) const
inline bool idExists(rowId) const
inline int getRowCount() const
inline int getColumnCount() const
StringTable& set(row, column, value)
inline StringTable& set(column, value)
static inline void treatIdZeroAsRow1(yes)
StringTable& setById(id, column, value, createRowIfNew)
inline StringTable& setById(id, column, value, createRowIfNew)
bool setRowCount(newRowCount)
bool setColumnCount(newColumnCount)
bool transpose()
StringTable& addColumn(columns)
StringTable& addRow(rows)
string toString(rowSeparator, columnSeparator) const
bool fromString(text, rowSeparator, columnSeparator)
Private Properties

#include <StringTable.h >

Summary

Contain a simple table of values that readily converts to/from a string.

The string contains CSV values in rows, separated by |.

Public Methods

StringTable(text, rowSeparator, columnSeparator)

const string& text

the string representation of the table

Default value: ""

const string& rowSeparator

the text that separates rows; default is |

Default value: "|"

const string& columnSeparator

the text that separates columns; default is ,

Default value: ","


Construct a StringTable. If text is provided, the table is populated from that

string (see fromString()).

inline bool valid() const

Determine if this instance of StringTable is valid.  A table is invalid when it

has no rows and no columns.

inline bool empty() const

Determine if this instance of StringTable is empty.  A table is empty when it

has no rows and no columns.

void clear()

Reset this instance to empty.

const string& get(row, column) const

int row

the row (1+) of the table where the value resides

int column

position of column (1+) in the specified row of table


Pull a string value out of the table at the row and column specified.  Fetching a

value outside the defined table returns null string.

Return value: the value at the position specified

inline const string& get(column) const

int column

position of column (1+) in first/only row of table


If there's only one row in the table (it's a vector of data), this is

shorthand for pulling a column string value. Fetching a value outside the defined

table returns null string.

Return value: the value at the position specified

const string& getById(id, column) const

const string& id

row id (id is first value of line)

int column

position of column (1+) in first/only row of table


If the first value on a row is the id, locate by row by that id and column.

Fetching a value outside the defined table returns null string.

Return value: the value at the position specified

inline const string& getById(id, column) const

int id

row id (id is first value of line)

int column

position of column (1+) in first/only row of table


If the first value on a row is the id, locate by row by that id and column.

Fetching a value outside the defined table returns null string.

Return value: the value at the position specified

const int findId(rowId) const

const string& rowId


If the first value on a row is the id, locate by row by that id and column.

Fetching a value outside the defined table returns null string.

@param id - row id (id is first value of line)

Return value: the row number for that id or 0 if id not found

IntList getIds() const

Get the list of valid ids from the records

Return value: list of row ids

inline bool idExists(rowId) const

const string& rowId


Determine if a row id exists

@param id - row id (id is first value of line)

Return value: the row number for that id or 0 if id not found

inline bool idExists(rowId) const

long rowId


Determine if a row id exists

@param id - row id (id is first value of line)

Return value: the row number for that id or 0 if id not found

inline int getRowCount() const

Get the known size of the table in rows.

inline int getColumnCount() const

Get the known size of the table in columns.

StringTable& set(row, column, value)

int row

the row (1+) of the table where the value resides

int column

position of column (1+) in the specified row of table

const string& value

the value to put at the location


Set a value at a row and column position in the table.

Note that if the position is outside the current table, then the table is

expanded.  By doing this, the table is auto-sizing.

Return value: the instance of this StringTable with the new value set

inline StringTable& set(column, value)

int column

position of column (1+) in the specified row of table

const string& value

the value to put at the location


Set a value at a column position in the table in the first/only row.

Note that if the position is outside the current table, then the table is

expanded.  By doing this, the table is auto-sizing.

@param row - the row (1+) of the table where the value resides

Return value: the instance of this StringTable with the new value set

static inline void treatIdZeroAsRow1(yes)

bool yes

true to treat id 0 as first row, false to not do so

Default value: true


If setById()/getById() is given rowId=0, it will return no value by default since

most applications have no row ids allowed as 0.  So, if your application would like

to treat rowId=0 as the first row of the table, set that here.

StringTable& setById(id, column, value, createRowIfNew)

const string& id

row id (id is first value of line)

int column

position of column (1+) in first/only row of table

const string& value

the value to put at the location

bool createRowIfNew

if true, a row is appended with the rowId if rowId not found

Default value: false


If the first value on a row is the id, locate by row by that id and column

and then set the provided value.

Fetching a value outside the defined table returns null string.

Return value: the value at the position specified

inline StringTable& setById(id, column, value, createRowIfNew)

int id

row id (id is first value of line)

int column

position of column (1+) in first/only row of table

const string& value

the value to put at the location

bool createRowIfNew

if true, a row is appended with the rowId if rowId not found

Default value: false


If the first value on a row is the id, locate by row by that id and column

and then set the provided value.

Fetching a value outside the defined table returns null string.

Return value: the value at the position specified

bool setRowCount(newRowCount)

int newRowCount

the new height (1+) of the table


Set the height of the table in rows.

Return value: true if table resized

bool setColumnCount(newColumnCount)

int newColumnCount

the new width (1+) of the table


Set the width of the table in columns.

Return value: true if table resized

bool transpose()

Transpose the table (swap columns and row)

Return value: transposed table; return false if table is invalid

StringTable& addColumn(columns)

const StringTable& columns


Add a column or columns to the table. Basically, the new table is added to the

right of the current table, making it wider. If the new table has more rows, then

the existing table will become taller.

Return value: the updated table

StringTable& addRow(rows)

const StringTable& rows


Add a row or rows to the table. Basically, the new table is added under the

current table, making it taller. If the new table has more columns, then

the existing table will become wider.

Return value: the updated table

string toString(rowSeparator, columnSeparator) const

const string& rowSeparator

the text that separates rows; default is |

Default value: "|"

const string& columnSeparator

the text that separates columns; default is ,

Default value: ","


Convert the StringTable to a string.  Columns are separated by commas; rows

are separated by |.  If any values contain either of these symbols, they are

escaped.

Return value: a string representing the table

bool fromString(text, rowSeparator, columnSeparator)

const string& text

the string representation of the table

const string& rowSeparator

the text that separates rows; default is |

Default value: "|"

const string& columnSeparator

the text that separates columns; default is ,

Default value: ","


Convert a string into a StringTable table.

Return value: true if table successfully converted from the string

Private Properties

int rowCount

int columnCount

vector < table

static bool idZeroIsFirstRow