TTable Class Reference

Private class that represents a table of tuples. More...

#include <TTable.h>

List of all members.

Public Member Functions

 TTable ()
 TTable (const TTable &inTable)
virtual ~TTable ()
TTableoperator= (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


Detailed Description

Private class that represents a table of tuples.

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.


Constructor & Destructor Documentation

TTable::TTable (  ) 

Constructs a tuple table.

Parameters: None

Returns:
Not applicable
Precondition:
None
Postcondition:
Constructed table has 0 rows and 0 columns.
Exceptions: None

TTable::TTable ( const TTable inTable  ) 

Constructs a tuple table by copying from another table (copy constructor).

Parameters:
[in] inTable - reference to a table that will be copied to the newly constructed table
Returns:
Not applicable
Precondition:
None
Postcondition:
Constructed table has the same content as the table referenced by inTable.
Exceptions: None

TTable::~TTable (  )  [virtual]

Destructs a table.

Parameters: None

Returns:
Not applicable
Precondition:
None
Postcondition:
None
Exceptions: None


Member Function Documentation

TTable & TTable::operator= ( const TTable inTable  ) 

Copies a tuple table to another table (assignment operator).

Parameters:
[in] inTable - reference to the source table
Returns:
Reference to the destination table
Precondition:
None
Postcondition:
Constructed table has the same content as the table referenced by inTable.
Exceptions: None

void TTable::Clear (  ) 

Deletes all the content from the table.

Parameters: None

Returns:
None
Precondition:
None
Postcondition:
Table has 0 rows and 0 columns.
Exceptions: None

unsigned int TTable::GetNumColumns (  )  const [inline]

Retrieves the number of columns in the table.

Parameters: None

Returns:
The number of columns in the table.
Precondition:
None
Postcondition:
None
Exceptions: 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.

Parameters:
[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".
Returns:
None
Precondition:
colIndex must be greater than 0 and less than or equal to the number of columns

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.

Postcondition:
If table is empty (0 rows) and col is specified, the number of rows is set to the size of col. Otherwise, the number of rows is unchanged.
Exceptions:
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.

Parameters:
[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.
Returns:
None
Precondition:
colIndex must be greater than 0 and less than the number of columns

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.

Postcondition:
If table is empty (0 rows) and col is specified, the number of rows is set to the size of col. Otherwise, the number of rows is unchanged.
Exceptions:
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.

Parameters:
[in] colName - the name of the column
Returns:
None
Precondition:
colName must be non-empty

Column with name colName must be present

Postcondition:
Column length is unchanged.
Exceptions:
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.

Parameters:
[in] colName - the name of the column
Returns:
None
Precondition:
colName must be non-empty

Column with name colName must be present

Postcondition:
The number of table columns is reduced by one.
Exceptions:
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

Returns:
The number of rows in the table.
Precondition:
None
Postcondition:
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.

Parameters:
[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.
Returns:
The new number of rows after the row addition.
Precondition:
Table must have at least one column, which can be empty.

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.

Postcondition:
The number of rows is increased by one.
Exceptions:
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.

Parameters:
[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.
Returns:
The new number of rows after the row insertion.
Precondition:
Table must have at least one column, which can be empty.

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.

Postcondition:
The number of rows is increased by one.

Row indices of the rows which are below the inserted row are invalidated by being increased by 1.

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

Parameters:
[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.
Returns:
None
Precondition:
rowIndex must be greater than 0 and less than the number of table rows.

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.

Postcondition:
None
Exceptions:
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.

Parameters:
[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.
Returns:
None
Precondition:
rowIndex must be greater than 0 and less than the number of table rows.

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.

Postcondition:
None
Exceptions:
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.

Parameters:
[in] rowIndex - index of the row that is to be cleared.
Returns:
None
Precondition:
rowIndex must be greater than 0 and less than the number of table rows.
Postcondition:
None
Exceptions:
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.

Parameters:
[in] rowIndex - index of the row that is to be deleted.
Returns:
None
Precondition:
rowIndex must be greater than 0 and less than the number of table rows.
Postcondition:
Number of table rows is reduced by 1.

Row indices of the rows which are below the deleted row are invalidated by being reduced by 1.

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

Parameters:
[in] rowIndex - row index of the cell that is to be updated.
[in] colName - the name of the column
Returns:
None
Precondition:
rowIndex must be greater than 0 and less than the number of table rows.

colName must be non-empty

Column with name colName must be present

Postcondition:
None
Exceptions:
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.

Parameters:
[in] rowIndex - row index of the cell that is to be updated.
[in] colName - the name of the column
Returns:
Constant reference to a cell in the table.
Precondition:
rowIndex must be greater than 0 and less than the number of table rows.

colName must be non-empty

Column with name colName must be present

Postcondition:
None
Exceptions:
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]


Member Data Documentation

unsigned int TTable::_numRows [private]

vector<vector<string>*> TTable::_data [private]

unsigned int TTable::_numDelRows [private]

vector<unsigned int> TTable::_rowMap [private]


The documentation for this class was generated from the following files:
Generated on Tue Apr 24 08:45:22 2007 for tables-v8.0 by  doxygen 1.5.1