Loading...
Searching...
No Matches
casacore::ROTableRow Class Reference
tables package (libcasa_tables) » Tables_module

More...

`#include <TableRow.h>`

## Public Member Functions

| ROTableRow ()
| Create a detached ROTableRow object.
| ROTableRow (const Table &table, Bool storedColumnsOnly=True)
| Create a ROTableRow object for the given Table.
| ROTableRow (const Table &table, const Vector< String > &columnNames, Bool exclude=False)
| Create a ROTableRow object for the given Table.
| ROTableRow (const ROTableRow &)
| Copy constructor (copy semantics).
| ~ROTableRow ()
ROTableRow & | operator= (const ROTableRow &)
| Assignment (copy semantics).
Bool | isAttached () const
| Test if a Table is attached to this object.
const Table & | table () const
| Get the Table used for this object.
const TableRecord & | record () const
| Get the record containing all fields.
Int64 | rowNumber () const
| Get the number of the last row read.
Vector< String > | columnNames () const
| Get a vector consisting of all columns names.
const TableRecord & | get (rownr_t rownr, Bool alwaysRead=False) const
| Get the values of all columns used from the given row.
const Block< Bool > & | getDefined () const
| Get the block telling for each column if its value in the row was indefined in the table.

## Protected Member Functions

void | copy (const ROTableRow &that)
| Copy that object to this object.
void | create (const Table &table, Bool storedColumnsOnly, Bool writable)
| Create the record, column, and field objects for all columns in the table.
void | create (const Table &table, const Vector< String > &columnNames, Bool exclude, Bool writable)
| Create the record, column, and field objects for the given columns.
void | putRecord (rownr_t rownr)
| Put the values found in the internal TableRecord at the given row.
void | putField (rownr_t rownr, const TableRecord &record, Int whichColumn, Int whichField)
| Put a value in the given field in the TableRecord into the given row and column.
void | setReread (rownr_t rownr)
| Set the switch to reread when the current row has been put.

## Protected Attributes

TableRecord * | itsRecord
Table | itsTable
Block< void * > | itsTabCols
Block< void * > | itsColumns
Block< void * > | itsFields
Block< Bool > | itsDefined
uInt | itsNrused
Int64 | itsLastRow
Bool | itsReread

## Private Member Functions

void | init ()
| Initialize the object.
void | makeDescExclude (RecordDesc &description, const Vector< String > &columnNames, Bool writable)
| Make a RecordDesc from the table with some excluded column names.
void | addColumnToDesc (RecordDesc &description, const TableColumn &column, Bool skipOther)
| Add a column to the record.
void | makeObjects (const RecordDesc &description)
| Make the required objects.
void | deleteObjects ()
| Delete all objects.

## Detailed Description

Readonly access to a table row

### Intended use:

Public interface

### Review Status

Reviewed By:
  Paul Shannon
Date Reviewed:
  1996/05/10
Test programs:
  tTableRow

### Prerequisite

- Table
- TableRecord

### Synopsis

This class provides easy access to the contents of a table, one row at a time. 'Normal' access to a table is by columns, each of which contains values of the same type. A table row, by contrast, will be a collection of heterogeneous data, similar to a C struct. For this reason, the TableRow classes (ROTableRow and TableRow) are built around and provide access to the class TableRecord . The TableRow delegates much of its behaviour to the TableRecord class. For example:

Table table ("some.table");
ROTableRow row (table); // construct TableRow object
cout << row.record().description(); // show its description
// Get the values in row 17.
const TableRecord& record = row.get (17);
// column name is "Title", and automatically becomes the record
// key for this field of the record:
String row17title = record.asString ("Title");
Int row17count = record.asInt ("Count");
casacore::ROTableRow::record
const TableRecord & record() const
Get the record containing all fields.
Definition TableRow.h:507
casacore::ROTableRow::table
const Table & table() const
Get the Table used for this object.
Definition TableRow.h:499
casacore::ROTableRow::ROTableRow
ROTableRow()
Create a detached ROTableRow object.
casacore::String
String: the storage and methods of handling collections of characters.
Definition String.h:223
casacore::TableRecord
Definition TableRecord.h:183
casacore::Table
Definition Table.h:157
casacore::Int
int Int
Definition aipstype.h:48

The simplest constructor will include all columns in the TableRow object (although columns with a non-standard data type will be excluded, because they cannot be represented in a TableRecord). However, it is possible to be more selective and to include only some columns in the TableRow object. The various constructors show how this can be done.

It is possible to have multiple TableRow objects for the same table. They can contain different columns or they can share columns.

On construction an internal TableRecord object is created containing the required fields. The contents of this record will be changed with each get call, but the structure of it is fixed. This means that RORecordFieldPtr objects can be constructed once and used many times. This results in potentially faster access to the record, because it avoids unnecessary name lookups.

### Example

// Open the table as readonly and define a row object containing
// the given columns.
// Note that the function stringToVector is a very convenient
// way to construct a Vector<String>.
// Show the description of the fields in the row.
Table table("Some.table");
ROTableRow row (table, stringToVector("col1,col2,col3"));
cout << row.record().description();
// Loop through all rows and get their values.
for (rownr_t i=0; i<table.nrow(); i++) {
const TableRecord& values = row.get (i);
someString = values.asString ("col1");
somedouble = values.asdouble ("col2");
someArrayInt = values.asArrayInt ("col3");
}
// Provided the structure of the record is known, the RecordFieldPtr
// objects could be used as follows.
// This is faster than the previous method, because it avoids a name
// lookup for each iteration.
RORecordFieldPtr<String> col1(row.record(), "col1");
RORecordFieldPtr<double> col2(row.record(), "col2");
RORecordFieldPtr<Array<Int> > col3(row.record(), "col3");
for (rownr_t i=0; i<table.nrow(); i++) {
row.get (i);
someString = *col1;
somedouble = *col2;
someArrayInt = *col3;
}
stringToVector
Vector< String > stringToVector(const String &string, char delim=',')
casacore::RORecordFieldPtr
Read-Only access to an individual field from a Record.
Definition RecordField.h:209
casacore::Table::nrow
rownr_t nrow() const
Get the number of rows.
Definition Table.h:1187
casacore::rownr_t
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44

Please note that the TableRecord& returned by the get() function is the same as returned by the record() function. Therefore the RORecordField objects can be created in advance.

Definition at line 135 of file TableRow.h.

## Constructor & Destructor Documentation

## ROTableRow() [1/4]

casacore::ROTableRow::ROTableRow | ( |  | ) |

Create a detached ROTableRow object.

This means that no Table, etc. is contained in it. Function isAttached will return False for it.
This constructor should normally not be used, because it does not result in a valid object. It should only be used when really needed (e.g. when an array of objects has to be used).

Referenced by copy(), operator=(), and ROTableRow().

## ROTableRow() [2/4]

casacore::ROTableRow::ROTableRow | ( | const Table & | table,
|  | Bool | storedColumnsOnly = True )

explicit

Create a ROTableRow object for the given Table.

Its TableRecord will contain all columns except columns with datatype TpOther (i.e. non-standard data types).
If the flag storedColumnsOnly is True, only the columns actually stored by a storage manager will be selected. This is useful when the contents of an entire row have to be copied. Virtual columns are calculated on-the-fly (often using stored columns), thus it makes no sense to copy their data.
Caution: If the table contains columns with large arrays, it may be better not to use this constructor; Each get will read in all data in the row, thus also the large data array(s); In that case it is better to use the constructor which includes selected columns only;

References table(), and casacore::True.

## ROTableRow() [3/4]

casacore::ROTableRow::ROTableRow | ( | const Table & | table,
|  | const Vector< String > & | columnNames,
|  | Bool | exclude = False )

Create a ROTableRow object for the given Table.

Its TableRecord will contain all columns given in the Vector. An exception is thrown if an unknown column name is given.
When exclude=True, all columns except the given columns are taken. In that case an unknown name does not result in an exception.

References columnNames(), casacore::False, and table().

## ROTableRow() [4/4]

casacore::ROTableRow::ROTableRow | ( | const ROTableRow & |  | ) |

Copy constructor (copy semantics).

References ROTableRow().

## ~ROTableRow()

casacore::ROTableRow::~ROTableRow | ( |  | ) |

## Member Function Documentation

## addColumnToDesc()

void casacore::ROTableRow::addColumnToDesc | ( | RecordDesc & | description,
|  | const TableColumn & | column,
|  | Bool | skipOther )

private

Add a column to the record.

When skipOther is True, columns with a non-standard data type will be silently skipped.

References casacore::description().

## columnNames()

Vector< String > casacore::ROTableRow::columnNames | ( |  | ) | const

Get a vector consisting of all columns names.

This can, for instance, be used to construct a TableRow object with the same columns in another table.

Referenced by create(), makeDescExclude(), ROTableRow(), and casacore::TableRow::TableRow().

## copy()

void casacore::ROTableRow::copy | ( | const ROTableRow & | that | ) |

protected

Copy that object to this object.

The writable flag determines if writable or readonly TableColumn objects will be created.

References ROTableRow().

## create() [1/2]

void casacore::ROTableRow::create | ( | const Table & | table,
|  | Bool | storedColumnsOnly,
|  | Bool | writable )

protected

Create the record, column, and field objects for all columns in the table.

The writable flag determines if writable or readonly TableColumn objects will be created.

References table().

## create() [2/2]

void casacore::ROTableRow::create | ( | const Table & | table,
|  | const Vector< String > & | columnNames,
|  | Bool | exclude,
|  | Bool | writable )

protected

Create the record, column, and field objects for the given columns.

The writable flag determines if writable or readonly TableColumn objects will be created.

References columnNames(), and table().

## deleteObjects()

void casacore::ROTableRow::deleteObjects | ( |  | ) |

private

Delete all objects.

## get()

const TableRecord & casacore::ROTableRow::get | ( | rownr_t | rownr,
|  | Bool | alwaysRead = False ) const

Get the values of all columns used from the given row.

When the given row number equals the current one, nothing will be read unless the alwaysRead flag is set to True.
The TableRecord& returned is the same one as returned by the record() function. So one can ignore the return value of get().

References casacore::False.

## getDefined()

const Block< Bool > & casacore::ROTableRow::getDefined | ( |  | ) | const

inline

Get the block telling for each column if its value in the row was indefined in the table.

Note that array values might be undefined in the table, but in the record they will be represented as empty arrays.

Definition at line 511 of file TableRow.h.

References itsDefined.

## init()

void casacore::ROTableRow::init | ( |  | ) |

private

Initialize the object.

## isAttached()

Bool casacore::ROTableRow::isAttached | ( |  | ) | const

inline

Test if a Table is attached to this object.

Definition at line 495 of file TableRow.h.

References itsRecord.

## makeDescExclude()

void casacore::ROTableRow::makeDescExclude | ( | RecordDesc & | description,
|  | const Vector< String > & | columnNames,
|  | Bool | writable )

private

Make a RecordDesc from the table with some excluded column names.

References columnNames(), and casacore::description().

## makeObjects()

void casacore::ROTableRow::makeObjects | ( | const RecordDesc & | description | ) |

private

Make the required objects.

These are the TableRecord and for each column a TableColumn and RecordFieldPtr.

References casacore::description().

## operator=()

ROTableRow & casacore::ROTableRow::operator= | ( | const ROTableRow & |  | ) |

Assignment (copy semantics).

References ROTableRow().

## putField()

void casacore::ROTableRow::putField | ( | rownr_t | rownr,
|  | const TableRecord & | record,
|  | Int | whichColumn,
|  | Int | whichField )

protected

Put a value in the given field in the TableRecord into the given row and column.

This is a helper function for class TableRow.

References record().

## putRecord()

void casacore::ROTableRow::putRecord | ( | rownr_t | rownr | ) |

protected

Put the values found in the internal TableRecord at the given row.

This is a helper function for class TableRow.

Referenced by casacore::TableRow::put().

## record()

const TableRecord & casacore::ROTableRow::record | ( |  | ) | const

inline

Get the record containing all fields.

Definition at line 507 of file TableRow.h.

References itsRecord.

Referenced by putField().

## rowNumber()

Int64 casacore::ROTableRow::rowNumber | ( |  | ) | const

inline

Get the number of the last row read.

-1 is returned when no Table is attached or no row has been read yet.

Definition at line 503 of file TableRow.h.

References itsLastRow.

## setReread()

void casacore::ROTableRow::setReread | ( | rownr_t | rownr | ) |

protected

Set the switch to reread when the current row has been put.

## table()

const Table & casacore::ROTableRow::table | ( |  | ) | const

inline

Get the Table used for this object.

Definition at line 499 of file TableRow.h.

References itsTable.

Referenced by create(), create(), ROTableRow(), ROTableRow(), casacore::TableRow::TableRow(), and casacore::TableRow::TableRow().

## Member Data Documentation

## itsColumns

Block<void*> casacore::ROTableRow::itsColumns

protected

Definition at line 253 of file TableRow.h.

## itsDefined

Block<Bool> casacore::ROTableRow::itsDefined

mutable protected

Definition at line 258 of file TableRow.h.

Referenced by getDefined().

## itsFields

Block<void*> casacore::ROTableRow::itsFields

protected

Definition at line 256 of file TableRow.h.

## itsLastRow

Int64 casacore::ROTableRow::itsLastRow

mutable protected

Definition at line 262 of file TableRow.h.

Referenced by rowNumber().

## itsNrused

uInt casacore::ROTableRow::itsNrused

protected

Definition at line 260 of file TableRow.h.

## itsRecord

TableRecord* casacore::ROTableRow::itsRecord

protected

Definition at line 245 of file TableRow.h.

Referenced by isAttached(), record(), and casacore::TableRow::record().

## itsReread

Bool casacore::ROTableRow::itsReread

mutable protected

Definition at line 265 of file TableRow.h.

## itsTabCols

Block<void*> casacore::ROTableRow::itsTabCols

protected

Definition at line 251 of file TableRow.h.

## itsTable

Table casacore::ROTableRow::itsTable

protected

Definition at line 247 of file TableRow.h.

Referenced by table().

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

- tables/Tables/TableRow.h