AipsrcValue.h

Classes

AipsrcValue -- Class to read values from the Aipsrc general resource files (full description)
AipsrcValue_Bool -- Specialization of AipsrcValue for Bool (full description)

template <class T> class AipsrcValue : public Aipsrc

Interface

Public Members
AipsrcValue()
~AipsrcValue()
static Bool find(T &value, const String &keyword)
static Bool find(T &value, const String &keyword, const T &deflt)
static Bool find(T &value, const String &keyword, const String &defun, const String &resun)
static Bool find(T &value, const String &keyword, const String &defun, const String &resun, const T &deflt)
static uInt registerRC(const String &keyword, const T &deflt)
static uInt registerRC(const String &keyword, const Unit &defun, const Unit &resun, const T &deflt)
static const T &get(uInt keyword)
static void set(uInt keyword, const T &deflt)
static void save(uInt keyword)
Private Members
AipsrcValue<T> &operator=(const AipsrcValue<T> &other)
AipsrcValue(const AipsrcValue<T> &other)

Description

Review Status

Reviewed By:
mhaller
Date Reviewed:
1997/10/08
Programs:
Tests:

Prerequisite

Etymology

A class for getting values from the Aipsrc files

Synopsis

The static AipsrcValue class can get typed values from the Aipsrc resource files.
The basic interaction with the class is with the static keyword match functions:
 Bool AipsrcValue<Type>::find(Type &result, const String &keyword)
 Bool AipsrcValue<Type>::find(Type &result, const String &keyword,
				const Type &deflt)
comparable to the standard (String) Aipsrc find.
If the resource file contains a multi-valued keyword, use the AipsrcVector class instead.

The class is templated. For ease of use typedefs are provided for:

    AipsrcDouble, AipsrcInt, AipsrcBool, AipsrcString
    AipsrcVDouble, AipsrcVInt, AipsrcVBool, AipsrcVString
    
In addition to the above finds, special finds:
 Bool AipsrcValue<Type>::find(Type &result, const String &keyword,
				const Unit &defun, const Unit &resun)
 Bool AipsrcValue<Type>::find(Type &result, const String &keyword,
				const Unit &defun, const Unit &resun,
				const Type &deflt)
are provided. These finds will read the keyword value as a Quantity. If no units are given, the defun are assumed. The result is converted to the resun, before the value is returned. E.g.
	Double x;
	find(x, "time.offset", "h", "d");
will return:

The class has registerRC, get, set functions as described in Aipsrc. Note that registration is on a per Type basis, and hence registration of the same keyword in different types (and possible sets) act on different values, but with the same result if no set has been done.

Specialisation exists for Bool, where True is any value string starting with one of 'yYtT123456789', and False in all other cases, and no finds with Units are provided. Strings are supposed to be handled by standard Aipsrc class for single values, and a specialisation exists for the AipsrcVector case.

Example

  String tzoff;		// result of keyword find
  if (!AipsrcValue<Double>::find(tzoff, "time.zone.offset")) {	// look for key
    tzoff = -5;
  };
A more convenient way of accomplishing the same result is:
    AipsrcDouble::find(tzoff, "time.zone.offset", -5);
or even:
    AipsrcDouble::find(tzoff, "time.zone.offset",
			 "h", "h", -5);
Here the final argument is the default to use if the keyword is not found at all.

Template Type Argument Requirements

Motivation

Programs need a way to interact with the AipsrcValue files.

Thrown Exceptions

To Do

Member Description

AipsrcValue()

Default constructor
Tip A constructor (and destructor) have been provided to be able to generate a (routine-level) static register list. This had to be done since static data members are not yet implemented in the gcc compiler for templated classes. Once they are available the tlist and ntlst data can become static, constructor and desctructor and all references to the init() method can disappear.

~AipsrcValue()

See note with constructor

static Bool find(T &value, const String &keyword)
static Bool find(T &value, const String &keyword, const T &deflt)

The find() functions will, given a keyword, return the value of a matched keyword found in the files. If no match found the function will be False, and the default returned if specified.

static Bool find(T &value, const String &keyword, const String &defun, const String &resun)
static Bool find(T &value, const String &keyword, const String &defun, const String &resun, const T &deflt)

These find() functions will, given a keyword, read the value of a matched keyword as a Quantity. If no unit has been given in the keyword value, the defun Unit will be assumed. The value returned will be converted to the resun Unit. If no match found, the default value is returned (see example above).

static uInt registerRC(const String &keyword, const T &deflt)
static uInt registerRC(const String &keyword, const Unit &defun, const Unit &resun, const T &deflt)

Functions to register keywords for later use in get() and set(). The returned value is the index for get() and set().

static const T &get(uInt keyword)

Gets are like find, but using registered integers rather than names. The aipsrc file is read only once, and values can be set as well.

static void set(uInt keyword, const T &deflt)

Sets allow registered values to be set

static void save(uInt keyword)

Save registered value to $HOME/.aipsrc

AipsrcValue<T> &operator=(const AipsrcValue<T> &other)

Copy constructor (not implemented)

AipsrcValue(const AipsrcValue<T> &other)


template <> class AipsrcValue_Bool<Bool> : public Aipsrc

Interface

Public Members
AipsrcValue_Bool()
~AipsrcValue_Bool()
static Bool find(Bool &value, const String &keyword)
static Bool find(Bool &value, const String &keyword, const Bool &deflt)
static uInt registerRC(const String &keyword, const Bool &deflt)
static const Bool &get(uInt keyword)
static void set(uInt keyword, const Bool &deflt)
static void save(uInt keyword)
Private Members
AipsrcValue_Bool<Bool> &operator=(const AipsrcValue_Bool<Bool> &other)
AipsrcValue_Bool(const AipsrcValue_Bool<Bool> &other)

Description

Synopsis

Warning The name AipsrcValue_Bool is only for cxx2html documentation problems. Use AipsrcValue in your code.

Member Description

AipsrcValue_Bool()

~AipsrcValue_Bool()

static Bool find(Bool &value, const String &keyword)

static Bool find(Bool &value, const String &keyword, const Bool &deflt)

static uInt registerRC(const String &keyword, const Bool &deflt)

static const Bool &get(uInt keyword)

static void set(uInt keyword, const Bool &deflt)

static void save(uInt keyword)

AipsrcValue_Bool<Bool> &operator=(const AipsrcValue_Bool<Bool> &other)

AipsrcValue_Bool(const AipsrcValue_Bool<Bool> &other)