GlishRecord.h

Classes

GlishRecord -- holds a Glish record (full description)

class GlishRecord : public GlishValue

Interface

Public Members
GlishRecord()
GlishRecord(const GlishRecord &other)
GlishRecord(const GlishValue &other)
~GlishRecord()
RecordDesc description (Bool recursive=False) const
void fromRecord(const RecordInterface &record)
void toRecord(RecordInterface &record) const
void toRecord(Record &record) const
GlishRecord &operator=(const GlishRecord &other)
GlishRecord &operator=(const GlishValue &other)
GlishRecord& add(const char *name, const char *value)
GlishRecord& add(const String &name, const GlishValue &value)
GlishRecord& add(const String &name, const GlishArray &value)
Bool exists(const String &name) const
GlishValue get(const String &name) const
GlishValue get(uInt fieldNumber) const
String name(uInt fieldNumber) const
Bool ok() const
Private Members
void toRecordCopy(Record &record) const

Description

Review Status

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

Prerequisite

Synopsis

A GlishRecord consists of a heterogeneous set of named GlishValues. The named GlishValue may in turn be a GlishRecord, so in this way the data structure is hierarchical.

A GlishRecord may be converted to and from an AIPS++ Record object.

Example

The following example creates a GlishRecord with two fields, and then retrieves a field.
    Vector<Complex> vis;  ...                                     // 1
    GlishRecord record;                                           // 2
    record.add("hello", 3.0)     ;                                // 3
    record.add("world", vis);                                     // 4
    ...
    GlishArray tmp;                                               // 5
    if (!record.exists("world")) {...}                            // 6
    tmp = record.get("world");                                    // 7
    Vector<DComplex> vis2(tmp.nelements();                        // 8
    if (!tmp.get(vis2)) { ... }                                   // 9
    ... use vis2 ...
    
    
  1. Declare a Vector containing some values.
  2. Declare a (record); initially empty.
  3. Add a field named "hello" containing the value 3.0.
  4. Add a field named "world" containing the Vector vis.
  5. Declare a GlishArray temporary value.
  6. See if a field named "world" exists in record (if not, an error).
  7. Get the field.
  8. Declare a Vector to hold the result, note that we are getting it out as DComplex rather than Complex (for some reason).
  9. Get the values out into a Vector. If this fails for some reason do some error handling.

To Do

Member Description

GlishRecord()

Null Glish record (no fields).

GlishRecord(const GlishValue &other)

Logically make this object a copy of other. Physically avoids the copy for as long as possible (copy on write).

If other isn't a record, an exception (AipsError) is thrown.

GlishRecord(const GlishRecord &other)

Logically make this object a copy of other. Physically avoids the copy for as long as possible (copy on write).

~GlishRecord()

RecordDesc description (Bool recursive=False) const

Describe the layout of this object. By default it is not done recursively (thus not for subrecords).

void fromRecord(const RecordInterface &record)
void toRecord(RecordInterface &record) const
void toRecord(Record &record) const

Interconvert a GlishRecord and a Record. The converted object is zero'd first, i.e. any existing fields are wiped out before copying the fields.

These functions could in principle be global functions instead of member functions, but it seemed likely that users would look for this functionality here. But they can be moved if this seems best to others. The present implementation isn't particularly fast.

GlishRecord &operator=(const GlishValue &other)

Logically make this object a copy of other. Physically avoids the copy for as long as possible (copy on write).

If other isn't a record, an exception (AipsError) is thrown.

GlishRecord &operator=(const GlishRecord &other)

Logically make this object a copy of other. Physically avoids the copy for as long as possible (copy on write).

GlishRecord& add(const String &name, const GlishArray &value)

Add field "name" with the supplied value to this GlishRecord. If one already exists, it is overwritten. These functions return a reference to the glish record itself so that you can write things like: rec.add("a", 1).add("b", 2);

This (overloaded) version was written so that automatic conversions of scalars and AIPS++ arrays will take place, e.g. record.add("pi", 3.14159).

GlishRecord& add(const char *name, const char *value)
GlishRecord& add(const String &name, const GlishValue &value)

Add field "name" with the supplied value to this GlishRecord. If one already exists, it is overwritten. These functions return a reference to the glish record itself so that you can write things like: rec.add("a", 1).add("b", 2);

Bool exists(const String &name) const

Does a field with the given name exist?

GlishValue get(const String &name) const

Get the field with the given name from this record. Returns False is no field with that name exists.

GlishValue get(uInt fieldNumber) const

Get the fieldNumber'th field from this record. fieldNumber ranges between 0 and nelements() - 1.

String name(uInt fieldNumber) const

Get the name corresponding to the fieldNumber'th field in this record.

Bool ok() const

Is this record consistent?

void toRecordCopy(Record &record) const