casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends
casa::TableRecord Class Reference

A hierarchical collection of named fields of various types. More...

#include <TableRecord.h>

Inheritance diagram for casa::TableRecord:
casa::RecordInterface casa::NoticeSource

List of all members.

Public Member Functions

 TableRecord ()
 Create a record with no fields.
 TableRecord (RecordType type, CheckFieldFunction *=0, const void *checkArgument=0)
 Create a record with no fields.
 TableRecord (const RecordDesc &description, RecordType type=Fixed, CheckFieldFunction *=0, const void *checkArgument=0)
 Create a record with the given description.
 TableRecord (const TableRecord &other)
 Create a copy of other using copy semantics.
 TableRecord (const RecordInterface &other)
 Create a TableRecord from another type of record.
TableRecordoperator= (const TableRecord &other)
 Copy the data in the other record to this record.
Bool operator== (const TableRecord &other)
 ~TableRecord ()
 Release resources associated with this object.
virtual RecordInterfaceclone () const
 Make a copy of this object.
virtual void assign (const RecordInterface &that)
 Assign that RecordInterface object to this one.
virtual const Stringcomment (const RecordFieldId &) const
 Get the comment for this field.
virtual void setComment (const RecordFieldId &, const String &comment)
 Set the comment for this field.
const RecordDescdescription () const
 Describes the current structure of this TableRecord.
virtual void restructure (const RecordDesc &newDescription, Bool recursive=True)
 Change the structure of this TableRecord to contain the fields in newDescription.
Bool conform (const TableRecord &other) const
 Returns True if this and other have the same RecordDesc, other than different names for the fields.
virtual uInt nfields () const
 How many fields does this structure have? A convenient synonym for description().nfields().
virtual Int fieldNumber (const String &fieldName) const
 Get the field number from the field name.
virtual DataType type (Int whichField) const
 Get the data type of this field.
void removeField (const RecordFieldId &)
 Remove a field from the record.
void renameField (const String &newName, const RecordFieldId &)
 Rename the given field.
void defineRecord (const RecordFieldId &, const TableRecord &value, RecordType type=Variable)
 Define a value for the given field.
virtual void defineRecord (const RecordFieldId &, const RecordInterface &value, RecordType=Variable)
void defineTable (const RecordFieldId &, const Table &value, RecordType type=Variable)
const TableRecordsubRecord (const RecordFieldId &) const
 Get the subrecord or table from the given field.
TableRecordrwSubRecord (const RecordFieldId &)
virtual const RecordInterfaceasRecord (const RecordFieldId &) const
virtual RecordInterfaceasrwRecord (const RecordFieldId &)
Table asTable (const RecordFieldId &) const
 Get the table from the given field.
Table asTable (const RecordFieldId &, const TableLock &lockOptions) const
const TableAttrtableAttributes (const RecordFieldId &) const
 Get the attributes of a table field.
void mergeField (const TableRecord &other, const RecordFieldId &, DuplicatesFlag=ThrowOnDuplicates)
 Merge a field from another record into this record.
void merge (const TableRecord &other, DuplicatesFlag=ThrowOnDuplicates)
 Merge all fields from the other record into this record.
void closeTable (const RecordFieldId &) const
 Close the table in the given field.
void closeTables () const
 Close all open tables.
void flushTables (Bool fsync=False) const
 Flush all open subtables.
void renameTables (const String &newParentName, const String &oldParentName)
 Rename the subtables with a path containing the old parent table name.
Bool areTablesMultiUsed () const
 Are subtables used in other processes.
void putRecord (AipsIO &os, const TableAttr &) const
 Put the data of a record.
void getRecord (AipsIO &os, const TableAttr &)
 Read a record.
void putData (AipsIO &os, const TableAttr &) const
 Put the data of a record.
void getData (AipsIO &os, uInt version, const TableAttr &)
 Read the data of a record.
virtual void print (std::ostream &, Int maxNrValues=25, const String &indent="") const
 Print the contents of the record.
void reopenRW ()
 Reopen possible tables in keywords as read/write.
void setTableAttr (const TableRecord &other, const TableAttr &defaultAttr)
 Set the attributes of subtables to te ones in the other record.
virtual void makeUnique ()
 Make a unique record representation (to do copy-on-write in RecordFieldPtr).

Protected Member Functions

virtual void * get_pointer (Int whichField, DataType type) const
 Used by the RecordField classes to attach in a type-safe way to the correct field.
virtual void * get_pointer (Int whichField, DataType type, const String &recordType) const
const TableRecordRepref () const
 Return a const reference to the underlying TableRecordRep.
TableRecordReprwRef ()
 Return a non-const reference to the underlying TableRecordRep.
virtual void addDataField (const String &name, DataType type, const IPosition &shape, Bool fixedShape, const void *value)
 Add a field to the record.
virtual void defineDataField (Int whichField, DataType type, const void *value)
 Define a value in the given field.

Private Member Functions

virtual RecordDesc getDescription () const
 Get the description of this record.
 TableRecord (TableRecordRep *parent, const RecordDesc &description)
 Create TableRecord as a subrecord.
 TableRecord (TableRecordRep *parent, RecordType type)
void setRecordType (RecordType type)
 Set the recordtype of this record and all its subrecords (recursively).

Private Attributes

COWPtr< TableRecordReprep_p
 The TableRecord representation.
TableRecordRepparent_p
 The parent TableRecord.

Friends

class TableRecordRep
AipsIOoperator<< (AipsIO &os, const TableRecord &rec)
 Write the TableRecord to an output stream.
AipsIOoperator>> (AipsIO &os, TableRecord &rec)
 Read the TableRecord from an input stream.

Detailed Description

A hierarchical collection of named fields of various types.

Intended use:

Public interface

Review Status

Reviewed By:
Mark Wieringa
Date Reviewed:
1996/04/15
Test programs:
tTableRecord

Prerequisite

Etymology

TableRecord is a Record to be used in the Table system.

Synopsis

Class RecordInterface describes the fundamental properties of records.
The TableRecord class is a particular type of a record class. The fields in TableRecord may be of scalar type, array type, a Table or a TableRecord. The types are chosen to be compatible with the native types of the Table system, viz: Bool, uChar, Short, Int, uInt, Float, Double, Complex, DComplex, String. Arrays of all these types are also available. Note that a TableRecord is not a space-efficient way of storing small objects.

The structure of a TableRecord is defined by the RecordDesc class. The structure of the TableRecord can be defined at construction time. It can thereafter be restructured. This has the effect, however, that any existing RecordFieldPtr objects become invalid (using the (see (file="Notice.h"))Notice classes).
It is possible to add or remove fields once a TableRecord is constructed. However, this is not possible when the TableRecord is constructed with a fixed structure (i.e. with the fixedStructure flag set).

A TableRecord is an hierarchical structure, because it can have fields containing TableRecord's (as layed out in the RecordDesc). A subrecord has a variable structure, when its RecordDesc is empty (i.e. contains no fields). It is fixed when its RecordDesc contains fields.

A TableRecord may be assigned to another only if they conform; that is if their fields have the identical type in the identical order. The field names do not need to be identical however, only the types. That is, the structure needs to be identical, but not the labels. Note that field order is significant, [ifield(type=Int),ffield(type=Float)] is not the same as [ffield(type=Float),ifield(type=Int)]
Conformance is checked recursively for fixed subrecords. That is, a variable structured subrecord is not checked, because any record can be assigned to it. A fixed structured subrecord has to conform the corresponding subrecord in the source.
A Table field is conforming when the name of the table description of the source table matches the table description name defined in the RecordDesc field. When that name is blank, every table matches. In fact, defining a table description name is identical to defining an array shape..

When a TableRecord is read back, possible Tables contained in fields are only opended and read back when they are accessed for the first time. In that way no needless table opens are done. When a table has been opened, it is possible to close it. This can be useful to save memory usage.

TableRecord uses copy-on-write semantics. This means that when a TableRecord is copied, only the pointer to the underlying TableRecordRep object is copied. Only when the TableRecord gets changed (i.e. when a non-const TableRecord member function is called), the TableRecordRep object is copied. This results in a cheap copy behaviour.

Example

     {
       TableDesc td ("td", TableDesc::Scratch);
       td.addColumn (ScalarColumnDesc<Int> ("col1"));
       td.addColumn (ScalarColumnDesc<float> ("col2"));
       SetupNewTable newtab ("tTableRecord_tmp.tab1", td1, Table::New);
       Table tab (newtab, 10);
       RecordDesc rd;
       rd.addTable ("tab1", "td");            // with description name
       rd.addField ("tab2", TpTable);         // without description name
       TableRecord rec (rd, RecordInterface::Variable);
       // Both define's are possible.
       // The first one because the table description name matches.
       // The second one because that field has no table description name,
       // thus every table description matches.
       rec.defineTable (rec.fieldNumber("tab1"), tab1);
       rec.defineTable (rec.fieldNumber("tab2"), tab1);
       Table t1 = rec.asTable ("tab1");
       AlwaysAssertExit (t1.nrow() == 10  &&  t1.tableDesc().ncolumn() == 2);
       Table t2 = rec.asTable ("tab2");
       AlwaysAssertExit (t2.nrow() == 10  &&  t2.tableDesc().ncolumn() == 2);
       AipsIO aos ("file.name", ByteIO::New);
       aos << rec;
     }
       // Note that he above is put in a separate scope to be sure that
       // all objects are deleted and tables are written.
     {
       TableRecord rec;
       AipsIO aos ("file.name");
       aos >> rec;
       // At this point the record is read back, but the tables are not opened.
       // The next statement accesses the table resulting in its open.
       Table t1 = rec.asTable ("tab1");
       // The following statement closes it again.
       rec.closeTable ("tab1");

Motivation

In principle the class Record could also support data type Table. However, this would have had the big disadvantage that all the Table code would have be linked in when only a simple Record is needed. It was decided that for that reason it was better to support tables in a separate class.

To Do

Definition at line 182 of file TableRecord.h.


Constructor & Destructor Documentation

Create a record with no fields.

The record has a variable structure.

casa::TableRecord::TableRecord ( RecordType  type,
CheckFieldFunction = 0,
const void *  checkArgument = 0 
) [explicit]

Create a record with no fields.

The type determines if the record has a fixed or variable structure. The callback function is called when a field is added to the Record. That function can check the name and of data type of the new field (for instance, the Table system uses it to ensure that table columns and keywords have different names).

casa::TableRecord::TableRecord ( const RecordDesc description,
RecordType  type = Fixed,
CheckFieldFunction = 0,
const void *  checkArgument = 0 
) [explicit]

Create a record with the given description.

If it is not possible to create all fields (for example, if a field with an unsupported data type is requested), an exception is thrown. The type determines if the record has a fixed or variable structure. All fields are checked by the field checking function (if defined) (for instance, the Table system uses it to ensure that table columns and keywords have different names).

Create a copy of other using copy semantics.

Create a TableRecord from another type of record.

It uses copy-on-write semantics if possible (i.e. if other is a TableRecord), otherwise each field is copied. Subrecords are also copied and converted to TableRecords if needed.

Release resources associated with this object.

casa::TableRecord::TableRecord ( TableRecordRep parent,
const RecordDesc description 
) [private]

Create TableRecord as a subrecord.

When the description is empty, the record has a variable structure. Otherwise it is fixed.

casa::TableRecord::TableRecord ( TableRecordRep parent,
RecordType  type 
) [private]

Member Function Documentation

virtual void casa::TableRecord::addDataField ( const String name,
DataType  type,
const IPosition shape,
Bool  fixedShape,
const void *  value 
) [protected, virtual]

Add a field to the record.

Implements casa::RecordInterface.

Are subtables used in other processes.

Definition at line 529 of file TableRecord.h.

References casa::TableRecordRep::areTablesMultiUsed(), and ref().

virtual const RecordInterface& casa::TableRecord::asRecord ( const RecordFieldId ) const [virtual]

Implements casa::RecordInterface.

Implements casa::RecordInterface.

virtual void casa::TableRecord::assign ( const RecordInterface that) [virtual]

Assign that RecordInterface object to this one.

If that is a TableRecord, copy-on-write is used. Otherwise each individual field is copied.

Implements casa::RecordInterface.

Referenced by casa::ImageInterface< Complex >::setMiscInfoMember().

Get the table from the given field.

Referenced by casa::CalSetMetaInfo::fullSubTableName().

Table casa::TableRecord::asTable ( const RecordFieldId ,
const TableLock lockOptions 
) const
virtual RecordInterface* casa::TableRecord::clone ( ) const [virtual]

Make a copy of this object.

Implements casa::RecordInterface.

void casa::TableRecord::closeTable ( const RecordFieldId ) const

Close the table in the given field.

When accessed again, it will be opened automatically. This can be useful to save memory usage.

void casa::TableRecord::closeTables ( ) const [inline]

Close all open tables.

When accessed again, it will be opened automatically. This can be useful to save memory usage.

Definition at line 513 of file TableRecord.h.

References casa::TableRecordRep::closeTables(), and ref().

virtual const String& casa::TableRecord::comment ( const RecordFieldId ) const [virtual]

Get the comment for this field.

Implements casa::RecordInterface.

Bool casa::TableRecord::conform ( const TableRecord other) const [inline]

Returns True if this and other have the same RecordDesc, other than different names for the fields.

That is, the number, type and the order of the fields must be identical (recursively for fixed structured sub-Records in this).
Caution: thisRecord;conform(thatRecord) == True does not imply
thatRecord;conform(thisRecord) == True, because a variable record in one conforms a fixed record in that, but not vice-versa;

Definition at line 491 of file TableRecord.h.

References casa::TableRecordRep::conform(), and ref().

virtual void casa::TableRecord::defineDataField ( Int  whichField,
DataType  type,
const void *  value 
) [protected, virtual]

Define a value in the given field.

Implements casa::RecordInterface.

void casa::TableRecord::defineRecord ( const RecordFieldId ,
const TableRecord value,
RecordType  type = Variable 
)

Define a value for the given field.

When the field is unknown, it will be added to the record. The second version is meant for any type of record (e.g. Record, TableRecord, GlishRecord). It is converted to a TableRecord using the TableRecord constructor taking a RecordInterface object.

virtual void casa::TableRecord::defineRecord ( const RecordFieldId ,
const RecordInterface value,
RecordType  = Variable 
) [virtual]

Implements casa::RecordInterface.

void casa::TableRecord::defineTable ( const RecordFieldId ,
const Table value,
RecordType  type = Variable 
)
const RecordDesc & casa::TableRecord::description ( ) const [inline]

Describes the current structure of this TableRecord.

Reimplemented from casa::RecordInterface.

Definition at line 486 of file TableRecord.h.

References casa::TableRecordRep::description(), and ref().

virtual Int casa::TableRecord::fieldNumber ( const String fieldName) const [virtual]

Get the field number from the field name.

-1 is returned if the field name is unknown.

Implements casa::RecordInterface.

void casa::TableRecord::flushTables ( Bool  fsync = False) const [inline]

Flush all open subtables.

Definition at line 518 of file TableRecord.h.

References casa::TableRecordRep::flushTables(), and ref().

virtual void* casa::TableRecord::get_pointer ( Int  whichField,
DataType  type 
) const [protected, virtual]

Used by the RecordField classes to attach in a type-safe way to the correct field.

Implements casa::RecordInterface.

virtual void* casa::TableRecord::get_pointer ( Int  whichField,
DataType  type,
const String recordType 
) const [protected, virtual]

Implements casa::RecordInterface.

void casa::TableRecord::getData ( AipsIO os,
uInt  version,
const TableAttr parentAttr 
) [inline]

Read the data of a record.

This is used to read a subrecord, whose description has already been read.

Definition at line 502 of file TableRecord.h.

References casa::TableRecordRep::getData(), and rwRef().

virtual RecordDesc casa::TableRecord::getDescription ( ) const [private, virtual]

Get the description of this record.

Implements casa::RecordInterface.

void casa::TableRecord::getRecord ( AipsIO os,
const TableAttr  
)

Read a record.

This is used to read a subrecord, whose description has not been read.

virtual void casa::TableRecord::makeUnique ( ) [virtual]

Make a unique record representation (to do copy-on-write in RecordFieldPtr).

Implements casa::RecordInterface.

Merge all fields from the other record into this record.

The DuplicatesFlag (as described in RecordInterface ) determines what will be done in case a field name already exists. An exception will be thrown if other is the same as this (i.e. if merging the record itself).

Merge a field from another record into this record.

The DuplicatesFlag (as described in RecordInterface ) determines what will be done in case the field name already exists.

virtual uInt casa::TableRecord::nfields ( ) const [virtual]

How many fields does this structure have? A convenient synonym for description().nfields().

Implements casa::RecordInterface.

TableRecord& casa::TableRecord::operator= ( const TableRecord other)

Copy the data in the other record to this record.

It can operate in 2 ways depending on the TableRecord structure flag.

  • For variable structured records the existing fields are thrown away and replaced by the new fields. This means that RecordFieldPtr's using this record get invalidated. Because copy-on-write semantics are used, this kind of assignment is a very efficient operation.
  • For fixed structured records the existing values are replaced by the new values. This means that RecordFieldPtr's using this record remain valid. The structure of the other record has to conform this record or this record has to be empty, otherwise an exception is thrown. This assignment is less efficient, because it has to check the conformance and because each value has to be copied.


Warning: Attributes like fixed structure flag and check function will not be copied;

Bool casa::TableRecord::operator== ( const TableRecord other) [inline]

Kluge to allow this class to interoperate with the templated ScalarColumnData<T>. In some situations, ScalarColumnData's T can specify the use of a sential value to indicate the value is undefined. This requires that T provide operator==. However, this prevent the TableRecord from being used without going to the large effort to properly define the operator. So, the class is defined and implemented which allows use in the template but if it were ever to be called it will throw the exception and at that time a real == operator will need to be defined (if that's feasible). See also JIRA CAS-4827. (jjacobs 2013-1-29)

Definition at line 535 of file TableRecord.h.

References casa::False.

virtual void casa::TableRecord::print ( std::ostream &  ,
Int  maxNrValues = 25,
const String indent = "" 
) const [virtual]

Print the contents of the record.

Only the first maxNrValues of an array will be printed. A value < 0 means the entire array.

Implements casa::RecordInterface.

void casa::TableRecord::putData ( AipsIO os,
const TableAttr parentAttr 
) const [inline]

Put the data of a record.

This is used to write a subrecord, whose description has already been written.

Definition at line 496 of file TableRecord.h.

References casa::TableRecordRep::putData(), and ref().

void casa::TableRecord::putRecord ( AipsIO os,
const TableAttr  
) const

Put the data of a record.

This is used to write a subrecord, whose description has not been written.

const TableRecordRep & casa::TableRecord::ref ( ) const [inline, protected]

Return a const reference to the underlying TableRecordRep.

Definition at line 482 of file TableRecord.h.

References casa::COWPtr< T >::ref(), and rep_p.

Referenced by areTablesMultiUsed(), closeTables(), conform(), description(), flushTables(), and putData().

void casa::TableRecord::removeField ( const RecordFieldId ) [virtual]

Remove a field from the record.


Caution: Removing a field means that the field number of the fields following it will be decremented; Only the RecordFieldPtr's pointing to the removed field will be invalidated;

Implements casa::RecordInterface.

void casa::TableRecord::renameField ( const String newName,
const RecordFieldId  
)

Rename the given field.

void casa::TableRecord::renameTables ( const String newParentName,
const String oldParentName 
) [inline]

Rename the subtables with a path containing the old parent table name.

Definition at line 523 of file TableRecord.h.

References casa::TableRecordRep::renameTables(), and rwRef().

void casa::TableRecord::reopenRW ( ) [inline]

Reopen possible tables in keywords as read/write.

Tables are not reopened if they are not writable.

Definition at line 508 of file TableRecord.h.

References casa::TableRecordRep::reopenRW(), and rwRef().

virtual void casa::TableRecord::restructure ( const RecordDesc newDescription,
Bool  recursive = True 
) [virtual]

Change the structure of this TableRecord to contain the fields in newDescription.

After calling restructure, description() == newDescription. Any existing RecordFieldPtr objects are invalidated (their isAttached() members return False) after this call.
When the new description contains subrecords, those subrecords will be restructured if recursive=True is given. Otherwise the subrecord is a variable empty record. Subrecords will be variable if their description is empty (i.e. does not contain any field), otherwise they are fixed.
Restructuring is not possible and an exception is thrown if the Record has a fixed structure.

Implements casa::RecordInterface.

Return a non-const reference to the underlying TableRecordRep.

When needed, the TableRecordRep will be copied and all RecordField objects will be notified.

Referenced by getData(), renameTables(), and reopenRW().

virtual void casa::TableRecord::setComment ( const RecordFieldId ,
const String comment 
) [virtual]

Set the comment for this field.

Implements casa::RecordInterface.

void casa::TableRecord::setRecordType ( RecordType  type) [private]

Set the recordtype of this record and all its subrecords (recursively).

void casa::TableRecord::setTableAttr ( const TableRecord other,
const TableAttr defaultAttr 
)

Set the attributes of subtables to te ones in the other record.

It is primarily a helper function for PlainTable::syncTable and ColumnSet::syncColumns.

Get the subrecord or table from the given field.


Note: The non-const version has a different name to prevent that the copy-on-write mechanism makes a copy when not necessary;

Get the attributes of a table field.

virtual DataType casa::TableRecord::type ( Int  whichField) const [virtual]

Get the data type of this field.

Implements casa::RecordInterface.


Friends And Related Function Documentation

AipsIO& operator<< ( AipsIO os,
const TableRecord rec 
) [friend]

Write the TableRecord to an output stream.

AipsIO& operator>> ( AipsIO os,
TableRecord rec 
) [friend]

Read the TableRecord from an input stream.

friend class TableRecordRep [friend]

Definition at line 184 of file TableRecord.h.


Member Data Documentation

The parent TableRecord.

Definition at line 477 of file TableRecord.h.

The TableRecord representation.

Definition at line 475 of file TableRecord.h.

Referenced by ref().


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