#include <TTable.h>
Public Member Functions | |
TTable () | |
TTable (const TTable &inTable) | |
virtual | ~TTable () |
TTable & | operator= (const TTable &inTable) |
void | Clear () |
unsigned int | GetNumColumns () const |
unsigned int | AddColumn (const vector< string > &col=vector< string >(0)) |
void | InsertColumn (const unsigned int colIndex, const vector< string > &col=vector< string >(0)) |
void | FillColumn (const unsigned int colIndex, const vector< string > &col, const unsigned int fromRowIndex=0) |
void | GetColumn (vector< string > &col, const unsigned int colIndex, const unsigned int fromRowIndex, unsigned int toRowIndex) |
void | ClearColumn (const unsigned int colIndex) |
void | DeleteColumn (const unsigned int colIndex) |
unsigned int | GetNumRows () const |
unsigned int | AddRow (const vector< string > &row=vector< string >(0)) |
unsigned int | InsertRow (const unsigned int atRowIndex, const vector< string > &row=vector< string >(0)) |
void | FillRow (const unsigned int rowIndex, const vector< string > &row, const unsigned int fromColIndex=0) |
void | GetRow (vector< string > &row, const unsigned int rowIndex, const unsigned int fromColIndex, unsigned int toColIndex) |
void | ClearRow (const unsigned int rowIndex) |
void | DeleteRow (const unsigned int rowIndex) |
string & | operator() (const unsigned int rowIndex, const unsigned int colIndex) |
const string & | operator() (const unsigned int rowIndex, const unsigned int colIndex) const |
int | Write (FileNavigator *fileNav, int &size) |
int | Read (Word index, FileNavigator *fileNav) |
Private Member Functions | |
void | CreateColumn (const unsigned int colIndex, const vector< string > &col=vector< string >(0)) |
unsigned int | IntRowIndex (const unsigned int rowIndex) const |
void | EnlargeRowMap (const unsigned int numRows) |
void | ReduceRowMap (const unsigned int numRows) |
void | MarkRowDeleted (const unsigned int rowIndex) |
void | UnMarkRowDeleted (const unsigned int rowIndex) |
Private Attributes | |
unsigned int | _numRows |
vector< vector< string > * > | _data |
unsigned int | _numDelRows |
vector< unsigned int > | _rowMap |
This class represents a two-dimensional table of cells. Each cell is represented by a text string. Tuples are horizontal table entities identified by tuple indices, which are unsigned integers ranging from zero to the number of tuples minus one. Columns are vertical table entities identified by column indices. The class provides methods for table construction and destruction, assignment operator, column and row based methods for addition, insertion, retrieval, update, deletion, cell based methods for update and retrieval and table printing.
TTable::TTable | ( | ) |
Constructs a tuple table.
Parameters: None
TTable::TTable | ( | const TTable & | inTable | ) |
Constructs a tuple table by copying from another table (copy constructor).
[in] | inTable | - reference to a table that will be copied to the newly constructed table |
TTable::~TTable | ( | ) | [virtual] |
Destructs a table.
Parameters: None
Copies a tuple table to another table (assignment operator).
[in] | inTable | - reference to the source table |
void TTable::Clear | ( | ) |
Deletes all the content from the table.
Parameters: None
unsigned int TTable::GetNumColumns | ( | ) | const [inline] |
Retrieves the number of columns in the table.
Parameters: None
unsigned int TTable::AddColumn | ( | const vector< string > & | col = vector< string >(0) |
) |
void TTable::InsertColumn | ( | const unsigned int | colIndex, | |
const vector< string > & | col = vector< string >(0) | |||
) |
Inserts a new column at the specified column index and shifts, to the right by one, the specified existing column and all columns after it.
[in] | colIndex | - the index of the column at which the new column is to be inserted |
[in] | col | - optional parameter that contains the values which are to be used to fill in the newly inserted column. If col is specified, filling starts at row index 0 and continues until size of col. If col is not specified, the newly inserted column is filled with empty values, where filling starts at row index 0 and ends at row index "number of rows - 1". |
If col is specified, the size of col must be less than or equal to the number of rows.
The column which comes, in order, before the column with name atColName, must be non-empty. This is to prevent creation of non-rectangular tables.
out_of_range | - if colIndex is greater than than the number of columns | |
out_of_range | - if size of col is greater than the number of rows | |
out_of_range | - if column, which comes, in order, before the column with name atColName, is empty. |
void TTable::FillColumn | ( | const unsigned int | colIndex, | |
const vector< string > & | col, | |||
const unsigned int | fromRowIndex = 0 | |||
) |
Inserts a new column at the specified column index and shifts, to the right by one, the specified existing column and all columns after it.
[in] | colIndex | - the index of the column at which the new column is to be inserted |
[in] | col | - contains the values which are to be used to fill in the newly inserted column. Filling starts at row index 0 and continues until size of col. |
The size of col must be less than or equal to the number of rows.
The column which comes, in order, before the column with name atColName, must be non-empty. This is to prevent creation of non-rectangular tables.
out_of_range | - if colIndex is greater than than the number of columns | |
out_of_range | - if size of col is greater than the number of rows | |
out_of_range | - if column, which comes, in order, before the column with name atColName, is empty. |
void TTable::GetColumn | ( | vector< string > & | col, | |
const unsigned int | colIndex, | |||
const unsigned int | fromRowIndex, | |||
unsigned int | toRowIndex | |||
) |
void TTable::ClearColumn | ( | const unsigned int | colIndex | ) |
Sets all cells in the column to empty string.
[in] | colName | - the name of the column |
Column with name colName must be present
EmptyValueException | - if colName is empty | |
NotFoundException | - if column with name colName does not exist |
void TTable::DeleteColumn | ( | const unsigned int | colIndex | ) |
Deletes a column from the table.
[in] | colName | - the name of the column |
Column with name colName must be present
EmptyValueException | - if colName is empty | |
NotFoundException | - if column with name colName does not exist |
unsigned int TTable::GetNumRows | ( | ) | const [inline] |
Retrieves the number of rows in the table.
Parameters: None
unsigned int TTable::AddRow | ( | const vector< string > & | row = vector< string >(0) |
) |
Adds a new row to the bottom end of the table. For an empty table, the number of inserted cells is equal to the number of table columns. For a non-empty table, the number of inserted cells is equal to the number of non-empty columns (this is in order to prevent creation of non-rectangular tables). The newly added row is, optionally, filled with values, starting at the first column.
[in] | row | - optional parameter that contains the values which are to be used to fill in the newly added row. Filling starts at the first column and continues until size of row. |
If table is not empty and row is specified, the size of row must be less than or equal to the number of non-empty columns. This is in order to prevent creation of non-rectangular tables.
If table is empty and row is specified, the size of row must be less than or equal to the number of columns.
EmptyContainerException | - if table has no columns. | |
out_of_range | - if table is not empty and size of row is greater than the number of non-empty columns. | |
out_of_range | - if table is empty and size of row is greater than the number of columns. |
unsigned int TTable::InsertRow | ( | const unsigned int | atRowIndex, | |
const vector< string > & | row = vector< string >(0) | |||
) |
Inserts a new row at the specified row index and shifts, down by one, the old row with the specified row index and all other rows below it. For an empty table, the number of inserted cells is equal to the number of table columns. For a non-empty table, the number of inserted cells is equal to the number of non-empty columns (this is in order to prevent creation of non-rectangular tables). The newly inserted row is optionally filled with values, starting at the first column.
[in] | atRowIndex | - index of the row at which the new row is to be inserted. Note: If atRowIndex is equal to the number of rows, the operation of this method is equivalent to AddRow(). |
[in] | row | - optional parameter that contains the values which are to be used to fill in the newly inserted row. Filling starts at the first column and continues until size of row. |
atRowIndex must be less than or equal to the number of table rows.
If table is not empty and row is specified, the size of row must be less than or equal to the number of non-empty columns. This is in order to prevent creation of non-rectangular tables.
If table is empty and row is specified, the size of row must be less than or equal to the number of columns.
Row indices of the rows which are below the inserted row are invalidated by being increased by 1.
EmptyContainerException | - if table has no columns. | |
out_of_range | - if atRowIndex is greater than the number of table rows. | |
out_of_range | - if table is not empty and size of row is greater than the number of non-empty columns. | |
out_of_range | - if table is empty and size of row is greater than the number of columns. |
void TTable::FillRow | ( | const unsigned int | rowIndex, | |
const vector< string > & | row, | |||
const unsigned int | fromColIndex = 0 | |||
) |
Fills, with values, a row at the specified row index, starting at the the first column.
[in] | rowIndex | - index of the row that is to be filled. |
[in] | row | - values which are to be used to fill in the row. Filling starts at the first column and continues until size of row. |
The size of row must be less than or equal to the number of non-empty columns. This is in order to prevent creation of non-rectangular tables.
out_of_range | - if rowIndex is greater than or equal to the number of table rows. | |
out_of_range | - if size of row is greater than the number of non-empty columns. |
void TTable::GetRow | ( | vector< string > & | row, | |
const unsigned int | rowIndex, | |||
const unsigned int | fromColIndex, | |||
unsigned int | toColIndex | |||
) |
Retrieves the values in the specified row.
[out] | row | - retrieved row values |
[in] | rowIndex | - index of the row which values are to be retrieved. |
[in] | fromColName | - optional parameter which specifies the row location of the first cell to be retrieved. If not specified the first column cell is used. |
[in] | toColName | - optional parameter which specifies the row location of the last cell to be retrieved. If not specified the last non-empty-column cell is used. |
If fromColName is specified, the column with name fromColName must be present and must be non-empty
If toColName is specified, the column with name toColName must be present and must be non-empty
If fromColName is different than toColName, it must come prior to it in the column order.
out_of_range | - if rowIndex is less than 0 or greater than or equal to the number of table rows. | |
NotFoundException | - If fromColName is specified and column with name fromColName does not exist | |
NotFoundException | - If toColName is specified and column with name toColName does not exist | |
out_of_range | - If fromColName is specified and column with name fromColName exists but is empty | |
out_of_range | - If toColName is specified and column with name toColName exists but is empty | |
out_of_range | - if fromColName is different than toColName and it comes after it in the column order. |
void TTable::ClearRow | ( | const unsigned int | rowIndex | ) |
Sets all cells in the row to empty string.
[in] | rowIndex | - index of the row that is to be cleared. |
out_of_range | - if rowIndex is less than 0 or greater than or equal to the number of table rows. |
void TTable::DeleteRow | ( | const unsigned int | rowIndex | ) |
Deletes a row with the specified row index.
[in] | rowIndex | - index of the row that is to be deleted. |
Row indices of the rows which are below the deleted row are invalidated by being reduced by 1.
out_of_range | - if rowIndex is less than 0 or greater than or equal to the number of table rows. |
string & TTable::operator() | ( | const unsigned int | rowIndex, | |
const unsigned int | colIndex | |||
) |
Updates a cell in the table.
[in] | rowIndex | - row index of the cell that is to be updated. |
[in] | colName | - the name of the column |
colName must be non-empty
Column with name colName must be present
out_of_range | - if rowIndex is less than 0 or greater than or equal to the number of table rows. | |
EmptyValueException | - if colName is empty | |
NotFoundException | - if column with name colName does not exist |
const string & TTable::operator() | ( | const unsigned int | rowIndex, | |
const unsigned int | colIndex | |||
) | const |
Retrieves a reference to the cell in the table.
[in] | rowIndex | - row index of the cell that is to be updated. |
[in] | colName | - the name of the column |
colName must be non-empty
Column with name colName must be present
out_of_range | - if rowIndex is less than 0 or greater than or equal to the number of table rows. | |
EmptyValueException | - if colName is empty | |
NotFoundException | - if column with name colName does not exist |
int TTable::Write | ( | FileNavigator * | fileNav, | |
int & | size | |||
) |
int TTable::Read | ( | Word | index, | |
FileNavigator * | fileNav | |||
) |
void TTable::CreateColumn | ( | const unsigned int | colIndex, | |
const vector< string > & | col = vector< string >(0) | |||
) | [private] |
unsigned int TTable::IntRowIndex | ( | const unsigned int | rowIndex | ) | const [inline, private] |
void TTable::EnlargeRowMap | ( | const unsigned int | numRows | ) | [private] |
void TTable::ReduceRowMap | ( | const unsigned int | numRows | ) | [private] |
void TTable::MarkRowDeleted | ( | const unsigned int | rowIndex | ) | [private] |
void TTable::UnMarkRowDeleted | ( | const unsigned int | rowIndex | ) | [private] |
unsigned int TTable::_numRows [private] |
vector<vector<string>*> TTable::_data [private] |
unsigned int TTable::_numDelRows [private] |
vector<unsigned int> TTable::_rowMap [private] |