casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::MeasureHolder Class Reference

A holder for Measures to enable record conversions. More...

#include <MeasureHolder.h>

Inheritance diagram for casacore::MeasureHolder:
casacore::RecordTransformable

Public Member Functions

 MeasureHolder ()
 Creates an empty holder. More...
 
 MeasureHolder (const Measure &in)
 Create from a Measure (copy made) More...
 
 MeasureHolder (const MeasureHolder &other)
 Copy a holder (copy semantics) More...
 
 ~MeasureHolder ()
 
MeasureHolderoperator= (const MeasureHolder &other)
 Assignment (copy semantics) More...
 
Bool isEmpty () const
 Check the the MeasureHolder holds the specified Measure type. More...
 
Bool isMeasure () const
 
Bool isMDirection () const
 
Bool isMDoppler () const
 
Bool isMEpoch () const
 
Bool isMFrequency () const
 
Bool isMPosition () const
 
Bool isMRadialVelocity () const
 
Bool isMBaseline () const
 
Bool isMuvw () const
 
Bool isMEarthMagnetic () const
 
const MeasureasMeasure () const
 
Get a specific Measure from the holder (with lifetime as long 

as holder exists). More...

 
const MDirectionasMDirection () const
 
const MDopplerasMDoppler () const
 
const MEpochasMEpoch () const
 
const MFrequencyasMFrequency () const
 
const MPositionasMPosition () const
 
const MRadialVelocityasMRadialVelocity () const
 
const MBaselineasMBaseline () const
 
const MuvwasMuvw () const
 
const MEarthMagneticasMEarthMagnetic () const
 
virtual Bool fromRecord (String &error, const RecordInterface &in)
 Create a Measure from a record. More...
 
virtual Bool fromString (String &error, const String &in)
 Initialise the class from a String representation. More...
 
virtual Bool toRecord (String &error, RecordInterface &out) const
 Create a record from a Measure. More...
 
virtual void toRecord (RecordInterface &outRecord) const
 This version throws an exception if the conversion cannot occur. More...
 
Bool toType (String &error, RecordInterface &out) const
 Create a default Measure or a record with only a type from a Measure. More...
 
Bool fromType (String &error, const RecordInterface &in)
 
virtual const Stringident () const
 Get identification of record. More...
 
Bool writeMV () const
 Do we write MeasValues to record? More...
 
void makeMV (uInt n)
 Make a block of n MeasValues. More...
 
uInt nelements () const
 Get number of MeasValue pointers in block. More...
 
Bool setMV (uInt pos, const MeasValue &in)
 Set a measvalue at position pos (False if illegal pos) More...
 
MeasValuegetMV (uInt pos) const
 Get a pointer to a MeasValue (or 0) More...
 
- Public Member Functions inherited from casacore::RecordTransformable
virtual ~RecordTransformable ()
 The destructor must be virtual so that the destructor of derived classes is actually used. More...
 

Private Member Functions

Bool putType (String &error, RecordInterface &out) const
 Aid for to/from Record, String and Type. More...
 
Bool getType (String &error, const RecordInterface &in)
 
Bool getType (String &error, const String &in)
 
void createMV (uInt n)
 Make a MeasValue block of pointers of length n. More...
 

Private Attributes

PtrHolder< Measurehold_p
 Pointer to a Measure. More...
 
Block< MeasValue * > mvhold_p
 Block of pointers to measure values to make a faster interface. More...
 
Bool convertmv_p
 Should the mvhold_p be converted into record? More...
 

Detailed Description

A holder for Measures to enable record conversions.

Intended use:

Public interface

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25
Test programs:
tMeasureHolder

Prerequisite

Etymology

A Holder of general Measures

Synopsis

This class can be used to handle heterogeneous collections of Measures, e.g. as a Vector<MeasureHolder>. With the aid of the toRecord() and fromRecord() functions it can be used to convert a Measure object into or from a record. A MeasureHolder is created from a Measure, or can be empty.

Checks on the contents can be made with functions like isMDirection and the contents can be obtained with functions like asMDirection. It is an error to try and retrieve a measure of the wrong type and doing so will generate an exception (AipsError).

The MeasureHolder can, in addition to the Measure it is holding, also hold a block of MeasValues. This is especially useful for intertask communication (e.g. with Glish), for reasons of speed. In general the additional values will be created when the record used to create a Holder contains a Quantity<Vector> rather than a quantity in the m0, m1 and/or m2 fields. The getMV() method can be used to access the nelements() additional information. They can be (re-)set with the setMV() method (after a possible creation of the extra block if not already there, or of the wrong length, with makeMV(). If any value is set they will be used in creating records, with the first value always overwriting the actual Measure value.

Example

TableRecord rec;
MDirection dir(MVDirection(Quantity(12.5, 'deg'), Quantity(-2, 'deg')),
String error; // error message
if (!MeasureHolder(dir).toRecord(error, rec)) {
cout << error << endl;
}
Record grec; // a Record
if (!MeasureHolder(dir).toRecord(error, grec)) { // make record
cout << error << endl;
}
// Note that for GlishRecords use can be made of the
// GlishRecord::to/fromrecord() methods.

Motivation

To make general conversions between Measures and records, without knowing the actual Measure being converted.

Definition at line 119 of file MeasureHolder.h.

Constructor & Destructor Documentation

casacore::MeasureHolder::MeasureHolder ( )

Creates an empty holder.

casacore::MeasureHolder::MeasureHolder ( const Measure in)

Create from a Measure (copy made)

casacore::MeasureHolder::MeasureHolder ( const MeasureHolder other)

Copy a holder (copy semantics)

casacore::MeasureHolder::~MeasureHolder ( )

Member Function Documentation

const MBaseline& casacore::MeasureHolder::asMBaseline ( ) const
const MDirection& casacore::MeasureHolder::asMDirection ( ) const
const MDoppler& casacore::MeasureHolder::asMDoppler ( ) const
const MEarthMagnetic& casacore::MeasureHolder::asMEarthMagnetic ( ) const
const Measure& casacore::MeasureHolder::asMeasure ( ) const

Get a specific Measure from the holder (with lifetime as long 

as holder exists).

Thrown Exceptions

const MEpoch& casacore::MeasureHolder::asMEpoch ( ) const
const MFrequency& casacore::MeasureHolder::asMFrequency ( ) const
const MPosition& casacore::MeasureHolder::asMPosition ( ) const
const MRadialVelocity& casacore::MeasureHolder::asMRadialVelocity ( ) const
const Muvw& casacore::MeasureHolder::asMuvw ( ) const
void casacore::MeasureHolder::createMV ( uInt  n)
private

Make a MeasValue block of pointers of length n.

Referenced by makeMV().

virtual Bool casacore::MeasureHolder::fromRecord ( String error,
const RecordInterface in 
)
virtual

Create a Measure from a record.

An error message is generated, and False returned if an invalid record is given. A valid record will return True. A valid record contains the following fields (any additional fields are ignored):

  • type = TpString: type of Measure (direction, epoch, etc; case insensitive)
  • refer = TpString: reference type of Measure (case insensitive; enough characters to be unique (e.g. J20, j200, utc, b1950, J2000); unknown reference type will log an error message and translate into the default type for the Measure.
  • m0, m1,... = TpRecord(Quantity): one or more Quantities giving the value(s) for this Measure (e.g. longitude and latitude for a direction). Each quantity can either be a scalar quantity or a Quantum<Vector<Double> >.
  • offset = TpRecord(Measure)–optional: an optional offset as a Measure of the same type as the main Measure (e.g. an MEpoch for an MEpoch)

A Measure can be created from a string. In that case the string will only indicate the type of measure (like direction), and will create a default measure of that given type. In essence identical to the fromType() method. Error messages are postfixed to error.

Implements casacore::RecordTransformable.

virtual Bool casacore::MeasureHolder::fromString ( String error,
const String inString 
)
virtual

Initialise the class from a String representation.

A string cannot contain enough information for many objects. Hence the default implementation of this class returns False, indicating that the class could not be initialised and an error message is appended to the supplied string. If the class can be initialised from a string then this function should be overridden.

Reimplemented from casacore::RecordTransformable.

Bool casacore::MeasureHolder::fromType ( String error,
const RecordInterface in 
)
MeasValue* casacore::MeasureHolder::getMV ( uInt  pos) const

Get a pointer to a MeasValue (or 0)

Bool casacore::MeasureHolder::getType ( String error,
const RecordInterface in 
)
private
Bool casacore::MeasureHolder::getType ( String error,
const String in 
)
private
virtual const String& casacore::MeasureHolder::ident ( ) const
virtual

Get identification of record.

Reimplemented from casacore::RecordTransformable.

Bool casacore::MeasureHolder::isEmpty ( ) const

Check the the MeasureHolder holds the specified Measure type.

Return True if if does and False otherwise.

Bool casacore::MeasureHolder::isMBaseline ( ) const
Bool casacore::MeasureHolder::isMDirection ( ) const
Bool casacore::MeasureHolder::isMDoppler ( ) const
Bool casacore::MeasureHolder::isMEarthMagnetic ( ) const
Bool casacore::MeasureHolder::isMeasure ( ) const
Bool casacore::MeasureHolder::isMEpoch ( ) const
Bool casacore::MeasureHolder::isMFrequency ( ) const
Bool casacore::MeasureHolder::isMPosition ( ) const
Bool casacore::MeasureHolder::isMRadialVelocity ( ) const
Bool casacore::MeasureHolder::isMuvw ( ) const
void casacore::MeasureHolder::makeMV ( uInt  n)
inline

Make a block of n MeasValues.

Definition at line 227 of file MeasureHolder.h.

References createMV().

uInt casacore::MeasureHolder::nelements ( ) const
inline

Get number of MeasValue pointers in block.

Definition at line 229 of file MeasureHolder.h.

References mvhold_p.

MeasureHolder& casacore::MeasureHolder::operator= ( const MeasureHolder other)

Assignment (copy semantics)

Bool casacore::MeasureHolder::putType ( String error,
RecordInterface out 
) const
private

Aid for to/from Record, String and Type.

Bool casacore::MeasureHolder::setMV ( uInt  pos,
const MeasValue in 
)

Set a measvalue at position pos (False if illegal pos)

virtual Bool casacore::MeasureHolder::toRecord ( String error,
RecordInterface out 
) const
virtual

Create a record from a Measure.

The return will be False and an error message generated only if the MeasureHolder does not contain a Measure. Error messages are postfixed to error.

Implements casacore::RecordTransformable.

virtual void casacore::MeasureHolder::toRecord ( RecordInterface outRecord) const
virtual

This version throws an exception if the conversion cannot occur.

It is meant for more allow more compact calling code for callers that are content with just letting the exception proceed up the call stack so they do not have to check a return status. This is, among other things, what exceptions are for after all.

Bool casacore::MeasureHolder::toType ( String error,
RecordInterface out 
) const

Create a default Measure or a record with only a type from a Measure.

Bool casacore::MeasureHolder::writeMV ( ) const
inline

Do we write MeasValues to record?

Definition at line 225 of file MeasureHolder.h.

References convertmv_p.

Member Data Documentation

Bool casacore::MeasureHolder::convertmv_p
private

Should the mvhold_p be converted into record?

Definition at line 243 of file MeasureHolder.h.

Referenced by writeMV().

PtrHolder<Measure> casacore::MeasureHolder::hold_p
private

Pointer to a Measure.

Definition at line 239 of file MeasureHolder.h.

Block<MeasValue *> casacore::MeasureHolder::mvhold_p
private

Block of pointers to measure values to make a faster interface.

Definition at line 241 of file MeasureHolder.h.

Referenced by nelements().


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