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
casa::RecordDescRep Class Reference

Representation of a RecordDesc. More...

#include <RecordDescRep.h>

List of all members.

Public Member Functions

 RecordDescRep ()
 Create a description with no fields.
 RecordDescRep (const RecordDescRep &other)
 Create a description which is a copy of other.
RecordDescRepoperator= (const RecordDescRep &other)
 Replace this description with other.
virtual ~RecordDescRep ()
uInt addField (const String &fieldName, DataType scalarOrArrayType)
 Add scalar or array field.
uInt addArray (const String &fieldName, DataType scalarOrArrayType, const IPosition &shape)
 Add an array field of the indicated type.
uInt addRecord (const String &fieldName, const RecordDesc &subDesc)
 Add a Record field to the description.
uInt addTable (const String &fieldName, const String &tableDescName)
 Add a Table field to the description.
const Stringcomment (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.
uInt mergeField (const RecordDescRep &other, Int whichFieldFromOther, int duplicateAction)
 Merge a single field from other.
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.
uInt nfields () const
 Number of fields in the description.
DataType type (Int whichField) const
 What is the type of the given field.
const Stringname (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).
String uniqueName (const String &name) const
 Make the given name unique by adding a suffix _j when needed.
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 IPositionshape (Int whichField) const
 What is the shape of the given field.
const StringtableDescName (Int whichField) const
 What is the name of the table description associated with a table.
const RecordDescsubRecord (Int whichField) const
 If whichField is a sub-record with a description, return its description.
RecordDescsubRecord (Int whichField)
Bool operator== (const RecordDescRep &other) const
 This and other compare equal if the field types and shapes are identical (recursively if there are described sub-records or tables).
Bool operator!= (const RecordDescRep &other) const
Bool conform (const RecordDescRep &other) const
 Test if this description conforms the other.
Bool isEqual (const RecordDescRep &other, Bool &equalDataTypes) const
 Test if this description equals another one.
Bool isSubset (const RecordDescRep &other, Bool &equalDataTypes) const
 Test if this description is a subset of another one.
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.

Protected Member Functions

void addFieldName (const String &fieldName, DataType type)
 Add a field name and its type.
virtual void addRepField (const RecordDescRep &other, const String &newName, Int whichField)
 Add a field from another Record description.
void addFieldAny (DataType scalarOrArrayType)
 Add the field info.
void addFieldArray (DataType scalarOrArrayType, const IPosition &shape)
void setShape (const IPosition &shape, Int whichField)
 Set the shape (for a derived class).
virtual void increment_length ()
 Helper functions.
void copy_other (const RecordDescRep &other)

Private Member Functions

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

Private Attributes

uInt n_p
 Number of fields in the description.
Block< Inttypes_p
 The DataType of each field.
Block< Stringnames_p
 The name of each field.
PtrBlock< RecordDesc * > sub_records_p
 The description of the subrecords.
Block< IPositionshapes_p
 The shape of the field [1] for scalars and sub-records.
Block< Boolis_array_p
 True if the corresponding field is an array.
Block< StringtableDescNames_p
 Table description name for table fields.
Block< Stringcomments_p
 Comments for each field.
SimpleOrderedMap< String, Intname_map_p
 Mapping of field name to field number.

Detailed Description

Representation of a RecordDesc.

Intended use:

Internal

Review Status

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

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

Definition at line 91 of file RecordDescRep.h.


Constructor & Destructor Documentation

Create a description with no fields.

Create a description which is a copy of other.

virtual casa::RecordDescRep::~RecordDescRep ( ) [virtual]

Member Function Documentation

uInt casa::RecordDescRep::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.

Referenced by casa::RecordDesc::addField().

uInt casa::RecordDescRep::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.

Referenced by casa::RecordDesc::addField().

void casa::RecordDescRep::addFieldAny ( DataType  scalarOrArrayType) [protected]

Add the field info.

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

void casa::RecordDescRep::addFieldArray ( DataType  scalarOrArrayType,
const IPosition shape 
) [protected]
void casa::RecordDescRep::addFieldName ( const String fieldName,
DataType  type 
) [protected]

Add a field name and its type.

It checks if the name is unique and it extends the various blocks using increment_length.

uInt casa::RecordDescRep::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.

Referenced by casa::RecordDesc::addField().

virtual void casa::RecordDescRep::addRepField ( const RecordDescRep other,
const String newName,
Int  whichField 
) [protected, virtual]

Add a field from another Record description.

This is used by the merge functions.

uInt casa::RecordDescRep::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.

Referenced by casa::RecordDesc::addTable().

Bool casa::RecordDescRep::allExist ( const RecordDescRep ,
Bool equalDataTypes 
) const [private]

     

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.

const String& casa::RecordDescRep::comment ( Int  whichField) const

Get the comment for this field.

Referenced by casa::RecordDesc::comment().

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.

Referenced by casa::RecordDesc::conform().

void casa::RecordDescRep::copy_other ( const RecordDescRep other) [protected]
Int casa::RecordDescRep::fieldNumber ( const String fieldName) const

Returns the index of the field named fieldName.

Returns -1 if fieldName does not exist.

Referenced by casa::RecordDesc::fieldNumber().

virtual void casa::RecordDescRep::increment_length ( ) [protected, virtual]

Helper functions.

Bool casa::RecordDescRep::isArray ( Int  whichField) const [inline]

Returns True if whichField is an array.

Definition at line 317 of file RecordDescRep.h.

References is_array_p.

Referenced by casa::RecordDesc::isArray().

Test if the set of field names in this and other record description is disjoint (i.e.

if they do not share names).

Referenced by casa::RecordDesc::isDisjoint().

Bool casa::RecordDescRep::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.

Referenced by casa::RecordDesc::isEqual().

Bool casa::RecordDescRep::isScalar ( Int  whichField) const [inline]

Returns True if whichField is a scalar.

Definition at line 322 of file RecordDescRep.h.

References types_p.

Referenced by casa::RecordDesc::isScalar().

Bool casa::RecordDescRep::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.

Referenced by casa::RecordDesc::isStrictSubset(), and casa::RecordDesc::isStrictSuperset().

Bool casa::RecordDescRep::isSubRecord ( Int  whichField) const [inline]

Returns True if whichField is a sub-record.

Definition at line 327 of file RecordDescRep.h.

References types_p.

Referenced by casa::RecordDesc::isSubRecord().

Bool casa::RecordDescRep::isSubset ( const RecordDescRep other,
Bool equalDataTypes 
) const

Test if this description is a subset of another one.

It is similar to isEqual above.

Referenced by casa::RecordDesc::isSubset(), and casa::RecordDesc::isSuperset().

Bool casa::RecordDescRep::isTable ( Int  whichField) const [inline]

Returns True if whichField is a table.

Definition at line 332 of file RecordDescRep.h.

References types_p.

Referenced by casa::RecordDesc::isTable().

String casa::RecordDescRep::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.

Referenced by casa::RecordDesc::makeName().

uInt casa::RecordDescRep::merge ( const RecordDescRep other,
int  duplicateAction 
)

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

Referenced by casa::RecordDesc::merge().

uInt casa::RecordDescRep::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.

Referenced by casa::RecordDesc::mergeField().

const String & casa::RecordDescRep::name ( Int  whichField) const [inline]

What is the name of the given field.

Definition at line 307 of file RecordDescRep.h.

References names_p.

Referenced by casa::RecordDesc::name().

uInt casa::RecordDescRep::nfields ( ) const [inline]

Number of fields in the description.

Definition at line 297 of file RecordDescRep.h.

References n_p.

Referenced by casa::RecordDesc::nfields().

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

Replace this description with other.

Bool casa::RecordDescRep::operator== ( const RecordDescRep other) const

This and other compare equal if the field types and shapes are identical (recursively if there are described sub-records or tables).

The field names are not used.

virtual uInt casa::RecordDescRep::removeField ( Int  whichField) [virtual]

Remove the given field from the description.

Referenced by casa::RecordDesc::removeField().

virtual void casa::RecordDescRep::renameField ( const String newName,
Int  whichField 
) [virtual]

Rename the given field.

Referenced by casa::RecordDesc::renameField().

void casa::RecordDescRep::setComment ( Int  whichField,
const String comment 
)

Set the comment for this field.

Referenced by casa::RecordDesc::setComment().

void casa::RecordDescRep::setShape ( Int  whichField,
const IPosition shape 
)

Set the shape for this field.

An exception will be thrown if the field is no array.

Referenced by casa::RecordDesc::setShape().

void casa::RecordDescRep::setShape ( const IPosition shape,
Int  whichField 
) [protected]

Set the shape (for a derived class).

const IPosition & casa::RecordDescRep::shape ( Int  whichField) const [inline]

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.

Definition at line 312 of file RecordDescRep.h.

References shapes_p.

Referenced by casa::RecordDesc::shape().

const RecordDesc & casa::RecordDescRep::subRecord ( Int  whichField) const [inline]

If whichField is a sub-record with a description, return its description.

Otherwise an exception is thrown.

Definition at line 337 of file RecordDescRep.h.

References casa::RecordDesc::subRecord().

Referenced by casa::RecordDesc::rwSubRecord(), and casa::RecordDesc::subRecord().

const String & casa::RecordDescRep::tableDescName ( Int  whichField) const [inline]

What is the name of the table description associated with a table.

Definition at line 343 of file RecordDescRep.h.

References tableDescNames_p.

Referenced by casa::RecordDesc::tableDescName().

DataType casa::RecordDescRep::type ( Int  whichField) const [inline]

What is the type of the given field.

Returns TpRecord if the field is a sub-Record.

Definition at line 302 of file RecordDescRep.h.

References types_p.

Referenced by casa::RecordDesc::type().

Make the given name unique by adding a suffix _j when needed.

j is the minimal number needed to make it unique.

Referenced by casa::RecordDesc::uniqueName().


Member Data Documentation

Comments for each field.

Definition at line 292 of file RecordDescRep.h.

True if the corresponding field is an array.

Definition at line 288 of file RecordDescRep.h.

Referenced by isArray().

Number of fields in the description.

Definition at line 275 of file RecordDescRep.h.

Referenced by nfields().

Mapping of field name to field number.

Definition at line 294 of file RecordDescRep.h.

The name of each field.

Definition at line 279 of file RecordDescRep.h.

Referenced by name().

The shape of the field [1] for scalars and sub-records.

Definition at line 286 of file RecordDescRep.h.

Referenced by shape().

The description of the subrecords.

Null if the field is not a subrecord. This isn't the most efficient representation. If this is ever an issue we could calculate these, or store them in one Block, or implement copy-on-write semantics.

Definition at line 284 of file RecordDescRep.h.

Table description name for table fields.

Definition at line 290 of file RecordDescRep.h.

Referenced by tableDescName().

The DataType of each field.

Definition at line 277 of file RecordDescRep.h.

Referenced by isScalar(), isSubRecord(), isTable(), and type().


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