00001 /* ES40 emulator. 00002 * Copyright (C) 2007-2008 by the ES40 Emulator Project 00003 * 00004 * WWW : http://sourceforge.net/projects/es40 00005 * E-mail : camiel@camicom.com 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License 00009 * as published by the Free Software Foundation; either version 2 00010 * of the License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00020 * 00021 * Although this is not required, the author would appreciate being notified of, 00022 * and receiving any modifications you may make to the source code that might serve 00023 * the general public. 00024 */ 00025 00039 class FreeTextQuestion: public Question 00040 { 00041 public: 00046 void setOptions(string options) 00047 { 00048 mOptions = options; 00049 } 00050 00054 virtual string ask() 00055 { 00056 for(;;) 00057 { 00058 cout << mQuestion; 00059 00060 /* If there is an options list, display it after the 00061 * question enclosed in (). 00062 */ 00063 if (mOptions != "") 00064 cout << " (" << mOptions << ")"; 00065 00066 /* If there is a default value, display it after the 00067 * question enclosed in []. 00068 */ 00069 if (mDefault != "") 00070 cout << " [" << mDefault << "]"; 00071 00072 cout << ": "; 00073 00074 /* Get the answer. 00075 */ 00076 getline(cin, mAnswer); 00077 00078 /* If the question is answered with '?', display the 00079 * explanation, then ask again. 00080 */ 00081 if (mAnswer == "?") 00082 { 00083 explain(); 00084 continue; 00085 } 00086 00087 /* If the question is answered with <return>, set the 00088 * answer to the default answer. 00089 */ 00090 if (mAnswer =="") 00091 mAnswer = mDefault; 00092 00093 /* Return the answer. 00094 */ 00095 return mAnswer; 00096 } 00097 } 00098 00099 protected: 00101 string mOptions; 00102 };