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