RecordDescRep.h

Classes

RecordDescRep -- Representation of a RecordDesc (full description)

class RecordDescRep

Interface

Public Members
RecordDescRep()
RecordDescRep (const RecordDescRep& other)
RecordDescRep& operator= (const RecordDescRep& other)
virtual ~RecordDescRep()
uInt addField (const String& fieldName, DataType scalarOrArrayType)
uInt addArray (const String& fieldName, DataType scalarOrArrayType, const IPosition& shape)
uInt addRecord (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 RecordDescRep& other, Int whichFieldFromOther, int duplicateAction)
uInt merge (const RecordDescRep& other, int duplicateAction)
virtual uInt removeField (Int whichField)
virtual 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& subRecord (Int whichField)
Bool operator== (const RecordDescRep& other) const
Bool operator!= (const RecordDescRep& other) const
Bool conform (const RecordDescRep& other) const
Bool isEqual (const RecordDescRep& other, Bool& equalDataTypes) const
Bool isSubset (const RecordDescRep& other, Bool& equalDataTypes) const
Bool isStrictSubset (const RecordDescRep& other, Bool& equalDataTypes) const
Bool isDisjoint (const RecordDescRep& other) const
Protected Members
void addFieldName (const String& fieldName, DataType type)
virtual void addRepField (const RecordDescRep& other, const String& newName, Int whichField)
void addFieldAny (DataType scalarOrArrayType)
void addFieldArray (DataType scalarOrArrayType, const IPosition& shape)
void setShape (const IPosition& shape, Int whichField)
virtual void increment_length()
void copy_other (const RecordDescRep& other)
Private Members
Bool allExist (const RecordDescRep&, Bool& equalDataTypes) const

Description

Review Status

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

Prerequisite

Etymology

Rep is an often used abbreviation for representation. Thus RecordDescRep is the representation of a RecordDesc.

Synopsis

RecordDescRep is used by RecordDesc to implement its copy-on-write semantics. RecordDesc is the interface to the user, while RecordDescRep contains the actual implementation. See RecordDesc for a more detailed description of a record description.

Example

See the example in the description of the Record class.

Motivation

RecordDescRep is needed to make copy-on-write semantics possible in class RecordDesc.

To Do

Member Description

RecordDescRep()

Create a description with no fields.

RecordDescRep (const RecordDescRep& other)

Create a description which is a copy of other.

RecordDescRep& operator= (const RecordDescRep& other)

Replace this description with other.

virtual ~RecordDescRep()

uInt addField (const String& fieldName, DataType scalarOrArrayType)

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

uInt addArray (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.

uInt addRecord (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.

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 RecordDescRep& other, Int whichFieldFromOther, int duplicateAction)

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 RecordDescRep& other, int duplicateAction)

Add all the fields from another RecordDescRep to the current objects.

virtual uInt removeField (Int whichField)

Remove the given field from the description.

virtual 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 associated with a table.

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

If whichField is a sub-record with a description, return its description. Otherwise an exception is thrown.

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

Bool conform (const RecordDescRep& other) const

Test if this description conforms the other. It is similar to operator==. However, a subrecord in that description always conforms an arbitrary (i.e. empty) subrecord in this description.
This is used by Record, to see if another record can be assigned to this record.

Bool isEqual (const RecordDescRep& 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 RecordDescRep& other, Bool& equalDataTypes) const

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

Bool isStrictSubset (const RecordDescRep& 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 isDisjoint (const RecordDescRep& 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).

void addFieldName (const String& fieldName, DataType type)

Add a field name and its type. It checks if the name is unique and it extends the various blocks using increment_length.

virtual void addRepField (const RecordDescRep& other, const String& newName, Int whichField)

Add a field from another Record description. This is used by the merge functions.

void addFieldAny (DataType scalarOrArrayType)
void addFieldArray (DataType scalarOrArrayType, const IPosition& shape)

Add the field info. These are helper functions for the add functions and can be used in derived classes too.

void setShape (const IPosition& shape, Int whichField)

Set the shape (for a derived class).

virtual void increment_length()
void copy_other (const RecordDescRep& other)

Helper functions

Bool allExist (const RecordDescRep&, Bool& equalDataTypes) const

Test if all fields are part of the other description. The flag equalDataTypes is set to True if the data types of the fields in both descriptions are the same.