//# AipsrcValue.h: Class to read values from the Aipsrc general resource files //# Copyright (C) 1995,1996,1997,1999,2002,2003 //# Associated Universities, Inc. Washington DC, USA. //# //# This library is free software; you can redistribute it and/or modify it //# under the terms of the GNU Library General Public License as published by //# the Free Software Foundation; either version 2 of the License, or (at your //# option) any later version. //# //# This library is distributed in the hope that it will be useful, but WITHOUT //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public //# License for more details. //# //# You should have received a copy of the GNU Library General Public License //# along with this library; if not, write to the Free Software Foundation, //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. //# //# Correspondence concerning AIPS++ should be addressed as follows: //# Internet email: aips2-request@nrao.edu. //# Postal address: AIPS++ Project Office //# National Radio Astronomy Observatory //# 520 Edgemont Road //# Charlottesville, VA 22903-2475 USA //# //# $Id$ #ifndef CASA_AIPSRCVALUE_H #define CASA_AIPSRCVALUE_H #include #include #include #include #include namespace casacore { //# NAMESPACE CASACORE - BEGIN //# Forward declarations class Unit; // Class to read values from the Aipsrc general resource files // // // // // //
  • Aipsrc // // // // A class for getting values from the Aipsrc files // // // // 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::find(Type &result, const String &keyword) // Bool AipsrcValue::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::find(Type &result, const String &keyword, // const Unit &defun, const Unit &resun) // Bool AipsrcValue::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: //
      //
    • 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. // //
    // // // // String tzoff; // result of keyword find // if (!AipsrcValue::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. // // // // //
  • All types with a >> defined. // // 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. // // // // // Programs need a way to interact with the AipsrcValue files. // // // //
  • AipsError if the environment variables HOME and/or AIPSPATH not set. // // // // template class AipsrcValue : public Aipsrc { public: //# Constructors // Default constructor // // 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(); //# Destructor // See note with constructor ~AipsrcValue(); //# Member functions // 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); static Bool find(T &value, const String &keyword, 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 Bool find(T &value, const String &keyword, const Unit &defun, const Unit &resun); static Bool find(T &value, 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 uInt registerRC(const String &keyword, const T &deflt); static uInt registerRC(const String &keyword, const Unit &defun, const Unit &resun, const T &deflt); // // 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 const T &get(uInt keyword); // // Sets allow registered values to be set // static void set(uInt keyword, const T &deflt); // // Save registered value to $HOME/.aipsrc static void save(uInt keyword); private: //# Data // The global AipsrcValue object static AipsrcValue myp_p; static std::mutex theirMutex; // Register list // Block tlst; Block ntlst; // //# Constructors // Copy constructor (not implemented) AipsrcValue &operator=(const AipsrcValue &other); //# Copy assignment (not implemented) AipsrcValue(const AipsrcValue &other); //# General member functions }; template <> Bool AipsrcValue::find(String &value, const String &keyword, const Unit &defun, const Unit &resun); // Specialization of AipsrcValue for Bool // // template <> class AipsrcValue : public Aipsrc { public: AipsrcValue(); ~AipsrcValue(); 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: static AipsrcValue myp_p; static std::mutex theirMutex; Block tlst; Block ntlst; AipsrcValue &operator=(const AipsrcValue &other); AipsrcValue(const AipsrcValue &other); }; //# Declare extern templates for often used types. extern template class AipsrcValue; extern template class AipsrcValue; extern template class AipsrcValue; extern template class AipsrcValue; } //# NAMESPACE CASACORE - END #ifndef CASACORE_NO_AUTO_TEMPLATES #include #endif //# CASACORE_NO_AUTO_TEMPLATES #endif