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