casa
$Rev:20696$
|
A holder for Quantums to enable record conversions. More...
#include <QuantumHolder.h>
Public Member Functions | |
QuantumHolder () | |
Creates an empty holder. | |
QuantumHolder (const QBase &in) | |
Create from a Quantum (copy semantics) | |
QuantumHolder (const QuantumHolder &other) | |
Copy a holder (copy semantics) | |
~QuantumHolder () | |
QuantumHolder & | operator= (const QuantumHolder &other) |
Assignment (copy semantics) | |
Bool | isEmpty () const |
Check if it holds a Quantity. | |
Bool | isQuantum () const |
Bool | isScalar () const |
Bool | isVector () const |
Bool | isArray () const |
Bool | isReal () const |
Bool | isComplex () const |
Bool | isQuantity () const |
Bool | isQuantumDouble () const |
Bool | isQuantumFloat () const |
Bool | isQuantumInt () const |
Bool | isQuantumComplex () const |
Bool | isQuantumDComplex () const |
Bool | isQuantumVectorDouble () const |
Bool | isQuantumVectorFloat () const |
Bool | isQuantumVectorInt () const |
Bool | isQuantumVectorComplex () const |
Bool | isQuantumVectorDComplex () const |
Bool | isQuantumArrayDouble () const |
Bool | isQuantumArrayFloat () const |
Bool | isQuantumArrayInt () const |
Bool | isQuantumArrayComplex () const |
Bool | isQuantumArrayDComplex () const |
Int | nelements () const |
Get number of numeric elements (1 if scalar, else vector length) or dimensions (0 if scalar) | |
Int | ndim () const |
const QBase & | asQuantum () const |
Get a Quantum from the holder (with lifetime as long as holder exists). | |
const Quantum< Double > & | asQuantity () |
const Quantum< Double > & | asQuantumDouble () |
const Quantum< Float > & | asQuantumFloat () |
const Quantum< Int > & | asQuantumInt () |
const Quantum< Complex > & | asQuantumComplex () |
const Quantum< DComplex > & | asQuantumDComplex () |
const Quantum< Vector< Double > > & | asQuantumVectorDouble () |
const Quantum< Vector< Float > > & | asQuantumVectorFloat () |
const Quantum< Vector< Int > > & | asQuantumVectorInt () |
const Quantum< Vector< Complex > > & | asQuantumVectorComplex () |
const Quantum< Vector < DComplex > > & | asQuantumVectorDComplex () |
const Quantum< Array< Double > > & | asQuantumArrayDouble () |
const Quantum< Array< Float > > & | asQuantumArrayFloat () |
const Quantum< Array< Int > > & | asQuantumArrayInt () |
const Quantum< Array< Complex > > & | asQuantumArrayComplex () |
const Quantum< Array< DComplex > > & | asQuantumArrayDComplex () |
virtual Bool | fromRecord (String &error, const RecordInterface &in) |
Create a Quantum from a record or a string. | |
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 Quantum. | |
virtual void | toRecord (RecordInterface &out) const |
this version throws an exception rather than returning false | |
virtual Record | toRecord () const |
this version throws an exception or returns the result Record. | |
virtual const String & | ident () const |
Return identification. | |
Private Member Functions | |
void | toReal (const uInt &tp) |
Convert to a different real scalar quantum. | |
void | toComplex (const uInt &tp) |
Convert to a different complex scalar quantum. | |
void | toVector () |
Convert scalar to Vector. | |
void | toArray () |
Convert scalar to Array. | |
Private Attributes | |
PtrHolder< QBase > | hold_p |
Pointer to a Quantity. |
A holder for Quantums 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>tQuantumHolder</dl>
A Holder of general Quantums
This class can be used to handle a heterogeneous list of Quantums, and can handle toRecord() and fromRecord() conversions. A QuantumHolder is created empty, from a Quantum (e.g. a Quantum<Double>
) or a Quantum<Vector<Float> >
).
The accepted range of Quantums is:
Quantum<Int>, Quantum<Float>, Quantum<Double> == Quantity
Quantum<Complex>, Quantum<DComplex>
Quantum<Vector<Int> >, Quantum<Vector<Float> >
, Quantum<Vector<Double> >
Quantum<Vector<Complex> >, Quantum<Vector<DComplex> >
Quantum<Array<Int> >, Quantum<Array<Float> >
, Quantum<Array<Double> >
Quantum<Array<Complex> >, Quantum<Array<DComplex> >
Scalars in the same group can be converted to any in the same group (e.g. Int to Double); Vectors of length 1 can be converted to scalars in the corresponding group; Scalars can always be converted to Vectors in the corresponding group. Real scalar values can be converted to Complex values. Vectors cannot be converted to other type vectors.
Checks on the contents can be made with functions like isQuantity
and the contents can be obtained with functions like asQuantity
. It is an error to try and retrieve a Quantum of the wrong type and doing so will generate an exception (AipsError).
TableRecord rec; // an empty record Quantity x(12.5, "km/s"); // a Quantity String error; // an error message if (!QuantumHolder(x).toRecord(error, rec)) { // make record cout << error << endl; }; Record grec; // a Record if (!QuantumHolder(x).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 Quantums and records, without knowing the actual Quantum being converted.
Definition at line 117 of file QuantumHolder.h.
Creates an empty holder.
casa::QuantumHolder::QuantumHolder | ( | const QBase & | in | ) |
Create from a Quantum (copy semantics)
casa::QuantumHolder::QuantumHolder | ( | const QuantumHolder & | other | ) |
Copy a holder (copy semantics)
const Quantum<Double>& casa::QuantumHolder::asQuantity | ( | ) |
const QBase& casa::QuantumHolder::asQuantum | ( | ) | const |
const Quantum<Array<Complex> >& casa::QuantumHolder::asQuantumArrayComplex | ( | ) |
const Quantum<Array<DComplex> >& casa::QuantumHolder::asQuantumArrayDComplex | ( | ) |
const Quantum<Array<Double> >& casa::QuantumHolder::asQuantumArrayDouble | ( | ) |
const Quantum<Array<Float> >& casa::QuantumHolder::asQuantumArrayFloat | ( | ) |
const Quantum<Array<Int> >& casa::QuantumHolder::asQuantumArrayInt | ( | ) |
const Quantum<Complex>& casa::QuantumHolder::asQuantumComplex | ( | ) |
const Quantum<DComplex>& casa::QuantumHolder::asQuantumDComplex | ( | ) |
const Quantum<Double>& casa::QuantumHolder::asQuantumDouble | ( | ) |
const Quantum<Float>& casa::QuantumHolder::asQuantumFloat | ( | ) |
const Quantum<Int>& casa::QuantumHolder::asQuantumInt | ( | ) |
const Quantum<Vector<Complex> >& casa::QuantumHolder::asQuantumVectorComplex | ( | ) |
const Quantum<Vector<DComplex> >& casa::QuantumHolder::asQuantumVectorDComplex | ( | ) |
const Quantum<Vector<Double> >& casa::QuantumHolder::asQuantumVectorDouble | ( | ) |
const Quantum<Vector<Float> >& casa::QuantumHolder::asQuantumVectorFloat | ( | ) |
const Quantum<Vector<Int> >& casa::QuantumHolder::asQuantumVectorInt | ( | ) |
virtual Bool casa::QuantumHolder::fromRecord | ( | String & | error, |
const RecordInterface & | in | ||
) | [virtual] |
Create a Quantum from a record or a string.
A valid record will contain the following fields:
A valid string will be one of the special time/angle formats or a value with a valid unit string. Illegal values or units will return False and write an error message.
Implements casa::RecordTransformable.
virtual Bool casa::QuantumHolder::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.
virtual const String& casa::QuantumHolder::ident | ( | ) | const [virtual] |
Return identification.
Reimplemented from casa::RecordTransformable.
Bool casa::QuantumHolder::isArray | ( | ) | const |
Bool casa::QuantumHolder::isComplex | ( | ) | const |
Bool casa::QuantumHolder::isEmpty | ( | ) | const |
Check if it holds a Quantity.
Note that a Vector of length 1 will give True to scalar questions.
Bool casa::QuantumHolder::isQuantity | ( | ) | const |
Bool casa::QuantumHolder::isQuantum | ( | ) | const |
Bool casa::QuantumHolder::isQuantumArrayFloat | ( | ) | const |
Bool casa::QuantumHolder::isQuantumArrayInt | ( | ) | const |
Bool casa::QuantumHolder::isQuantumComplex | ( | ) | const |
Bool casa::QuantumHolder::isQuantumDComplex | ( | ) | const |
Bool casa::QuantumHolder::isQuantumDouble | ( | ) | const |
Bool casa::QuantumHolder::isQuantumFloat | ( | ) | const |
Bool casa::QuantumHolder::isQuantumInt | ( | ) | const |
Bool casa::QuantumHolder::isQuantumVectorInt | ( | ) | const |
Bool casa::QuantumHolder::isReal | ( | ) | const |
Bool casa::QuantumHolder::isScalar | ( | ) | const |
Bool casa::QuantumHolder::isVector | ( | ) | const |
Int casa::QuantumHolder::ndim | ( | ) | const |
Int casa::QuantumHolder::nelements | ( | ) | const |
Get number of numeric elements (1 if scalar, else vector length) or dimensions (0 if scalar)
QuantumHolder& casa::QuantumHolder::operator= | ( | const QuantumHolder & | other | ) |
Assignment (copy semantics)
void casa::QuantumHolder::toArray | ( | ) | [private] |
Convert scalar to Array.
void casa::QuantumHolder::toComplex | ( | const uInt & | tp | ) | [private] |
Convert to a different complex scalar quantum.
void casa::QuantumHolder::toReal | ( | const uInt & | tp | ) | [private] |
Convert to a different real scalar quantum.
virtual Bool casa::QuantumHolder::toRecord | ( | String & | error, |
RecordInterface & | out | ||
) | const [virtual] |
Create a record from a Quantum.
A False return and an error message is only generated if there is no valid Quantum in the holder.
Implements casa::RecordTransformable.
virtual void casa::QuantumHolder::toRecord | ( | RecordInterface & | out | ) | const [virtual] |
this version throws an exception rather than returning false
virtual Record casa::QuantumHolder::toRecord | ( | ) | const [virtual] |
this version throws an exception or returns the result Record.
void casa::QuantumHolder::toVector | ( | ) | [private] |
Convert scalar to Vector.
PtrHolder<QBase> casa::QuantumHolder::hold_p [private] |
Pointer to a Quantity.
Definition at line 233 of file QuantumHolder.h.