Choice.h

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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1