CARMA C++
|
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< ColumnType > | getColumnTypes () 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< ColumnType > | colTypesVector_ |
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) |
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).
carma::dbms::Table::Table | ( | const std::string & | name | ) |
Table constructor.
name | the table name |
carma::dbms::Table::~Table | ( | ) |
Table destructor.
void carma::dbms::Table::addBigIntColumn | ( | const Column< long long > & | col | ) |
add a big (64 bit) int column to the table
col | the column to add |
carma::util::IllegalArgumentException | if 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 |
void carma::dbms::Table::addColumn | ( | const Column< T > & | col | ) |
template function for adding columns to tables
col | the column to add |
carma::util::IllegalArgumentException | if 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 |
void carma::dbms::Table::addDecimalColumn | ( | const Column< std::string > & | col | ) |
add a decimal column to the table
col | the column to add |
carma::util::IllegalArgumentException | if 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 |
void carma::dbms::Table::addDoubleColumn | ( | const Column< double > & | col | ) |
add a double column to the table
col | the column to add |
carma::util::IllegalArgumentException | if 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 |
void carma::dbms::Table::addFloatColumn | ( | const Column< float > & | col | ) |
add a float column to the table
col | the column to add |
carma::util::IllegalArgumentException | if 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 |
void carma::dbms::Table::addIntColumn | ( | const Column< int > & | col | ) |
add an int column to the table
col | the column to add |
carma::util::IllegalArgumentException | if 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 |
|
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
col | the column to add |
carma::util::IllegalArgumentException | if 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 |
void carma::dbms::Table::addStringColumn | ( | const Column< std::string > & | col | ) |
add a string column to the table
col | the column to add |
carma::util::IllegalArgumentException | if 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 |
unsigned carma::dbms::Table::columnCount | ( | ) | const |
|
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
colNames | the 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
index | the zero-based column index |
out_of_range | if index >= number of columns |
carma::util::IllegalArgumentException | if 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
columnName | name of the column to get |
carma::util::IllegalArgumentException | if the column with the specified name is not a BigIntColumn or if the column name doesn't exist |
carma::dbms::Column< T > carma::dbms::Table::getColumn | ( | const unsigned & | index | ) | const |
carma::dbms::Column< T > carma::dbms::Table::getColumn | ( | const std::string & | columnName | ) | const |
template function for getting columns for generic type
columnName | name of the column to get |
carma::util::IllegalArgumentException | if the column name doesn't exist |
|
protected |
checks to run when get*Column is called
std::vector<std::string> carma::dbms::Table::getColumnNames | ( | ) | const |
std::vector< ColumnType > carma::dbms::Table::getColumnTypes | ( | ) | const |
carma::dbms::Column<std::string> carma::dbms::Table::getDecimalColumn | ( | const unsigned & | index | ) | const |
get a column containing decimal values
index | the zero-based column index |
out_of_range | if index >= number of columns |
carma::util::IllegalArgumentException | if column at index is not a DecimalColumn |
carma::dbms::Column<std::string> carma::dbms::Table::getDecimalColumn | ( | const std::string & | columnName | ) | const |
get a column containing decimal values
columnName | name of the column to get |
carma::util::IllegalArgumentException | if the column with the specified name is not a DecimalColumn or if the column name doesn't exist |
carma::dbms::Column<double> carma::dbms::Table::getDoubleColumn | ( | const unsigned & | index | ) | const |
get a column containing double values
index | the zero-based column index |
out_of_range | if index >= number of columns |
carma::util::IllegalArgumentException | if column at index is not a DoubleColumn |
carma::dbms::Column<double> carma::dbms::Table::getDoubleColumn | ( | const std::string & | columnName | ) | const |
get a column containing double values
columnName | name of the column to get |
carma::util::IllegalArgumentException | if the column with the specified name is not a DoubleColumn or if the column name doesn't exist |
carma::dbms::Column<float> carma::dbms::Table::getFloatColumn | ( | const unsigned & | index | ) | const |
get a column containing float values
index | the zero-based column index |
out_of_range | if index >= number of columns |
carma::util::IllegalArgumentException | if column at index is not a FloatColumn |
carma::dbms::Column<float> carma::dbms::Table::getFloatColumn | ( | const std::string & | columnName | ) | const |
get a column containing float values
columnName | name of the column to get |
carma::util::IllegalArgumentException | if column with the specified name is not a FloatColumn or if the column name doesn't exist |
carma::dbms::Column<int> carma::dbms::Table::getIntColumn | ( | const unsigned & | index | ) | const |
get a column containing integer values
index | the zero-based column index |
out_of_range | if index >= number of columns |
carma::util::IllegalArgumentException | if column at index is not an IntegerColumn |
carma::dbms::Column<int> carma::dbms::Table::getIntColumn | ( | const std::string & | columnName | ) | const |
get a column containing int values
columnName | name of the column to get |
carma::util::IllegalArgumentException | if the column with the specified name is not a IntColumn or if the column name doesn't exist |
std::string carma::dbms::Table::getName | ( | ) | const |
carma::dbms::Column<short> carma::dbms::Table::getShortColumn | ( | const unsigned & | index | ) | const |
get a column containing short values
index | the zero-based column index |
out_of_range | if index >= number of columns |
carma::util::IllegalArgumentException | if column at index is not a ShortColumn |
carma::dbms::Column<short> carma::dbms::Table::getShortColumn | ( | const std::string & | columnName | ) | const |
get a column containing short values
columnName | name of the column to get |
carma::util::IllegalArgumentException | if the column with the specified name is not a ShortColumn or if the column name doesn't exist |
carma::dbms::Column<std::string> carma::dbms::Table::getStringColumn | ( | const unsigned & | index | ) | const |
get a column containing string values
index | the zero-based column index |
out_of_range | if index >= number of columns |
carma::util::IllegalArgumentException | if column at index is not a StringColumn |
carma::dbms::Column<std::string> carma::dbms::Table::getStringColumn | ( | const std::string & | columnName | ) | const |
get a column containing string values
columnName | name of the column to get |
carma::util::IllegalArgumentException | if the column with the specified name is not a StringColumn or if the column name doesn't exist |
unsigned carma::dbms::Table::rowCount | ( | ) | const |
void carma::dbms::Table::setName | ( | const std::string & | name | ) |
std::string carma::dbms::Table::toString | ( | ) | const |
get a string representation of the table
|
related |
Insert (i.e. output) a presentation of a carma::dbms::Table instance into an output stream.
os
output stream parameter so that stream insertions can be chained in the usual C++ way.os | The output stream to insert the presentation into. |
table | The carma::dbms::Table instance to present |