casacore
Loading...
Searching...
No Matches
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: 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_CHOICE_H
27#define CASA_CHOICE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/casa/BasicSL/String.h>
33#include <iostream>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// <summary>
38// Class to ask a user a choice
39// </summary>
40
41// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
42// </reviewed>
43
44// <prerequisite>
45// </prerequisite>
46
47// <etymology>
48// </etymology>
49
50// <synopsis>
51// </synopsis>
52
53class Choice {
54 public:
55 // Define the signature of the choice function.
56 typedef String ChoiceFunc(const String& descriptiveText, const Vector<String>& choices);
57
58 // Get a choice from the user.
59 // The choice function to be used can be set using setChoiceFunc.
60 // It can, for instance, be done by ObjectController.
61 // Initially no choice function is set. In that case it returns
62 // the first choice (so that should be the default choice).
63 // If choices is zero length, an empty string is returned.
64 static String choice(const String& descriptiveText, const Vector<String>& choices);
65
66 // Set the choice function.
67 // It returns the old choice function.
69
70 // A choice function asking on stderr.
71 static String stderrChoice(const String& descriptiveText, const Vector<String>& choices) {
72 return ostreamChoice(std::cerr, descriptiveText, choices);
73 }
74
75 // A choice function asking on stdout.
76 // It outputs the descriptiveText followed by a blank, the options (enclosed
77 // in parentheses) and a colon.
78 // The default option is shown in square brackets.
79 static String stdoutChoice(const String& descriptiveText, const Vector<String>& choices) {
80 return ostreamChoice(std::cout, descriptiveText, choices);
81 }
82
83 private:
84 // Ask on an ostream.
85 static String ostreamChoice(std::ostream&, const String& descriptiveText,
86 const Vector<String>& choices);
87
88 // # Pointer to the choice function.
90};
91
92} // namespace casacore
93
94#endif
static String stdoutChoice(const String &descriptiveText, const Vector< String > &choices)
A choice function asking on stdout.
Definition Choice.h:79
static ChoiceFunc * setChoiceFunc(ChoiceFunc *func)
Set the choice function.
String ChoiceFunc(const String &descriptiveText, const Vector< String > &choices)
Define the signature of the choice function.
Definition Choice.h:56
static String choice(const String &descriptiveText, const Vector< String > &choices)
Get a choice from the user.
static String stderrChoice(const String &descriptiveText, const Vector< String > &choices)
A choice function asking on stderr.
Definition Choice.h:71
static String ostreamChoice(std::ostream &, const String &descriptiveText, const Vector< String > &choices)
Ask on an ostream.
static ChoiceFunc * theirChoiceFunc
Definition Choice.h:89
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