casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::RecordDescRep Class Reference

Representation of a RecordDesc. More...

#include <RecordDescRep.h>

Public Member Functions

 RecordDescRep ()
 Create a description with no fields. More...
 
 RecordDescRep (const RecordDescRep &other)
 Create a description which is a copy of other. More...
 
RecordDescRepoperator= (const RecordDescRep &other)
 Replace this description with other. More...
 
virtual ~RecordDescRep ()
 
uInt addField (const String &fieldName, DataType scalarOrArrayType)
 Add scalar or array field. More...
 
uInt addArray (const String &fieldName, DataType scalarOrArrayType, const IPosition &shape)
 Add an array field of the indicated type. More...
 
uInt addRecord (const String &fieldName, const RecordDesc &subDesc)
 Add a Record field to the description. More...
 
uInt addTable (const String &fieldName, const String &tableDescName)
 Add a Table field to the description. More...
 
const Stringcomment (Int whichField) const
 Get the comment for this field. More...
 
void setComment (Int whichField, const String &comment)
 Set the comment for this field. More...
 
void setShape (Int whichField, const IPosition &shape)
 Set the shape for this field. More...
 
uInt mergeField (const RecordDescRep &other, Int whichFieldFromOther, int duplicateAction)
 Merge a single field from other. More...
 
uInt merge (const RecordDescRep &other, int duplicateAction)
 Add all the fields from another RecordDescRep to the current objects. More...
 
virtual uInt removeField (Int whichField)
 Remove the given field from the description. More...
 
virtual void renameField (const String &newName, Int whichField)
 Rename the given field. More...
 
Int fieldNumber (const String &fieldName) const
 Returns the index of the field named fieldName. More...
 
uInt nfields () const
 Number of fields in the description. More...
 
DataType type (Int whichField) const
 What is the type of the given field. More...
 
const Stringname (Int whichField) const
 What is the name of the given field. More...
 
String makeName (Int whichField) const
 Create a name for a field defined by index as *i (similar to glish). More...
 
String uniqueName (const String &name) const
 Make the given name unique by adding a suffix _j when needed. More...
 
Bool isArray (Int whichField) const
 Returns True if whichField is an array. More...
 
Bool isScalar (Int whichField) const
 Returns True if whichField is a scalar. More...
 
Bool isSubRecord (Int whichField) const
 Returns True if whichField is a sub-record. More...
 
Bool isTable (Int whichField) const
 Returns True if whichField is a table. More...
 
const IPositionshape (Int whichField) const
 What is the shape of the given field. More...
 
const StringtableDescName (Int whichField) const
 What is the name of the table description associated with a table. More...
 
const RecordDescsubRecord (Int whichField) const
 If whichField is a sub-record with a description, return its description. More...
 
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). More...
 
Bool operator!= (const RecordDescRep &other) const
 
Bool conform (const RecordDescRep &other) const
 Test if this description conforms the other. More...
 
Bool isEqual (const RecordDescRep &other, Bool &equalDataTypes) const
 Test if this description equals another one. More...
 
Bool isSubset (const RecordDescRep &other, Bool &equalDataTypes) const
 Test if this description is a subset of another one. More...
 
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. More...
 
Bool isDisjoint (const RecordDescRep &other) const
 Test if the set of field names in this and other record description is disjoint (i.e. More...
 

Protected Member Functions

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

Private Member Functions

Bool allExist (const RecordDescRep &, Bool &equalDataTypes) const
 Test if all fields are part of the other description. More...
 

Private Attributes

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

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

casacore::RecordDescRep::RecordDescRep ( )

Create a description with no fields.

casacore::RecordDescRep::RecordDescRep ( const RecordDescRep other)

Create a description which is a copy of other.

virtual casacore::RecordDescRep::~RecordDescRep ( )
virtual

Member Function Documentation

uInt casacore::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.

uInt casacore::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.

void casacore::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 casacore::RecordDescRep::addFieldArray ( DataType  scalarOrArrayType,
const IPosition shape 
)
protected
void casacore::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 casacore::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.

virtual void casacore::RecordDescRep::addRepField ( const RecordDescRep other,
const String newName,
Int  whichField 
)
protectedvirtual

Add a field from another Record description.

This is used by the merge functions.

uInt casacore::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.

Bool casacore::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& casacore::RecordDescRep::comment ( Int  whichField) const

Get the comment for this field.

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

void casacore::RecordDescRep::copy_other ( const RecordDescRep other)
protected
Int casacore::RecordDescRep::fieldNumber ( const String fieldName) const

Returns the index of the field named fieldName.

Returns -1 if fieldName does not exist.

virtual void casacore::RecordDescRep::increment_length ( )
protectedvirtual

Helper functions.

Bool casacore::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.

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

Bool casacore::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.

Bool casacore::RecordDescRep::isScalar ( Int  whichField) const
inline

Returns True if whichField is a scalar.

Definition at line 322 of file RecordDescRep.h.

References types_p.

Bool casacore::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.

Bool casacore::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.

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

Test if this description is a subset of another one.

It is similar to isEqual above.

Bool casacore::RecordDescRep::isTable ( Int  whichField) const
inline

Returns True if whichField is a table.

Definition at line 332 of file RecordDescRep.h.

References types_p.

String casacore::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.

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

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

uInt casacore::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.

const String & casacore::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.

uInt casacore::RecordDescRep::nfields ( ) const
inline

Number of fields in the description.

Definition at line 297 of file RecordDescRep.h.

References n_p.

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

Replace this description with other.

Bool casacore::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 casacore::RecordDescRep::removeField ( Int  whichField)
virtual

Remove the given field from the description.

virtual void casacore::RecordDescRep::renameField ( const String newName,
Int  whichField 
)
virtual

Rename the given field.

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

Set the comment for this field.

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

Set the shape for this field.

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

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

Set the shape (for a derived class).

const IPosition & casacore::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.

const RecordDesc & casacore::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 casacore::RecordDesc::subRecord().

RecordDesc& casacore::RecordDescRep::subRecord ( Int  whichField)
const String & casacore::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.

DataType casacore::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.

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

Member Data Documentation

Block<String> casacore::RecordDescRep::comments_p
private

Comments for each field.

Definition at line 292 of file RecordDescRep.h.

Block<Bool> casacore::RecordDescRep::is_array_p
private

True if the corresponding field is an array.

Definition at line 288 of file RecordDescRep.h.

Referenced by isArray().

uInt casacore::RecordDescRep::n_p
private

Number of fields in the description.

Definition at line 275 of file RecordDescRep.h.

Referenced by nfields().

std::map<String,Int> casacore::RecordDescRep::name_map_p
private

Mapping of field name to field number.

Definition at line 294 of file RecordDescRep.h.

Block<String> casacore::RecordDescRep::names_p
private

The name of each field.

Definition at line 279 of file RecordDescRep.h.

Referenced by name().

Block<IPosition> casacore::RecordDescRep::shapes_p
private

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

Definition at line 286 of file RecordDescRep.h.

Referenced by shape().

PtrBlock<RecordDesc*> casacore::RecordDescRep::sub_records_p
private

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.

Block<String> casacore::RecordDescRep::tableDescNames_p
private

Table description name for table fields.

Definition at line 290 of file RecordDescRep.h.

Referenced by tableDescName().

Block<Int> casacore::RecordDescRep::types_p
private

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: