casacore
|
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... | |
RecordDescRep & | operator= (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 String & | comment (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 String & | name (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 IPosition & | shape (Int whichField) const |
What is the shape of the given field. More... | |
const String & | tableDescName (Int whichField) const |
What is the name of the table description associated with a table. More... | |
const RecordDesc & | subRecord (Int whichField) const |
If whichField is a sub-record with a description, return its description. More... | |
RecordDesc & | subRecord (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< Int > | types_p |
The DataType of each field. More... | |
Block< String > | names_p |
The name of each field. More... | |
PtrBlock< RecordDesc * > | sub_records_p |
The description of the subrecords. More... | |
Block< IPosition > | shapes_p |
The shape of the field [1] for scalars and sub-records. More... | |
Block< Bool > | is_array_p |
True if the corresponding field is an array. More... | |
Block< String > | tableDescNames_p |
Table description name for table fields. More... | |
Block< String > | comments_p |
Comments for each field. More... | |
std::map< String, Int > | name_map_p |
Mapping of field name to field number. More... | |
Representation of a RecordDesc.
Internal
Rep is an often used abbreviation for representation. Thus RecordDescRep is the representation of a RecordDesc.
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.
See the example in the description of the Record class.
RecordDescRep is needed to make copy-on-write semantics possible in class RecordDesc.
Definition at line 91 of file RecordDescRep.h.
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 |
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.
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.
|
protected |
Add the field info.
These are helper functions for the add functions and can be used in derived classes too.
|
protected |
|
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.
|
protectedvirtual |
Add a field from another Record description.
This is used by the merge functions.
|
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.
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.
|
protected |
Returns the index of the field named fieldName.
Returns -1 if fieldName does not exist.
|
protectedvirtual |
Helper functions.
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.
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.
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.
Returns True if whichField is a table.
Definition at line 332 of file RecordDescRep.h.
References types_p.
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.
What is the name of the given field.
Definition at line 307 of file RecordDescRep.h.
References names_p.
|
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.
Remove the given field from the description.
|
virtual |
Rename the given field.
Set the comment for this field.
Set the shape for this field.
An exception will be thrown if the field is no array.
Set the shape (for a derived class).
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.
|
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 | ) |
What is the name of the table description associated with a table.
Definition at line 343 of file RecordDescRep.h.
References tableDescNames_p.
|
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.
Make the given name unique by adding a suffix _j when needed.
j is the minimal number needed to make it unique.
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().
|
private |
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 shape of the field [1] for scalars and sub-records.
Definition at line 286 of file RecordDescRep.h.
Referenced by shape().
|
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.
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().