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