00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef ST_PROMPT_HH
00058 #define ST_PROMPT_HH
00059
00060 #include <Stiostream.h>
00061 #include <Stsstream.h>
00062 #include <string>
00063 #include <ctype.h>
00064 #if !defined(ST_NO_NAMESPACES)
00065 using std::string;
00066 #endif
00067
00068 inline void StPrompt()
00069 {
00070 cout << "-- Press return to continue -- ";
00071 cin.get();
00072 }
00073
00074 template<class T>
00075 inline void StPrompt(const char *text, T& var)
00076 {
00077 string line;
00078 char c;
00079
00080 cout << text << " [" << var << "]: ";
00081 while ((c = cin.get()) && c != '\n') line += c;
00082 if (line.length() > 0) {
00083 istrstream ist(line.c_str(), line.length());
00084 ist >> var;
00085 }
00086 }
00087
00088 inline void StPrompt(const char *text, string& var)
00089 {
00090 string line;
00091 char c;
00092
00093 cout << text << " [" << var.c_str() << "]: ";
00094 while ((c = cin.get()) && c != '\n') line += c;
00095 if (line.length() > 0) var = line;
00096 }
00097
00098 #if defined (__SUNPRO_CC) && __SUNPRO_CC < 0x500
00099 inline void StBoolPrompt(const char *text, bool& var)
00100 #else
00101 inline void StPrompt(const char *text, bool& var)
00102 #endif
00103 {
00104 string line;
00105 char c;
00106 string svar = var ? "true" : "false";
00107
00108 cout << text << " [" << svar.c_str() << "]: ";
00109 while ((c = cin.get()) && c != '\n') line += c;
00110 if (line.length() > 0) {
00111 if (line == "true")
00112 var = true;
00113 else if (line == "t")
00114 var = true;
00115 else if (line == "yes")
00116 var = true;
00117 else if (line == "y")
00118 var = true;
00119 else if (line == "on")
00120 var = true;
00121 else if (line == "1")
00122 var = true;
00123 else
00124 var = false;
00125 }
00126 }
00127
00128
00129 inline void StPrompt(const char *text, char* var, unsigned int maxlength)
00130 {
00131 string line;
00132 unsigned char c;
00133
00134 cout << text << " [" << var << "]: ";
00135 while ((c = cin.get()) && c != '\n' && line.length() < maxlength)
00136 line += c;
00137 if (line.length() > 0) strcpy(var, line.c_str());
00138 }
00139
00140 #endif