00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TRunInformation.hh"
00017 #include "TOutputHtmlFileStream.hh"
00018
00019 static const Tstring _defaultvalue = "***";
00020
00021 TRunInformation::TRunInformation()
00022 : theInformationType( tInfoUnknown ),
00023 theItem(),
00024 theDefaultValue( _defaultvalue ),
00025 theValue( theDefaultValue ),
00026 theSelectableList()
00027 {
00028 theSelectableList.clear();
00029 }
00030
00031 TRunInformation::TRunInformation( const Tstring& item )
00032 : theInformationType( tInfoSelectableValue ),
00033 theItem( item ),
00034 theDefaultValue( _defaultvalue ),
00035 theValue( theDefaultValue ),
00036 theSelectableList()
00037 {
00038 theSelectableList.clear();
00039 }
00040
00041 TRunInformation::TRunInformation( const Tstring& item, Truninfo_t type )
00042 : theInformationType( type ),
00043 theItem( item ),
00044 theDefaultValue( _defaultvalue ),
00045 theValue( theDefaultValue ),
00046 theSelectableList()
00047 {
00048 theSelectableList.clear();
00049 }
00050
00051 TRunInformation::TRunInformation( const Tstring& item, const TstringList& list )
00052 : theInformationType( tInfoSelectableValue ),
00053 theItem( item ),
00054 theDefaultValue( _defaultvalue ),
00055 theValue( theDefaultValue ),
00056 theSelectableList( list )
00057 {;}
00058
00059 TRunInformation::TRunInformation( const Tstring& item, const Tstring& value )
00060 : theInformationType( tInfoFreeValue ),
00061 theItem( item ),
00062 theDefaultValue( value ),
00063 theValue( theDefaultValue ),
00064 theSelectableList()
00065 {;}
00066
00067 TRunInformation::TRunInformation( const Tstring& item, const Tstring& value, Truninfo_t type )
00068 : theInformationType( type ),
00069 theItem( item ),
00070 theDefaultValue( value ),
00071 theValue( theDefaultValue ),
00072 theSelectableList()
00073 {;}
00074
00075 TRunInformation::TRunInformation( const Tstring& item, const Tstring& value, const TstringList& list )
00076 : theInformationType( tInfoSelectableValue ),
00077 theItem( item ),
00078 theDefaultValue( value ),
00079 theValue( theDefaultValue ),
00080 theSelectableList( list )
00081 {;}
00082
00083 TRunInformation::TRunInformation( const TRunInformation& right )
00084 : theInformationType( right.theInformationType ),
00085 theItem( right.theItem ),
00086 theDefaultValue( right.theDefaultValue ),
00087 theValue( right.theValue ),
00088 theSelectableList( right.theSelectableList )
00089 {;}
00090
00091 TRunInformation::~TRunInformation()
00092 {;}
00093
00094 const TRunInformation& TRunInformation::operator=( const TRunInformation& right )
00095 {
00096 theInformationType = right.theInformationType;
00097 theItem = right.theItem;
00098 theDefaultValue = right.theDefaultValue;
00099 theValue = right.theValue;
00100 theSelectableList = right.theSelectableList;
00101 return *this;
00102 }
00103
00104 Tbool TRunInformation::operator==( const TRunInformation& right ) const
00105 {
00106 Tbool retval = Ttrue;
00107 retval &= ( theInformationType == right.theInformationType );
00108 retval &= ( theItem == right.theItem );
00109 retval &= ( theValue == right.theValue );
00110 return retval;
00111 }
00112
00113 Tbool TRunInformation::operator!=( const TRunInformation& right ) const
00114 {
00115 Tbool retval = Tfalse;
00116 retval |= ( theInformationType != right.theInformationType );
00117 retval |= ( theItem != right.theItem );
00118 retval |= ( theValue != right.theValue );
00119 return retval;
00120 }
00121
00122 Tostream& operator<<( Tostream& tos, const TRunInformation& right )
00123 {
00124 switch ( right.theInformationType ) {
00125 case tInfoFreeValue:
00126 case tInfoSelectableValue:
00127 tos << right.theItem << ": " << right.theValue << Tflush;
00128 break;
00129 case tInfoFreeText:
00130 tos << right.theItem << ", follow as:" << Tendl;
00131 tos << right.theValue << Tflush;
00132 break;
00133 case tInfoUnknown:
00134 default:
00135 tos << right.theItem << ": " << right.theValue << Tflush;
00136 break;
00137 }
00138 return tos;
00139 }
00140
00141 TOutputHtmlFileStream& operator<<( TOutputHtmlFileStream& html, const TRunInformation& right )
00142 {
00143 if ( html.IsOpen() ) {
00144 if ( !html.OpenTable() ) {
00145 html.OpenTable();
00146 }
00147 html << "<tr><td><b>" << right.theItem << "</b></td>" << Tflush;
00148 html << "<td>" << right.theValue << "</td></tr>" << Tendl;
00149 if ( !html.CloseTable() ) {
00150 html.CloseTable();
00151 }
00152 }
00153 return html;
00154 }
00155
00156 Tvoid SetInformation( TRunInformation& info )
00157 {
00158 switch ( info.theInformationType ) {
00159 case tInfoFreeValue:
00160 info.setFreeValue();
00161 break;
00162 case tInfoSelectableValue:
00163 info.setSelectableValue();
00164 break;
00165 case tInfoFreeText:
00166 info.setFreeText();
00167 break;
00168 case tInfoUnknown:
00169 default:
00170 info.setInformation();
00171 break;
00172 }
00173 return;
00174 }
00175
00176 Tvoid TRunInformation::setFreeValue()
00177 {
00178 static const Tsize_t bufflen = 1024;
00179 Tstring strbuf;
00180 Tchar linebuf[ bufflen ];
00181
00182 Tbool validinput = Tfalse;
00183 while ( validinput == Tfalse ) {
00184 Tcout << theItem << " [" << theValue << "]: " << Tflush;
00185 Tcin.getline( linebuf, bufflen );
00186 strbuf = linebuf;
00187
00188 if ( !strbuf.empty() ) {
00189 for ( Tsize_t i = 0; i < strbuf.size(); i ++ ) {
00190 if ( isprint( strbuf[ i ] ) == 0 ) {
00191 Tcerr << "TRunInformation::setFreeValue: invalid input." << Tendl;
00192 strbuf.erase();
00193 break;
00194 }
00195 }
00196 if ( !strbuf.empty() ) {
00197 theValue = strbuf;
00198 validinput = Ttrue;
00199 }
00200 } else {
00201 validinput = Ttrue;
00202 }
00203 }
00204
00205 return;
00206 }
00207
00208 Tvoid TRunInformation::setSelectableValue()
00209 {
00210 if ( theSelectableList.empty() ) {
00211 Tcerr << "TRunInformation::setSelectableValue: list is empty." << Tendl;
00212 theInformationType = tInfoFreeValue;
00213 setFreeValue();
00214 return;
00215 }
00216
00217 Tcout << theItem << " [" << theValue << "]:" << Tendl;
00218 for ( Tsize_t i = 0; i < theSelectableList.size(); i ++ ) {
00219 Tcout.setf( Tios::right );
00220 Tcout << setw( 6 ) << i + 1 << ". " << theSelectableList[ i ] << Tendl;
00221 Tcout.unsetf( Tios::right );
00222 }
00223
00224 Tbool validinput = Tfalse;
00225 while ( validinput == Tfalse ) {
00226 Tcout << "Select: " << Tflush;
00227 Tchar cbuf;
00228 Tstring strbuf;
00229 while ( Tcin.get( cbuf ).gcount() == 1 && !Tcin.fail() && cbuf != '\n' ) {
00230 strbuf += cbuf;
00231 }
00232 if ( strbuf.empty() ) {
00233
00234 validinput = Ttrue;
00235 } else {
00236 Tbool validdigit = Ttrue;
00237
00238 for ( Tsize_t i = 0; i < strbuf.size(); i ++ ) {
00239 if ( isdigit( strbuf[ i ] ) == 0 ) {
00240
00241 Tcerr << "enable key: 1 to " << theSelectableList.size() << Tendl;
00242 validdigit = Tfalse;
00243 break;
00244 }
00245 }
00246 if ( validdigit ) {
00247 Tint input = strtol( strbuf.c_str(), 0, 0 ) - 1;
00248 if ( input >= 0 && input < (Tint)theSelectableList.size() ) {
00249
00250 theValue = theSelectableList[ input ];
00251 validinput = Ttrue;
00252 } else {
00253
00254 Tcerr << "enable key: 1 to " << theSelectableList.size() << Tendl;
00255 validdigit = Tfalse;
00256 }
00257 }
00258 }
00259 }
00260 return;
00261 }
00262
00263 Tvoid TRunInformation::setFreeText()
00264 {
00265 static const Tstring terminater = "\n.\n";
00266 static const Tsize_t termlen = terminater.size();
00267 static const Tstring emp = ".\n";
00268 static const Tsize_t emplen = emp.size();
00269
00270 Tcout << theItem << " ('.' to escape, like as SMTP):" << Tendl;
00271 Tstring text;
00272 Tchar cbuf;
00273
00274 struct termios tiosbuf;
00275 struct termios tiosorg;
00276 tcgetattr( 0, &tiosorg );
00277 tiosbuf = tiosorg;
00278 tiosbuf.c_iflag |= IGNBRK;
00279 tiosbuf.c_iflag |= IGNPAR;
00280 tiosbuf.c_lflag &= ~ICANON;
00281 tiosbuf.c_lflag |= ECHO;
00282 tiosbuf.c_lflag |= ISIG;
00283 tiosbuf.c_cc[ VMIN ] = 1;
00284 tiosbuf.c_cc[ VTIME ] = 0;
00285 tcsetattr( 0, TCSANOW, &tiosbuf );
00286
00287
00288 while ( Tcin.read( &cbuf, 1 ).gcount() == 1 && !Tcin.fail() ) {
00289 if ( isprint( cbuf ) != 0 || isspace( cbuf ) != 0 ) {
00290 text += cbuf;
00291 }
00292
00293 if ( text.size() >= termlen && text.substr( text.size() - termlen, termlen ) == terminater ) {
00294
00295 text.erase( text.size() - termlen, termlen );
00296 theValue = text;
00297 break;
00298 } else if ( text.size() == emplen && text == emp ) {
00299
00300 break;
00301 } else if ( text.size() == 1 && text[ 0 ] == '\n' ) {
00302
00303 break;
00304 }
00305 }
00306
00307 tcsetattr( 0, TCSANOW, &tiosorg );
00308 return;
00309 }
00310
00311 Tvoid TRunInformation::setInformation()
00312 {
00313 Tcout << "TRunInformation::setInformation: not implemented." << Tendl;
00314 return;
00315 }
00316
00317 Tvoid TRunInformation::Clear()
00318 {
00319 theValue = theDefaultValue;
00320 return;
00321 }
00322
00323 #ifdef __CLDAQ_ROOT_DLL
00324 ClassImp(TRunInformation)
00325 #endif