Loading...
Searching...
No Matches
casacore::AipsrcValue< T > Class Template Reference
casa package (libcasa_casa) » System_module

More...

`#include <AipsrcValue.h>`

## Public Member Functions

Bool | find (String &value, const String &keyword, const Unit &defun, const Unit &resun)

## Static Public Member Functions

static Bool | find (T &value, const String &keyword)
| The find() functions will, given a keyword, return the value of a matched keyword found in the files.
static Bool | find (T &value, const String &keyword, const T &deflt)
static Bool | find (T &value, const String &keyword, const Unit &default_unit, const Unit &result_unit)
| These find() functions will, given a keyword, read the value of a matched keyword as a Quantity.
static Bool | find (T &value, const String &keyword, const Unit &default_unit, const Unit &result_unit, const T &deflt)
static uInt | registerRC (const String &keyword, const T &deflt)
| Functions to register keywords for later use in get() and set().
static uInt | registerRC (const String &keyword, const Unit &default_unit, const Unit &result_unit, const T &deflt)
static const T | get (uInt keyword)
| Gets are like find, but using registered integers rather than names.
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.
Static Public Member Functions inherited from casacore::Aipsrc
static Bool | find (String &value, const String &keyword)
static Bool | findNoHome (String &value, const String &keyword)
static Bool | find (uInt &value, const String &keyword, Int Nname, const String tname[])
| These finds check a (possible) value of the keyword against a list of coded values provided, and return an index into the list (N if not found).
static Bool | find (uInt &value, const String &keyword, const Vector< String > &tname)
static Bool | find (String &value, const String &keyword, const String &default_value)
| This find usually saves you some lines of code, since you can supply the default you want to use when no such keyword is defined.
static Bool | findNoHome (String &value, const String &keyword, const String &default_value)
static Bool | find (uInt &value, const String &keyword, Int Nname, const String tname[], const String &default_value)
static Bool | find (uInt &value, const String &keyword, const Vector< String > &tname, const String &default_value)
static Bool | findDir (String &foundDir, const String &lastPart="", const Vector< String > &prepends=Vector< String >(), const Vector< String > &appends=Vector< String >(), Bool useStds=True)
| Sets foundDir to the first /firstPart/lastPart path that it finds present on the system, where /firstPart comes from, in order, this list: contents of prepends.
static uInt | registerRC (const String &keyword, const String &default_value)
| Functions to register keywords for later use in get() and set().
static uInt | registerRC (const String &keyword, Int Nname, const String tname[], const String &default_value)
static uInt | registerRC (const String &keyword, const Vector< String > &tname, const String &default_value)
static const String & | get (uInt keyword)
| Gets are like find, but using registered integers rather than names.
static const uInt & | get (uInt &code, uInt keyword)
| get for code
static void | set (uInt keyword, const String &default_value)
| Sets allow registered values to be set.
static void | set (uInt keyword, Int Nname, const String tname[], const String &default_value)
static void | set (uInt keyword, const Vector< String > &tname, const String &default_value)
static void | save (uInt keyword)
| Save a registered keyword value to $HOME/.aipsrc.
static void | save (uInt keyword, const String tname[])
static void | save (uInt keyword, const Vector< String > &tname)
static void | setAipsPath (const String &path=String())
| Set an AIPSPATH that should be used in stead of a global AIPSPATH.
static const String & | aipsRoot ()
| Returns the appropriate Casacore or system variable values.
static const String & | aipsArch ()
static const String & | aipsSite ()
static const String & | aipsHost ()
static const String & | aipsHome ()
| Returns: ~/aips++.
static void | reRead ()
| The reRead() function will reinitialise the static maps and read the aipsrc files again.
static Double | lastRead ()
static const Block< String > & | values ()
| The following functions return the full lists of available data.
static const Block< String > & | patterns ()
static void | show (ostream &oStream)
| The following show() function, useful for debugging, outputs all keyword/value pairs found.
static void | show ()
| Prints all info on cout.
static uInt | genRestore (Vector< String > &namlst, Vector< String > &vallst, const String &fileList)
| The following set is a general set of functions.
static void | genSave (Vector< String > &namlst, Vector< String > &vallst, const String &fnam)
| Save the names/values in file.
static void | genSet (Vector< String > &namlst, Vector< String > &vallst, const String &nam, const String &val)
| Set (new or overwrite) keyword/value pair.
static Bool | genUnSet (Vector< String > &namlst, Vector< String > &vallst, const String &nam)
| Remove a keyword from list (False if not in list).
static Bool | genGet (String &val, Vector< String > &namlst, Vector< String > &vallst, const String &nam)
| Get the value of a keyword.

## Static Private Attributes

static std::mutex | theirMutex
| The global AipsrcValue object.
static std::vector< T > | tlst
| Register list.
static std::vector< String > | ntlst

## Additional Inherited Members

Static Protected Member Functions inherited from casacore::Aipsrc
static Bool | find (String &value, const String &keyword, uInt start)
| Actual find function.
static Bool | findNoParse (String &value, const String &keyword, uInt start)
| Actual find function to use during parse() without recursing into parse().
static uInt | registerRC (const String &keyword, std::vector< String > &nlst)
| The registration function.
static void | save (const String keyword, const String val)
| Actual saving.

## Detailed Description

template<class T>
class casacore::AipsrcValue< T >

Class to read values from the Aipsrc general resource files

### Intended use:

Public interface

### Review Status

Reviewed By:
  mhaller
Date Reviewed:
  1997/10/08
Test programs:
  tAipsrcValue

### Prerequisite

- Aipsrc

### 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)
casacore::AipsrcValue::find
static Bool find(T &value, const String &keyword)
The find() functions will, given a keyword, return the value of a matched keyword found in the files.
casacore::String
String: the storage and methods of handling collections of characters.
Definition String.h:223
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40

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
casacore::AipsrcDouble
AipsrcValue< Double > AipsrcDouble
Definition Aipsrc.h:44
casacore::AipsrcBool
AipsrcValue< Bool > AipsrcBool
Definition Aipsrc.h:46
casacore::AipsrcVBool
AipsrcVector< Bool > AipsrcVBool
Definition Aipsrc.h:50
casacore::AipsrcInt
AipsrcValue< Int > AipsrcInt
Definition Aipsrc.h:45
casacore::AipsrcVInt
AipsrcVector< Int > AipsrcVInt
Definition Aipsrc.h:49
casacore::AipsrcVDouble
AipsrcVector< Double > AipsrcVDouble
Definition Aipsrc.h:48
casacore::AipsrcVString
AipsrcVector< String > AipsrcVString
Definition Aipsrc.h:51
casacore::AipsrcString
Aipsrc AipsrcString
Definition Aipsrc.h:47

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)
casacore::Unit
Definition Unit.h:187

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");
casacore::Double
double Double
Definition aipstype.h:53

will return:

- 2.5/24 for a value specified as 2.5 in resource file
- 2.5/24 for 2:30:00
- 0.5/24 for 30min
- 0.5 for 0.5d

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

- All types with a >> defined.
  Warning: Since interpretation of the keyword value string is done with the standard input right-shift operator, specialisations are necessary for non-standard cases like Bool; They are provided; String is supposed to be handled by standard Aipsrc;

### Motivation

Programs need a way to interact with the AipsrcValue files.

### Thrown Exceptions

- AipsError if the environment variables HOME and/or AIPSPATH not set.

Definition at line 157 of file AipsrcValue.h.

## Member Function Documentation

## find() [1/5]

Bool casacore::AipsrcValue< String >::find | ( | String & | value,
|  | const String & | keyword,
|  | const Unit & | defun,
|  | const Unit & | resun )

## find() [2/5]

template<class T>

Bool casacore::AipsrcValue< T >::find | ( | T & | value,
|  | const String & | keyword )

static

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.

## find() [3/5]

template<class T>

Bool casacore::AipsrcValue< T >::find | ( | T & | value,
|  | const String & | keyword,
|  | const T & | deflt )

static

## find() [4/5]

template<class T>

Bool casacore::AipsrcValue< T >::find | ( | T & | value,
|  | const String & | keyword,
|  | const Unit & | default_unit,
|  | const Unit & | result_unit )

static

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 default_unit Unit will be assumed. The value returned will be converted to the result_unit Unit. If no match found, the default value is returned (see example above).

## find() [5/5]

template<class T>

Bool casacore::AipsrcValue< T >::find | ( | T & | value,
|  | const String & | keyword,
|  | const Unit & | default_unit,
|  | const Unit & | result_unit,
|  | const T & | deflt )

static

## get()

template<class T>

const T casacore::AipsrcValue< T >::get | ( | uInt | keyword | ) |

static

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. This function can't return a reference, because this would give access to the value without protection by the mutex.

Referenced by casacore::AppInfo::timeZone().

## registerRC() [1/2]

template<class T>

uInt casacore::AipsrcValue< T >::registerRC | ( | const String & | keyword,
|  | const T & | deflt )

static

Functions to register keywords for later use in get() and set().

The returned value is the index for get() and set().

## registerRC() [2/2]

template<class T>

uInt casacore::AipsrcValue< T >::registerRC | ( | const String & | keyword,
|  | const Unit & | default_unit,
|  | const Unit & | result_unit,
|  | const T & | deflt )

static

## save()

template<class T>

void casacore::AipsrcValue< T >::save | ( | uInt | keyword | ) |

static

Save registered value to $HOME/.aipsrc.

## set()

template<class T>

void casacore::AipsrcValue< T >::set | ( | uInt | keyword,
|  | const T & | deflt )

static

Sets allow registered values to be set.

## Member Data Documentation

## ntlst

template<class T>

std::vector<String> casacore::AipsrcValue< T >::ntlst

inline static private

Definition at line 213 of file AipsrcValue.h.

## theirMutex

template<class T>

std::mutex casacore::AipsrcValue< T >::theirMutex

inline static private

The global AipsrcValue object.

Definition at line 209 of file AipsrcValue.h.

## tlst

template<class T>

std::vector<T> casacore::AipsrcValue< T >::tlst

inline static private

Register list.

Definition at line 212 of file AipsrcValue.h.

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

- casa/System/Aipsrc.h
- casa/System/AipsrcValue.h