casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
AipsrcVector.h
Go to the documentation of this file.
00001 //# AipsrcVector.h: Read multiple values from the  Aipsrc resource files
00002 //# Copyright (C) 1995,1996,1997,1999,2002
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: AipsrcVector.h 21051 2011-04-20 11:46:29Z gervandiepen $
00027 
00028 #ifndef CASA_AIPSRCVECTOR_H
00029 #define CASA_AIPSRCVECTOR_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/BasicSL/String.h>
00033 #include <casa/Containers/Block.h>
00034 #include <casa/System/Aipsrc.h>
00035 #include <casa/OS/Mutex.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 //# Forward declarations
00040 template<class T> class Vector;
00041 class Unit;
00042 
00043 // <summary> Read multiple values from the  Aipsrc resource files </summary>
00044 
00045 // <use visibility=export>
00046 
00047 // <reviewed reviewer="mhaller" date="1997/10/08" tests="tAipsrcValue" demos="">
00048 // </reviewed>
00049 
00050 // <prerequisite>
00051 //  <li> <linkto class=AipsrcValue>AipsrcValue</linkto>
00052 // </prerequisite>
00053 //
00054 // <etymology>
00055 // A class for getting multiple values from the Aipsrc files
00056 // </etymology>
00057 //
00058 // <synopsis>
00059 // The available functions (and notes) are the same as in
00060 // <linkto class=AipsrcValue>AipsrcValue</linkto>, but with a Vector result.
00061 // </synopsis>
00062 // 
00063 // <templating>
00064 //  <li> All types with a <src>>></src> defined. 
00065 // <note role=warning>
00066 // Since interpretation of the keyword value string is done with the standard
00067 // input right-shift operator, specialisations are necessary for non-standard
00068 // cases like Bool and String. They are provided.
00069 // </note>
00070 // </templating>
00071 //
00072 // <example>
00073 // </example>
00074 //
00075 // <motivation>
00076 // Programs need a way to get multi-valued keywords from the Aipsrc files.
00077 // </motivation>
00078 //
00079 // <thrown>
00080 //    <li>AipsError if the environment variables HOME and/or AIPSPATH not set.
00081 // </thrown>
00082 //
00083 // <todo asof="1997/08/07">
00084 // </todo>
00085 
00086 template <class T> class AipsrcVector : public Aipsrc {
00087 
00088 public:
00089   //# Constructors
00090   // Default constructor
00091   // See a note in <linkto class=AipsrcValue>AipsrcValue</linkto>.
00092   AipsrcVector();
00093   //# Destructor
00094   ~AipsrcVector();
00095 
00096   //# Member functions
00097   // The <src>find()</src> functions will, given a keyword, return the value
00098   // of a matched keyword found in the files. If no match found the
00099   // function will be False, and the default returned if specified.
00100   // <group>
00101   static Bool find(Vector<T> &value, const String &keyword);
00102   static Bool find(Vector<T> &value, const String &keyword, 
00103                    const Vector<T> &deflt);
00104   // </group>
00105   // These <src>find()</src> functions will, given a keyword, read the values
00106   // of a matched keyword as a Quantity. If no unit has been given in the
00107   // keyword value, the defun Unit will be assumed. The value returned
00108   // will be converted to the resun Unit. If no match found, the default
00109   // value is returned (see example above).
00110   // <group>
00111   static Bool find(Vector<T> &value, const String &keyword,
00112                    const Unit &defun, const Unit &resun);
00113   static Bool find(Vector<T> &value, const String &keyword,
00114                    const Unit &defun, const Unit &resun,
00115                    const Vector<T> &deflt);
00116   // </group>
00117   // Functions to register keywords for later use in get() and set(). The
00118   // returned value is the index for get() and set().
00119   // <group>
00120   static uInt registerRC(const String &keyword,
00121                          const Vector<T> &deflt);
00122   static uInt registerRC(const String &keyword,
00123                          const Unit &defun, const Unit &resun,
00124                          const Vector<T> &deflt);
00125   // </group>
00126   
00127   // Gets are like find, but using registered integers rather than names.
00128   // <group>
00129   static const Vector<T> &get(uInt keyword);
00130   // </group>
00131   
00132   // Sets allow registered values to be set
00133   // <group>
00134   static void set(uInt keyword, const Vector<T> &deflt);
00135   // </group>
00136   
00137   // Save registered value to <src>$HOME/.aipsrc</src>
00138   static void save(uInt keyword);
00139 
00140 private:
00141   //# Data
00142   static AipsrcVector myp_p;
00143   static Mutex theirMutex;
00144   // register list
00145   // <group>
00146   Block<Vector<T> > tlst;
00147   Block<String> ntlst;
00148   // </group>
00149   
00150   //# Constructors
00151   // Copy constructor (not implemented)
00152   AipsrcVector<T> &operator=(const AipsrcVector<T> &other);
00153   
00154   //# Copy assignment (not implemented)
00155   AipsrcVector(const AipsrcVector<T> &other);
00156   
00157   //# General member functions
00158 };
00159 
00160 #define AipsrcVector_String AipsrcVector
00161 
00162 // <summary> Specialization of AipsrcVector for String </summary>
00163 
00164 // <synopsis>
00165 // <note role=warning>
00166 // The name <src>AipsrcVector_String</src> is only for cxx2html
00167 // documentation problems. Use <src>AipsrcVector</src> in your code.</note>
00168 // </synopsis>
00169 
00170 template <> class AipsrcVector_String<String> : public Aipsrc {
00171  public:
00172   AipsrcVector_String();
00173   ~AipsrcVector_String();
00174   static Bool find(Vector<String> &value, const String &keyword);
00175   static Bool find(Vector<String> &value, const String &keyword, 
00176                    const Vector<String> &deflt);
00177   static uInt registerRC(const String &keyword, const Vector<String> &deflt);
00178   static const Vector<String> &get(uInt keyword);
00179   static void set(uInt keyword, const Vector<String> &deflt);
00180   static void save(uInt keyword);
00181 
00182 private:
00183   static AipsrcVector_String myp_p;
00184   static Mutex theirMutex;
00185   Block<Vector<String> > tlst;
00186   Block<String> ntlst;
00187   AipsrcVector_String<String>
00188     &operator=(const AipsrcVector_String<String> &other);
00189   AipsrcVector_String(const AipsrcVector_String<String> &other);
00190 };
00191 
00192 #undef AipsrcVector_String
00193 
00194 #define AipsrcVector_Bool AipsrcVector
00195 
00196 // <summary> Specialization of AipsrcVector for Bool </summary>
00197 
00198 // <synopsis>
00199 // <note role=warning>
00200 // The name <src>AipsrcVector_Bool</src> is only for cxx2html
00201 // documentation problems. Use <src>AipsrcVector</src> in your code.</note>
00202 // </synopsis>
00203 
00204 template <> class AipsrcVector_Bool<Bool> : public Aipsrc {
00205  public:
00206   AipsrcVector_Bool();
00207   ~AipsrcVector_Bool();
00208   static Bool find(Vector<Bool> &value, const String &keyword);
00209   static Bool find(Vector<Bool> &value, const String &keyword, 
00210                    const Vector<Bool> &deflt);
00211   static uInt registerRC(const String &keyword, const Vector<Bool> &deflt);
00212   static const Vector<Bool> &get(uInt keyword);
00213   static void set(uInt keyword, const Vector<Bool> &deflt);
00214   static void save(uInt keyword);
00215 
00216 private:
00217   static AipsrcVector_Bool myp_p;
00218   static Mutex theirMutex;
00219   Block<Vector<Bool> > tlst;
00220   Block<String> ntlst;
00221   AipsrcVector_Bool<Bool>
00222     &operator=(const AipsrcVector_Bool<Bool> &other);
00223   AipsrcVector_Bool(const AipsrcVector_Bool<Bool> &other);
00224 };
00225 
00226 #undef AipsrcVector_Bool
00227 
00228 
00229 } //# NAMESPACE CASA - END
00230 
00231 #ifndef CASACORE_NO_AUTO_TEMPLATES
00232 #include <casa/System/AipsrcVector.tcc>
00233 #endif //# CASACORE_NO_AUTO_TEMPLATES
00234 #endif