CARMA C++
carma::dbms::Table Class Reference

Class to mimic a db table The Table class is meant to mimic a database table. More...

#include <carma/dbms/Table.h>

Public Types

enum  ColumnType {
  INT_COLUMN_TYPE, SHORT_COLUMN_TYPE, FLOAT_COLUMN_TYPE, DOUBLE_COLUMN_TYPE,
  STRING_COLUMN_TYPE, BIGINT_COLUMN_TYPE, DECIMAL_COLUMN_TYPE
}
 describes the type of data a column holds. More...
 

Public Member Functions

void addBigIntColumn (const Column< long long > &col)
 add a big (64 bit) int column to the table More...
 
template<typename T >
void addColumn (const Column< T > &col)
 template function for adding columns to tables More...
 
void addDecimalColumn (const Column< std::string > &col)
 add a decimal column to the table More...
 
void addDoubleColumn (const Column< double > &col)
 add a double column to the table More...
 
void addFloatColumn (const Column< float > &col)
 add a float column to the table More...
 
void addIntColumn (const Column< int > &col)
 add an int column to the table More...
 
void addShortColumn (const Column< short > &col)
 add a short column to the table More...
 
void addStringColumn (const Column< std::string > &col)
 add a string column to the table More...
 
unsigned columnCount () const
 get the number of columns More...
 
carma::dbms::Table createSubTable (const std::vector< std::string > &colNames, const std::string &tableName="subtable") const
 create a table from a subset of columns in this table More...
 
carma::dbms::Column< long long > getBigIntColumn (const unsigned &index) const
 get a column containing big (64 bit) int values More...
 
carma::dbms::Column< long long > getBigIntColumn (const std::string &columnName) const
 get a column containing big (64 bit) int values More...
 
template<typename T >
carma::dbms::Column< T > getColumn (const unsigned &index) const
 template function for getting columns for generic type More...
 
template<typename T >
carma::dbms::Column< T > getColumn (const std::string &columnName) const
 template function for getting columns for generic type More...
 
std::vector< std::string > getColumnNames () const
 get the column names in this table in the order in which the columns were added More...
 
std::vector< ColumnTypegetColumnTypes () const
 get the column types in this table in the order in which the columns were added More...
 
carma::dbms::Column< std::string > getDecimalColumn (const unsigned &index) const
 get a column containing decimal values More...
 
carma::dbms::Column< std::string > getDecimalColumn (const std::string &columnName) const
 get a column containing decimal values More...
 
carma::dbms::Column< double > getDoubleColumn (const unsigned &index) const
 get a column containing double values More...
 
carma::dbms::Column< double > getDoubleColumn (const std::string &columnName) const
 get a column containing double values More...
 
carma::dbms::Column< float > getFloatColumn (const unsigned &index) const
 get a column containing float values More...
 
carma::dbms::Column< float > getFloatColumn (const std::string &columnName) const
 get a column containing float values More...
 
carma::dbms::Column< int > getIntColumn (const unsigned &index) const
 get a column containing integer values More...
 
carma::dbms::Column< int > getIntColumn (const std::string &columnName) const
 get a column containing int values More...
 
std::string getName () const
 get the table name More...
 
carma::dbms::Column< short > getShortColumn (const unsigned &index) const
 get a column containing short values More...
 
carma::dbms::Column< short > getShortColumn (const std::string &columnName) const
 get a column containing short values More...
 
carma::dbms::Column< std::string > getStringColumn (const unsigned &index) const
 get a column containing string values More...
 
carma::dbms::Column< std::string > getStringColumn (const std::string &columnName) const
 get a column containing string values More...
 
unsigned rowCount () const
 get the number of rows in the table More...
 
void setName (const std::string &name)
 set the table name More...
 
 Table (const std::string &name)
 Table constructor. More...
 
std::string toString () const
 get a string representation of the table More...
 
 ~Table ()
 Table destructor. More...
 

Static Public Member Functions

static std::string columnType2String (const ColumnType &ctype)
 get a string representation of the column type More...
 

Protected Member Functions

void addNewColumn_ (const unsigned int &columnSize, const std::string &columnName)
 check that the new column has the correct size and set the number in the table More...
 
void getColumn_ (const unsigned &index, const ColumnType &colType) const
 checks to run when get*Column is called More...
 
void getColumn_ (const std::string &columnName) const
 

Protected Attributes

std::vector
< carma::dbms::Column< long
long > > 
bigIntColumns_
 
std::map< std::string, unsigned > colNames2Indices_
 
std::vector< std::string > colNames_
 
std::vector< ColumnTypecolTypesVector_
 
std::vector
< carma::dbms::Column
< std::string > > 
decimalColumns_
 
std::vector
< carma::dbms::Column< double > > 
doubleColumns_
 
std::vector
< carma::dbms::Column< float > > 
floatColumns_
 
std::vector< int > indicesVector_
 
std::vector
< carma::dbms::Column< int > > 
intColumns_
 
std::string name_
 
unsigned nRows_
 
std::vector
< carma::dbms::Column< short > > 
shortColumns_
 
std::vector
< carma::dbms::Column
< std::string > > 
stringColumns_
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (::std::ostream &os, const carma::dbms::Table &table)
 

Detailed Description

Class to mimic a db table The Table class is meant to mimic a database table.

Tables are composed of Columns of various types (e.g., StringColumns, IntegerColumns). Columns are added to a Table object using the addColumn() method. Non-rectangular Tables are not supported; all columns must contain the same number of elements (rows). Column names are required to be unique. Column and row indices are zero-based (as in Java Swing JTable related classes).

See Also
carma::dbms::Column

Definition at line 34 of file Table.h.

Member Enumeration Documentation

describes the type of data a column holds.

Note: DECIMALs aren't meant to be used in tables. Support for them is limited to dealing with the way mysql 5 returns some function results.

Definition at line 42 of file Table.h.

Constructor & Destructor Documentation

carma::dbms::Table::Table ( const std::string &  name)

Table constructor.

Parameters
namethe table name
carma::dbms::Table::~Table ( )

Table destructor.

Member Function Documentation

void carma::dbms::Table::addBigIntColumn ( const Column< long long > &  col)

add a big (64 bit) int column to the table

Parameters
colthe column to add
Exceptions
carma::util::IllegalArgumentExceptionif the length of the candidate column is different from the number of rows in the table or if the name of the candidate column matches that of a column which already exists in the table
Deprecated:
template<typename T >
void carma::dbms::Table::addColumn ( const Column< T > &  col)

template function for adding columns to tables

Parameters
colthe column to add
Exceptions
carma::util::IllegalArgumentExceptionif the length of the candidate column is different from the number of rows in the table or if the name of the candidate column matches that of a column which already exists in the table

Definition at line 510 of file Table.h.

void carma::dbms::Table::addDecimalColumn ( const Column< std::string > &  col)

add a decimal column to the table

Parameters
colthe column to add
Exceptions
carma::util::IllegalArgumentExceptionif the length of the candidate column is different from the number of rows in the table or if the name of the candidate column matches that of a column which already exists in the table
Deprecated:
void carma::dbms::Table::addDoubleColumn ( const Column< double > &  col)

add a double column to the table

Parameters
colthe column to add
Exceptions
carma::util::IllegalArgumentExceptionif the length of the candidate column is different from the number of rows in the table or if the name of the candidate column matches that of a column which already exists in the table
Deprecated:
void carma::dbms::Table::addFloatColumn ( const Column< float > &  col)

add a float column to the table

Parameters
colthe column to add
Exceptions
carma::util::IllegalArgumentExceptionif the length of the candidate column is different from the number of rows in the table or if the name of the candidate column matches that of a column which already exists in the table
Deprecated:
void carma::dbms::Table::addIntColumn ( const Column< int > &  col)

add an int column to the table

Parameters
colthe column to add
Exceptions
carma::util::IllegalArgumentExceptionif the length of the candidate column is different from the number of rows in the table or if the name of the candidate column matches that of a column which already exists in the table
Deprecated:
void carma::dbms::Table::addNewColumn_ ( const unsigned int &  columnSize,
const std::string &  columnName 
)
protected

check that the new column has the correct size and set the number in the table

void carma::dbms::Table::addShortColumn ( const Column< short > &  col)

add a short column to the table

Parameters
colthe column to add
Exceptions
carma::util::IllegalArgumentExceptionif the length of the candidate column is different from the number of rows in the table or if the name of the candidate column matches that of a column which already exists in the table
Deprecated:
void carma::dbms::Table::addStringColumn ( const Column< std::string > &  col)

add a string column to the table

Parameters
colthe column to add
Exceptions
carma::util::IllegalArgumentExceptionif the length of the candidate column is different from the number of rows in the table or if the name of the candidate column matches that of a column which already exists in the table
Deprecated:
unsigned carma::dbms::Table::columnCount ( ) const

get the number of columns

Returns
the number of columns in the table

Definition at line 82 of file Table.h.

static std::string carma::dbms::Table::columnType2String ( const ColumnType ctype)
static

get a string representation of the column type

carma::dbms::Table carma::dbms::Table::createSubTable ( const std::vector< std::string > &  colNames,
const std::string &  tableName = "subtable" 
) const

create a table from a subset of columns in this table

Parameters
colNamesthe columnNames to extract from this table and place into the new table
carma::dbms::Column<long long> carma::dbms::Table::getBigIntColumn ( const unsigned &  index) const

get a column containing big (64 bit) int values

Parameters
indexthe zero-based column index
Returns
the big int column
Exceptions
out_of_rangeif index >= number of columns
carma::util::IllegalArgumentExceptionif column at index is not a BigIntColumn
carma::dbms::Column<long long> carma::dbms::Table::getBigIntColumn ( const std::string &  columnName) const

get a column containing big (64 bit) int values

Parameters
columnNamename of the column to get
Returns
the big int column
Exceptions
carma::util::IllegalArgumentExceptionif the column with the specified name is not a BigIntColumn or if the column name doesn't exist
Deprecated:
template<typename T >
carma::dbms::Column< T > carma::dbms::Table::getColumn ( const unsigned &  index) const

template function for getting columns for generic type

Parameters
indexthe zero-based column index
Returns
column
Exceptions
out_of_rangeif index >= number of columns

Definition at line 593 of file Table.h.

template<typename T >
carma::dbms::Column< T > carma::dbms::Table::getColumn ( const std::string &  columnName) const

template function for getting columns for generic type

Parameters
columnNamename of the column to get
Returns
column
the big int column
Exceptions
carma::util::IllegalArgumentExceptionif the column name doesn't exist

Definition at line 585 of file Table.h.

void carma::dbms::Table::getColumn_ ( const unsigned &  index,
const ColumnType colType 
) const
protected

checks to run when get*Column is called

std::vector<std::string> carma::dbms::Table::getColumnNames ( ) const

get the column names in this table in the order in which the columns were added

Returns
vector of column names

Definition at line 370 of file Table.h.

std::vector< ColumnType > carma::dbms::Table::getColumnTypes ( ) const

get the column types in this table in the order in which the columns were added

Returns
vector of column types

Definition at line 361 of file Table.h.

carma::dbms::Column<std::string> carma::dbms::Table::getDecimalColumn ( const unsigned &  index) const

get a column containing decimal values

Parameters
indexthe zero-based column index
Returns
the decimal column
Exceptions
out_of_rangeif index >= number of columns
carma::util::IllegalArgumentExceptionif column at index is not a DecimalColumn
Deprecated:
carma::dbms::Column<std::string> carma::dbms::Table::getDecimalColumn ( const std::string &  columnName) const

get a column containing decimal values

Parameters
columnNamename of the column to get
Returns
the decimal column
Exceptions
carma::util::IllegalArgumentExceptionif the column with the specified name is not a DecimalColumn or if the column name doesn't exist
Deprecated:
carma::dbms::Column<double> carma::dbms::Table::getDoubleColumn ( const unsigned &  index) const

get a column containing double values

Parameters
indexthe zero-based column index
Returns
the double column
Exceptions
out_of_rangeif index >= number of columns
carma::util::IllegalArgumentExceptionif column at index is not a DoubleColumn
Deprecated:
carma::dbms::Column<double> carma::dbms::Table::getDoubleColumn ( const std::string &  columnName) const

get a column containing double values

Parameters
columnNamename of the column to get
Returns
the double column
Exceptions
carma::util::IllegalArgumentExceptionif the column with the specified name is not a DoubleColumn or if the column name doesn't exist
Deprecated:
carma::dbms::Column<float> carma::dbms::Table::getFloatColumn ( const unsigned &  index) const

get a column containing float values

Parameters
indexthe zero-based column index
Returns
the float column
Exceptions
out_of_rangeif index >= number of columns
carma::util::IllegalArgumentExceptionif column at index is not a FloatColumn
Deprecated:
carma::dbms::Column<float> carma::dbms::Table::getFloatColumn ( const std::string &  columnName) const

get a column containing float values

Parameters
columnNamename of the column to get
Returns
the float column
Exceptions
carma::util::IllegalArgumentExceptionif column with the specified name is not a FloatColumn or if the column name doesn't exist
Deprecated:
carma::dbms::Column<int> carma::dbms::Table::getIntColumn ( const unsigned &  index) const

get a column containing integer values

Parameters
indexthe zero-based column index
Returns
the integer column
Exceptions
out_of_rangeif index >= number of columns
carma::util::IllegalArgumentExceptionif column at index is not an IntegerColumn
Deprecated:
carma::dbms::Column<int> carma::dbms::Table::getIntColumn ( const std::string &  columnName) const

get a column containing int values

Parameters
columnNamename of the column to get
Returns
the int column
Exceptions
carma::util::IllegalArgumentExceptionif the column with the specified name is not a IntColumn or if the column name doesn't exist
Deprecated:
std::string carma::dbms::Table::getName ( ) const

get the table name

Returns
the table name

Definition at line 70 of file Table.h.

carma::dbms::Column<short> carma::dbms::Table::getShortColumn ( const unsigned &  index) const

get a column containing short values

Parameters
indexthe zero-based column index
Returns
the short column
Exceptions
out_of_rangeif index >= number of columns
carma::util::IllegalArgumentExceptionif column at index is not a ShortColumn
Deprecated:
carma::dbms::Column<short> carma::dbms::Table::getShortColumn ( const std::string &  columnName) const

get a column containing short values

Parameters
columnNamename of the column to get
Returns
the short column
Exceptions
carma::util::IllegalArgumentExceptionif the column with the specified name is not a ShortColumn or if the column name doesn't exist
Deprecated:
carma::dbms::Column<std::string> carma::dbms::Table::getStringColumn ( const unsigned &  index) const

get a column containing string values

Parameters
indexthe zero-based column index
Returns
the string column
Exceptions
out_of_rangeif index >= number of columns
carma::util::IllegalArgumentExceptionif column at index is not a StringColumn
Deprecated:
carma::dbms::Column<std::string> carma::dbms::Table::getStringColumn ( const std::string &  columnName) const

get a column containing string values

Parameters
columnNamename of the column to get
Returns
the string column
Exceptions
carma::util::IllegalArgumentExceptionif the column with the specified name is not a StringColumn or if the column name doesn't exist
Deprecated:
unsigned carma::dbms::Table::rowCount ( ) const

get the number of rows in the table

Returns
the number of rows in the table

Definition at line 88 of file Table.h.

void carma::dbms::Table::setName ( const std::string &  name)

set the table name

Parameters
namewhat to set the table name to

Definition at line 76 of file Table.h.

std::string carma::dbms::Table::toString ( ) const

get a string representation of the table

Friends And Related Function Documentation

std::ostream & operator<< ( ::std::ostream &  os,
const carma::dbms::Table table 
)
related

Insert (i.e. output) a presentation of a carma::dbms::Table instance into an output stream.

Returns
The os output stream parameter so that stream insertions can be chained in the usual C++ way.
Parameters
osThe output stream to insert the presentation into.
tableThe carma::dbms::Table instance to present

The documentation for this class was generated from the following file: