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

Read/write access to a table row. More...

`#include <TableRow.h>`

## Public Member Functions

| TableRow ()
| Create a detached TableRow object.
| TableRow (const Table &table, Bool storedColumnsOnly=True)
| Create a TableRow object for the given Table.
| TableRow (const Table &table, const Vector< String > &columnNames, Bool exclude=False)
| Create a TableRow object for the given Table.
| TableRow (const TableRow &)
| Copy constructor (copy semantics).
| ~TableRow ()
TableRow & | operator= (const TableRow &)
| Assignment (copy semantics).
TableRecord & | record ()
| Get non-const access to the TableRecord in this object.
void | put ()
| Put into the last row read.
void | put (rownr_t rownr)
| Put into the given row.
void | put (rownr_t rownr, const TableRecord &record, Bool checkConformance=True)
| Put the values found in the TableRecord in the appropriate columns in the given row.
void | put (rownr_t rownr, const TableRecord &record, const Block< Bool > &valuesDefined, Bool checkConformance=True)
void | putMatchingFields (rownr_t rownr, const TableRecord &record)
| Put the values found in the TableRecord.
Public Member Functions inherited from casacore::ROTableRow
| 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.

## Private Member Functions

Bool | namesConform (const TableRecord &that) const
| Check if the names of the given record match this row.

## Additional Inherited Members

Protected Member Functions inherited from casacore::ROTableRow
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 inherited from casacore::ROTableRow
TableRecord * | itsRecord
Table | itsTable
Block< void * > | itsTabCols
Block< void * > | itsColumns
Block< void * > | itsFields
Block< Bool > | itsDefined
uInt | itsNrused
Int64 | itsLastRow
Bool | itsReread

## Detailed Description

Read/write access to a table row.

### Intended use:

Public interface

### Review Status

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

### Prerequisite

- ROTableRow

### Synopsis

The class TableRow is derived from ROTableRow and as an extra it provides write-access to a row in a table. With the put function, all values in the TableRecord object will be put in the corresponding columns in the table row. There is, however, an extra consideration:

- Constructing a TableRow object fails if the table is not writable. Non-writable columns will not be part of the object. If an explicitly given column is non-writable, the construction will also fail.

There are effectively 3 ways of writing data.

1. The function
   put (rownr, tableRecord);
   casacore::TableRow::put
   void put()
   Put into the last row read.
   can be used to put all values from the given TableRecord, which has to be conforming (i.e. matching order and names). Optionally the conformance is checked. This put function is capable of data type promotion. For instance, if column COL1 is float, the corresponding field in the TableRecord can be Int.
2. A faster way is using the functions record and put. It is possible to use RecordFieldPtr objects to get direct access to the fields in the record (provided the structure of the record is known). E.g.
   TableRow row (someTable, stringToVector("col1,col2,col3"));
   RecordFieldPtr<String> col1(row.record(), "col1");
   RecordFieldPtr<double> col2(row.record(), "col2");
   RecordFieldPtr<Array<Int> > col3(row.record(), "col3");
   for (rownr_t i=0; i<n; i++) {
   *col1 = someString;
   *col2 = somedouble;
   *col3 = someArrayInt;
   row.put (i);
   }
   stringToVector
   Vector< String > stringToVector(const String &string, char delim=',')
   casacore::RecordFieldPtr
   Definition ColumnsIndex.h:42
   casacore::TableRow::TableRow
   TableRow()
   Create a detached TableRow object.
   casacore::rownr_t
   uInt64 rownr_t
   Define the type of a row number in a table.
   Definition aipsxtype.h:44
4. The function
   putMatchingFields (rownr, tableRecord);
   casacore::TableRow::putMatchingFields
   void putMatchingFields(rownr_t rownr, const TableRecord &record)
   Put the values found in the TableRecord.
   can be used to put some fields from the given TableRecord. Only fields having a corresponding name in the TableRow object will be put. Similar to the first way data type promotion will be applied for numeric values.
   E.g.: Suppose the TableRow object has columns A, C, and B, and the given TableRecord has fields B, D, and C. Only fields B and C will be put. As the example shows, the order of the fields is not important.
   This way is (much) slower than the other 2, because a name lookup is involved for each field. It can, however, be more convenient to use.

### Example

// Open the new table (with 10 rows) and define a row object containing
// values from the given column.
// Note that the function stringToVector is a very convenient
// way to construct a Vector<String>.
SetupNewTable newtab(tableDesc, Table::new);
Table table(newtab, 10);
TableRow row (table, stringToVector("col1,col2,col3,col4"));
// Loop through all rows and get their values.
for (rownr_t i=0; i<table.nrow(); i++) {
// Some magic filler function returns a filled TableRecord
// (with the correct fields in the correct order).
TableRecord record = fillerFunction();
row.put (i, record);
}
casacore::ROTableRow::table
const Table & table() const
Get the Table used for this object.
Definition TableRow.h:499
casacore::SetupNewTable
Create a new table - define shapes, data managers, etc.
Definition SetupNewTab.h:337
casacore::TableRecord
Definition TableRecord.h:183
casacore::TableRow::record
TableRecord & record()
Get non-const access to the TableRecord in this object.
Definition TableRow.h:515
casacore::Table
Definition Table.h:157

Definition at line 387 of file TableRow.h.

## Constructor & Destructor Documentation

## TableRow() [1/4]

casacore::TableRow::TableRow | ( |  | ) |

Create a detached TableRow object.

This means that no Table, etc. is contained in it. Function isAttached (in the base class) 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 operator=(), and TableRow().

## TableRow() [2/4]

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

explicit

Create a TableRow object for the given Table.

Its TableRecord will contain all columns except columns with datatype TpOther and columns which are not writable.
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 next constructor which works selectively;

References casacore::ROTableRow::table(), and casacore::True.

## TableRow() [3/4]

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

Create a TableRow 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 or if a column is given which is not writable.
When exclude=True, all columns except the given columns are taken. In that case an unknown name does not result in an exception and non-writable columns are simply skipped.

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

## TableRow() [4/4]

casacore::TableRow::TableRow | ( | const TableRow & |  | ) |

Copy constructor (copy semantics).

References TableRow().

## ~TableRow()

casacore::TableRow::~TableRow | ( |  | ) |

## Member Function Documentation

## namesConform()

Bool casacore::TableRow::namesConform | ( | const TableRecord & | that | ) | const

private

Check if the names of the given record match this row.

## operator=()

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

Assignment (copy semantics).

References TableRow().

## put() [1/4]

void casacore::TableRow::put | ( |  | ) |

Put into the last row read.

An exception is thrown if no row has been read yet. The values in the TableRecord contained in this object are put. This TableRecord can be accessed and updated using the function record.

## put() [2/4]

void casacore::TableRow::put | ( | rownr_t | rownr | ) |

inline

Put into the given row.

The values in the TableRecord contained in this object are put. This TableRecord can be accessed and updated using the function record.

Definition at line 519 of file TableRow.h.

References casacore::ROTableRow::putRecord().

## put() [3/4]

void casacore::TableRow::put | ( | rownr_t | rownr,
|  | const TableRecord & | record,
|  | Bool | checkConformance = True )

Put the values found in the TableRecord in the appropriate columns in the given row.

The names and order of the fields in the TableRecord must conform those of the description of the TableRow. The data types of numeric values do not need to conform exactly; they can be promoted (e.g. an Int value in the record may correspond to a float column). If not conforming, an exception is thrown.
Note: For performance reasons it is optional to check the name order conformance;
The valuesDefined block tells if the value in the corresponding field in the record is actually defined. If not, nothing will be written. It is meant for array values which might be undefined in a table.

References record(), and casacore::True.

## put() [4/4]

void casacore::TableRow::put | ( | rownr_t | rownr,
|  | const TableRecord & | record,
|  | const Block< Bool > & | valuesDefined,
|  | Bool | checkConformance = True )

References record(), and casacore::True.

## putMatchingFields()

void casacore::TableRow::putMatchingFields | ( | rownr_t | rownr,
|  | const TableRecord & | record )

Put the values found in the TableRecord.

Only fields with a matching name in the TableRow object will be put. This makes it possible to put fields in a selective way.
E.g.: If the TableRow contains columns A and B, and the record contains fields B and C, only field B will be put.
In principle the data types of the matching fields must match, but data type promotion of numeric values will be applied.

References record().

## record()

TableRecord & casacore::TableRow::record | ( |  | ) |

inline

Get non-const access to the TableRecord in this object.

This can be used to change values in it which can thereafter be put using the function put(rownr).
Note: The returned TableRecord has a fixed structure, so it is not possible to add or remove fields; It is only possible to change values;

Definition at line 515 of file TableRow.h.

References casacore::ROTableRow::itsRecord.

Referenced by put(), put(), and putMatchingFields().

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

- tables/Tables/TableRow.h