casa
$Rev:20696$
|
00001 //# Choice.h: Ask a choice to the user 00002 //# Copyright (C) 2004 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 //# 00027 //# $Id: Choice.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00028 00029 #ifndef CASA_CHOICE_H 00030 #define CASA_CHOICE_H 00031 00032 00033 //# Includes 00034 #include <casa/BasicSL/String.h> 00035 #include <iostream> 00036 00037 namespace casa { //# NAMESPACE CASA - BEGIN 00038 00039 //# Forward Declarations 00040 template<class T> class Vector; 00041 00042 // <summary> 00043 // Class to ask a user a choice 00044 // </summary> 00045 00046 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00047 // </reviewed> 00048 00049 // <prerequisite> 00050 // </prerequisite> 00051 00052 // <etymology> 00053 // </etymology> 00054 00055 // <synopsis> 00056 // </synopsis> 00057 00058 class Choice 00059 { 00060 public: 00061 // Define the signature of the choice function. 00062 typedef String ChoiceFunc (const String& descriptiveText, 00063 const Vector<String>& choices); 00064 00065 // Get a choice from the user. 00066 // The choice function to be used can be set using setChoiceFunc. 00067 // It can, for instance, be done by ObjectController. 00068 // Initially no choice function is set. In that case it returns 00069 // the first choice (so that should be the default choice). 00070 // If choices is zero length, an empty string is returned. 00071 static String choice (const String& descriptiveText, 00072 const Vector<String>& choices); 00073 00074 // Set the choice function. 00075 // It returns the old choice function. 00076 static ChoiceFunc* setChoiceFunc (ChoiceFunc* func); 00077 00078 // A choice function asking on stderr. 00079 static String stderrChoice (const String& descriptiveText, 00080 const Vector<String>& choices) 00081 { return ostreamChoice (std::cerr, descriptiveText, choices); } 00082 00083 // A choice function asking on stdout. 00084 // It outputs the descriptiveText followed by a blank, the options (enclosed 00085 // in parentheses) and a colon. 00086 // The default option is shown in square brackets. 00087 static String stdoutChoice (const String& descriptiveText, 00088 const Vector<String>& choices) 00089 { return ostreamChoice (std::cout, descriptiveText, choices); } 00090 00091 00092 private: 00093 // Ask on an ostream. 00094 static String ostreamChoice (std::ostream&, 00095 const String& descriptiveText, 00096 const Vector<String>& choices); 00097 00098 //# Pointer to the choice function. 00099 static ChoiceFunc* theirChoiceFunc; 00100 00101 }; 00102 00103 00104 00105 } //# NAMESPACE CASA - END 00106 00107 #endif