QuantumHolder.h
Classes
- QuantumHolder -- A holder for Quantums to enable record conversions (full description)
Interface
- Public Members
- QuantumHolder()
- QuantumHolder(const QBase &in)
- QuantumHolder(const QuantumHolder &other)
- ~QuantumHolder()
- QuantumHolder &operator=(const QuantumHolder &other)
- Bool isEmpty() const
- 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
- Int ndim() const
- const QBase &asQuantum() const
- 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)
- virtual Bool fromString(String &error, const String &in)
- virtual Bool toRecord(String &error, RecordInterface &out) const
- virtual const String &ident() const
- Private Members
- void toReal(const uInt &tp)
- void toComplex(const uInt &tp)
- void toVector()
- void toArray()
Review Status
- Reviewed By:
- UNKNOWN
- Date Reviewed:
- before2004/08/25
- Programs:
- Tests:
Prerequisite
Etymology
A Holder of general Quantums
Synopsis
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).
Example
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.
Motivation
To make general conversions between Quantums and records, without knowing
the actual Quantum being converted.
Member Description
Creates an empty holder
Create from a Quantum (copy semantics)
QuantumHolder(const QuantumHolder &other)
Copy a holder (copy semantics)
QuantumHolder &operator=(const QuantumHolder &other)
Assignment (copy semantics)
Check if it holds a Quantity. Note that a Vector of length 1 will give
True to scalar questions.
Get number of numeric elements (1 if scalar, else
vector length) or dimensions (0 if scalar)
Thrown Exceptions
- AipsError if holder empty
Get a Quantum from the holder (with lifetime as long
as holder exists). Conversions done if necessary and as described in
introduction.
Thrown Exceptions
- AipsError if holder empty or no conversion possible
virtual Bool fromRecord(String &error, const RecordInterface &in)
virtual Bool fromString(String &error, const String &in)
Create a Quantum from a record or a string.
A valid record will contain the following fields:
- value: contains a numeric value of Int, Float, Double, Complex,
DComplex or a vector thereof
- unit: a string with a valid unit string.
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.
virtual Bool toRecord(String &error, RecordInterface &out) const
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.
virtual const String &ident() const
Return identification
void toReal(const uInt &tp)
Convert to a different real scalar quantum
void toComplex(const uInt &tp)
Convert to a different complex scalar quantum
Convert scalar to Vector
Convert scalar to Array