casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Choice.h
Go to the documentation of this file.
1 //# Choice.h: Ask a choice to the user
2 //# Copyright (C) 2004
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 //#
27 //# $Id$
28 
29 #ifndef CASA_CHOICE_H
30 #define CASA_CHOICE_H
31 
32 
33 //# Includes
34 #include <casacore/casa/aips.h>
36 #include <iostream>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 //# Forward Declarations
41 template<class T> class Vector;
42 
43 // <summary>
44 // Class to ask a user a choice
45 // </summary>
46 
47 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
48 // </reviewed>
49 
50 // <prerequisite>
51 // </prerequisite>
52 
53 // <etymology>
54 // </etymology>
55 
56 // <synopsis>
57 // </synopsis>
58 
59 class Choice
60 {
61 public:
62  // Define the signature of the choice function.
63  typedef String ChoiceFunc (const String& descriptiveText,
64  const Vector<String>& choices);
65 
66  // Get a choice from the user.
67  // The choice function to be used can be set using setChoiceFunc.
68  // It can, for instance, be done by ObjectController.
69  // Initially no choice function is set. In that case it returns
70  // the first choice (so that should be the default choice).
71  // If choices is zero length, an empty string is returned.
72  static String choice (const String& descriptiveText,
73  const Vector<String>& choices);
74 
75  // Set the choice function.
76  // It returns the old choice function.
77  static ChoiceFunc* setChoiceFunc (ChoiceFunc* func);
78 
79  // A choice function asking on stderr.
80  static String stderrChoice (const String& descriptiveText,
81  const Vector<String>& choices)
82  { return ostreamChoice (std::cerr, descriptiveText, choices); }
83 
84  // A choice function asking on stdout.
85  // It outputs the descriptiveText followed by a blank, the options (enclosed
86  // in parentheses) and a colon.
87  // The default option is shown in square brackets.
88  static String stdoutChoice (const String& descriptiveText,
89  const Vector<String>& choices)
90  { return ostreamChoice (std::cout, descriptiveText, choices); }
91 
92 
93 private:
94  // Ask on an ostream.
95  static String ostreamChoice (std::ostream&,
96  const String& descriptiveText,
97  const Vector<String>& choices);
98 
99  //# Pointer to the choice function.
101 
102 };
103 
104 
105 
106 } //# NAMESPACE CASACORE - END
107 
108 #endif
A 1-D Specialization of the Array class.
static String ostreamChoice(std::ostream &, const String &descriptiveText, const Vector< String > &choices)
Ask on an ostream.
std::vector< double > Vector
Definition: ds9context.h:24
static ChoiceFunc * theirChoiceFunc
Definition: Choice.h:100
static String stdoutChoice(const String &descriptiveText, const Vector< String > &choices)
A choice function asking on stdout.
Definition: Choice.h:88
Class to ask a user a choice.
Definition: Choice.h:59
static String stderrChoice(const String &descriptiveText, const Vector< String > &choices)
A choice function asking on stderr.
Definition: Choice.h:80
String ChoiceFunc(const String &descriptiveText, const Vector< String > &choices)
Define the signature of the choice function.
Definition: Choice.h:63
static ChoiceFunc * setChoiceFunc(ChoiceFunc *func)
Set the choice function.
static String choice(const String &descriptiveText, const Vector< String > &choices)
Get a choice from the user.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42