Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4UIcommand << 27 // 23 // 28 // Author: Makoto Asai (SLAC), 1998 << 24 // $Id: G4UIcommand.cc,v 1.21 2002/12/05 16:25:34 asaim Exp $ 29 // ------------------------------------------- << 25 // GEANT4 tag $Name: geant4-05-01-patch-01 $ >> 26 // >> 27 // 30 28 31 #include "G4UIcommand.hh" 29 #include "G4UIcommand.hh" 32 << 33 #include "G4StateManager.hh" << 34 #include "G4Threading.hh" << 35 #include "G4Tokenizer.hh" << 36 #include "G4UIcommandStatus.hh" << 37 #include "G4UImanager.hh" << 38 #include "G4UImessenger.hh" 30 #include "G4UImessenger.hh" 39 #include "G4UIparsing.hh" << 31 #include "G4UImanager.hh" >> 32 #include "G4UIcommandStatus.hh" >> 33 #include "G4StateManager.hh" 40 #include "G4UnitsTable.hh" 34 #include "G4UnitsTable.hh" >> 35 #include "G4Tokenizer.hh" 41 #include "G4ios.hh" 36 #include "G4ios.hh" 42 37 43 // ------------------------------------------- << 38 G4UIcommand::G4UIcommand() 44 G4UIcommand::G4UIcommand(const char* theComman << 39 :messenger(0),token(IDENTIFIER),paramERR(0) 45 : toBeBroadcasted(tBB), messenger(theMesseng << 40 {;} >> 41 >> 42 G4UIcommand::G4UIcommand(const char * theCommandPath, >> 43 G4UImessenger * theMessenger) >> 44 :messenger(theMessenger),token(IDENTIFIER),paramERR(0) 46 { 45 { 47 G4String comStr = theCommandPath; 46 G4String comStr = theCommandPath; 48 G4UIcommandCommonConstructorCode(comStr); << 47 if(!theMessenger) 49 availabelStateList = {G4State_PreInit, G4 << 48 { // this must be a directory 50 G4State_GeomClosed, G4 << 49 if(comStr(comStr.length()-1)!='/') >> 50 { >> 51 G4cerr << "G4UIcommand Warning : " << G4endl; >> 52 G4cerr << " <" << theCommandPath << "> must be a directory." << G4endl; >> 53 G4cerr << " '/' is appended." << G4endl; >> 54 comStr += "/"; >> 55 } >> 56 } >> 57 G4UIcommandCommonConstructorCode (comStr); >> 58 G4String nullString; >> 59 availabelStateList.clear(); >> 60 availabelStateList.push_back(G4State_PreInit); >> 61 availabelStateList.push_back(G4State_Init); >> 62 availabelStateList.push_back(G4State_Idle); >> 63 availabelStateList.push_back(G4State_GeomClosed); >> 64 availabelStateList.push_back(G4State_EventProc); >> 65 availabelStateList.push_back(G4State_Abort); 51 } 66 } 52 67 53 // ------------------------------------------- << 68 void G4UIcommand::G4UIcommandCommonConstructorCode 54 void G4UIcommand::G4UIcommandCommonConstructor << 69 (const char * theCommandPath) 55 { << 70 { 56 commandPath = theCommandPath; 71 commandPath = theCommandPath; 57 commandName = theCommandPath; 72 commandName = theCommandPath; 58 auto commandNameIndex = (G4int)commandName.r << 73 G4int commandNameIndex = commandName.last('/'); 59 commandName.erase(0, commandNameIndex + 1); << 74 commandName.remove(0,commandNameIndex+1); 60 #ifdef G4MULTITHREADED << 61 if ((messenger != nullptr) && messenger->Com << 62 && G4Threading::IsWorkerThread()) << 63 { << 64 toBeBroadcasted = false; << 65 G4UImanager::GetMasterUIpointer()->AddNewC << 66 } << 67 else { << 68 G4UImanager::GetUIpointer()->AddNewCommand << 69 } << 70 #else << 71 G4UImanager::GetUIpointer()->AddNewCommand(t << 72 #endif << 73 } << 74 75 75 // ------------------------------------------- << 76 G4UImanager::GetUIpointer()->AddNewCommand(this); 76 void G4UIcommand::SetCommandType(CommandType t << 77 { << 78 if (messenger == nullptr) { // this must be << 79 if (typ != CmdDirectory) { << 80 G4ExceptionDescription ed; << 81 ed << "A UI command <" << commandPath << << 82 G4Exception("G4UIcommand::SetCommandType << 83 } << 84 else if (commandPath.back() != '/') { << 85 G4ExceptionDescription ed; << 86 ed << "G4UIcommand Warning : \n" << 87 << " <" << commandPath << "> must be << 88 << " '/' is appended."; << 89 G4Exception("G4UIcommand::SetCommandType << 90 commandPath += "/"; << 91 } << 92 } << 93 commandType = typ; << 94 } 77 } 95 78 96 // ------------------------------------------- << 97 G4UIcommand::~G4UIcommand() 79 G4UIcommand::~G4UIcommand() 98 { 80 { 99 G4UImanager* fUImanager = G4UImanager::GetUI 81 G4UImanager* fUImanager = G4UImanager::GetUIpointer(); 100 if (fUImanager != nullptr) { << 82 if(fUImanager) fUImanager->RemoveCommand(this); 101 fUImanager->RemoveCommand(this); << 83 102 } << 84 G4int n_parameterEntry = parameter.size(); 103 << 85 for( G4int i_thParameter=0; i_thParameter < n_parameterEntry; i_thParameter++ ) 104 for (const auto& p : parameter) { << 86 { delete parameter[i_thParameter]; } 105 delete p; << 87 parameter.clear(); 106 } << 107 } 88 } 108 89 109 // ------------------------------------------- << 90 G4int G4UIcommand::operator==(const G4UIcommand &right) const 110 G4bool G4UIcommand::operator==(const G4UIcomma << 111 { 91 { 112 return (commandPath == right.GetCommandPath( << 92 return ( commandPath == right.GetCommandPath() ); 113 } 93 } 114 94 115 // ------------------------------------------- << 95 G4int G4UIcommand::operator!=(const G4UIcommand &right) const 116 G4bool G4UIcommand::operator!=(const G4UIcomma << 117 { 96 { 118 return (commandPath != right.GetCommandPath( << 97 return ( commandPath != right.GetCommandPath() ); 119 } 98 } 120 99 121 // ------------------------------------------- << 100 G4int G4UIcommand::DoIt(G4String parameterList) 122 G4int G4UIcommand::DoIt(const G4String& parame << 123 { 101 { 124 G4String correctParameters; 102 G4String correctParameters; 125 std::size_t n_parameterEntry = parameter.siz << 103 G4int n_parameterEntry = parameter.size(); 126 if (n_parameterEntry != 0) { << 104 if( n_parameterEntry != 0 ) >> 105 { 127 G4String aToken; 106 G4String aToken; 128 G4String correctToken; 107 G4String correctToken; 129 G4Tokenizer parameterToken(parameterList); << 108 G4Tokenizer parameterToken( parameterList ); 130 for (std::size_t i_thParameter = 0; i_thPa << 109 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) 131 if (i_thParameter > 0) { << 110 { >> 111 if(i_thParameter > 0) >> 112 { 132 correctParameters.append(" "); 113 correctParameters.append(" "); 133 } 114 } 134 aToken = parameterToken(); 115 aToken = parameterToken(); 135 if (aToken.length() > 0 && aToken[0] == << 116 if( aToken.length()>0 && aToken(0)=='"' ) 136 while (aToken.back() != '"' || (aToken << 117 { >> 118 while( aToken(aToken.length()-1) != '"' >> 119 || ( aToken.length()==1 && aToken(0)=='"' )) >> 120 { 137 G4String additionalToken = parameter 121 G4String additionalToken = parameterToken(); 138 if (additionalToken.empty()) { << 122 if( additionalToken.isNull() ) 139 return G4int(fParameterUnreadable << 123 { return fParameterUnreadable+i_thParameter; } 140 } << 141 aToken += " "; 124 aToken += " "; 142 aToken += additionalToken; 125 aToken += additionalToken; 143 } 126 } 144 } 127 } 145 else if (i_thParameter == n_parameterEnt << 128 else if(i_thParameter==n_parameterEntry-1 && parameter[i_thParameter]->GetParameterType()=='s') 146 && parameter[i_thParameter]->Ge << 147 { 129 { 148 G4String anotherToken; 130 G4String anotherToken; 149 while (!((anotherToken = parameterToke << 131 while(!((anotherToken=parameterToken()).isNull())) 150 std::size_t idxs = anotherToken.find << 132 { 151 if (idxs == std::string::npos) { << 133 G4int idxs = anotherToken.index("#"); >> 134 if(idxs==G4int(G4std::string::npos)) >> 135 { 152 aToken += " "; 136 aToken += " "; 153 aToken += anotherToken; 137 aToken += anotherToken; 154 } 138 } 155 else if (idxs > 0) { << 139 else if(idxs>0) >> 140 { 156 aToken += " "; 141 aToken += " "; 157 aToken += anotherToken.substr(0, i << 142 aToken += anotherToken(0,idxs); 158 break; << 159 } << 160 else { << 161 break; 143 break; 162 } 144 } >> 145 else >> 146 { break; } 163 } 147 } 164 } 148 } 165 149 166 if (aToken.empty() || aToken == "!") { << 150 if( aToken.isNull() || aToken == "!" ) 167 if (parameter[i_thParameter]->IsOmitta << 151 { 168 if (parameter[i_thParameter]->GetCur << 152 if(parameter[i_thParameter]->IsOmittable()) >> 153 { >> 154 if(parameter[i_thParameter]->GetCurrentAsDefault()) >> 155 { 169 G4Tokenizer cvSt(messenger->GetCur 156 G4Tokenizer cvSt(messenger->GetCurrentValue(this)); 170 G4String parVal; 157 G4String parVal; 171 for (std::size_t ii = 0; ii < i_th << 158 for(G4int ii=0;ii<i_thParameter;ii++) 172 parVal = cvSt(); << 159 { 173 if (parVal[0] == '"') { << 160 parVal = cvSt(); 174 while (parVal.back() != '"') { << 161 if (parVal(0)=='"') 175 G4String additionalToken = c << 162 { 176 if (additionalToken.empty()) << 163 while( parVal(parVal.length()-1) != '"' ) 177 return G4int(fParameterUnr << 164 { 178 } << 165 G4String additionalToken = cvSt(); 179 parVal += " "; << 166 if( additionalToken.isNull() ) 180 parVal += additionalToken; << 167 { return fParameterUnreadable+i_thParameter; } 181 } << 168 parVal += " "; 182 } << 169 parVal += additionalToken; 183 } << 170 } 184 G4String aCVToken = cvSt(); << 171 } 185 if (aCVToken[0] == '"') { << 172 } 186 while (aCVToken.back() != '"') { << 173 G4String aCVToken = cvSt(); 187 G4String additionalToken = cvS << 174 if (aCVToken(0)=='"') 188 if (additionalToken.empty()) { << 175 { 189 return G4int(fParameterUnrea << 176 while( aCVToken(aCVToken.length()-1) != '"' ) 190 } << 177 { 191 aCVToken += " "; << 178 G4String additionalToken = cvSt(); 192 aCVToken += additionalToken; << 179 if( additionalToken.isNull() ) 193 } << 180 { return fParameterUnreadable+i_thParameter; } 194 } << 181 aCVToken += " "; >> 182 aCVToken += additionalToken; >> 183 } >> 184 // aCVToken.strip(G4String::both,'"'); >> 185 } 195 correctParameters.append(aCVToken) 186 correctParameters.append(aCVToken); 196 } 187 } 197 else { << 188 else 198 correctParameters.append(parameter << 189 { correctParameters.append(parameter[i_thParameter]->GetDefaultValue()); } 199 } << 200 } << 201 else { << 202 return G4int(fParameterUnreadable + << 203 } 190 } >> 191 else >> 192 { return fParameterUnreadable+i_thParameter; } 204 } 193 } 205 else { << 194 else 206 G4int stat = parameter[i_thParameter]- << 195 { 207 if (stat != 0) { << 196 G4int stat = parameter[i_thParameter]->CheckNewValue( aToken ); 208 return stat + G4int(i_thParameter); << 197 if(stat) return stat+i_thParameter; 209 } << 210 correctParameters.append(aToken); 198 correctParameters.append(aToken); 211 } 199 } 212 } 200 } 213 } 201 } 214 202 215 if (CheckNewValue(correctParameters) != 0) { << 203 if(CheckNewValue( correctParameters )) 216 return fParameterOutOfRange + 99; << 204 { return fParameterOutOfRange+99; } 217 } << 218 << 219 if (workerThreadOnly && G4Threading::IsMaste << 220 return 0; << 221 } << 222 205 223 messenger->SetNewValue(this, std::move(corre << 206 messenger->SetNewValue( this, correctParameters ); 224 return 0; 207 return 0; 225 } 208 } 226 209 227 // ------------------------------------------- << 228 G4String G4UIcommand::GetCurrentValue() 210 G4String G4UIcommand::GetCurrentValue() 229 { 211 { 230 return messenger->GetCurrentValue(this); 212 return messenger->GetCurrentValue(this); 231 } 213 } 232 214 233 // ------------------------------------------- << 234 void G4UIcommand::AvailableForStates(G4Applica 215 void G4UIcommand::AvailableForStates(G4ApplicationState s1) 235 { 216 { 236 availabelStateList = {s1}; << 217 availabelStateList.clear(); >> 218 availabelStateList.push_back(s1); 237 } 219 } 238 220 239 // ------------------------------------------- << 221 void G4UIcommand::AvailableForStates(G4ApplicationState s1, 240 void G4UIcommand::AvailableForStates(G4Applica << 222 G4ApplicationState s2) 241 { 223 { 242 availabelStateList = {s1, s2}; << 224 availabelStateList.clear(); >> 225 availabelStateList.push_back(s1); >> 226 availabelStateList.push_back(s2); 243 } 227 } 244 228 245 // ------------------------------------------- << 229 void G4UIcommand::AvailableForStates(G4ApplicationState s1, 246 void G4UIcommand::AvailableForStates(G4Applica << 230 G4ApplicationState s2, 247 G4Applica 231 G4ApplicationState s3) 248 { 232 { 249 availabelStateList = {s1, s2, s3}; << 233 availabelStateList.clear(); 250 } << 234 availabelStateList.push_back(s1); 251 << 235 availabelStateList.push_back(s2); 252 // ------------------------------------------- << 236 availabelStateList.push_back(s3); 253 void G4UIcommand::AvailableForStates(G4Applica << 237 } 254 G4Applica << 238 255 { << 239 void G4UIcommand::AvailableForStates(G4ApplicationState s1, 256 availabelStateList = {s1, s2, s3, s4}; << 240 G4ApplicationState s2, 257 } << 241 G4ApplicationState s3, 258 << 242 G4ApplicationState s4) 259 // ------------------------------------------- << 243 { 260 void G4UIcommand::AvailableForStates(G4Applica << 244 availabelStateList.clear(); 261 G4Applica << 245 availabelStateList.push_back(s1); >> 246 availabelStateList.push_back(s2); >> 247 availabelStateList.push_back(s3); >> 248 availabelStateList.push_back(s4); >> 249 } >> 250 >> 251 void G4UIcommand::AvailableForStates(G4ApplicationState s1, >> 252 G4ApplicationState s2, >> 253 G4ApplicationState s3, >> 254 G4ApplicationState s4, 262 G4Applica 255 G4ApplicationState s5) 263 { 256 { 264 availabelStateList = {s1, s2, s3, s4, s5}; << 257 availabelStateList.clear(); >> 258 availabelStateList.push_back(s1); >> 259 availabelStateList.push_back(s2); >> 260 availabelStateList.push_back(s3); >> 261 availabelStateList.push_back(s4); >> 262 availabelStateList.push_back(s5); 265 } 263 } 266 264 267 // ------------------------------------------- << 268 G4bool G4UIcommand::IsAvailable() 265 G4bool G4UIcommand::IsAvailable() 269 { 266 { 270 G4ApplicationState currentState = G4StateMan << 267 G4bool av = false; 271 << 268 G4ApplicationState currentState 272 for (const auto& s : availabelStateList) { << 269 = G4StateManager::GetStateManager()->GetCurrentState(); 273 if (s == currentState) { << 270 274 return true; << 271 G4int nState = availabelStateList.size(); 275 } << 272 for(G4int i=0;i<nState;i++) >> 273 { >> 274 if(availabelStateList[i]==currentState) >> 275 { >> 276 av = true; >> 277 break; >> 278 } 276 } 279 } 277 280 278 return false; << 281 return av; 279 } 282 } 280 283 281 // ------------------------------------------- << 282 G4double G4UIcommand::ValueOf(const char* unit 284 G4double G4UIcommand::ValueOf(const char* unitName) 283 { 285 { 284 return G4UnitDefinition::GetValueOf(unitName << 286 G4double value = 0.; >> 287 value = G4UnitDefinition::GetValueOf(unitName); >> 288 return value; 285 } 289 } 286 290 287 // ------------------------------------------- << 288 G4String G4UIcommand::CategoryOf(const char* u 291 G4String G4UIcommand::CategoryOf(const char* unitName) 289 { 292 { 290 return G4UnitDefinition::GetCategory(unitNam << 293 return G4UnitDefinition::GetCategory(unitName); 291 } 294 } 292 295 293 // ------------------------------------------- << 294 G4String G4UIcommand::UnitsList(const char* un 296 G4String G4UIcommand::UnitsList(const char* unitCategory) 295 { 297 { >> 298 G4String retStr; 296 G4UnitsTable& UTbl = G4UnitDefinition::GetUn 299 G4UnitsTable& UTbl = G4UnitDefinition::GetUnitsTable(); 297 << 300 size_t i; 298 auto ucatIter = std::find_if(std::cbegin(UTb << 301 for(i=0;i<UTbl.size();i++) 299 return ud->GetName() == unitCategory; << 302 { if(UTbl[i]->GetName()==unitCategory) break; } 300 }); << 303 if(i==UTbl.size()) 301 << 304 { 302 if (ucatIter == std::cend(UTbl)) { << 303 G4cerr << "Unit category <" << unitCategor 305 G4cerr << "Unit category <" << unitCategory << "> is not defined." << G4endl; 304 return G4String(); << 306 return retStr; 305 } 307 } 306 << 308 G4UnitsContainer& UCnt = UTbl[i]->GetUnitsList(); 307 G4String symList; << 309 retStr = UCnt[0]->GetSymbol(); 308 G4String nameList; << 310 G4int je = UCnt.size(); 309 G4UnitsContainer& UCnt = (*ucatIter)->GetUni << 311 for(G4int j=1;j<je;j++) 310 << 312 { 311 for (const auto& uDef : UCnt) { << 313 retStr += " "; 312 symList += uDef->GetSymbol(); << 314 retStr += UCnt[j]->GetSymbol(); 313 symList += " "; << 314 nameList += uDef->GetName(); << 315 nameList += " "; << 316 } 315 } 317 symList += nameList; << 316 for(G4int k=0;k<je;k++) 318 G4StrUtil::rstrip(symList); << 317 { 319 return symList; << 318 retStr += " "; >> 319 retStr += UCnt[k]->GetName(); >> 320 } >> 321 return retStr; 320 } 322 } 321 << 323 322 // ------------------------------------------- << 323 void G4UIcommand::List() 324 void G4UIcommand::List() 324 { 325 { 325 G4cout << G4endl; 326 G4cout << G4endl; 326 G4cout << G4endl; 327 G4cout << G4endl; 327 if (commandPath.back() != '/') { << 328 if(commandPath(commandPath.length()-1)!='/') 328 G4cout << "Command " << commandPath << G4e << 329 { G4cout << "Command " << commandPath << G4endl; } 329 } << 330 if (workerThreadOnly) { << 331 G4cout << " ---- available only in work << 332 } << 333 << 334 G4cout << "Guidance :" << G4endl; 330 G4cout << "Guidance :" << G4endl; 335 for (const auto& i_thGuidance : commandGuida << 331 G4int n_guidanceEntry = commandGuidance.size(); 336 G4cout << i_thGuidance << G4endl; << 332 for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) 337 } << 333 { G4cout << commandGuidance[i_thGuidance] << G4endl; } 338 << 334 if( ! rangeString.isNull() ) 339 if (!rangeExpression.empty()) { << 335 { G4cout << " Range of parameters : " << rangeString << G4endl; } 340 G4cout << " Range of parameters : " << ran << 336 G4int n_parameterEntry = parameter.size(); 341 } << 337 if( n_parameterEntry > 0 ) 342 << 338 { 343 for (const auto& i_thParameter : parameter) << 339 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) 344 i_thParameter->List(); << 340 { parameter[i_thParameter]->List(); } 345 } 341 } 346 G4cout << G4endl; 342 G4cout << G4endl; 347 } 343 } 348 344 349 // ------------------------------------------- << 345 // ----- the following is used by CheckNewValue() ------------ 350 G4String G4UIcommand::ConvertToString(G4bool b << 351 { << 352 return boolVal ? "1" : "0"; << 353 } << 354 346 355 // ------------------------------------------- << 356 G4String G4UIcommand::ConvertToString(G4int in << 357 { << 358 return G4UIparsing::TtoS(intValue); << 359 } << 360 347 361 // ------------------------------------------- << 348 #include <ctype.h> // isalpha(), toupper() 362 G4String G4UIcommand::ConvertToString(G4long l << 349 #include "g4std/strstream" 363 { << 350 364 return G4UIparsing::TtoS(longValue); << 351 //#include "checkNewValue_debug.icc" >> 352 //#define DEBUG 1 >> 353 >> 354 G4int G4UIcommand:: >> 355 CheckNewValue(const char * newValue) >> 356 { >> 357 yystype result; >> 358 // if( TypeCheck(newValue) == 0 ) return 1; >> 359 if( ! rangeString.isNull() ) >> 360 { if( RangeCheck(newValue) == 0 ) return fParameterOutOfRange; } >> 361 return 0; // succeeded >> 362 } >> 363 >> 364 // ------------------ type check routines ------------------- >> 365 >> 366 G4int G4UIcommand:: >> 367 TypeCheck(const char * t) >> 368 { >> 369 G4String aNewValue; >> 370 char type; >> 371 G4std::istrstream is((char*)t); >> 372 for (unsigned i=0; i< parameter.size(); i++) { >> 373 is >> aNewValue; >> 374 type = toupper(parameter[i]->GetParameterType()); >> 375 switch ( type ) { >> 376 case 'D': >> 377 if( IsDouble(aNewValue)==0 ){ >> 378 G4cerr << aNewValue << ": double value expected." >> 379 << G4endl; >> 380 return 0; >> 381 } break; >> 382 case 'I': >> 383 if( IsInt(aNewValue,20)==0 ){ >> 384 G4cerr <<aNewValue<<": integer expected." >> 385 <<G4endl; >> 386 return 0; >> 387 } break; >> 388 case 'S': >> 389 break; >> 390 case 'B': >> 391 aNewValue.toUpper(); >> 392 if (aNewValue == "Y" || aNewValue == "N" >> 393 ||aNewValue == "YES" || aNewValue == "NO" >> 394 ||aNewValue == "1" || aNewValue == "0" >> 395 ||aNewValue == "T" || aNewValue == "F" >> 396 ||aNewValue == "TRUE" || aNewValue == "FALSE") >> 397 return 1; >> 398 else return 0; >> 399 break; >> 400 default: ; >> 401 } >> 402 } >> 403 return 1; 365 } 404 } 366 405 367 // ------------------------------------------- << 406 368 G4String G4UIcommand::ConvertToString(G4double << 407 G4int G4UIcommand:: >> 408 IsInt(const char* buf, short maxDigits) 369 { 409 { 370 std::ostringstream os; << 410 const char* p= buf; 371 if (G4UImanager::DoublePrecisionStr()) { << 411 G4int length=0; 372 os << std::setprecision(17); << 412 if( *p == '+' || *p == '-') { ++p; } 373 } << 413 if( isdigit( (G4int)(*p) )) { 374 os << doubleValue; << 414 while( isdigit( (G4int)(*p) )) { ++p; ++length; } 375 return os.str(); << 415 if( *p == '\0' ) { >> 416 if( length > maxDigits) { >> 417 G4cerr <<"digit length exceeds"<<G4endl; >> 418 return 0; >> 419 } >> 420 return 1; >> 421 } else { >> 422 // G4cerr <<"illegal character after int:"<<buf<<G4endl; >> 423 } >> 424 } else { >> 425 // G4cerr <<"illegal int:"<<buf<<G4endl; >> 426 } >> 427 return 0; 376 } 428 } 377 429 378 // ------------------------------------------- << 430 379 G4String G4UIcommand::ConvertToString(G4double << 431 G4int G4UIcommand:: >> 432 ExpectExponent(const char* str) // used only by IsDouble() 380 { 433 { 381 std::ostringstream os; << 434 G4int maxExplength; 382 if (G4UImanager::DoublePrecisionStr()) { << 435 if( IsInt( str, maxExplength=7 )) return 1; 383 os << std::setprecision(17); << 436 else return 0; 384 } << 385 os << doubleValue / ValueOf(unitName) << " " << 386 return os.str(); << 387 } 437 } 388 438 389 // ------------------------------------------- << 439 390 G4String G4UIcommand::ConvertToString(const G4 << 440 G4int G4UIcommand:: 391 { << 441 IsDouble(const char* buf) 392 std::ostringstream os; << 442 { 393 if (G4UImanager::DoublePrecisionStr()) { << 443 const char* p= buf; 394 os << std::setprecision(17); << 444 switch( *p) { 395 } << 445 case '+': case '-': ++p; 396 os << vec.x() << " " << vec.y() << " " << ve << 446 if( isdigit(*p) ) { 397 return os.str(); << 447 while( isdigit( (G4int)(*p) )) { ++p; } >> 448 switch ( *p ) { >> 449 case '\0': return 1; >> 450 // break; >> 451 case 'E': case 'e': >> 452 return ExpectExponent(++p ); >> 453 // break; >> 454 case '.': ++p; >> 455 if( *p == '\0' ) return 1; >> 456 if( *p == 'e' || *p =='E' ) return ExpectExponent(++p ); >> 457 if( isdigit(*p) ) { >> 458 while( isdigit( (G4int)(*p) )) { ++p; } >> 459 if( *p == '\0' ) return 1; >> 460 if( *p == 'e' || *p =='E') return ExpectExponent(++p); >> 461 } else return 0; break; >> 462 default: return 0; >> 463 } >> 464 } >> 465 if( *p == '.' ) { ++p; >> 466 if( isdigit(*p) ) { >> 467 while( isdigit( (G4int)(*p) )) { ++p; } >> 468 if( *p == '\0' ) return 1; >> 469 if( *p == 'e' || *p =='E') return ExpectExponent(++p); >> 470 } >> 471 } >> 472 break; >> 473 case '.': ++p; >> 474 if( isdigit(*p) ) { >> 475 while( isdigit( (G4int)(*p) )) { ++p; } >> 476 if( *p == '\0' ) return 1; >> 477 if( *p == 'e' || *p =='E' ) return ExpectExponent(++p); >> 478 } break; >> 479 default: // digit is expected >> 480 if( isdigit(*p) ) { >> 481 while( isdigit( (G4int)(*p) )) { ++p; } >> 482 if( *p == '\0' ) return 1; >> 483 if( *p == 'e' || *p =='E') return ExpectExponent(++p); >> 484 if( *p == '.' ) { ++p; >> 485 if( *p == '\0' ) return 1; >> 486 if( *p == 'e' || *p =='E') return ExpectExponent(++p); >> 487 if( isdigit(*p) ) { >> 488 while( isdigit( (G4int)(*p) )) { ++p; } >> 489 if( *p == '\0' ) return 1; >> 490 if( *p == 'e' || *p =='E') return ExpectExponent(++p); >> 491 } >> 492 } >> 493 } >> 494 } >> 495 return 0; 398 } 496 } 399 497 400 // ------------------------------------------- << 401 G4String G4UIcommand::ConvertToString(const G4 << 402 { << 403 G4double uv = ValueOf(unitName); << 404 498 405 std::ostringstream os; << 499 // ------------------ range Check routines ------------------- 406 if (G4UImanager::DoublePrecisionStr()) { << 500 G4int G4UIcommand:: 407 os << std::setprecision(17); << 501 RangeCheck(const char* t) { 408 } << 502 yystype result; 409 os << vec.x() / uv << " " << vec.y() / uv << << 503 char type; 410 return os.str(); << 504 bp = 0; // reset buffer pointer for G4UIpGetc() >> 505 G4std::istrstream is((char*)t); >> 506 for (unsigned i=0; i< parameter.size(); i++) { >> 507 type= toupper(parameter[i]->GetParameterType()); >> 508 switch ( type ) { >> 509 case 'D': is >> newVal[i].D; break; >> 510 case 'I': is >> newVal[i].I; break; >> 511 case 'S': >> 512 case 'B': >> 513 default: ; >> 514 } >> 515 } >> 516 // PrintToken(); // Print tokens (consumes all tokens) >> 517 token= Yylex(); >> 518 result = Expression(); >> 519 >> 520 if( paramERR == 1 ) return 0; >> 521 if( result.type != CONSTINT) { >> 522 G4cerr << "Illegal Expression in parameter range." << G4endl; >> 523 return 0; >> 524 } >> 525 if ( result.I ) return 1; >> 526 G4cerr << "parameter out of range: "<< rangeString << G4endl; >> 527 return 0; >> 528 } >> 529 >> 530 // ------------------ syntax node functions ------------------ >> 531 yystype G4UIcommand:: >> 532 Expression(void) >> 533 { >> 534 yystype result; >> 535 #ifdef DEBUG >> 536 G4cerr << " Expression()" << G4endl; >> 537 #endif >> 538 result = LogicalORExpression(); >> 539 return result; >> 540 } >> 541 >> 542 yystype G4UIcommand:: >> 543 LogicalORExpression(void) >> 544 { >> 545 yystype result; >> 546 yystype p; >> 547 p = LogicalANDExpression(); >> 548 if( token != LOGICALOR) return p; >> 549 if( p.type == CONSTSTRING || p.type == IDENTIFIER ) { >> 550 G4cerr << "Parameter range: illegal type at '||'" << G4endl; >> 551 paramERR = 1; >> 552 } >> 553 result.I = p.I; >> 554 while (token == LOGICALOR) >> 555 { >> 556 token = Yylex(); >> 557 p = LogicalANDExpression(); >> 558 if( p.type == CONSTSTRING || p.type == IDENTIFIER ) { >> 559 G4cerr << "Parameter range: illegal type at '||'" <<G4endl; >> 560 paramERR = 1; >> 561 } >> 562 switch (p.type) { >> 563 case CONSTINT: >> 564 result.I += p.I; >> 565 result.type = CONSTINT; break; >> 566 case CONSTDOUBLE: >> 567 result.I += (p.D != 0.0); >> 568 result.type = CONSTINT; break; >> 569 default: >> 570 G4cerr << "Parameter range: unknown type"<<G4endl; >> 571 paramERR = 1; >> 572 } >> 573 } >> 574 return result; 411 } 575 } 412 576 413 // ------------------------------------------- << 577 yystype G4UIcommand:: 414 G4bool G4UIcommand::ConvertToBool(const char* << 578 LogicalANDExpression(void) 415 { 579 { 416 G4String v = G4StrUtil::to_upper_copy(st); << 580 yystype result; 417 return (v == "Y" || v == "YES" || v == "1" | << 581 yystype p; >> 582 p = EqualityExpression(); >> 583 if( token != LOGICALAND) return p; >> 584 if( p.type == CONSTSTRING || p.type == IDENTIFIER ) { >> 585 G4cerr << "Parameter range: illegal type at '&&'" << G4endl; >> 586 paramERR = 1; >> 587 } >> 588 result.I = p.I; >> 589 while (token == LOGICALAND) >> 590 { >> 591 token = Yylex(); >> 592 p = EqualityExpression(); >> 593 if( p.type == CONSTSTRING || p.type == IDENTIFIER ) { >> 594 G4cerr << "Parameter range: illegal type at '&&'" << G4endl; >> 595 paramERR = 1; >> 596 } >> 597 switch (p.type) { >> 598 case CONSTINT: >> 599 result.I *= p.I; >> 600 result.type = CONSTINT; break; >> 601 case CONSTDOUBLE: >> 602 result.I *= (p.D != 0.0); >> 603 result.type = CONSTINT; break; >> 604 default: >> 605 G4cerr << "Parameter range: unknown type."<< G4endl; >> 606 paramERR = 1; >> 607 } >> 608 } >> 609 return result; 418 } 610 } 419 611 420 // ------------------------------------------- << 612 421 G4int G4UIcommand::ConvertToInt(const char* st << 613 yystype G4UIcommand:: 422 { << 614 EqualityExpression(void) 423 return G4UIparsing::StoT<G4int>(st); << 615 { >> 616 yystype arg1, arg2; >> 617 G4int operat; >> 618 yystype result; >> 619 #ifdef DEBUG >> 620 G4cerr << " EqualityExpression()" <<G4endl; >> 621 #endif >> 622 result = RelationalExpression(); >> 623 if( token==EQ || token==NE ) { >> 624 operat = token; >> 625 token = Yylex(); >> 626 arg1 = result; >> 627 arg2 = RelationalExpression(); >> 628 result.I = Eval2( arg1, operat, arg2 ); // semantic action >> 629 result.type = CONSTINT; >> 630 #ifdef DEBUG >> 631 G4cerr << " return code of Eval2(): " << result.I <<G4endl; >> 632 #endif >> 633 } else { >> 634 if (result.type != CONSTINT && result.type != CONSTDOUBLE) { >> 635 G4cerr << "Parameter range: error at EqualityExpression" >> 636 << G4endl; >> 637 paramERR = 1; >> 638 } >> 639 } >> 640 return result; 424 } 641 } 425 642 426 // ------------------------------------------- << 643 427 G4long G4UIcommand::ConvertToLongInt(const cha << 644 yystype G4UIcommand:: 428 { << 645 RelationalExpression(void) 429 return G4UIparsing::StoT<G4long>(st); << 646 { >> 647 yystype arg1, arg2; >> 648 G4int operat; >> 649 yystype result; >> 650 #ifdef DEBUG >> 651 G4cerr << " RelationalExpression()" <<G4endl; >> 652 #endif >> 653 >> 654 arg1 = AdditiveExpression(); >> 655 if( token==GT || token==GE || token==LT || token==LE ) { >> 656 operat = token; >> 657 token = Yylex(); >> 658 arg2 = AdditiveExpression(); >> 659 result.I = Eval2( arg1, operat, arg2 ); // semantic action >> 660 result.type = CONSTINT; >> 661 #ifdef DEBUG >> 662 G4cerr << " return code of Eval2(): " << result.I << G4endl; >> 663 #endif >> 664 } else { >> 665 result = arg1; >> 666 } >> 667 #ifdef DEBUG >> 668 G4cerr <<" return RelationalExpression()"<< G4endl; >> 669 #endif >> 670 return result; >> 671 } >> 672 >> 673 yystype G4UIcommand:: >> 674 AdditiveExpression(void) >> 675 { yystype result; >> 676 result = MultiplicativeExpression(); >> 677 if( token != '+' && token != '-' ) return result; >> 678 G4cerr << "Parameter range: operator " >> 679 << (char)token >> 680 << " is not supported." << G4endl; >> 681 paramERR = 1; >> 682 return result; >> 683 } >> 684 >> 685 yystype G4UIcommand:: >> 686 MultiplicativeExpression(void) >> 687 { yystype result; >> 688 result = UnaryExpression(); >> 689 if( token != '*' && token != '/' && token != '%' ) return result; >> 690 G4cerr << "Parameter range: operator " >> 691 << (char)token >> 692 << " is not supported." << G4endl; >> 693 paramERR = 1; >> 694 return result; >> 695 } >> 696 >> 697 yystype G4UIcommand:: >> 698 UnaryExpression(void) >> 699 { >> 700 yystype result; >> 701 yystype p; >> 702 #ifdef DEBUG >> 703 G4cerr <<" UnaryExpression"<< G4endl; >> 704 #endif >> 705 switch(token) { >> 706 case '-': >> 707 token = Yylex(); >> 708 p = UnaryExpression(); >> 709 if (p.type == CONSTINT) { >> 710 result.I = - p.I; >> 711 result.type = CONSTINT; >> 712 } >> 713 if (p.type == CONSTDOUBLE) { >> 714 result.D = - p.D; >> 715 result.type = CONSTDOUBLE; >> 716 } break; >> 717 case '+': >> 718 token = Yylex(); >> 719 result = UnaryExpression(); break; >> 720 case '!': >> 721 token = Yylex(); >> 722 G4cerr << "Parameter range error: " >> 723 << "operator '!' is not supported (sorry)." >> 724 << G4endl; >> 725 paramERR = 1; >> 726 result = UnaryExpression(); break; >> 727 default: >> 728 result = PrimaryExpression(); >> 729 } >> 730 return result; 430 } 731 } 431 732 432 // ------------------------------------------- << 733 433 G4double G4UIcommand::ConvertToDouble(const ch << 734 yystype G4UIcommand:: >> 735 PrimaryExpression(void) 434 { 736 { 435 return G4UIparsing::StoT<G4double>(st); << 737 yystype result; >> 738 #ifdef DEBUG >> 739 G4cerr <<" primary_exp"<<G4endl; >> 740 #endif >> 741 switch (token) { >> 742 case IDENTIFIER: >> 743 result.S = yylval.S; >> 744 result.type = token; >> 745 token = Yylex(); break; >> 746 case CONSTINT: >> 747 result.I = yylval.I; >> 748 result.type = token; >> 749 token= Yylex(); break; >> 750 case CONSTDOUBLE: >> 751 result.D = yylval.D; >> 752 result.type = token; >> 753 token = Yylex(); break; >> 754 case '(' : >> 755 token= Yylex(); >> 756 result = Expression(); >> 757 if( token != ')' ) { >> 758 G4cerr << " ')' expected" << G4endl; >> 759 paramERR = 1; >> 760 } >> 761 token = Yylex(); >> 762 break; >> 763 default: >> 764 return result; >> 765 } >> 766 return result; // never executed 436 } 767 } 437 768 438 // ------------------------------------------- << 769 //---------------- semantic routines --------------------------------- 439 G4double G4UIcommand::ConvertToDimensionedDoub << 770 >> 771 G4int G4UIcommand:: >> 772 Eval2(yystype arg1, G4int op, yystype arg2) 440 { 773 { 441 G4double vl; << 774 char newValtype; 442 char unts[30]; << 775 if( (arg1.type != IDENTIFIER) && (arg2.type != IDENTIFIER)) { >> 776 G4cerr << commandName >> 777 << ": meaningless comparison" >> 778 << G4endl; >> 779 paramERR = 1; >> 780 } 443 781 444 std::istringstream is(st); << 782 if( arg1.type == IDENTIFIER) { 445 is >> vl >> unts; << 783 unsigned i = IndexOf( arg1.S ); 446 G4String unt = unts; << 784 newValtype = toupper(parameter[i]->GetParameterType()); >> 785 switch ( newValtype ) { >> 786 case 'I': >> 787 if( arg2.type == CONSTINT ) { >> 788 return CompareInt( newVal[i].I, op, arg2.I ); >> 789 } else { >> 790 G4cerr << "integer operand expected for " >> 791 << rangeString >> 792 << '.' << G4endl; >> 793 } break; >> 794 case 'D': >> 795 if( arg2.type == CONSTDOUBLE ) { >> 796 return CompareDouble( newVal[i].D, op, arg2.D ); >> 797 } else >> 798 if ( arg2.type == CONSTINT ) { // integral promotion >> 799 return CompareDouble( newVal[i].D, op, arg2.I ); >> 800 } break; >> 801 default: ; >> 802 } >> 803 } >> 804 if( arg2.type == IDENTIFIER) { >> 805 unsigned i = IndexOf( arg2.S ); >> 806 newValtype = toupper(parameter[i]->GetParameterType()); >> 807 switch ( newValtype ) { >> 808 case 'I': >> 809 if( arg1.type == CONSTINT ) { >> 810 return CompareInt( arg1.I, op, newVal[i].I ); >> 811 } else { >> 812 G4cerr << "integer operand expected for " >> 813 << rangeString >> 814 << '.' << G4endl; >> 815 } break; >> 816 case 'D': >> 817 if( arg1.type == CONSTDOUBLE ) { >> 818 return CompareDouble( arg1.D, op, newVal[i].D ); >> 819 } else >> 820 if ( arg1.type == CONSTINT ) { // integral promotion >> 821 return CompareDouble( arg1.I, op, newVal[i].D ); >> 822 } break; >> 823 default: ; >> 824 } >> 825 } >> 826 return 0; >> 827 } 447 828 448 return (vl * ValueOf(unt)); << 829 G4int G4UIcommand:: >> 830 CompareInt(G4int arg1, G4int op, G4int arg2) >> 831 { >> 832 G4int result=-1; >> 833 G4String opr; >> 834 switch (op) { >> 835 case GT: result = ( arg1 > arg2); opr= ">" ; break; >> 836 case GE: result = ( arg1 >= arg2); opr= ">="; break; >> 837 case LT: result = ( arg1 < arg2); opr= "<" ; break; >> 838 case LE: result = ( arg1 <= arg2); opr= "<="; break; >> 839 case EQ: result = ( arg1 == arg2); opr= "=="; break; >> 840 case NE: result = ( arg1 != arg2); opr= "!="; break; >> 841 default: >> 842 G4cerr << "Parameter range: error at CompareInt" << G4endl; >> 843 paramERR = 1; >> 844 } >> 845 #ifdef DEBUG >> 846 G4cerr << "CompareInt " >> 847 << arg1 << " " << opr << arg2 >> 848 << " result: " << result >> 849 << G4endl; >> 850 #endif >> 851 return result; >> 852 } >> 853 >> 854 G4int G4UIcommand:: >> 855 CompareDouble(G4double arg1, G4int op, G4double arg2) >> 856 { >> 857 G4int result=-1; >> 858 G4String opr; >> 859 switch (op) { >> 860 case GT: result = ( arg1 > arg2); opr= ">"; break; >> 861 case GE: result = ( arg1 >= arg2); opr= ">="; break; >> 862 case LT: result = ( arg1 < arg2); opr= "<"; break; >> 863 case LE: result = ( arg1 <= arg2); opr= "<="; break; >> 864 case EQ: result = ( arg1 == arg2); opr= "=="; break; >> 865 case NE: result = ( arg1 != arg2); opr= "!="; break; >> 866 default: >> 867 G4cerr << "Parameter range: error at CompareDouble" >> 868 << G4endl; >> 869 paramERR = 1; >> 870 } >> 871 #ifdef DEBUG >> 872 G4cerr << "CompareDouble " >> 873 << arg1 <<" " << opr << " "<< arg2 >> 874 << " result: " << result >> 875 << G4endl; >> 876 #endif >> 877 return result; >> 878 } >> 879 >> 880 unsigned G4UIcommand:: >> 881 IndexOf(const char* nam) >> 882 { >> 883 unsigned i; >> 884 G4String pname; >> 885 for( i=0; i<parameter.size(); i++) >> 886 { >> 887 pname = parameter[i]-> GetParameterName(); >> 888 if( pname == nam ) { >> 889 return i; >> 890 } >> 891 } >> 892 paramERR = 1; >> 893 G4cerr << "parameter name:"<<nam<<" not found."<< G4endl; >> 894 return 0; 449 } 895 } 450 896 451 // ------------------------------------------- << 897 452 G4ThreeVector G4UIcommand::ConvertTo3Vector(co << 898 unsigned G4UIcommand:: >> 899 IsParameter(const char* nam) 453 { 900 { 454 G4double vx; << 901 G4String pname; 455 G4double vy; << 902 for(unsigned i=0; i<parameter.size(); i++) 456 G4double vz; << 903 { 457 std::istringstream is(st); << 904 pname = parameter[i]-> GetParameterName(); 458 is >> vx >> vy >> vz; << 905 if( pname == nam ) return 1; 459 return G4ThreeVector(vx, vy, vz); << 906 } >> 907 return 0; 460 } 908 } 461 909 462 // ------------------------------------------- << 910 463 G4ThreeVector G4UIcommand::ConvertToDimensione << 911 // --------------------- utility functions -------------------------- 464 { << 912 465 G4double vx; << 913 tokenNum G4UIcommand:: 466 G4double vy; << 914 Yylex() // reads input and returns token number, KR486 467 G4double vz; << 915 { // (returns EOF) 468 char unts[30]; << 916 G4int c; 469 std::istringstream is(st); << 917 G4String buf; 470 is >> vx >> vy >> vz >> unts; << 918 471 G4String unt = unts; << 919 while(( c= G4UIpGetc())==' '|| c=='\t' || c== '\n' ) 472 G4double uv = ValueOf(unt); << 920 ; 473 return G4ThreeVector(vx * uv, vy * uv, vz * << 921 if (c== EOF) >> 922 return (tokenNum)EOF; // KR488 >> 923 buf= ""; >> 924 if (isdigit(c) || c== '.') { // I or D >> 925 do { >> 926 buf += G4String((unsigned char)c); >> 927 c=G4UIpGetc(); >> 928 } while (c=='.' || isdigit(c) || >> 929 c=='e' || c=='E' || c=='+' || c=='-'); >> 930 G4UIpUngetc(c); >> 931 const char* t = buf; >> 932 G4std::istrstream is((char*)t); >> 933 if ( IsInt(buf.data(),20) ) { >> 934 is >> yylval.I; >> 935 return CONSTINT; >> 936 } else >> 937 if ( IsDouble(buf.data()) ) { >> 938 is >> yylval.D; >> 939 return CONSTDOUBLE; >> 940 } else { >> 941 G4cerr << buf<<": numeric format error."<<G4endl; >> 942 } >> 943 } >> 944 buf=""; >> 945 if (isalpha(c)|| c=='_') { // IDENTIFIER >> 946 do { >> 947 buf += G4String((unsigned char)c); >> 948 } while ((c=G4UIpGetc()) != EOF && (isalnum(c) || c=='_')); >> 949 G4UIpUngetc(c); >> 950 if( IsParameter(buf) ) { >> 951 yylval.S =buf; >> 952 return IDENTIFIER; >> 953 } else { >> 954 G4cerr << buf << " is not a parameter name."<< G4endl; >> 955 paramERR = 1; >> 956 } >> 957 } >> 958 switch (c) { >> 959 case '>': return (tokenNum) Follow('=', GE, GT); >> 960 case '<': return (tokenNum) Follow('=', LE, LT); >> 961 case '=': return (tokenNum) Follow('=', EQ, '='); >> 962 case '!': return (tokenNum) Follow('=', NE, '!'); >> 963 case '|': return (tokenNum) Follow('|', LOGICALOR, '|'); >> 964 case '&': return (tokenNum) Follow('&', LOGICALAND, '&'); >> 965 default: >> 966 return (tokenNum) c; >> 967 } 474 } 968 } 475 969 476 G4int G4UIcommand::CheckNewValue(const char* n << 970 >> 971 G4int G4UIcommand:: >> 972 Follow(G4int expect, G4int ifyes, G4int ifno) 477 { 973 { 478 if (!G4UIparsing::RangeCheck(*this, newValue << 974 G4int c = G4UIpGetc(); 479 return fParameterOutOfRange; << 975 if ( c== expect) 480 } << 976 return ifyes; 481 return 0; // succeeded << 977 G4UIpUngetc(c); >> 978 return ifno; >> 979 } >> 980 >> 981 //------------------ low level routines ----------------------------- >> 982 G4int G4UIcommand:: >> 983 G4UIpGetc() { // emulation of getc() >> 984 G4int length = rangeString.length(); >> 985 if( bp < length) >> 986 return rangeString(bp++); >> 987 else >> 988 return EOF; >> 989 } >> 990 G4int G4UIcommand:: >> 991 G4UIpUngetc(G4int c) { // emulation of ungetc() >> 992 if (c<0) return -1; >> 993 if (bp >0 && c == rangeString(bp-1)) { >> 994 --bp; >> 995 } else { >> 996 G4cerr << "G4UIpUngetc() failed." << G4endl; >> 997 G4cerr << "bp="<<bp <<" c="<<c >> 998 << " pR(bp-1)=" << rangeString(bp-1) >> 999 << G4endl; >> 1000 paramERR = 1; >> 1001 return -1; >> 1002 } >> 1003 return 0; 482 } 1004 } 483 1005