casacore
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
casacore::ROTableRow Class Reference

More...

#include <TableRow.h>

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

TableRecorditsRecord
 
Table itsTable
 
Block< void * > itsTabCols
 
Block< void * > itsColumns
 
Block< void * > itsFields
 
Block< BoolitsDefined
 
uInt itsNrused
 
Int64 itsLastRow
 
Bool itsReread
 

Private Member Functions

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

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

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");
const TableRecord & record() const
Get the record containing all fields.
Definition: TableRow.h:509
const Table & table() const
Get the Table used for this object.
Definition: TableRow.h:501
ROTableRow()
Create a detached ROTableRow object.
Int asInt(const RecordFieldId &) const
const String & asString(const RecordFieldId &) const
void get(const RecordFieldId &, Bool &value) const
Get the value of the given field.
int Int
Definition: aipstype.h:50

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;
}
Vector< String > stringToVector(const String &string, char delim=',')
rownr_t nrow() const
Get the number of rows.
Definition: Table.h:1171
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46

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 137 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).

◆ 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;

◆ 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.

◆ ROTableRow() [4/4]

casacore::ROTableRow::ROTableRow ( const ROTableRow )

Copy constructor (copy semantics).

◆ ~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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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().

◆ 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 513 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 497 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.

◆ 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.

◆ operator=()

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

Assignment (copy semantics).

◆ 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.

◆ 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 509 of file TableRow.h.

References itsRecord.

◆ 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 505 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 501 of file TableRow.h.

References itsTable.

Member Data Documentation

◆ itsColumns

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

Definition at line 255 of file TableRow.h.

◆ itsDefined

Block<Bool> casacore::ROTableRow::itsDefined
mutableprotected

Definition at line 260 of file TableRow.h.

Referenced by getDefined().

◆ itsFields

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

Definition at line 258 of file TableRow.h.

◆ itsLastRow

Int64 casacore::ROTableRow::itsLastRow
mutableprotected

Definition at line 264 of file TableRow.h.

Referenced by rowNumber().

◆ itsNrused

uInt casacore::ROTableRow::itsNrused
protected

Definition at line 262 of file TableRow.h.

◆ itsRecord

TableRecord* casacore::ROTableRow::itsRecord
protected

Definition at line 247 of file TableRow.h.

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

◆ itsReread

Bool casacore::ROTableRow::itsReread
mutableprotected

Definition at line 267 of file TableRow.h.

◆ itsTabCols

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

Definition at line 253 of file TableRow.h.

◆ itsTable

Table casacore::ROTableRow::itsTable
protected

Definition at line 249 of file TableRow.h.

Referenced by table().


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