GlishArray.h

Classes

GlishArray -- holds any Glish array (full description)

class GlishArray : public GlishValue

Types

enum ElementType

BOOL
BYTE
SHORT
INT
FLOAT
DOUBLE
COMPLEX
DCOMPLEX
STRING

Interface

Public Members
GlishArray()
GlishArray(const GlishArray &other)
GlishArray(const GlishValue &other)
GlishArray(const Array<Bool> &values)
GlishArray(const Array<uChar> &values)
GlishArray(const Array<Short> &values)
GlishArray(const Array<Int> &values)
GlishArray(const Array<Float> &values)
GlishArray(const Array<Double> &values)
GlishArray(const Array<Complex> &values)
GlishArray(const Array<DComplex> &values)
GlishArray(const Array<String> &values)
GlishArray(Bool value)
GlishArray(uChar value)
GlishArray(Short value)
GlishArray(Int value)
GlishArray(Float value)
GlishArray(Double value)
GlishArray(Complex value)
GlishArray(DComplex value)
GlishArray(const String &value)
GlishArray(const Char *value)
~GlishArray()
GlishArray &operator=(const GlishArray &other)
GlishArray &operator=(const GlishValue &other)
void reset()
IPosition shape() const
ElementType elementType() const
Bool get(Array<Bool> &values, Bool attemptResize=True) const
Bool get(Array<uChar> &values, Bool attemptResize=True) const
Bool get(Array<Short> &values, Bool attemptResize=True) const
Bool get(Array<Int> &values, Bool attemptResize=True) const
Bool get(Array<Float> &values, Bool attemptResize=True) const
Bool get(Array<Double> &values, Bool attemptResize=True) const
Bool get(Array<Complex> &values, Bool attemptResize=True) const
Bool get(Array<DComplex> &values, Bool attemptResize=True) const
Bool get(Array<String> &values, Bool attemptResize=True) const
Bool get(Bool &val, uInt index = 0) const
Bool get(uChar &val, uInt index = 0) const
Bool get(Short &val, uInt index = 0) const
Bool get(Int &val, uInt index = 0) const
Bool get(Float &val, uInt index = 0) const
Bool get(Double &val, uInt index = 0) const
Bool get(Complex &val, uInt index = 0) const
Bool get(DComplex &val, uInt index = 0) const
Bool get(String &val, uInt index = 0) const
Bool ok() const

Description

Review Status

Reviewed By:
pshannon
Date Reviewed:
1994/10/28
Programs:
Demos:

Prerequisite

Synopsis

A GlishArray stores a (multidimensional) array of Glish values which are all of the same (scalar) type. It is also used for storing single values. (A scalar in Glish is just a 1-element Array).

GlishArray values are polymorphic. For example, an array which was created as Float, may be retrieved as Complex. The only interconversion which is not allowed is String to and from any other type. Complex values are converted to real types by dropping the imaginary part.

Example

The following code fragment illustrates GlishArrays being interconverted between scalars and AIPS++ arrays.
     GlishArray ga(3.0);                         // 1
     Array<Complex> ac = getArrayComplex();      // 2
     ga = ac;                                    // 3
     DComplex val;                               // 4
     if (! ga.get(val,2)) { ... }                // 5
     if (! ga.get(ac)) { ... }                   // 6
     
  1. Declares a GlishArray object, ga, containing the single value 3.0. This illustrates the creation of a GlishArray from a scalar.
  2. Get an Array from some function.
  3. ga now contains the values in ac, and the shapes will also be identical.
  4. Define a DComplex variable, val.
  5. Read the third value from the GlishArray into variable val. Note that it it will be converted to a DComplex even though the underlying values are Complex. If the conversion couldn't be done, the if statement (...) would be taken.
  6. Read from the GlishArray into the Array ac. If the underlying type cannot be converted the get would fail and the if would be taken.

To Do

Member Description

enum ElementType

GlishArray()

Make a False, length=1, array.

GlishArray(const GlishArray &other)

Make a logical copy of other. A physical copy is only made when necessary (copy-on-write), so this is efficient.

GlishArray(const GlishValue &other)

Create a GlishArray from a GlishValue. If type() isn't ARRAY, then an exception (AipsError) is thrown.

GlishArray(const Array<Bool> &values)
GlishArray(const Array<uChar> &values)
GlishArray(const Array<Short> &values)
GlishArray(const Array<Int> &values)
GlishArray(const Array<Float> &values)
GlishArray(const Array<Double> &values)
GlishArray(const Array<Complex> &values)
GlishArray(const Array<DComplex> &values)
GlishArray(const Array<String> &values)

Create a GlishArray by copying from "values". After creation, the shape of the GlishArray will match "values.shape()".

GlishArray(Bool value)
GlishArray(uChar value)
GlishArray(Short value)
GlishArray(Int value)
GlishArray(Float value)
GlishArray(Double value)
GlishArray(Complex value)
GlishArray(DComplex value)
GlishArray(const String &value)
GlishArray(const Char *value)

Create a length one GlishArray containing "value".

~GlishArray()

GlishArray &operator=(const GlishArray &other)
GlishArray &operator=(const GlishValue &other)

Make a logical copy of other. A physical copy is only made when necessary (copy-on-write), so this is efficient.

void reset()

Since a GlishArray might be very large, "reset" has been provided as a way to reclaim its storage. After reset, the GlishArray consists of a one element Boolean containing False, i.e. like the result of the default constructor.

IPosition shape() const

shape() returns the length of each axis, i.e. nelements() == shape.product();

ElementType elementType() const

Returns the element type of the GlishArray.

Bool get(Array<Bool> &values, Bool attemptResize=True) const
Bool get(Array<uChar> &values, Bool attemptResize=True) const
Bool get(Array<Short> &values, Bool attemptResize=True) const
Bool get(Array<Int> &values, Bool attemptResize=True) const
Bool get(Array<Float> &values, Bool attemptResize=True) const
Bool get(Array<Double> &values, Bool attemptResize=True) const
Bool get(Array<Complex> &values, Bool attemptResize=True) const
Bool get(Array<DComplex> &values, Bool attemptResize=True) const
Bool get(Array<String> &values, Bool attemptResize=True) const

Get all the values as an AIPS++ Array. If "values.nelements()" differs from this.nelements(), an attempt is made to resize the array to this.shape() if attemptResize is True.

Bool get(Bool &val, uInt index = 0) const
Bool get(uChar &val, uInt index = 0) const
Bool get(Short &val, uInt index = 0) const
Bool get(Int &val, uInt index = 0) const
Bool get(Float &val, uInt index = 0) const
Bool get(Double &val, uInt index = 0) const
Bool get(Complex &val, uInt index = 0) const
Bool get(DComplex &val, uInt index = 0) const
Bool get(String &val, uInt index = 0) const

Get the indexth element of the GlishArray. This should be particularly useful for GlishArray objects with only one element, i.e. a scalar. Note that unlike the native Glish classes, indexing is zero-relative.

Bool ok() const

Is this GlishArray object consistent?