casacore
Public Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::QuantumHolder Class Reference

More...

#include <QuantumHolder.h>

Public Member Functions

 QuantumHolder ()
 Creates an empty holder. More...
 
 QuantumHolder (const QBase &in)
 Create from a Quantum (copy semantics) More...
 
 QuantumHolder (const QuantumHolder &other)
 Copy a holder (copy semantics) More...
 
 ~QuantumHolder ()
 
QuantumHolderoperator= (const QuantumHolder &other)
 Assignment (copy semantics) More...
 
Bool isEmpty () const
 Check if it holds a Quantity. More...
 
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) More...
 
Int ndim () const
 
const QBaseasQuantum () const
 Get a Quantum from the holder (with lifetime as long as holder exists). More...
 
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. 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 Quantum. More...
 
virtual void toRecord (RecordInterface &out) const
 this version throws an exception rather than returning false More...
 
virtual Record toRecord () const
 this version throws an exception or returns the result Record. More...
 
virtual const Stringident () const
 Return identification. 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

void toReal (const uInt &tp)
 Convert to a different real scalar quantum. More...
 
void toComplex (const uInt &tp)
 Convert to a different complex scalar quantum. More...
 
void toVector ()
 Convert scalar to Vector. More...
 
void toArray ()
 Convert scalar to Array. More...
 

Private Attributes

PtrHolder< QBasehold_p
 Pointer to a Quantity. More...
 

Detailed Description

A holder for Quantums to enable record conversions

Intended use:

Public interface

Review Status

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

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:

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.
QuantumHolder()
Creates an empty holder.
virtual Record toRecord() const
this version throws an exception or returns the result Record.
Quantum< Double > Quantity
Definition: Quantum.h:38

Motivation

To make general conversions between Quantums and records, without knowing the actual Quantum being converted.

Definition at line 116 of file QuantumHolder.h.

Constructor & Destructor Documentation

◆ QuantumHolder() [1/3]

casacore::QuantumHolder::QuantumHolder ( )

Creates an empty holder.

◆ QuantumHolder() [2/3]

casacore::QuantumHolder::QuantumHolder ( const QBase in)

Create from a Quantum (copy semantics)

◆ QuantumHolder() [3/3]

casacore::QuantumHolder::QuantumHolder ( const QuantumHolder other)

Copy a holder (copy semantics)

◆ ~QuantumHolder()

casacore::QuantumHolder::~QuantumHolder ( )

Member Function Documentation

◆ asQuantity()

const Quantum<Double>& casacore::QuantumHolder::asQuantity ( )

◆ asQuantum()

const QBase& casacore::QuantumHolder::asQuantum ( ) const

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

◆ asQuantumArrayComplex()

const Quantum<Array<Complex> >& casacore::QuantumHolder::asQuantumArrayComplex ( )

◆ asQuantumArrayDComplex()

const Quantum<Array<DComplex> >& casacore::QuantumHolder::asQuantumArrayDComplex ( )

◆ asQuantumArrayDouble()

const Quantum<Array<Double> >& casacore::QuantumHolder::asQuantumArrayDouble ( )

◆ asQuantumArrayFloat()

const Quantum<Array<Float> >& casacore::QuantumHolder::asQuantumArrayFloat ( )

◆ asQuantumArrayInt()

const Quantum<Array<Int> >& casacore::QuantumHolder::asQuantumArrayInt ( )

◆ asQuantumComplex()

const Quantum<Complex>& casacore::QuantumHolder::asQuantumComplex ( )

◆ asQuantumDComplex()

const Quantum<DComplex>& casacore::QuantumHolder::asQuantumDComplex ( )

◆ asQuantumDouble()

const Quantum<Double>& casacore::QuantumHolder::asQuantumDouble ( )

◆ asQuantumFloat()

const Quantum<Float>& casacore::QuantumHolder::asQuantumFloat ( )

◆ asQuantumInt()

const Quantum<Int>& casacore::QuantumHolder::asQuantumInt ( )

◆ asQuantumVectorComplex()

const Quantum<Vector<Complex> >& casacore::QuantumHolder::asQuantumVectorComplex ( )

◆ asQuantumVectorDComplex()

const Quantum<Vector<DComplex> >& casacore::QuantumHolder::asQuantumVectorDComplex ( )

◆ asQuantumVectorDouble()

const Quantum<Vector<Double> >& casacore::QuantumHolder::asQuantumVectorDouble ( )

◆ asQuantumVectorFloat()

const Quantum<Vector<Float> >& casacore::QuantumHolder::asQuantumVectorFloat ( )

◆ asQuantumVectorInt()

const Quantum<Vector<Int> >& casacore::QuantumHolder::asQuantumVectorInt ( )

◆ fromRecord()

virtual Bool casacore::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:

  • 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.

Implements casacore::RecordTransformable.

◆ fromString()

virtual Bool casacore::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 casacore::RecordTransformable.

◆ ident()

virtual const String& casacore::QuantumHolder::ident ( ) const
virtual

Return identification.

Reimplemented from casacore::RecordTransformable.

◆ isArray()

Bool casacore::QuantumHolder::isArray ( ) const

◆ isComplex()

Bool casacore::QuantumHolder::isComplex ( ) const

◆ isEmpty()

Bool casacore::QuantumHolder::isEmpty ( ) const

Check if it holds a Quantity.

Note that a Vector of length 1 will give True to scalar questions.

◆ isQuantity()

Bool casacore::QuantumHolder::isQuantity ( ) const

◆ isQuantum()

Bool casacore::QuantumHolder::isQuantum ( ) const

◆ isQuantumArrayComplex()

Bool casacore::QuantumHolder::isQuantumArrayComplex ( ) const

◆ isQuantumArrayDComplex()

Bool casacore::QuantumHolder::isQuantumArrayDComplex ( ) const

◆ isQuantumArrayDouble()

Bool casacore::QuantumHolder::isQuantumArrayDouble ( ) const

◆ isQuantumArrayFloat()

Bool casacore::QuantumHolder::isQuantumArrayFloat ( ) const

◆ isQuantumArrayInt()

Bool casacore::QuantumHolder::isQuantumArrayInt ( ) const

◆ isQuantumComplex()

Bool casacore::QuantumHolder::isQuantumComplex ( ) const

◆ isQuantumDComplex()

Bool casacore::QuantumHolder::isQuantumDComplex ( ) const

◆ isQuantumDouble()

Bool casacore::QuantumHolder::isQuantumDouble ( ) const

◆ isQuantumFloat()

Bool casacore::QuantumHolder::isQuantumFloat ( ) const

◆ isQuantumInt()

Bool casacore::QuantumHolder::isQuantumInt ( ) const

◆ isQuantumVectorComplex()

Bool casacore::QuantumHolder::isQuantumVectorComplex ( ) const

◆ isQuantumVectorDComplex()

Bool casacore::QuantumHolder::isQuantumVectorDComplex ( ) const

◆ isQuantumVectorDouble()

Bool casacore::QuantumHolder::isQuantumVectorDouble ( ) const

◆ isQuantumVectorFloat()

Bool casacore::QuantumHolder::isQuantumVectorFloat ( ) const

◆ isQuantumVectorInt()

Bool casacore::QuantumHolder::isQuantumVectorInt ( ) const

◆ isReal()

Bool casacore::QuantumHolder::isReal ( ) const

◆ isScalar()

Bool casacore::QuantumHolder::isScalar ( ) const

◆ isVector()

Bool casacore::QuantumHolder::isVector ( ) const

◆ ndim()

Int casacore::QuantumHolder::ndim ( ) const

◆ nelements()

Int casacore::QuantumHolder::nelements ( ) const

Get number of numeric elements (1 if scalar, else vector length) or dimensions (0 if scalar)

Thrown Exceptions

◆ operator=()

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

Assignment (copy semantics)

◆ toArray()

void casacore::QuantumHolder::toArray ( )
private

Convert scalar to Array.

◆ toComplex()

void casacore::QuantumHolder::toComplex ( const uInt tp)
private

Convert to a different complex scalar quantum.

◆ toReal()

void casacore::QuantumHolder::toReal ( const uInt tp)
private

Convert to a different real scalar quantum.

◆ toRecord() [1/3]

virtual Record casacore::QuantumHolder::toRecord ( ) const
virtual

this version throws an exception or returns the result Record.

◆ toRecord() [2/3]

virtual void casacore::QuantumHolder::toRecord ( RecordInterface out) const
virtual

this version throws an exception rather than returning false

◆ toRecord() [3/3]

virtual Bool casacore::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 casacore::RecordTransformable.

◆ toVector()

void casacore::QuantumHolder::toVector ( )
private

Convert scalar to Vector.

Member Data Documentation

◆ hold_p

PtrHolder<QBase> casacore::QuantumHolder::hold_p
private

Pointer to a Quantity.

Definition at line 232 of file QuantumHolder.h.


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