casa
$Rev:20696$
|
A holder for Measures to enable record conversions. More...
#include <MeasureHolder.h>
Public Member Functions | |
MeasureHolder () | |
Creates an empty holder. | |
MeasureHolder (const Measure &in) | |
Create from a Measure (copy made) | |
MeasureHolder (const MeasureHolder &other) | |
Copy a holder (copy semantics) | |
~MeasureHolder () | |
MeasureHolder & | operator= (const MeasureHolder &other) |
Assignment (copy semantics) | |
Bool | isEmpty () const |
Check the the MeasureHolder holds the specified Measure type. | |
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 Measure & | asMeasure () const |
Get a specific Measure from the holder (with lifetime as long as holder exists). | |
const MDirection & | asMDirection () const |
const MDoppler & | asMDoppler () const |
const MEpoch & | asMEpoch () const |
const MFrequency & | asMFrequency () const |
const MPosition & | asMPosition () const |
const MRadialVelocity & | asMRadialVelocity () const |
const MBaseline & | asMBaseline () const |
const Muvw & | asMuvw () const |
const MEarthMagnetic & | asMEarthMagnetic () const |
virtual Bool | fromRecord (String &error, const RecordInterface &in) |
Create a Measure from a record. | |
virtual Bool | fromString (String &error, const String &in) |
Initialise the class from a String representation. | |
virtual Bool | toRecord (String &error, RecordInterface &out) const |
Create a record from a Measure. | |
virtual void | toRecord (RecordInterface &outRecord) const |
This version throws an exception if the conversion cannot occur. | |
Bool | toType (String &error, RecordInterface &out) const |
Create a default Measure or a record with only a type from a Measure. | |
Bool | fromType (String &error, const RecordInterface &in) |
virtual const String & | ident () const |
Get identification of record. | |
Bool | writeMV () const |
Do we write MeasValues to record? | |
void | makeMV (uInt n) |
Make a block of n MeasValues. | |
uInt | nelements () const |
Get number of MeasValue pointers in block. | |
Bool | setMV (uInt pos, const MeasValue &in) |
Set a measvalue at position pos (False if illegal pos) | |
MeasValue * | getMV (uInt pos) const |
Get a pointer to a MeasValue (or 0) | |
Private Member Functions | |
Bool | putType (String &error, RecordInterface &out) const |
Aid for to/from Record, String and Type. | |
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. | |
Private Attributes | |
PtrHolder< Measure > | hold_p |
Pointer to a Measure. | |
Block< MeasValue * > | mvhold_p |
Block of pointers to measure values to make a faster interface. | |
Bool | convertmv_p |
Should the mvhold_p be converted into record? |
A holder for Measures to enable record conversions.
Public interface
<h3>Review Status</h3><dl><dt>Reviewed By:<dd>UNKNOWN<dt>Date Reviewed:<dd>before2004/08/25<dt>Test programs:<dd>tMeasureHolder</dl>
A Holder of general Measures
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.
TableRecord rec; MDirection dir(MVDirection(Quantity(12.5, 'deg'), Quantity(-2, 'deg')), MDirection::J2000); 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.
To make general conversions between Measures and records, without knowing the actual Measure being converted.
Definition at line 119 of file MeasureHolder.h.
Creates an empty holder.
casa::MeasureHolder::MeasureHolder | ( | const Measure & | in | ) |
Create from a Measure (copy made)
casa::MeasureHolder::MeasureHolder | ( | const MeasureHolder & | other | ) |
Copy a holder (copy semantics)
const MBaseline& casa::MeasureHolder::asMBaseline | ( | ) | const |
const MDirection& casa::MeasureHolder::asMDirection | ( | ) | const |
const MDoppler& casa::MeasureHolder::asMDoppler | ( | ) | const |
const MEarthMagnetic& casa::MeasureHolder::asMEarthMagnetic | ( | ) | const |
const Measure& casa::MeasureHolder::asMeasure | ( | ) | const |
const MEpoch& casa::MeasureHolder::asMEpoch | ( | ) | const |
const MFrequency& casa::MeasureHolder::asMFrequency | ( | ) | const |
const MPosition& casa::MeasureHolder::asMPosition | ( | ) | const |
const MRadialVelocity& casa::MeasureHolder::asMRadialVelocity | ( | ) | const |
const Muvw& casa::MeasureHolder::asMuvw | ( | ) | const |
void casa::MeasureHolder::createMV | ( | uInt | n | ) | [private] |
virtual Bool casa::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):
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 casa::RecordTransformable.
virtual Bool casa::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 casa::RecordTransformable.
Bool casa::MeasureHolder::fromType | ( | String & | error, |
const RecordInterface & | in | ||
) |
MeasValue* casa::MeasureHolder::getMV | ( | uInt | pos | ) | const |
Get a pointer to a MeasValue (or 0)
Bool casa::MeasureHolder::getType | ( | String & | error, |
const RecordInterface & | in | ||
) | [private] |
Bool casa::MeasureHolder::getType | ( | String & | error, |
const String & | in | ||
) | [private] |
virtual const String& casa::MeasureHolder::ident | ( | ) | const [virtual] |
Get identification of record.
Reimplemented from casa::RecordTransformable.
Bool casa::MeasureHolder::isEmpty | ( | ) | const |
Check the the MeasureHolder holds the specified Measure type.
Return True if if does and False otherwise.
Bool casa::MeasureHolder::isMBaseline | ( | ) | const |
Bool casa::MeasureHolder::isMDirection | ( | ) | const |
Bool casa::MeasureHolder::isMDoppler | ( | ) | const |
Bool casa::MeasureHolder::isMEarthMagnetic | ( | ) | const |
Bool casa::MeasureHolder::isMeasure | ( | ) | const |
Bool casa::MeasureHolder::isMEpoch | ( | ) | const |
Bool casa::MeasureHolder::isMFrequency | ( | ) | const |
Bool casa::MeasureHolder::isMPosition | ( | ) | const |
Bool casa::MeasureHolder::isMRadialVelocity | ( | ) | const |
Bool casa::MeasureHolder::isMuvw | ( | ) | const |
void casa::MeasureHolder::makeMV | ( | uInt | n | ) | [inline] |
Make a block of n MeasValues.
Definition at line 235 of file MeasureHolder.h.
References createMV().
uInt casa::MeasureHolder::nelements | ( | ) | const [inline] |
Get number of MeasValue pointers in block.
Definition at line 237 of file MeasureHolder.h.
References mvhold_p, and casa::Block< T >::nelements().
MeasureHolder& casa::MeasureHolder::operator= | ( | const MeasureHolder & | other | ) |
Assignment (copy semantics)
Bool casa::MeasureHolder::putType | ( | String & | error, |
RecordInterface & | out | ||
) | const [private] |
Bool casa::MeasureHolder::setMV | ( | uInt | pos, |
const MeasValue & | in | ||
) |
Set a measvalue at position pos (False if illegal pos)
virtual Bool casa::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 casa::RecordTransformable.
virtual void casa::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. TODO. I'd rather return the RecordInterface, but since RecordInterface is abstract, that means returning a pointer that is created internally. That really should be done using a smart pointer, but other than our own PtrHolder (which I'd really rather not use), auto_ptr is really the only thing that can be used at this point. auto_ptr has its own issues and is frowned on by other casacore partners, so I don't want to litter casacore code with that. unique_ptr is a much better solution, but as of now that is still not available. When it becomes available this issue can be revisited.
Bool casa::MeasureHolder::toType | ( | String & | error, |
RecordInterface & | out | ||
) | const |
Bool casa::MeasureHolder::writeMV | ( | ) | const [inline] |
Do we write MeasValues to record?
Definition at line 233 of file MeasureHolder.h.
References convertmv_p.
Bool casa::MeasureHolder::convertmv_p [private] |
Should the mvhold_p be converted into record?
Definition at line 251 of file MeasureHolder.h.
Referenced by writeMV().
PtrHolder<Measure> casa::MeasureHolder::hold_p [private] |
Pointer to a Measure.
Definition at line 247 of file MeasureHolder.h.
Block<MeasValue *> casa::MeasureHolder::mvhold_p [private] |
Block of pointers to measure values to make a faster interface.
Definition at line 249 of file MeasureHolder.h.
Referenced by nelements().