casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AipsrcValue.h
Go to the documentation of this file.
1 //# AipsrcValue.h: Class to read values from the Aipsrc general resource files
2 //# Copyright (C) 1995,1996,1997,1999,2002,2003
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef CASA_AIPSRCVALUE_H
29 #define CASA_AIPSRCVALUE_H
30 
31 #include <casacore/casa/aips.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward declarations
39 class Unit;
40 
41 // <summary> Class to read values from the Aipsrc general resource files
42 // </summary>
43 
44 // <use visibility=export>
45 
46 // <reviewed reviewer="mhaller" date="1997/10/08" tests="tAipsrcValue" demos="">
47 // </reviewed>
48 
49 // <prerequisite>
50 // <li> <linkto class=Aipsrc>Aipsrc</linkto>
51 // </prerequisite>
52 //
53 // <etymology>
54 // A class for getting values from the Aipsrc files
55 // </etymology>
56 //
57 // <synopsis>
58 // The static AipsrcValue class can get typed values from the Aipsrc
59 // resource files.<br>
60 // The basic interaction with the class is with the static keyword match
61 // functions:
62 // <srcblock>
63 // Bool AipsrcValue<Type>::find(Type &result, const String &keyword)
64 // Bool AipsrcValue<Type>::find(Type &result, const String &keyword,
65 // const Type &deflt)
66 // </srcblock>
67 // comparable to the standard (String) <linkto class=Aipsrc>Aipsrc</linkto>
68 // find.<br>
69 // If the resource file contains a multi-valued keyword, use the
70 // <linkto class=AipsrcVector>AipsrcVector</linkto> class instead.
71 //
72 // The class is templated. For ease of use typedefs are provided for:
73 // <srcblock>
74 // AipsrcDouble, AipsrcInt, AipsrcBool, AipsrcString
75 // AipsrcVDouble, AipsrcVInt, AipsrcVBool, AipsrcVString
76 // </srcblock>
77 // In addition to the above finds, special finds:
78 // <srcblock>
79 // Bool AipsrcValue<Type>::find(Type &result, const String &keyword,
80 // const Unit &defun, const Unit &resun)
81 // Bool AipsrcValue<Type>::find(Type &result, const String &keyword,
82 // const Unit &defun, const Unit &resun,
83 // const Type &deflt)
84 // </srcblock>
85 // are provided. These finds will read the keyword value as a Quantity.
86 // If no units are given, the defun are assumed. The result is converted
87 // to the resun, before the value is returned. E.g.
88 // <srcblock>
89 // Double x;
90 // find(x, "time.offset", "h", "d");
91 // </srcblock>
92 // will return:
93 // <ul>
94 // <li> 2.5/24 for a value specified as 2.5 in resource file
95 // <li> 2.5/24 for 2:30:00
96 // <li> 0.5/24 for 30min
97 // <li> 0.5 for 0.5d
98 // </ul>
99 //
100 // The class has <src>registerRC, get, set</src> functions as described in
101 // <linkto class=Aipsrc>Aipsrc</linkto>. Note that registration is on a
102 // per Type basis, and hence registration of the same keyword in different
103 // types (and possible sets) act on different values, but with the same
104 // result if no set has been done.
105 //
106 // Specialisation exists for <src>Bool</src>, where <src>True</src> is
107 // any value string starting with one of 'yYtT123456789', and False in
108 // all other cases, and no finds with Units are provided. Strings are
109 // supposed to be handled by standard <linkto class=Aipsrc>Aipsrc</linkto>
110 // class for single values, and a specialisation exists for the
111 // <linkto class=AipsrcVector>AipsrcVector</linkto> case.
112 //
113 // </synopsis>
114 //
115 // <example>
116 // <srcblock>
117 // String tzoff; // result of keyword find
118 // if (!AipsrcValue<Double>::find(tzoff, "time.zone.offset")) { // look for key
119 // tzoff = -5;
120 // };
121 // </srcblock>
122 // A more convenient way of accomplishing the same result is:
123 // <srcblock>
124 // AipsrcDouble::find(tzoff, "time.zone.offset", -5);
125 // </srcblock>
126 // or even:
127 // <srcblock>
128 // AipsrcDouble::find(tzoff, "time.zone.offset",
129 // "h", "h", -5);
130 // </srcblock>
131 // Here the final argument is the default to use if the keyword is not found
132 // at all.
133 // </example>
134 //
135 //
136 // <templating>
137 // <li> All types with a <src>>></src> defined.
138 // <note role=warning>
139 // Since interpretation of the keyword value string is done with the standard
140 // input right-shift operator, specialisations are necessary for non-standard
141 // cases like Bool. They are provided. String is supposed to be handled by
142 // standard Aipsrc.
143 // </note>
144 // </templating>
145 //
146 // <motivation>
147 // Programs need a way to interact with the AipsrcValue files.
148 // </motivation>
149 //
150 // <thrown>
151 // <li>AipsError if the environment variables HOME and/or AIPSPATH not set.
152 // </thrown>
153 //
154 // <todo asof="1997/08/07">
155 // </todo>
156 
157 template <class T> class AipsrcValue : public Aipsrc {
158 
159 public:
160  //# Constructors
161  // Default constructor
162  // <note role=tip>
163  // A constructor (and destructor) have been provided to be able to generate
164  // a (routine-level) static register list. This had to be done since
165  // static data members are not yet implemented in the gcc compiler for
166  // templated classes. Once they are available the <tt>tlist</tt> and
167  // <tt>ntlst</tt> data can become static, constructor and desctructor and
168  // all references to the init() method can disappear.
169  // </note>
170  AipsrcValue();
171  //# Destructor
172  // See note with constructor
173  ~AipsrcValue();
174 
175  //# Member functions
176  // The <src>find()</src> functions will, given a keyword, return the value
177  // of a matched keyword found in the files. If no match found the
178  // function will be False, and the default returned if specified.
179  // <group>
180  static Bool find(T &value, const String &keyword);
181  static Bool find(T &value, const String &keyword, const T &deflt);
182  // </group>
183  // These <src>find()</src> functions will, given a keyword, read the value
184  // of a matched keyword as a Quantity. If no unit has been given in the
185  // keyword value, the defun Unit will be assumed. The value returned
186  // will be converted to the resun Unit. If no match found, the default
187  // value is returned (see example above).
188  // <group>
189  static Bool find(T &value, const String &keyword,
190  const Unit &defun, const Unit &resun);
191  static Bool find(T &value, const String &keyword,
192  const Unit &defun, const Unit &resun,
193  const T &deflt);
194  // </group>
195  // Functions to register keywords for later use in get() and set(). The
196  // returned value is the index for get() and set().
197  // <group>
198  static uInt registerRC(const String &keyword,
199  const T &deflt);
200  static uInt registerRC(const String &keyword,
201  const Unit &defun, const Unit &resun,
202  const T &deflt);
203  // </group>
204 
205  // Gets are like find, but using registered integers rather than names. The
206  // aipsrc file is read only once, and values can be set as well.
207  // <group>
208  static const T &get(uInt keyword);
209  // </group>
210 
211  // Sets allow registered values to be set
212  // <group>
213  static void set(uInt keyword, const T &deflt);
214  // </group>
215 
216  // Save registered value to <src>$HOME/.aipsrc</src>
217  static void save(uInt keyword);
218 
219 private:
220  //# Data
221  // The global AipsrcValue object
224  // Register list
225  // <group>
228  // </group>
229 
230  //# Constructors
231  // Copy constructor (not implemented)
232  AipsrcValue<T> &operator=(const AipsrcValue<T> &other);
233 
234  //# Copy assignment (not implemented)
235  AipsrcValue(const AipsrcValue<T> &other);
236 
237  //# General member functions
238 };
239 
240 template <>
242  const String &keyword,
243  const Unit &defun, const Unit &resun);
244 
245 
246 // <summary> Specialization of AipsrcValue for Bool </summary>
247 
248 // <synopsis>
249 // </synopsis>
250 
251 template <> class AipsrcValue<Bool> : public Aipsrc {
252 public:
253  AipsrcValue();
254  ~AipsrcValue();
255  static Bool find(Bool &value, const String &keyword);
256  static Bool find(Bool &value, const String &keyword, const Bool &deflt);
257  static uInt registerRC(const String &keyword, const Bool &deflt);
258  static const Bool &get(uInt keyword);
259  static void set(uInt keyword, const Bool &deflt);
260  static void save(uInt keyword);
261 private:
267  AipsrcValue(const AipsrcValue<Bool> &other);
268 };
269 
270 
271 //# Declare extern templates for often used types.
272  extern template class AipsrcValue<Bool>;
273  extern template class AipsrcValue<Int>;
274  extern template class AipsrcValue<Double>;
275  extern template class AipsrcValue<String>;
276 
277 } //# NAMESPACE CASACORE - END
278 
279 #ifndef CASACORE_NO_AUTO_TEMPLATES
280 #include <casacore/casa/System/AipsrcValue.tcc>
281 #endif //# CASACORE_NO_AUTO_TEMPLATES
282 #endif
Specialization of AipsrcValue for Bool.
Definition: AipsrcValue.h:251
Block< String > ntlst
Definition: AipsrcValue.h:227
static AipsrcValue myp_p
Definition: AipsrcValue.h:262
~AipsrcValue()
See note with constructor.
Block< T > tlst
Register list.
Definition: AipsrcValue.h:226
defines physical units
Definition: Unit.h:189
static AipsrcValue myp_p
The global AipsrcValue object.
Definition: AipsrcValue.h:222
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...
AipsrcValue()
Default constructor Tip: A constructor (and destructor) have been provided to be able to generate a ...
static uInt registerRC(const String &keyword, const T &deflt)
Functions to register keywords for later use in get() and set().
static Mutex theirMutex
Definition: AipsrcValue.h:223
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
static void set(uInt keyword, const T &deflt)
Sets allow registered values to be set.
Wrapper around a pthreads mutex.
Definition: Mutex.h:58
simple 1-D array
AipsrcValue< T > & operator=(const AipsrcValue< T > &other)
Copy constructor (not implemented)
Class to read values from the Aipsrc general resource files.
Definition: Aipsrc.h:40
static void save(uInt keyword)
Save registered value to $HOME/.aipsrc
Class to read the casa general resource files.
Definition: Aipsrc.h:218
String: the storage and methods of handling collections of characters.
Definition: String.h:223
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42