casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Inputs.h
Go to the documentation of this file.
00001 //# Inputs.h: a module for simple command line user interface classes
00002 //# Copyright (C) 1994,1995,1996,1999,2000
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: Inputs.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef CASA_INPUTS_H
00029 #define CASA_INPUTS_H
00030 
00031 #include <casa/Inputs/Input.h>
00032 #include <casa/Inputs/Param.h>
00033 
00034 namespace casa { //# NAMESPACE CASA - BEGIN
00035 
00036 // <module> 
00037 //
00038 // <summary> 
00039 // A module for simple command line user interface classes
00040 // </summary>
00041 
00042 // <prerequisite>
00043 //   <li> String
00044 //   <li> The C language int main(int argc, const char* argv[]) convention.
00045 // </prerequisite>
00046 
00047 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" demos="">
00048 //</reviewed>
00049 
00050 // <etymology> 
00051 // The Inputs module name reflects the AIPS++convention of pluralizing 
00052 // the name of the major class it contains.
00053 // The Input class name is a reflection of it's role as the early command 
00054 // line user interface for AIPS++ applications.  This class provides "inputs" 
00055 // in the form "key=value" or "-key value."  
00056 //</etymology> 
00057 //
00058 // <synopsis> 
00059 
00060 // During the AIPS++ prototyping stage a basic command line user
00061 // interface was developed. This attempt at easing the trouble of passing
00062 // information to an executable program resulted in a set of C++ classes
00063 // called Param and Input.  The programmer may simply include the Input
00064 // class into their code and have immediate Command Line User Interface
00065 // (CLUI) capabilities.  The programmer's AIPS++ application is run from
00066 // the unix level prompt by invoking its name and listing linearly on the
00067 // same command line the "keyword=values" or "-keyword values" associated
00068 // with proper execution.  The Input and Param classes will successfully
00069 // parse the command line into the executable program and check for
00070 // appropriateness.
00071 
00072 // The CLUI capabilities are further extended to a Graphical User
00073 // Interface through the use of the Khoros Cantata environment. The user
00074 // starts up Cantata from the unix prompt and, by utilizing a series of
00075 // pull down windows, invisibly creates an X-based window for visual
00076 // display of all parameters associated with the AIPS++ application's
00077 // need for external input.
00078 
00079 // The Input and Param classes and their associated user interfaces
00080 // should be viewed as AIPS++ development tools only.  The limitations
00081 // imposed by the current Khoros GUI techniques dictate the need for a
00082 // more flexible system.  It is believed that as the C++ environment
00083 // matures an obvious candidate for the final AIPS++ Graphic User
00084 // Interface will emerge.  Until that time, the methods outlined here
00085 // will, hopefully, reduce the programmer's worry list.
00086 // 
00087 // The basic command line user interface is an ordered series of
00088 // "keyword=value" pairs, which we call parameters. The names parameter
00089 // and keyword may correctly be used to refer to each other.
00090 // 
00091 // The class Param (see Param.h) implements one single such parameter.
00092 // Values may be Int, Block<Int>, double, Block<double>, Bool, or
00093 // Strings.  In addition to a name and a value, a Param parameter has a
00094 // variety of other attributes, such as a one-line help string (useful
00095 // when being prompted for input or with hypertext identifiers, etc...),
00096 // a type, a range and optional units.  All of these attributes are
00097 // character strings; parsing and error checking is done at a different
00098 // (hidden) level.  The programmer, however, will never interact with a
00099 // parameter through it's Param class interface.  Interaction is done
00100 // with the class Input, which is a container of Param's, with a variety
00101 // of user interface attributes (help-level, debug-level, etc...).
00102 // 
00103 // Although the programmer must supply the user interface with a number
00104 // of predefined program parameters, the user interface itself will
00105 // create a small number of system parameters (help=, debug=).  The
00106 // purpose of these is to tell the task how to communicate with the user
00107 // and it's environment, and give the user control over these items.  For
00108 // example, the user may want to see (debug) messages above a certain
00109 // threshold level.  The programmer simply adds debug levels to their
00110 // code and allows the user to specify how deeply they wish the debugging
00111 // to progress.
00112 // 
00113 // For example, a interactive UNIX shell session may look like:
00114 // 
00115 //<srcblock>
00116 //     1% MyProgram key1=val1 key3=val3
00117 //     2% MyProgram key1=val1 key2=val3 debug=5
00118 //     3% MyProgram help=prompt
00119 //     4% MyProgram help=pane > prog.pane
00120 //</srcblock>
00121 // 
00122 // In command 1% the user has set several parameters for the program
00123 // MyProgram to applicable values.  The 2% command line invokes the
00124 // executable and sets the level of displayed debugging to the programmer
00125 // specified 5th level.  Command 3%: the user is prompted, and parameter
00126 // default values are restored.  Command 4% gives an example of the
00127 // self-describing mode of programs, where a pane description file for
00128 // Khoros has been constructed.  The latter is the first step toward
00129 // building a Khoros Graphic User Interface.
00130 // 
00131 // The Input class is a means for building a linked list of parameters
00132 // and gaining access to them once created.  Input takes care of
00133 // system/environment variables and assigns their values within the
00134 // programmer's code.  The linked list of parameters is limited only by
00135 // the number of names the programmer can dream up.  The programmer need
00136 // not think hard on the order of definition of parameters in Input. The
00137 // list of key=values given on the command line by the user need not be
00138 // in any specific order.
00139 // 
00140 // The definition of parameters is by simply creating an Input and then
00141 // using the appropriate Input Create member function.  Then the
00142 // programmer adds to the list of parameters as necessary.
00143 // </synopsis> 
00144 //
00145 // <example>
00146 // <srcblock>
00147 // 01 #include <casa/Inputs/Input.h>      // need this if you want it to work
00148 // 02 #include <aips/Plot.h>
00149 // 03 int main(int argc, const char* argv[])
00150 // 04 {
00151 // 05    Input inputs(1);
00152 // 06    // Define our input structure
00153 // 07    inputs.version("Id: xyPlot.C,v 1.1 1993/01/29 20:45:48 bglenden Exp");
00154 // 08    inputs.create("xyfile", 
00155 // 09                "/tmp/xy.aipsio",
00156 // 10                "File which contains xy vectors",
00157 // 11                "InFile");
00158 // 12    inputs.create("overplot", "False", "Multiple plots?", "Bool");
00159 // 13    inputs.create("lines", "True", "Plot lines or points?", "Bool");
00160 // 14    
00161 // 15    // and Fill them from the command line
00162 // 16    inputs.readArguments(argc, argv);
00163 // 17
00164 // 18    try {
00165 // 19      const Char *filename = inputs.getString("xyfile");
00166 // 20      AipsIO xyfile(filename, ByteIO::Old);
00167 // 21      Vector<float> x, y;
00168 // 22      Plot plot;
00169 // 23
00170 // 24      xyfile >> x >> y; // initial vectors
00171 // 25      plot(x,y,inputs.getBool("lines"));
00172 // 26
00173 // 27      for (;;) { // forever
00174 // 28          xyfile >> x >> y;
00175 // 29          if (inputs.getBool("overplot") == True) {
00176 // 30              plot(x,y,inputs.getBool("lines"));
00177 // 31          } else {
00178 // 32              plot.newPlot();
00179 // 33              plot(x,y,inputs.getBool("lines"));
00180 // 34          }
00181 // 35      }
00182 // 36  } catch (AipsIOError x) {
00183 // 37       ; // nothing - no more data
00184 // 38  } catch (AllocError x) {
00185 // 39       cerr << "AllocError : " << x.getMesg() << endl;
00186 // 40       cerr << "Size is : " << x.size() << endl;
00187 // 41  } catch (AipsError x) {
00188 // 42       cerr << "aipserror: error " << x.getMesg() << endl;
00189 // 43       return 1;
00190 // 44  }
00191 // 45
00192 // 46    cout << "Any key to exit:\n";
00193 // 47
00194 // 48  char ch;
00195 // 49  cin.get(ch);
00196 // 50
00197 // 51  return 0;
00198 // 52 }
00199 // </srcblock>
00200 // Let us discuss this program line for line.
00201 // 
00202 // 03 - This is the method of passing the command line through to the
00203 // main body of code.  This obviously makes it mandatory.  The inclusion
00204 // of the argc, argv is very well discussed in Stroustrup, The
00205 // C++ Programming Language, page 87.
00206 // 
00207 // 05 - The instantiation of Input in the variable inputs(1) is done with
00208 // an integer argument of (1) to indicate the constructor should build
00209 // inputs with a pair of system parameters and read in values for them.
00210 // An argument of (0) would build an Input that was empty and would
00211 // obligate the programmer to build a list of Params explicitly.
00212 // 
00213 // 07 - The version of the code is stored within the Input.  Note the
00214 // optional use of RCS keyword substitution.  See the "co" man page for
00215 // details. This allows the code to be automatically updated.
00216 // 
00217 // 08-11 - The create member function of Input builds, in this case, a
00218 // parameter called xyfile, immediately filled with the String containing
00219 // the directory that holds the data. The help String is useful for new
00220 // users or prompting.  The fourth argument of InFile is the optional
00221 // type of the parameter's value.  Any suitable String may be used.
00222 // Missing from this example are the optional fifth and sixth arguments,
00223 // the parameter's value's range and units, respectively.
00224 // 
00225 // 12 - This is another instantiation of a Param inside of Input.  This
00226 // parameter will be referenced by the keyword "overplot".  It is
00227 // initialized to False and is of type Bool.
00228 // 
00229 // 13 - This line is the third and final Param placed in inputs and is
00230 // recognized by the code when accessed with keyword "lines".
00231 // 
00232 // 16 - The call of readArguments(argc, argv) should be done after the
00233 // list of Params has been completed.  This line of code fills the values
00234 // from the command line. A keyword that doesn't match will throw an
00235 // error.
00236 // 
00237 // 19 - At this point the local variable filename is initialized to the
00238 // String value held within the parameter accessed through the key
00239 // "xyfile".  Recall that the value of xyfile was originally set to
00240 // "/tmp/xy.aipsio" but would be replaced with the proper value at
00241 // execution.  The getString member function returns either the default
00242 // value specified during the xyfile parameter's instantiation or the
00243 // value placed into it from the command line use of xyfile=myfile.
00244 // 
00245 // 25 - Here the boolean value of the Param called lines is inserted into
00246 // the call to the function plot.
00247 // 
00248 // 29 - Again the Input interface has its parameter called overplot
00249 // return a boolean to be used as a test for an "if".  The getBool(key)
00250 // Input member function may be reading the default value of the
00251 // appropriate parameter called key or using the value passed from the
00252 // command line.
00253 // 
00254 // 30 & 33 - Another call to plot that uses the boolean value stored in
00255 // the parameter called lines.
00256 // </example> 
00257 // 
00258 //<motivation> 
00259 // This module fit the early needs of a a simple user interface.
00260 // </motivation>
00261 
00262 // <todo asof="Thu 199504/06 21:26:43 GMT">
00263 //   <li> possibly replace the Param class with Keywords
00264 // </todo>
00265 
00266 // </module>
00267 
00268 
00269 } //# NAMESPACE CASA - END
00270 
00271 #endif
00272 
00273 
00274 
00275 
00276 
00277