casacore
Loading...
Searching...
No Matches
Param.h
Go to the documentation of this file.
1//# Param: A simple keyword/value pair with internal help Strings.
2//# Copyright (C) 1993,1994,1995,1999,2000,2001
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: casa-feedback@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#ifndef CASA_PARAM_H
27#define CASA_PARAM_H
28
29
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Containers/Block.h>
32#include <casacore/casa/BasicSL/String.h>
33#include <casacore/casa/IO/AipsIO.h>
34#include <casacore/casa/stdlib.h>
35#include <casacore/casa/string.h> // need things like strlen() and such
36
37//# Forward declarations
38#include <casacore/casa/iosfwd.h>
39
40namespace casacore { //# NAMESPACE CASACORE - BEGIN
41
42// <summary>
43// A simple keyword/value pair with internal help Strings.
44// </summary>
45
46// <use visibility=local>
47
48// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tParam.cc" demos="">
49//</reviewed>
50
51// <prerequisite>
52// <li> none noted
53// </prerequisite>
54//
55// <etymology>
56// The Param class name is a shortening of "parameter" and is indicative of
57// the class being designed as a keyword/value pair relating to command line
58// arguments. The existing Keyword class does a much better job for most
59// other purposes.
60// </etymology>
61//
62// <synopsis>
63// The Param is constructed with all arguments being Strings. This is a
64// reflection of the C-type command line argument method of passing
65// an integer (argc or argument count) and an array of pointers to characters
66// (argv or argument vector.) If "char* argv[]" is broken into its individual
67// arguments they may be used to fill a Param. The constructor pairs up a
68// "key" to a value. A help String argument is provided to assist in prompted
69// filling of Param values. The expected return type may be entered as well
70// as a range of potential values. Finally, the units of the value are also
71// specified. The intent is to provide a well documented value and a "key"
72// by which to "call" it.
73//
74// The "getWhatever" member functions of Param convert the internal Strings
75// into the desired output data type. The Strings themselves may also be
76// returned.
77// </synopsis>
78//
79// <example>
80// <srcblock>
81// // we will create a Param which contains the boundary for an iteration loop.
82// String key("IterBound");
83// // give "IterBound" a default value
84// String value("200");
85// // a help String for prompting
86// String help("The Boundary value for the chutzpah iterator.");
87// // The expected return type is an integer
88// String type("Int");
89// // The range of "legal" values
90// String range("10-10000");
91// // the units of the value
92// String unit("unitless"):
93// // Now we may build our Param
94// Param PleaseDontTouchMeThere(key, value, help, type, range, unit);
95// // to retrieve the value we use the GetInt function
96// for (Int i=0, i<PleaseDontTouchMeThere.getInt(); i++, chutzpah++);
97// </srcblock></example>
98//
99// <motivation>
100// The Param class was an early attempt at keywords within Casacore. They have
101// become obsolete but hang on due to their relationship with the Input class.
102// </motivation>
103//
104// <todo asof="Thu 1995/04/06 21:26:43 GMT">
105// <li> fix the GetStringArray() function
106// <li> convert from Block<T> to Array<T> as return values.
107// <li> replace entirely with Casacore Keywords?
108// </todo>
109
110
111class Param
112{
113public:
114 // constructors and destructor
115 // default constructor
117
118 // normal constructor with optional value and help strings
119 Param (const String& key, const String& value, const String& help,
120 const String& type, const String& range, const String& unit);
121
122 // copy constructor
123 Param (const Param&);
124
125 // destructor
127
128 // assignment operator
130
131 // Equality comparitor.
132 // <note role=warning> This function ALWAYS returns
133 // false. I have no idea why it was designed to do this. </note>
134 Bool operator== (const Param&) const;
135
136 // I/O operators
137 //<group>
138 friend ostream& operator<< (ostream&, const Param& p);
139 friend istream& operator>> (istream&, Param& p);
140 friend AipsIO& operator<< (AipsIO&, const Param& p);
142 //</group>
143
144 // get a double parameter value; prompt if switch is TRUE
145 Double getDouble (Bool do_prompt=False) const;
146
147 // get a Block<double> parameter value; prompt if switch is TRUE
149
150 // get an Int parameter value; prompt if switch is TRUE
151 Int getInt (Bool do_prompt=False) const;
152
153 // get an Block<Int> parameter value; prompt if switch is TRUE
154 Block<Int> getIntArray (Bool do_prompt=False) const;
155
156 // get a String parameter value; prompt if switch is TRUE
157 const String& getString (Bool do_prompt=False) const;
158
159 // get a Block<String> parameter value; prompt if switch is TRUE
161
162 // get a Boolean parameter value; prompt if switch is TRUE
163 Bool getBool (Bool do_prompt=False) const;
164
165 // get parameter value as a string
166 const String& get() const
167 { return value; }
168
169 // get parameter help string
170 const String& getHelp() const
171 { return help; }
172
173 // get parameter name
174 const String& getKey() const
175 { return key; }
176
177 // get the string `key = value' for the parameter
179 { return key + "=" + value; }
180
181 // get the type of a parameter
182 const String& getType() const
183 { return type; }
184
185 // get the valid range of a parameter
186 const String& getRange() const
187 { return range; }
188
189 // get the units of a parameter
190 const String& getUnit() const
191 { return unit; }
192
193 // set new parameter value; return FALSE if invalid value
194 Bool put (const String& a_value);
195
196 // set a parameter as a system parameter
197 void setSystem (Bool val)
198 { system = val; }
199
200 // check if a parameter is a system parameter
202 { return system; }
203
204 // set an index for a program parameter
205 void setIndex (Int inx)
206 { index = inx; }
207
208 // get the index of a parameter
209 Int getIndex() const
210 { return index; }
211
212
213private:
214 // parameter name
216
217 // parameter value
219
220 // help string
222
223 // type of parameter
225
226 // range/validity/pre-check
228
229 // optional unit associated with value
231
232 // boolean data member which indicates the Param's key has a value.
234
235 // boolean data member which indicates the Param is system wide.
237
238 // index for program keywords (>=1)
240};
241
242
243
244} //# NAMESPACE CASACORE - END
245
246#endif
247
248
249
simple 1-D array
Definition Block.h:198
Bool getBool(Bool do_prompt=False) const
get a Boolean parameter value; prompt if switch is TRUE
String key
parameter name
Definition Param.h:215
Double getDouble(Bool do_prompt=False) const
get a double parameter value; prompt if switch is TRUE
String keyVal() const
get the string ‘key = value’ for the parameter
Definition Param.h:178
Param(const Param &)
copy constructor
void setSystem(Bool val)
set a parameter as a system parameter
Definition Param.h:197
Int getInt(Bool do_prompt=False) const
get an Int parameter value; prompt if switch is TRUE
const String & getString(Bool do_prompt=False) const
get a String parameter value; prompt if switch is TRUE
Param & operator=(const Param &)
assignment operator
Int index
index for program keywords (>=1)
Definition Param.h:239
friend istream & operator>>(istream &, Param &p)
String range
range/validity/pre-check
Definition Param.h:227
Bool system
boolean data member which indicates the Param is system wide.
Definition Param.h:236
~Param()
destructor
Param()
constructors and destructor default constructor
const String & getHelp() const
get parameter help string
Definition Param.h:170
const String & getUnit() const
get the units of a parameter
Definition Param.h:190
void setIndex(Int inx)
set an index for a program parameter
Definition Param.h:205
Int getIndex() const
get the index of a parameter
Definition Param.h:209
Bool isSystem() const
check if a parameter is a system parameter
Definition Param.h:201
friend ostream & operator<<(ostream &, const Param &p)
I/O operators.
Block< Int > getIntArray(Bool do_prompt=False) const
get an Block<Int> parameter value; prompt if switch is TRUE
const String & getRange() const
get the valid range of a parameter
Definition Param.h:186
String type
type of parameter
Definition Param.h:224
const String & get() const
get parameter value as a string
Definition Param.h:166
String value
parameter value
Definition Param.h:218
Bool put(const String &a_value)
set new parameter value; return FALSE if invalid value
Bool operator==(const Param &) const
Equality comparitor.
const String & getType() const
get the type of a parameter
Definition Param.h:182
String unit
optional unit associated with value
Definition Param.h:230
String help
help string
Definition Param.h:221
const String & getKey() const
get parameter name
Definition Param.h:174
Bool hasvalue
boolean data member which indicates the Param's key has a value.
Definition Param.h:233
Block< Double > getDoubleArray(Bool do_prompt=False) const
get a Block<double> parameter value; prompt if switch is TRUE
Param(const String &key, const String &value, const String &help, const String &type, const String &range, const String &unit)
normal constructor with optional value and help strings
Block< String > getStringArray(Bool do_prompt=False) const
get a Block<String> parameter value; prompt if switch is TRUE
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
double Double
Definition aipstype.h:53