#include <TTable.h>
Public Member Functions | |
TTable () | |
TTable (const TTable &inTable) | |
virtual | ~TTable () |
TTable & | operator= (const TTable &inTable) |
void | Clear () |
unsigned int | GetNumTuples () const |
unsigned int | AddTuple (const vector< string > &tuple=vector< string >(0)) |
void | InsertTuple (const unsigned int tupleIndex, const vector< string > &tuple=vector< string >(0)) |
void | InsertTuple (const unsigned int tupleIndex, vector< string >::const_iterator tupleBeg, vector< string >::const_iterator tupleEnd) |
void | FillTuple (const unsigned int tupleIndex, const vector< string > &tuple, const unsigned int fromColIndex=0) |
void | GetTuple (vector< string > &tuple, const unsigned int tupleIndex, const unsigned int fromColIndex, unsigned int toColIndex) |
const vector< string > & | GetTuple (const unsigned int tupleIndex) |
void | ClearTuple (const unsigned int tupleIndex) |
void | DeleteTuple (const unsigned int tupleIndex) |
unsigned int | GetNumColumns () const |
unsigned int | AddColumn (const vector< string > &col=vector< string >(0)) |
unsigned int | InsertColumn (const unsigned int atColIndex, const vector< string > &col=vector< string >(0)) |
void | InsertColumn (const unsigned int atColIndex, vector< string >::const_iterator colBeg, vector< string >::const_iterator colEnd) |
void | FillColumn (const unsigned int colIndex, const vector< string > &col, const unsigned int fromTupleIndex=0) |
void | FillColumn (const unsigned int colIndex, vector< string >::const_iterator colBeg, vector< string >::const_iterator colEnd, const unsigned int fromTupleIndex=0) |
void | GetColumn (vector< string > &col, const unsigned int colIndex, const unsigned int fromTupleIndex, unsigned int toTupleIndex) |
void | ClearColumn (const unsigned int colIndex) |
void | DeleteColumn (const unsigned int colIndex) |
string & | operator() (const unsigned int tupleIndex, const unsigned int colIndex) |
const string & | operator() (const unsigned int tupleIndex, const unsigned int colIndex) const |
int | Write (Serializer *ser, unsigned int &size) |
int | Read (UInt32 index, Serializer *ser) |
Private Member Functions | |
unsigned int | IntColIndex (const unsigned int colIndex) const |
void | EnlargeColMap (const unsigned int numCols) |
void | ReduceColMap (const unsigned int numCols) |
void | MarkColDeleted (const unsigned int colIndex) |
void | UnMarkColDeleted (const unsigned int colIndex) |
Private Attributes | |
unsigned int | _numCols |
vector< vector< string > * > | _tuples |
unsigned int | _numDelCols |
vector< unsigned int > | _delColMap |
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. Tuples are vertical table entities identified by tuple indices. The class provides methods for table construction and destruction, assignment operator, tuple and column 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::GetNumTuples | ( | ) | const [inline] |
Retrieves the number of tuples in the table.
Parameters: None
unsigned int TTable::AddTuple | ( | const vector< string > & | tuple = vector< string >(0) |
) |
void TTable::InsertTuple | ( | const unsigned int | tupleIndex, | |
const vector< string > & | tuple = vector< string >(0) | |||
) |
Inserts a new tuple at the specified tuple index and shifts, to the right by one, the specified existing tuple and all tuples after it.
[in] | tupleIndex | - the index of the tuple at which the new tuple is to be inserted |
[in] | tuple | - optional parameter that contains the values which are to be used to fill in the newly inserted tuple. If tuple is specified, filling starts at column index 0 and continues until size of tuple. If tuple is not specified, the newly inserted tuple is filled with empty values, where filling starts at column index 0 and ends at column index "number of columns - 1". |
If tuple is specified, the size of tuple must be less than or equal to the number of columns.
The tuple which comes, in order, before the tuple with name atColName, must be non-empty. This is to prevent creation of non-rectangular tables.
out_of_range | - if tupleIndex is greater than than the number of tuples | |
out_of_range | - if size of tuple is greater than the number of columns | |
out_of_range | - if tuple, which comes, in order, before the tuple with name atColName, is empty. |
void TTable::InsertTuple | ( | const unsigned int | tupleIndex, | |
vector< string >::const_iterator | tupleBeg, | |||
vector< string >::const_iterator | tupleEnd | |||
) |
void TTable::FillTuple | ( | const unsigned int | tupleIndex, | |
const vector< string > & | tuple, | |||
const unsigned int | fromColIndex = 0 | |||
) |
Inserts a new tuple at the specified tuple index and shifts, to the right by one, the specified existing tuple and all tuples after it.
[in] | tupleIndex | - the index of the tuple at which the new tuple is to be inserted |
[in] | tuple | - contains the values which are to be used to fill in the newly inserted tuple. Filling starts at column index 0 and continues until size of tuple. |
The size of tuple must be less than or equal to the number of columns.
The tuple which comes, in order, before the tuple with name atColName, must be non-empty. This is to prevent creation of non-rectangular tables.
out_of_range | - if tupleIndex is greater than than the number of tuples | |
out_of_range | - if size of tuple is greater than the number of columns | |
out_of_range | - if tuple, which comes, in order, before the tuple with name atColName, is empty. |
void TTable::GetTuple | ( | vector< string > & | tuple, | |
const unsigned int | tupleIndex, | |||
const unsigned int | fromColIndex, | |||
unsigned int | toColIndex | |||
) |
const vector< string > & TTable::GetTuple | ( | const unsigned int | tupleIndex | ) |
void TTable::ClearTuple | ( | const unsigned int | tupleIndex | ) |
Sets all cells in the tuple to empty string.
[in] | colName | - the name of the tuple |
Tuple with name colName must be present
EmptyValueException | - if colName is empty | |
NotFoundException | - if tuple with name colName does not exist |
void TTable::DeleteTuple | ( | const unsigned int | tupleIndex | ) |
Deletes a tuple from the table.
[in] | colName | - the name of the tuple |
Tuple with name colName must be present
EmptyValueException | - if colName is empty | |
NotFoundException | - if tuple with name colName does not exist |
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) |
) |
Adds a new column to the bottom end of the table. For an empty table, the number of inserted cells is equal to the number of table tuples. For a non-empty table, the number of inserted cells is equal to the number of non-empty tuples (this is in order to prevent creation of non-rectangular tables). The newly added column is, optionally, filled with values, starting at the first tuple.
[in] | column | - optional parameter that contains the values which are to be used to fill in the newly added column. Filling starts at the first tuple and continues until size of column. |
If table is not empty and column is specified, the size of column must be less than or equal to the number of non-empty tuples. This is in order to prevent creation of non-rectangular tables.
If table is empty and column is specified, the size of column must be less than or equal to the number of tuples.
EmptyContainerException | - if table has no tuples. | |
out_of_range | - if table is not empty and size of column is greater than the number of non-empty tuples. | |
out_of_range | - if table is empty and size of column is greater than the number of tuples. |
unsigned int TTable::InsertColumn | ( | const unsigned int | atColIndex, | |
const vector< string > & | col = vector< string >(0) | |||
) |
Inserts a new column at the specified column index and shifts, down by one, the old column with the specified column index and all other columns below it. For an empty table, the number of inserted cells is equal to the number of table tuples. For a non-empty table, the number of inserted cells is equal to the number of non-empty tuples (this is in order to prevent creation of non-rectangular tables). The newly inserted column is optionally filled with values, starting at the first tuple.
[in] | atColIndex | - index of the column at which the new column is to be inserted. Note: If atColIndex is equal to the number of columns, the operation of this method is equivalent to AddRow(). |
[in] | column | - optional parameter that contains the values which are to be used to fill in the newly inserted column. Filling starts at the first tuple and continues until size of column. |
atColIndex must be less than or equal to the number of table columns.
If table is not empty and column is specified, the size of column must be less than or equal to the number of non-empty tuples. This is in order to prevent creation of non-rectangular tables.
If table is empty and column is specified, the size of column must be less than or equal to the number of tuples.
Row indices of the columns which are below the inserted column are invalidated by being increased by 1.
EmptyContainerException | - if table has no tuples. | |
out_of_range | - if atColIndex is greater than the number of table columns. | |
out_of_range | - if table is not empty and size of column is greater than the number of non-empty tuples. | |
out_of_range | - if table is empty and size of column is greater than the number of tuples. |
void TTable::InsertColumn | ( | const unsigned int | atColIndex, | |
vector< string >::const_iterator | colBeg, | |||
vector< string >::const_iterator | colEnd | |||
) |
void TTable::FillColumn | ( | const unsigned int | colIndex, | |
const vector< string > & | col, | |||
const unsigned int | fromTupleIndex = 0 | |||
) |
Fills, with values, a column at the specified column index, starting at the the first tuple.
[in] | colIndex | - index of the column that is to be filled. |
[in] | column | - values which are to be used to fill in the column. Filling starts at the first tuple and continues until size of column. |
The size of column must be less than or equal to the number of non-empty tuples. This is in order to prevent creation of non-rectangular tables.
out_of_range | - if colIndex is greater than or equal to the number of table columns. | |
out_of_range | - if size of column is greater than the number of non-empty tuples. |
void TTable::FillColumn | ( | const unsigned int | colIndex, | |
vector< string >::const_iterator | colBeg, | |||
vector< string >::const_iterator | colEnd, | |||
const unsigned int | fromTupleIndex = 0 | |||
) |
void TTable::GetColumn | ( | vector< string > & | col, | |
const unsigned int | colIndex, | |||
const unsigned int | fromTupleIndex, | |||
unsigned int | toTupleIndex | |||
) |
Retrieves the values in the specified column.
[out] | column | - retrieved column values |
[in] | colIndex | - index of the column which values are to be retrieved. |
[in] | fromColName | - optional parameter which specifies the column location of the first cell to be retrieved. If not specified the first tuple cell is used. |
[in] | toColName | - optional parameter which specifies the column location of the last cell to be retrieved. If not specified the last non-empty-tuple cell is used. |
If fromColName is specified, the tuple with name fromColName must be present and must be non-empty
If toColName is specified, the tuple 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 tuple order.
out_of_range | - if colIndex is less than 0 or greater than or equal to the number of table columns. | |
NotFoundException | - If fromColName is specified and tuple with name fromColName does not exist | |
NotFoundException | - If toColName is specified and tuple with name toColName does not exist | |
out_of_range | - If fromColName is specified and tuple with name fromColName exists but is empty | |
out_of_range | - If toColName is specified and tuple with name toColName exists but is empty | |
out_of_range | - if fromColName is different than toColName and it comes after it in the tuple order. |
void TTable::ClearColumn | ( | const unsigned int | colIndex | ) |
Sets all cells in the column to empty string.
[in] | colIndex | - index of the column that is to be cleared. |
out_of_range | - if colIndex is less than 0 or greater than or equal to the number of table columns. |
void TTable::DeleteColumn | ( | const unsigned int | colIndex | ) |
Deletes a column with the specified column index.
[in] | colIndex | - index of the column that is to be deleted. |
Row indices of the columns which are below the deleted column are invalidated by being reduced by 1.
out_of_range | - if colIndex is less than 0 or greater than or equal to the number of table columns. |
string & TTable::operator() | ( | const unsigned int | tupleIndex, | |
const unsigned int | colIndex | |||
) |
Updates a cell in the table.
[in] | colIndex | - column index of the cell that is to be updated. |
[in] | colName | - the name of the tuple |
colName must be non-empty
Tuple with name colName must be present
out_of_range | - if colIndex is less than 0 or greater than or equal to the number of table columns. | |
EmptyValueException | - if colName is empty | |
NotFoundException | - if tuple with name colName does not exist |
const string & TTable::operator() | ( | const unsigned int | tupleIndex, | |
const unsigned int | colIndex | |||
) | const |
Retrieves a reference to the cell in the table.
[in] | colIndex | - column index of the cell that is to be updated. |
[in] | colName | - the name of the tuple |
colName must be non-empty
Tuple with name colName must be present
out_of_range | - if colIndex is less than 0 or greater than or equal to the number of table columns. | |
EmptyValueException | - if colName is empty | |
NotFoundException | - if tuple with name colName does not exist |
int TTable::Write | ( | Serializer * | ser, | |
unsigned int & | size | |||
) |
int TTable::Read | ( | UInt32 | index, | |
Serializer * | ser | |||
) |
unsigned int TTable::IntColIndex | ( | const unsigned int | colIndex | ) | const [inline, private] |
void TTable::EnlargeColMap | ( | const unsigned int | numCols | ) | [private] |
void TTable::ReduceColMap | ( | const unsigned int | numCols | ) | [private] |
void TTable::MarkColDeleted | ( | const unsigned int | colIndex | ) | [private] |
void TTable::UnMarkColDeleted | ( | const unsigned int | colIndex | ) | [private] |
unsigned int TTable::_numCols [private] |
vector<vector<string>*> TTable::_tuples [private] |
unsigned int TTable::_numDelCols [private] |
vector<unsigned int> TTable::_delColMap [private] |