ScalarColumn.h

Classes

ROScalarColumn -- Readonly access to a scalar table column with arbitrary data type (full description)
ScalarColumn -- Read/write access to a scalar table column with arbitrary data type (full description)

class ROScalarColumn : virtual public ROTableColumn

Interface

Public Members
ROScalarColumn()
ROScalarColumn (const Table&, const String& columnName)
ROScalarColumn (const ROTableColumn&)
ROScalarColumn (const ROScalarColumn<T>&)
~ROScalarColumn()
virtual ROTableColumn* clone() const
void reference (const ROScalarColumn<T>&)
void attach (const Table& table, const String& columnName)
void get (uInt rownr, T& value) const
T operator() (uInt rownr) const
void getColumn (Vector<T>& vec, Bool resize = False) const
Vector<T> getColumn() const
void getColumnRange (const Slicer& rowRange, Vector<T>& vec, Bool resize = False) const
Vector<T> getColumnRange (const Slicer& rowRange) const
void getColumnCells (const RefRows& rownrs, Vector<T>& vec, Bool resize = False) const
Vector<T> getColumnCells (const RefRows& rownrs) const
Private Members
ROScalarColumn<T>& operator= (const ROScalarColumn<T>&)
void reference (const ROTableColumn&)
void checkDataType() const

Description

Review Status

Reviewed By:
dschieb
Date Reviewed:
1994/08/10
Programs:
Tests:

Prerequisite

Etymology

ROScalarColumn gives readonly access to an column in a table containing a scalar with data type T.

Synopsis

The class ROScalarColumn allows readonly access to a column containing scalar values with an arbitrary data type. It is possible to get the data in an individual cell (i.e. table row) and to get the column as a whole.

A default constructor is defined to allow construction of an array of ROScalarColumn objects. However, this constructs an object not referencing a column. Functions like get, etc. will fail (i.e. result in a segmentation fault) when used on such objects. The functions isNull and throwIfNull can be used to test on this. The functions attach and reference can fill in the object.

The assignment operator is not defined for this class, because it was felt it would be too confusing. Instead the function reference can be used to do assignment with reference semantics. An assignment with copy semantics makes no sense for a readonly column.

Example

See module Tables.

Member Description

ROScalarColumn()

The default constructor creates a null object, i.e. it does not reference a table column. The sole purpose of this constructor is to allow construction of an array of ROScalarColumn objects. The functions reference and attach can be used to make a null object reference a column. Note that get functions, etc. will cause a segmentation fault when operating on a null object. It was felt it was too expensive to test on null over and over again. The user should use the isNull or throwIfNull function in case of doubt.

ROScalarColumn (const Table&, const String& columnName)

Construct for the given column in the given table.

ROScalarColumn (const ROTableColumn&)

Construct from the given table column. This constructor is useful if first a table column was constructed, its type is determined and thereafter used to construct the correct column object.

ROScalarColumn (const ROScalarColumn<T>&)

Copy constructor (reference semantics).

~ROScalarColumn()

virtual ROTableColumn* clone() const

Clone the object.

void reference (const ROScalarColumn<T>&)

Change the reference to another column. This is in fact an assignment operator with reference semantics. It removes the reference to the current column and creates a reference to the column referenced in the other object. It will handle null objects correctly.

void attach (const Table& table, const String& columnName)

Attach a column to the object. This is in fact only a shorthand for
reference (ROScalarColumn<T> (table, columnName));

void get (uInt rownr, T& value) const
T operator() (uInt rownr) const

Get the data from a particular cell (i.e. table row). The row numbers count from 0 until #rows-1.

void getColumn (Vector<T>& vec, Bool resize = False) const

Get the vector of all values in the column. According to the assignment rules of class Array, the destination vector must be empty or its length must be the number of cells in the column (i.e. the number of rows in the table).

Vector<T> getColumn() const

Get the vector of all values in the column.

void getColumnRange (const Slicer& rowRange, Vector<T>& vec, Bool resize = False) const

Get the vector of a range of values in the column. The Slicer object can be used to specify start, end (or length), and stride of the rows to get. According to the assignment rules of class Array, the destination vector must be empty or its length must be the number of cells in the column (i.e. the number of rows in the slicer).

Vector<T> getColumnRange (const Slicer& rowRange) const

Get the vector of a range of values in the column. The Slicer object can be used to specify start, end (or length), and stride of the rows to get..

void getColumnCells (const RefRows& rownrs, Vector<T>& vec, Bool resize = False) const

Get the vector of some values in the column. The Slicer object can be used to specify start, end (or length), and stride of the rows to get. According to the assignment rules of class Array, the destination vector must be empty or its length must be the number of cells in the column (i.e. the number of rows in the RefRows object).

Vector<T> getColumnCells (const RefRows& rownrs) const

Get the vector of some values in the column.

ROScalarColumn<T>& operator= (const ROScalarColumn<T>&)

Assignment makes no sense for a readonly class. Declaring this operator private, makes it unusable.

void reference (const ROTableColumn&)

Referencing any other typed column cannot be done. If we do not put this function here, the conversion constructor ROScalarColumn (const ROTableColumn&) will be used and no compile error is given.

void checkDataType() const

Check if the data type matches the column data type.


template<class T> class ScalarColumn : public ROScalarColumn<T>, public TableColumn

Interface

Public Members
ScalarColumn()
ScalarColumn (const Table&, const String& columnName)
ScalarColumn (const TableColumn&)
ScalarColumn (const ScalarColumn<T>&)
~ScalarColumn()
virtual ROTableColumn* clone() const
void reference (const ScalarColumn<T>&)
void attach (const Table& table, const String& columnName)
void put (uInt rownr, const T& value)
void put (uInt rownr, const ROScalarColumn<T>& that)
void put (uInt thisRownr, const ROScalarColumn<T>& that, uInt thatRownr)
void put (uInt rownr, const ROTableColumn& that)
void put (uInt thisRownr, const ROTableColumn& that, uInt thatRownr)
void putColumn (const Vector<T>& vec)
void putColumnRange (const Slicer& rowRange, const Vector<T>& vec)
void putColumnCells (const RefRows& rownrs, const Vector<T>& vec)
void fillColumn (const T& value)
void putColumn (const ROScalarColumn<T>& that)
Private Members
ScalarColumn<T>& operator= (const ScalarColumn<T>&)
void reference (const TableColumn&)
void putColumn (const ROTableColumn&)

Description

Review Status

Reviewed By:
dschieb
Date Reviewed:
1994/08/10
Programs:
Tests:
  • none

Prerequisite

Synopsis

The class ScalarColumn allows read/write access to a column containing scalar values with an arbitrary data type. It augments the class ROScalarColumn with the possibility to put data into a cell or into the whole column.

A default constructor is defined to allow construction of an array of ScalarColumn objects. However, this constructs an object not referencing a column. Functions like get, etc. will fail (i.e. result in a segmentation fault) when used on such objects. The functions ROTableColumn::isNull and throwIfNull can be used to test on this. The functions attach and reference can fill in the object.

The assignment operator is not defined for this class, because it was felt it would be too confusing. Instead the function reference can be used to do assignment with reference semantics. An assignment with copy semantics can be done with a putColumn function.

Example

See module Tables.

Member Description

ScalarColumn()

The default constructor creates a null object, i.e. it does not reference a table column. The sole purpose of this constructor is to allow construction of an array of ScalarColumn objects. The functions reference and attach can be used to make a null object reference a column. Note that get functions, etc. will cause a segmentation fault when operating on a null object. It was felt it was too expensive to test on null over and over again. The user should use the isNull or throwIfNull function in case of doubt.

ScalarColumn (const Table&, const String& columnName)

Construct the scalar column object for the table column.

ScalarColumn (const TableColumn&)

Construct from the given table column. This constructor is useful if first a table column was constructed, its type is determined and thereafter used to construct the correct column object.

ScalarColumn (const ScalarColumn<T>&)

Copy constructor (reference semantics).

~ScalarColumn()

virtual ROTableColumn* clone() const

Clone the object.

void reference (const ScalarColumn<T>&)

Change the reference to another column. This is in fact an assignment operator with reference semantics. It removes the reference to the current column and creates a reference to the column referenced in the other object. It will handle null objects correctly.

void attach (const Table& table, const String& columnName)

Attach a column to the object. This is in fact only a shorthand for
reference (ScalarColumn<T> (table, columnName));

void put (uInt rownr, const T& value)

Put the value in a particular cell (i.e. table row). The row numbers count from 0 until #rows-1.

void put (uInt rownr, const ROScalarColumn<T>& that)

Copy the value of a cell of that column to a cell of this column. The data types of both columns must be the same.

Use the same row numbers for both cells.

void put (uInt thisRownr, const ROScalarColumn<T>& that, uInt thatRownr)

Copy the value of a cell of that column to a cell of this column. The data types of both columns must be the same.

Use possibly different row numbers for that (i.e. input) and and this (i.e. output) cell.

void put (uInt thisRownr, const ROTableColumn& that, uInt thatRownr)

Copy the value of a cell of that column to a cell of this column. This function uses a generic ROTableColumn object as input. If possible the data will be promoted to the data type of this column. Otherwise an exception is thrown.

Use possibly different row numbers for that (i.e. input) and and this (i.e. output) cell.

void put (uInt rownr, const ROTableColumn& that)

Copy the value of a cell of that column to a cell of this column. This function uses a generic ROTableColumn object as input. If possible the data will be promoted to the data type of this column. Otherwise an exception is thrown.

void putColumn (const Vector<T>& vec)

Put the vector of all values in the column. The length of the vector must be the number of cells in the column (i.e. the number of rows in the table).

void putColumnRange (const Slicer& rowRange, const Vector<T>& vec)

Put the vector of a range of values in the column. The Slicer object can be used to specify start, end (or length), and stride of the rows to put. The length of the vector must be the number of cells in the slice.

void putColumnCells (const RefRows& rownrs, const Vector<T>& vec)

Put the vector of some values in the column. The length of the vector must be the number of cells in the RefRows object.

void fillColumn (const T& value)

Put the same value in all cells of the column.

void putColumn (const ROScalarColumn<T>& that)

Put the contents of a column with the same data type into this column. To put the contents of a column with a different data type into this column, the function TableColumn::putColumn can be used (provided the data type promotion is possible). In fact, this function is an assignment operator with copy semantics.

ScalarColumn<T>& operator= (const ScalarColumn<T>&)

Assigning one column to another suggests a deep copy. Because the copy constructor has reference semantics, it was felt it would be too confusing to allow assignment. Instead the function reference (with reference semantics) and putColumn (with copy semantics) exist. Declaring this operator private, makes it unusable.

void reference (const TableColumn&)
void putColumn (const ROTableColumn&)

Referencing any other typed column cannot be done. If we do not put this function here, the conversion constructor ROScalarColumn (const TableColumn&) will be used and no compile error is given.