CARMA C++
carma::dbms::Column< T > Class Template Reference

template to mimic a db column. More...

#include <carma/dbms/Column.h>

Inherits vector< T >.

Public Member Functions

 Column (const std::string &name)
 constuctor More...
 
Column getDistinctValues (const ::std::string &name="Distinct Values", bool includeNull=true) const
 get distinct values of a column More...
 
std::string getName () const
 get the column name More...
 
std::vector< unsigned > getNullIndices () const
 get the indices for NULL values. More...
 
getNullValue () const
 get the NULL data value More...
 
bool hasNulls () const
 return true if the column contains NULL values More...
 
int indexOf (const T &value) const
 find the first occurence of a specified value More...
 
bool isElementNull (unsigned index) const
 is the specified element null? More...
 
max () const
 get the maximum non-null column values More...
 
mean () const
 get the average of the non-null column values More...
 
min () const
 get the minumum non-null column value More...
 
void push_back_null ()
 add a NULL element to the end of the column More...
 
void setNullValue (const T &nullValue)
 Set the value of NULL values. More...
 
sum () const
 sum all non-null column values FIXME probably need a way to guard against doing this for strings More...
 
std::string toString () const
 return a string representation of the column More...
 
virtual ~Column ()
 destructor, derived classes may want to override More...
 

Protected Attributes

std::string name_
 
std::vector< unsigned > nullIndices_
 
nullValue_
 

Related Functions

(Note that these are not member functions.)

template<typename T , typename U >
std::map< T, U > columnsToMap (const carma::dbms::Column< T > &keyColumn, const carma::dbms::Column< U > &valueColumn)
 

Detailed Description

template<typename T>
class carma::dbms::Column< T >

template to mimic a db column.

Definition at line 31 of file Column.h.

Constructor & Destructor Documentation

template<typename T>
carma::dbms::Column< T >::Column ( const std::string &  name)

constuctor

Parameters
namecolumn name

Definition at line 39 of file Column.h.

template<typename T>
virtual carma::dbms::Column< T >::~Column ( )
virtual

destructor, derived classes may want to override

Definition at line 46 of file Column.h.

Member Function Documentation

template<typename T >
carma::dbms::Column< T > carma::dbms::Column< T >::getDistinctValues ( const ::std::string &  name = "Distinct Values",
bool  includeNull = true 
) const

get distinct values of a column

Parameters
theresulting column name
includeNullinclude a null entry if the column has at least one null value
Returns
a column containing only distinct values

Definition at line 385 of file Column.h.

template<typename T>
std::string carma::dbms::Column< T >::getName ( ) const

get the column name

Returns
the column name

Definition at line 53 of file Column.h.

template<typename T>
std::vector< unsigned > carma::dbms::Column< T >::getNullIndices ( ) const

get the indices for NULL values.

The values (data indices) in the returned vector are garaunteed to be in ascending order

Returns
vector containing indices of NULL values in the column

Definition at line 66 of file Column.h.

template<typename T>
T carma::dbms::Column< T >::getNullValue ( ) const

get the NULL data value

Returns
the value used for the NULL value

Definition at line 93 of file Column.h.

template<typename T>
bool carma::dbms::Column< T >::hasNulls ( ) const

return true if the column contains NULL values

Returns
true if the column contains NULL values

Definition at line 59 of file Column.h.

template<typename T>
int carma::dbms::Column< T >::indexOf ( const T &  value) const

find the first occurence of a specified value

Parameters
thevalue to search for
Returns
the index of the first occurence of the non-null specified value or -1 if the value is not found FIXME probably need a sorting algorithm to improve performance for large columns

Definition at line 223 of file Column.h.

template<typename T>
bool carma::dbms::Column< T >::isElementNull ( unsigned  index) const

is the specified element null?

Parameters
indexthe index of the element
Returns
true if the element is null
Exceptions
outof range if the specified index equals or exceeds the column size

Definition at line 127 of file Column.h.

template<typename T>
T carma::dbms::Column< T >::max ( ) const

get the maximum non-null column values

Returns
the max non-null value

Definition at line 177 of file Column.h.

template<typename T>
T carma::dbms::Column< T >::mean ( ) const

get the average of the non-null column values

Returns
the mean value of the non-nulls

Definition at line 168 of file Column.h.

template<typename T>
T carma::dbms::Column< T >::min ( ) const

get the minumum non-null column value

Returns
the min non-null value

Definition at line 199 of file Column.h.

template<typename T>
void carma::dbms::Column< T >::push_back_null ( )

add a NULL element to the end of the column

Definition at line 71 of file Column.h.

template<typename T>
void carma::dbms::Column< T >::setNullValue ( const T &  nullValue)

Set the value of NULL values.

All existing NULL elements will be changed to this value

Parameters
nullValuethe NULL value

Definition at line 81 of file Column.h.

template<typename T>
T carma::dbms::Column< T >::sum ( ) const

sum all non-null column values FIXME probably need a way to guard against doing this for strings

Returns
the summed value

Definition at line 153 of file Column.h.

template<typename T>
std::string carma::dbms::Column< T >::toString ( ) const

return a string representation of the column

Returns
string repreentation of the column

Definition at line 99 of file Column.h.

Friends And Related Function Documentation

template<typename T , typename U >
std::map< T, U > columnsToMap ( const carma::dbms::Column< T > &  keyColumn,
const carma::dbms::Column< U > &  valueColumn 
)
related

Map the values in keyColumn to the values in valueColumn. This function will throw an carma::util::IllegalArgumentException if, either (or both) columns have at least one null value or if the columns have a different number of elements. Furthermore, keyColumn must have all unique elements since these elements will be the keys of the returned map. If the columns pass these tests, the returned map will have the elments of keyColumn as keys mapped to the elements of valueColumn. The mapping is done by index.

Parameters
keyColumnthe column whose elements will be the keys of the mapping
otherColumnthe column whose elements will be the values of the mapping
Returns
the mapping
Exceptions
carma::util::IllegalArgumentException

Definition at line 297 of file Column.h.


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