RecordDesc.h

Classes

RecordDesc -- Description of the fields in a record object (full description)

class RecordDesc

Interface

Public Members
friend ostream& operator<< (ostream& os, const RecordDesc& desc)
friend AipsIO& operator<< (AipsIO& os, const RecordDesc& desc)
friend AipsIO& operator>> (AipsIO& os, RecordDesc& desc)
RecordDesc()
RecordDesc (const RecordDesc& other)
RecordDesc& operator= (const RecordDesc& other)
~RecordDesc()
uInt addField (const String& fieldName, DataType dataType)
uInt addField (const String& fieldName, DataType scalarOrArrayType, const IPosition& shape)
uInt addField (const String& fieldName, const RecordDesc& subDesc)
uInt addTable (const String& fieldName, const String& tableDescName)
const String& comment (Int whichField) const
void setComment (Int whichField, const String& comment)
void setShape (Int whichField, const IPosition& shape)
uInt mergeField (const RecordDesc& other, Int whichFieldFromOther, RecordInterface::DuplicatesFlag DuplicateAction = RecordInterface::ThrowOnDuplicates)
uInt merge (const RecordDesc& other, RecordInterface::DuplicatesFlag DuplicateAction = RecordInterface::ThrowOnDuplicates)
uInt removeField (Int whichField)
void renameField (const String& newName, Int whichField)
Int fieldNumber (const String& fieldName) const
uInt nfields() const
DataType type (Int whichField) const
const String& name (Int whichField) const
String makeName (Int whichField) const
String uniqueName (const String& name) const
Bool isArray (Int whichField) const
Bool isScalar (Int whichField) const
Bool isSubRecord (Int whichField) const
Bool isTable (Int whichField) const
const IPosition& shape (Int whichField) const
const String& tableDescName (Int whichField) const
const RecordDesc& subRecord (Int whichField) const
RecordDesc& rwSubRecord (Int whichField)
Bool operator== (const RecordDesc& other) const
Bool operator!= (const RecordDesc& other) const
Bool conform (const RecordDesc& other) const
Bool isEqual (const RecordDesc& other, Bool& equalDataTypes) const
Bool isSubset (const RecordDesc& other, Bool& equalDataTypes) const
Bool isStrictSubset (const RecordDesc& other, Bool& equalDataTypes) const
Bool isSuperset (const RecordDesc& other, Bool& equalDataTypes) const
Bool isStrictSuperset (const RecordDesc& other, Bool& equalDataTypes) const
Bool isDisjoint (const RecordDesc& other) const
Private Members
ostream& put (ostream& os) const
AipsIO& put (AipsIO& os) const
AipsIO& get (AipsIO& os)

Description

Review Status

Reviewed By:
Mark Wieringa
Date Reviewed:
1996/04/15
Programs:
Tests:

Prerequisite

Etymology

RecordStructure would perhaps have been the clearest possible name. However it was decided to name it ``RecordDesc'' to use a compatible naming convention with other classes in the system, such as TableDesc. This class Describes the structure of a Record.

Synopsis

RecordDesc describes the structure of Record objects. A Record consists of a number of fields. A RecordDesc describes those fields by assigning to each one: Only one field with a given name is allowed (although fields in subrecords may have the same name as a field in a parent or child Record).

Field indices are zero relative, i.e. they range from 0 to nfields()-1.

Example

See the example in the description of the Record class.

Motivation

It is useful to be able to create many new objects with the same structure as some other, without necessarily cloning it by copying all the values. A ``Description'' type is necessary to do this (e.g., shape for an Array).

To Do

Member Description

friend ostream& operator<< (ostream& os, const RecordDesc& desc)
friend AipsIO& operator<< (AipsIO& os, const RecordDesc& desc)
friend AipsIO& operator>> (AipsIO& os, RecordDesc& desc)

Writes/reads the RecordDesc to/from an output stream.

RecordDesc()

Create a description with no fields.

RecordDesc (const RecordDesc& other)

Create a description which is a copy of other.

RecordDesc& operator= (const RecordDesc& other)

Replace this description with other.

~RecordDesc()

uInt addField (const String& fieldName, DataType dataType)

Add scalar, array, sub-record, or table field. If of array type, the shape is set to [-1], which indicates a variable sized array. If of sub-record type, the sub-record is free format. Returns the number of fields in the description.

uInt addField (const String& fieldName, DataType scalarOrArrayType, const IPosition& shape)

Add an array field of the indicated type. The DataType is promoted from a scalar type to an array type if necessary, e.g., TpInt ->TpArrayInt. Returns the number of fields in the description. A shape of [-1] indicates a variable shape.

uInt addField (const String& fieldName, const RecordDesc& subDesc)

Add a Record field to the description. This allows hierarchical descriptions to be developed. Returns the number of fields in the description.

uInt addTable (const String& fieldName, const String& tableDescName)

Add a Table field to the description. The Table description has the given name. Returns the number of fields in the description.
When a table is put in a record field, it is checked if the name of its description matches this name. If this name is empty, it matches any table description.

Warning Note that not all record types are able to instantiate a table field. E.g. TableRecord can instantiate it, while Record cannot and throws an exception when a record description containing a table field is used.

const String& comment (Int whichField) const

Get the comment for this field.

void setComment (Int whichField, const String& comment)

Set the comment for this field.

void setShape (Int whichField, const IPosition& shape)

Set the shape for this field. An exception will be thrown if the field is no array.

uInt mergeField (const RecordDesc& other, Int whichFieldFromOther, RecordInterface::DuplicatesFlag DuplicateAction = RecordInterface::ThrowOnDuplicates)

Merge a single field from other. If allowDuplicates is True, silently throw away fields if one with the same name and type already exists, otherwise an exception is thrown. Conflicting types always cause an exception. Returns the number of fields in the description.

uInt merge (const RecordDesc& other, RecordInterface::DuplicatesFlag DuplicateAction = RecordInterface::ThrowOnDuplicates)

Add all the fields from another RecordDesc to the current objects. It returns the new number of fields.

uInt removeField (Int whichField)

Remove the given field from the description. It returns the new number of fields.

void renameField (const String& newName, Int whichField)

Rename the given field.

Int fieldNumber (const String& fieldName) const

Returns the index of the field named fieldName. Returns -1 if fieldName does not exist.

uInt nfields() const

Number of fields in the description.

DataType type (Int whichField) const

What is the type of the given field. Returns TpRecord if the field is a sub-Record.

const String& name (Int whichField) const

What is the name of the given field.

String makeName (Int whichField) const

Create a name for a field defined by index as *i (similar to glish). It takes care that the resulting name is unique by adding a suffix _j when needed.

String uniqueName (const String& name) const

Make the given name unique by adding a suffix _j when needed. j is the minimal number needed to make it unique.

Bool isArray (Int whichField) const

Returns True if whichField is an array.

Bool isScalar (Int whichField) const

Returns True if whichField is a scalar.

Bool isSubRecord (Int whichField) const

Returns True if whichField is a sub-record.

Bool isTable (Int whichField) const

Returns True if whichField is a table.

const IPosition& shape (Int whichField) const

What is the shape of the given field. Returns [1] if the field is a scalar, table or, sub-record, [-1] if it is a variable length array, and the actual shape for a fixed length array.

const String& tableDescName (Int whichField) const

What is the name of the table description. Returns an empty string when the field is no table.

const RecordDesc& subRecord (Int whichField) const
RecordDesc& rwSubRecord (Int whichField)

If whichField is a sub-record return its description. Otherwise an exception is thrown. The non-const version is named differently to prevent accidental use of the non-const version.

Bool operator== (const RecordDesc& other) const
Bool operator!= (const RecordDesc& other) const

This and other compare equal if the field types and shapes are identical (recursively if there are described sub-records). The field names are not used.
Use function isEqual if names are important, but order is not.

Bool conform (const RecordDesc& other) const

Test if this description conforms the other. It is NOT doing it recursively, thus is does not check if sub-records are conforming.
This is used by Record, to see if another record can be assigned to this record.

Bool isEqual (const RecordDesc& other, Bool& equalDataTypes) const

Test if this description equals another one. It is equal if the number of fields is equal and all field names in this description occur in the other too. The order of the fields is not important.
The flag equalDataTypes is set to True if the data types of all fields match.
Use function operator== if order and types are important, but names are not.

Bool isSubset (const RecordDesc& other, Bool& equalDataTypes) const

Test if this description is a subset of another one. It is similar to isEqual above.

Bool isStrictSubset (const RecordDesc& other, Bool& equalDataTypes) const

Test if this description is a strict subset of another one, thus if it is a subset and not equal.

Bool isSuperset (const RecordDesc& other, Bool& equalDataTypes) const

Test if this description is a superset of another one.

Bool isStrictSuperset (const RecordDesc& other, Bool& equalDataTypes) const

Test if this description is a strict superset of another one, thus if it is a superset and not equal.

Bool isDisjoint (const RecordDesc& other) const

Test if the set of field names in this and other record description is disjoint (i.e. if they do not share names).

ostream& put (ostream& os) const
AipsIO& put (AipsIO& os) const
AipsIO& get (AipsIO& os)

Writes/reads the RecordDesc to/from an output stream.