Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/intercoms/src/G4UIcommand.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /intercoms/src/G4UIcommand.cc (Version 11.3.0) and /intercoms/src/G4UIcommand.cc (Version 7.0.p1)


  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.23 2004/05/16 18:42:30 asaim Exp $
 29 // ------------------------------------------- <<  25 // GEANT4 tag $Name: geant4-07-00-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(std::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 += " ";                            << 315   }
314     nameList += uDef->GetName();               << 316   for(G4int k=0;k<je;k++)
315     nameList += " ";                           << 317   {
                                                   >> 318     retStr += " ";
                                                   >> 319     retStr += UCnt[k]->GetName();
316   }                                               320   }
317   symList += nameList;                         << 321   return retStr;
318   G4StrUtil::rstrip(symList);                  << 
319   return symList;                              << 
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 // ------------------------------------------- << 
350 G4String G4UIcommand::ConvertToString(G4bool b    345 G4String G4UIcommand::ConvertToString(G4bool boolVal)
351 {                                                 346 {
352   return boolVal ? "1" : "0";                  << 347   G4String vl = "0";
                                                   >> 348   if(boolVal) vl = "1";
                                                   >> 349   return vl;
353 }                                                 350 }
354                                                   351 
355 // ------------------------------------------- << 
356 G4String G4UIcommand::ConvertToString(G4int in    352 G4String G4UIcommand::ConvertToString(G4int intValue)
357 {                                                 353 {
358   return G4UIparsing::TtoS(intValue);          << 354   char st[20];
359 }                                              << 355   std::ostrstream os(st,20);
360                                                << 356   os << intValue << '\0';
361 // ------------------------------------------- << 357   G4String vl = st;
362 G4String G4UIcommand::ConvertToString(G4long l << 358   return vl;
363 {                                              << 
364   return G4UIparsing::TtoS(longValue);         << 
365 }                                                 359 }
366                                                   360 
367 // ------------------------------------------- << 
368 G4String G4UIcommand::ConvertToString(G4double    361 G4String G4UIcommand::ConvertToString(G4double doubleValue)
369 {                                                 362 {
370   std::ostringstream os;                       << 363   char st[40];
371   if (G4UImanager::DoublePrecisionStr()) {     << 364   std::ostrstream os(st,40);
372     os << std::setprecision(17);               << 365   os << doubleValue << '\0';
373   }                                            << 366   G4String vl = st;
374   os << doubleValue;                           << 367   return vl;
375   return os.str();                             << 
376 }                                                 368 }
377                                                   369 
378 // ------------------------------------------- << 370 G4String G4UIcommand::ConvertToString(G4double doubleValue,const char* unitName)
379 G4String G4UIcommand::ConvertToString(G4double << 
380 {                                                 371 {
381   std::ostringstream os;                       << 372   G4String unt = unitName;
382   if (G4UImanager::DoublePrecisionStr()) {     << 373   G4double uv = ValueOf(unitName);
383     os << std::setprecision(17);               << 374 
384   }                                            << 375   char st[60];
385   os << doubleValue / ValueOf(unitName) << " " << 376   std::ostrstream os(st,60);
386   return os.str();                             << 377   os << doubleValue/uv << " " << unitName << '\0';
                                                   >> 378   G4String vl = st;
                                                   >> 379   return vl;
387 }                                                 380 }
388                                                   381 
389 // ------------------------------------------- << 382 G4String G4UIcommand::ConvertToString(G4ThreeVector vec)
390 G4String G4UIcommand::ConvertToString(const G4 << 
391 {                                                 383 {
392   std::ostringstream os;                       << 384   char st[100];
393   if (G4UImanager::DoublePrecisionStr()) {     << 385   std::ostrstream os(st,100);
394     os << std::setprecision(17);               << 386   os << vec.x() << " " << vec.y() << " " << vec.z() << '\0';
395   }                                            << 387   G4String vl = st;
396   os << vec.x() << " " << vec.y() << " " << ve << 388   return vl;
397   return os.str();                             << 
398 }                                                 389 }
399                                                   390 
400 // ------------------------------------------- << 391 G4String G4UIcommand::ConvertToString(G4ThreeVector vec,const char* unitName)
401 G4String G4UIcommand::ConvertToString(const G4 << 
402 {                                                 392 {
                                                   >> 393   G4String unt = unitName;
403   G4double uv = ValueOf(unitName);                394   G4double uv = ValueOf(unitName);
404                                                   395 
405   std::ostringstream os;                       << 396   char st[120];
406   if (G4UImanager::DoublePrecisionStr()) {     << 397   std::ostrstream os(st,120);
407     os << std::setprecision(17);               << 398   os << vec.x()/uv << " " << vec.y()/uv << " " << vec.z()/uv
408   }                                            << 399      << " " << unitName << '\0';
409   os << vec.x() / uv << " " << vec.y() / uv << << 400   G4String vl = st;
410   return os.str();                             << 401   return vl;
411 }                                                 402 }
412                                                   403 
413 // ------------------------------------------- << 
414 G4bool G4UIcommand::ConvertToBool(const char*     404 G4bool G4UIcommand::ConvertToBool(const char* st)
415 {                                                 405 {
416   G4String v = G4StrUtil::to_upper_copy(st);   << 406   G4String v = st;
417   return (v == "Y" || v == "YES" || v == "1" | << 407   v.toUpper();
                                                   >> 408   G4bool vl = false;
                                                   >> 409   if( v=="Y" || v=="YES" || v=="1" || v=="T" || v=="TRUE" )
                                                   >> 410   { vl = true; }
                                                   >> 411   return vl;
418 }                                                 412 }
419                                                   413 
420 // ------------------------------------------- << 
421 G4int G4UIcommand::ConvertToInt(const char* st    414 G4int G4UIcommand::ConvertToInt(const char* st)
422 {                                                 415 {
423   return G4UIparsing::StoT<G4int>(st);         << 416   G4int vl;
                                                   >> 417   std::istrstream is((char*)st);
                                                   >> 418   is >> vl;
                                                   >> 419   return vl;
424 }                                                 420 }
425                                                   421 
426 // ------------------------------------------- << 
427 G4long G4UIcommand::ConvertToLongInt(const cha << 
428 {                                              << 
429   return G4UIparsing::StoT<G4long>(st);        << 
430 }                                              << 
431                                                << 
432 // ------------------------------------------- << 
433 G4double G4UIcommand::ConvertToDouble(const ch    422 G4double G4UIcommand::ConvertToDouble(const char* st)
434 {                                                 423 {
435   return G4UIparsing::StoT<G4double>(st);      << 424   G4double vl;
                                                   >> 425   std::istrstream is((char*)st);
                                                   >> 426   is >> vl;
                                                   >> 427   return vl;
436 }                                                 428 }
437                                                   429 
438 // ------------------------------------------- << 
439 G4double G4UIcommand::ConvertToDimensionedDoub    430 G4double G4UIcommand::ConvertToDimensionedDouble(const char* st)
440 {                                                 431 {
441   G4double vl;                                    432   G4double vl;
442   char unts[30];                                  433   char unts[30];
443                                                   434 
444   std::istringstream is(st);                   << 435   std::istrstream is((char*)st);
445   is >> vl >> unts;                               436   is >> vl >> unts;
446   G4String unt = unts;                            437   G4String unt = unts;
447                                                   438 
448   return (vl * ValueOf(unt));                  << 439   return (vl*ValueOf(unt));
449 }                                                 440 }
450                                                   441 
451 // ------------------------------------------- << 
452 G4ThreeVector G4UIcommand::ConvertTo3Vector(co    442 G4ThreeVector G4UIcommand::ConvertTo3Vector(const char* st)
453 {                                                 443 {
454   G4double vx;                                    444   G4double vx;
455   G4double vy;                                    445   G4double vy;
456   G4double vz;                                    446   G4double vz;
457   std::istringstream is(st);                   << 447   std::istrstream is((char*)st);
458   is >> vx >> vy >> vz;                           448   is >> vx >> vy >> vz;
459   return G4ThreeVector(vx, vy, vz);            << 449   return G4ThreeVector(vx,vy,vz);
460 }                                                 450 }
461                                                   451 
462 // ------------------------------------------- << 
463 G4ThreeVector G4UIcommand::ConvertToDimensione    452 G4ThreeVector G4UIcommand::ConvertToDimensioned3Vector(const char* st)
464 {                                                 453 {
465   G4double vx;                                    454   G4double vx;
466   G4double vy;                                    455   G4double vy;
467   G4double vz;                                    456   G4double vz;
468   char unts[30];                                  457   char unts[30];
469   std::istringstream is(st);                   << 458   std::istrstream is((char*)st);
470   is >> vx >> vy >> vz >> unts;                   459   is >> vx >> vy >> vz >> unts;
471   G4String unt = unts;                            460   G4String unt = unts;
472   G4double uv = ValueOf(unt);                     461   G4double uv = ValueOf(unt);
473   return G4ThreeVector(vx * uv, vy * uv, vz *  << 462   return G4ThreeVector(vx*uv,vy*uv,vz*uv);
474 }                                                 463 }
475                                                   464 
476 G4int G4UIcommand::CheckNewValue(const char* n << 465 
                                                   >> 466 // ----- the following is used by CheckNewValue()  ------------
                                                   >> 467 
                                                   >> 468 
                                                   >> 469 #include <ctype.h>          // isalpha(), toupper()
                                                   >> 470 #include <strstream>
                                                   >> 471 
                                                   >> 472 //#include "checkNewValue_debug.icc"
                                                   >> 473 //#define DEBUG 1
                                                   >> 474 
                                                   >> 475 G4int G4UIcommand::
                                                   >> 476 CheckNewValue(const char * newValue)
                                                   >> 477 {
                                                   >> 478    yystype result;
                                                   >> 479    // if( TypeCheck(newValue) == 0 ) return 1;
                                                   >> 480    if( ! rangeString.isNull() )
                                                   >> 481    { if( RangeCheck(newValue) == 0 ) return fParameterOutOfRange; }
                                                   >> 482    return 0;  // succeeded
                                                   >> 483 }
                                                   >> 484 
                                                   >> 485 // ------------------ type check routines -------------------
                                                   >> 486 
                                                   >> 487 G4int G4UIcommand::
                                                   >> 488 TypeCheck(const char * t)
                                                   >> 489 {
                                                   >> 490     G4String aNewValue;
                                                   >> 491     char type;
                                                   >> 492     std::istrstream is((char*)t);
                                                   >> 493     for (unsigned i=0; i< parameter.size(); i++) {
                                                   >> 494         is >> aNewValue;
                                                   >> 495         type = toupper(parameter[i]->GetParameterType());
                                                   >> 496         switch ( type ) {
                                                   >> 497             case 'D':
                                                   >> 498                 if( IsDouble(aNewValue)==0 ){
                                                   >> 499                     G4cerr << aNewValue << ": double value expected."
                                                   >> 500                          << G4endl;
                                                   >> 501                     return 0;
                                                   >> 502                 } break;
                                                   >> 503             case 'I':
                                                   >> 504                 if( IsInt(aNewValue,20)==0 ){
                                                   >> 505                     G4cerr <<aNewValue<<": integer expected."
                                                   >> 506                          <<G4endl;
                                                   >> 507                      return 0;
                                                   >> 508                 } break;
                                                   >> 509             case 'S':
                                                   >> 510                 break;
                                                   >> 511             case 'B':
                                                   >> 512                 aNewValue.toUpper(); 
                                                   >> 513                 if (aNewValue == "Y"   || aNewValue == "N"
                                                   >> 514                   ||aNewValue == "YES" || aNewValue == "NO"
                                                   >> 515                   ||aNewValue == "1"   || aNewValue == "0"
                                                   >> 516                   ||aNewValue == "T"   || aNewValue == "F"
                                                   >> 517                   ||aNewValue == "TRUE" || aNewValue == "FALSE")
                                                   >> 518                 return 1;
                                                   >> 519                 else return 0; 
                                                   >> 520                 break;
                                                   >> 521             default:  ;
                                                   >> 522         }
                                                   >> 523     }
                                                   >> 524     return 1;
                                                   >> 525 }
                                                   >> 526 
                                                   >> 527 
                                                   >> 528 G4int G4UIcommand::
                                                   >> 529 IsInt(const char* buf, short maxDigits)
477 {                                                 530 {
478   if (!G4UIparsing::RangeCheck(*this, newValue << 531     const char* p= buf;
479     return fParameterOutOfRange;               << 532     G4int length=0;
480   }                                            << 533     if( *p == '+' || *p == '-') { ++p; }
481   return 0;  // succeeded                      << 534     if( isdigit( (G4int)(*p) )) {
                                                   >> 535         while( isdigit( (G4int)(*p) )) { ++p;  ++length; }
                                                   >> 536         if( *p == '\0' ) {
                                                   >> 537             if( length > maxDigits) {
                                                   >> 538                 G4cerr <<"digit length exceeds"<<G4endl;
                                                   >> 539                 return 0;
                                                   >> 540             }
                                                   >> 541             return 1;
                                                   >> 542         } else {
                                                   >> 543             // G4cerr <<"illegal character after int:"<<buf<<G4endl;
                                                   >> 544         }
                                                   >> 545     } else {
                                                   >> 546         // G4cerr <<"illegal int:"<<buf<<G4endl;
                                                   >> 547     }
                                                   >> 548     return 0;
                                                   >> 549 }
                                                   >> 550 
                                                   >> 551 
                                                   >> 552 G4int G4UIcommand::
                                                   >> 553 ExpectExponent(const char* str)   // used only by IsDouble()
                                                   >> 554 {
                                                   >> 555     G4int maxExplength;
                                                   >> 556     if( IsInt( str, maxExplength=7 )) return 1;
                                                   >> 557     else return 0;
                                                   >> 558 }
                                                   >> 559 
                                                   >> 560 
                                                   >> 561 G4int G4UIcommand::
                                                   >> 562 IsDouble(const char* buf)
                                                   >> 563 {
                                                   >> 564     const char* p= buf;
                                                   >> 565     switch( *p) {
                                                   >> 566         case '+':  case '-': ++p;
                                                   >> 567             if( isdigit(*p) ) {
                                                   >> 568                  while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 569                  switch ( *p ) {
                                                   >> 570                      case '\0':    return 1;
                                                   >> 571             // break;
                                                   >> 572                      case 'E':  case 'e':
                                                   >> 573                          return ExpectExponent(++p );
                                                   >> 574       // break;
                                                   >> 575                      case '.':  ++p;
                                                   >> 576                          if( *p == '\0' )  return 1;
                                                   >> 577                          if( *p == 'e' || *p =='E' ) return ExpectExponent(++p );
                                                   >> 578                          if( isdigit(*p) ) {
                                                   >> 579                              while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 580                              if( *p == '\0' )  return 1;
                                                   >> 581                              if( *p == 'e' || *p =='E') return ExpectExponent(++p);
                                                   >> 582                          } else return 0;   break;
                                                   >> 583                      default: return 0;
                                                   >> 584                  }
                                                   >> 585             }
                                                   >> 586             if( *p == '.' ) { ++p;
                                                   >> 587                  if( isdigit(*p) ) {
                                                   >> 588                      while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 589                      if( *p == '\0' )  return 1;
                                                   >> 590                      if( *p == 'e' || *p =='E')  return ExpectExponent(++p);
                                                   >> 591                  }
                                                   >> 592             }
                                                   >> 593             break;
                                                   >> 594         case '.':  ++p;
                                                   >> 595             if( isdigit(*p) ) {
                                                   >> 596                  while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 597                  if( *p == '\0' )  return 1;
                                                   >> 598                  if( *p == 'e' || *p =='E' )  return ExpectExponent(++p);
                                                   >> 599             }    break;
                                                   >> 600         default: // digit is expected
                                                   >> 601             if( isdigit(*p) ) {
                                                   >> 602                  while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 603                  if( *p == '\0' )  return 1;
                                                   >> 604                  if( *p == 'e' || *p =='E')  return ExpectExponent(++p);
                                                   >> 605                  if( *p == '.' ) { ++p;
                                                   >> 606                       if( *p == '\0' )  return 1;
                                                   >> 607                       if( *p == 'e' || *p =='E')  return ExpectExponent(++p);
                                                   >> 608                       if( isdigit(*p) ) {
                                                   >> 609                           while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 610                           if( *p == '\0' )  return 1;
                                                   >> 611                           if( *p == 'e' || *p =='E') return ExpectExponent(++p);
                                                   >> 612                       }
                                                   >> 613                  }
                                                   >> 614             }
                                                   >> 615      }
                                                   >> 616      return 0;
                                                   >> 617 }
                                                   >> 618 
                                                   >> 619 
                                                   >> 620 // ------------------ range Check routines -------------------
                                                   >> 621 G4int G4UIcommand::
                                                   >> 622 RangeCheck(const char* t) {
                                                   >> 623     yystype result;
                                                   >> 624     char type;
                                                   >> 625     bp = 0;                 // reset buffer pointer for G4UIpGetc()
                                                   >> 626     std::istrstream is((char*)t);
                                                   >> 627     for (unsigned i=0; i< parameter.size(); i++) {
                                                   >> 628         type= toupper(parameter[i]->GetParameterType());
                                                   >> 629         switch ( type ) {
                                                   >> 630             case 'D':  is >> newVal[i].D;  break;
                                                   >> 631             case 'I':  is >> newVal[i].I;  break;
                                                   >> 632             case 'S':
                                                   >> 633             case 'B':
                                                   >> 634             default:  ;
                                                   >> 635         }
                                                   >> 636    }
                                                   >> 637    // PrintToken();          // Print tokens (consumes all tokens)
                                                   >> 638    token= Yylex();
                                                   >> 639    result = Expression();
                                                   >> 640 
                                                   >> 641    if( paramERR == 1 ) return 0;
                                                   >> 642    if( result.type != CONSTINT) {
                                                   >> 643       G4cerr << "Illegal Expression in parameter range." << G4endl;
                                                   >> 644       return 0;
                                                   >> 645    }
                                                   >> 646    if ( result.I ) return 1;
                                                   >> 647    G4cerr << "parameter out of range: "<< rangeString << G4endl;
                                                   >> 648    return 0;
                                                   >> 649 }
                                                   >> 650 
                                                   >> 651 // ------------------ syntax node functions  ------------------
                                                   >> 652 yystype G4UIcommand:: 
                                                   >> 653 Expression(void)
                                                   >> 654 {
                                                   >> 655     yystype result;
                                                   >> 656     #ifdef DEBUG
                                                   >> 657         G4cerr << " Expression()" << G4endl;
                                                   >> 658     #endif
                                                   >> 659     result = LogicalORExpression();
                                                   >> 660     return result;
                                                   >> 661 }
                                                   >> 662 
                                                   >> 663 yystype G4UIcommand:: 
                                                   >> 664 LogicalORExpression(void)
                                                   >> 665 {
                                                   >> 666     yystype result;
                                                   >> 667     yystype p;
                                                   >> 668     p = LogicalANDExpression();
                                                   >> 669     if( token != LOGICALOR)  return p;
                                                   >> 670     if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
                                                   >> 671         G4cerr << "Parameter range: illegal type at '||'" << G4endl;
                                                   >> 672         paramERR = 1;
                                                   >> 673     }
                                                   >> 674     result.I = p.I;
                                                   >> 675     while (token == LOGICALOR) 
                                                   >> 676     {  
                                                   >> 677         token = Yylex();
                                                   >> 678         p = LogicalANDExpression();
                                                   >> 679         if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
                                                   >> 680             G4cerr << "Parameter range: illegal type at '||'" <<G4endl;
                                                   >> 681             paramERR = 1;
                                                   >> 682         }
                                                   >> 683         switch (p.type) {
                                                   >> 684             case CONSTINT: 
                                                   >> 685                 result.I  += p.I; 
                                                   >> 686                 result.type = CONSTINT;      break;
                                                   >> 687             case CONSTDOUBLE:
                                                   >> 688                 result.I += (p.D != 0.0); 
                                                   >> 689                 result.type = CONSTINT;      break;
                                                   >> 690             default: 
                                                   >> 691                 G4cerr << "Parameter range: unknown type"<<G4endl; 
                                                   >> 692                 paramERR = 1;
                                                   >> 693         } 
                                                   >> 694     }
                                                   >> 695     return result;
                                                   >> 696 }
                                                   >> 697 
                                                   >> 698 yystype G4UIcommand:: 
                                                   >> 699 LogicalANDExpression(void)
                                                   >> 700 {
                                                   >> 701     yystype result;
                                                   >> 702     yystype p;
                                                   >> 703     p = EqualityExpression();
                                                   >> 704     if( token != LOGICALAND)  return p;
                                                   >> 705     if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
                                                   >> 706         G4cerr << "Parameter range: illegal type at '&&'" << G4endl;
                                                   >> 707         paramERR = 1;
                                                   >> 708     }
                                                   >> 709     result.I = p.I;
                                                   >> 710     while (token == LOGICALAND)
                                                   >> 711     {
                                                   >> 712         token = Yylex();
                                                   >> 713         p = EqualityExpression();
                                                   >> 714         if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
                                                   >> 715             G4cerr << "Parameter range: illegal type at '&&'" << G4endl;
                                                   >> 716             paramERR = 1;
                                                   >> 717         }
                                                   >> 718         switch (p.type) {
                                                   >> 719             case CONSTINT:
                                                   >> 720                 result.I  *= p.I;
                                                   >> 721                 result.type = CONSTINT;      break;
                                                   >> 722             case CONSTDOUBLE:
                                                   >> 723                 result.I *= (p.D != 0.0);
                                                   >> 724                 result.type = CONSTINT;      break;
                                                   >> 725             default:
                                                   >> 726                 G4cerr << "Parameter range: unknown type."<< G4endl;
                                                   >> 727                 paramERR = 1;
                                                   >> 728         } 
                                                   >> 729     }
                                                   >> 730     return result;
                                                   >> 731 }
                                                   >> 732 
                                                   >> 733 
                                                   >> 734 yystype G4UIcommand:: 
                                                   >> 735 EqualityExpression(void)
                                                   >> 736 { 
                                                   >> 737     yystype  arg1, arg2;
                                                   >> 738     G4int operat;
                                                   >> 739     yystype result;
                                                   >> 740     #ifdef DEBUG
                                                   >> 741         G4cerr << " EqualityExpression()" <<G4endl;
                                                   >> 742     #endif
                                                   >> 743     result = RelationalExpression();
                                                   >> 744     if( token==EQ || token==NE ) {
                                                   >> 745         operat = token;
                                                   >> 746         token =  Yylex();
                                                   >> 747         arg1 = result;
                                                   >> 748         arg2 = RelationalExpression();
                                                   >> 749         result.I = Eval2( arg1, operat, arg2 );   // semantic action
                                                   >> 750         result.type = CONSTINT;
                                                   >> 751         #ifdef DEBUG
                                                   >> 752             G4cerr << " return code of Eval2(): " << result.I <<G4endl;
                                                   >> 753         #endif
                                                   >> 754     } else {
                                                   >> 755         if (result.type != CONSTINT && result.type != CONSTDOUBLE) {  
                                                   >> 756             G4cerr << "Parameter range: error at EqualityExpression"
                                                   >> 757                  << G4endl;
                                                   >> 758             paramERR = 1;
                                                   >> 759         }
                                                   >> 760     }
                                                   >> 761     return  result;
                                                   >> 762 }
                                                   >> 763 
                                                   >> 764 
                                                   >> 765 yystype G4UIcommand:: 
                                                   >> 766 RelationalExpression(void)
                                                   >> 767 { 
                                                   >> 768     yystype  arg1, arg2;
                                                   >> 769     G4int operat;
                                                   >> 770     yystype result;
                                                   >> 771     #ifdef DEBUG
                                                   >> 772         G4cerr << " RelationalExpression()" <<G4endl;
                                                   >> 773     #endif
                                                   >> 774 
                                                   >> 775     arg1 = AdditiveExpression();
                                                   >> 776     if( token==GT || token==GE || token==LT || token==LE  ) {
                                                   >> 777         operat = token;
                                                   >> 778         token =  Yylex();
                                                   >> 779         arg2 = AdditiveExpression();
                                                   >> 780         result.I = Eval2( arg1, operat, arg2 );    // semantic action
                                                   >> 781         result.type = CONSTINT;
                                                   >> 782         #ifdef DEBUG
                                                   >> 783             G4cerr << " return code of Eval2(): " << result.I << G4endl;
                                                   >> 784         #endif
                                                   >> 785     } else {
                                                   >> 786               result = arg1;
                                                   >> 787     }
                                                   >> 788     #ifdef DEBUG
                                                   >> 789        G4cerr <<" return RelationalExpression()"<< G4endl;
                                                   >> 790     #endif
                                                   >> 791     return  result;
                                                   >> 792 }
                                                   >> 793 
                                                   >> 794 yystype G4UIcommand::
                                                   >> 795 AdditiveExpression(void)
                                                   >> 796 {   yystype result;
                                                   >> 797     result = MultiplicativeExpression();
                                                   >> 798     if( token != '+' && token != '-' )  return result;
                                                   >> 799     G4cerr << "Parameter range: operator " 
                                                   >> 800          << (char)token 
                                                   >> 801          << " is not supported." << G4endl;
                                                   >> 802     paramERR = 1;
                                                   >> 803     return  result;
                                                   >> 804 }
                                                   >> 805 
                                                   >> 806 yystype G4UIcommand::
                                                   >> 807 MultiplicativeExpression(void)
                                                   >> 808 {   yystype result;
                                                   >> 809     result = UnaryExpression();
                                                   >> 810     if( token != '*' && token != '/' && token != '%' ) return result;
                                                   >> 811     G4cerr << "Parameter range: operator "
                                                   >> 812          << (char)token
                                                   >> 813          << " is not supported." << G4endl;
                                                   >> 814     paramERR = 1;
                                                   >> 815     return  result;
                                                   >> 816 }
                                                   >> 817 
                                                   >> 818 yystype G4UIcommand::
                                                   >> 819 UnaryExpression(void)
                                                   >> 820 {
                                                   >> 821     yystype result;
                                                   >> 822     yystype p;
                                                   >> 823     #ifdef DEBUG
                                                   >> 824         G4cerr <<" UnaryExpression"<< G4endl;
                                                   >> 825     #endif
                                                   >> 826     switch(token) {
                                                   >> 827         case '-':
                                                   >> 828             token = Yylex();
                                                   >> 829             p = UnaryExpression();
                                                   >> 830             if (p.type == CONSTINT) {
                                                   >> 831                 result.I = - p.I;
                                                   >> 832                 result.type = CONSTINT;
                                                   >> 833             }
                                                   >> 834             if (p.type == CONSTDOUBLE) {
                                                   >> 835                 result.D = - p.D;
                                                   >> 836                 result.type = CONSTDOUBLE;
                                                   >> 837             }                              break;
                                                   >> 838         case '+':
                                                   >> 839             token = Yylex();
                                                   >> 840             result = UnaryExpression();   break;
                                                   >> 841         case '!':
                                                   >> 842             token = Yylex();
                                                   >> 843             G4cerr << "Parameter range error: "
                                                   >> 844                  << "operator '!' is not supported (sorry)."
                                                   >> 845                  << G4endl;
                                                   >> 846             paramERR = 1;
                                                   >> 847             result = UnaryExpression();   break;
                                                   >> 848         default:
                                                   >> 849             result = PrimaryExpression();
                                                   >> 850     }
                                                   >> 851     return result;
                                                   >> 852 }
                                                   >> 853 
                                                   >> 854 
                                                   >> 855 yystype G4UIcommand:: 
                                                   >> 856 PrimaryExpression(void)
                                                   >> 857 {
                                                   >> 858      yystype result;
                                                   >> 859      #ifdef DEBUG
                                                   >> 860          G4cerr <<" primary_exp"<<G4endl;
                                                   >> 861      #endif
                                                   >> 862      switch (token) {
                                                   >> 863          case IDENTIFIER:
                                                   >> 864               result.S = yylval.S;
                                                   >> 865               result.type =  token;
                                                   >> 866               token = Yylex();           break;
                                                   >> 867          case CONSTINT:
                                                   >> 868               result.I = yylval.I;
                                                   >> 869               result.type =  token;
                                                   >> 870               token= Yylex();            break;
                                                   >> 871          case CONSTDOUBLE:
                                                   >> 872               result.D = yylval.D;
                                                   >> 873               result.type =  token;
                                                   >> 874               token = Yylex();           break;
                                                   >> 875          case '(' :
                                                   >> 876               token= Yylex();
                                                   >> 877               result = Expression();
                                                   >> 878               if( token !=  ')'  ) {
                                                   >> 879                   G4cerr << " ')' expected" << G4endl;
                                                   >> 880                   paramERR = 1;
                                                   >> 881               }
                                                   >> 882               token = Yylex();
                                                   >> 883                                          break;
                                                   >> 884          default:
                                                   >> 885          return result;
                                                   >> 886     }
                                                   >> 887     return result; // never executed
                                                   >> 888 }
                                                   >> 889 
                                                   >> 890 //---------------- semantic routines ---------------------------------
                                                   >> 891 
                                                   >> 892 G4int G4UIcommand::
                                                   >> 893 Eval2(yystype arg1, G4int op, yystype arg2)
                                                   >> 894 {
                                                   >> 895     char newValtype;
                                                   >> 896     if( (arg1.type != IDENTIFIER) && (arg2.type != IDENTIFIER)) {
                                                   >> 897         G4cerr << commandName
                                                   >> 898              << ": meaningless comparison"
                                                   >> 899              << G4endl;
                                                   >> 900         paramERR = 1;
                                                   >> 901     }
                                                   >> 902 
                                                   >> 903     if( arg1.type == IDENTIFIER) {
                                                   >> 904         unsigned i = IndexOf( arg1.S );
                                                   >> 905         newValtype = toupper(parameter[i]->GetParameterType());
                                                   >> 906         switch ( newValtype ) {
                                                   >> 907             case 'I': 
                                                   >> 908                 if( arg2.type == CONSTINT ) {
                                                   >> 909                     return CompareInt( newVal[i].I, op, arg2.I );
                                                   >> 910                 } else {
                                                   >> 911                     G4cerr << "integer operand expected for "
                                                   >> 912                          <<  rangeString 
                                                   >> 913                          << '.' << G4endl;
                                                   >> 914                 } break;
                                                   >> 915             case 'D':
                                                   >> 916                 if( arg2.type == CONSTDOUBLE ) {
                                                   >> 917                     return CompareDouble( newVal[i].D, op, arg2.D );
                                                   >> 918                 } else
                                                   >> 919                 if ( arg2.type == CONSTINT ) {  // integral promotion
                                                   >> 920                     return CompareDouble( newVal[i].D, op, arg2.I );
                                                   >> 921                 } break;
                                                   >> 922             default: ;
                                                   >> 923         }
                                                   >> 924     }
                                                   >> 925     if( arg2.type == IDENTIFIER) {
                                                   >> 926         unsigned i = IndexOf( arg2.S );
                                                   >> 927         newValtype = toupper(parameter[i]->GetParameterType());
                                                   >> 928         switch ( newValtype ) {
                                                   >> 929             case 'I': 
                                                   >> 930                 if( arg1.type == CONSTINT ) {
                                                   >> 931                     return CompareInt( arg1.I, op, newVal[i].I );
                                                   >> 932                 } else {
                                                   >> 933                     G4cerr << "integer operand expected for "
                                                   >> 934                          <<  rangeString
                                                   >> 935                          << '.' << G4endl;
                                                   >> 936                 } break;
                                                   >> 937             case 'D':
                                                   >> 938                 if( arg1.type == CONSTDOUBLE ) {
                                                   >> 939                     return CompareDouble( arg1.D, op, newVal[i].D );
                                                   >> 940                 } else
                                                   >> 941                 if ( arg1.type == CONSTINT ) {  // integral promotion
                                                   >> 942                     return CompareDouble( arg1.I, op, newVal[i].D );
                                                   >> 943                 } break;
                                                   >> 944             default: ;
                                                   >> 945         }
                                                   >> 946     }
                                                   >> 947     return 0;
                                                   >> 948 }
                                                   >> 949 
                                                   >> 950 G4int G4UIcommand::
                                                   >> 951 CompareInt(G4int arg1, G4int op, G4int arg2)
                                                   >> 952 {   
                                                   >> 953     G4int result=-1;
                                                   >> 954     G4String opr;
                                                   >> 955     switch (op) {
                                                   >> 956        case GT:  result = ( arg1 >  arg2); opr= ">" ;  break;
                                                   >> 957        case GE:  result = ( arg1 >= arg2); opr= ">=";  break;
                                                   >> 958        case LT:  result = ( arg1 <  arg2); opr= "<" ;  break;
                                                   >> 959        case LE:  result = ( arg1 <= arg2); opr= "<=";  break;
                                                   >> 960        case EQ:  result = ( arg1 == arg2); opr= "==";  break;
                                                   >> 961        case NE:  result = ( arg1 != arg2); opr= "!=";  break;
                                                   >> 962        default: 
                                                   >> 963            G4cerr << "Parameter range: error at CompareInt" << G4endl;
                                                   >> 964            paramERR = 1;
                                                   >> 965     }
                                                   >> 966     #ifdef DEBUG
                                                   >> 967         G4cerr << "CompareInt "
                                                   >> 968              << arg1 << " " << opr << arg2 
                                                   >> 969              << " result: " << result
                                                   >> 970              << G4endl;
                                                   >> 971     #endif
                                                   >> 972     return result;
                                                   >> 973 }
                                                   >> 974 
                                                   >> 975 G4int G4UIcommand::
                                                   >> 976 CompareDouble(G4double arg1, G4int op, G4double arg2)
                                                   >> 977 {   
                                                   >> 978     G4int result=-1;
                                                   >> 979     G4String opr;
                                                   >> 980     switch (op) {
                                                   >> 981         case GT:  result = ( arg1 >  arg2); opr= ">";   break;
                                                   >> 982         case GE:  result = ( arg1 >= arg2); opr= ">=";  break;
                                                   >> 983         case LT:  result = ( arg1 <  arg2); opr= "<";   break;
                                                   >> 984         case LE:  result = ( arg1 <= arg2); opr= "<=";  break;
                                                   >> 985         case EQ:  result = ( arg1 == arg2); opr= "==";  break;
                                                   >> 986         case NE:  result = ( arg1 != arg2); opr= "!=";  break;
                                                   >> 987         default:
                                                   >> 988            G4cerr << "Parameter range: error at CompareDouble"
                                                   >> 989                 << G4endl;
                                                   >> 990            paramERR = 1;
                                                   >> 991     }
                                                   >> 992     #ifdef DEBUG
                                                   >> 993         G4cerr << "CompareDouble " 
                                                   >> 994              << arg1 <<" " << opr << " "<< arg2
                                                   >> 995              << " result: " << result
                                                   >> 996              << G4endl;
                                                   >> 997     #endif
                                                   >> 998     return result;
                                                   >> 999 }
                                                   >> 1000 
                                                   >> 1001 unsigned G4UIcommand::
                                                   >> 1002 IndexOf(const char* nam)
                                                   >> 1003 {
                                                   >> 1004     unsigned i;
                                                   >> 1005     G4String pname;
                                                   >> 1006     for( i=0;  i<parameter.size(); i++)
                                                   >> 1007     {
                                                   >> 1008         pname = parameter[i]-> GetParameterName();
                                                   >> 1009         if( pname == nam ) {
                                                   >> 1010             return i;
                                                   >> 1011         }
                                                   >> 1012     }
                                                   >> 1013     paramERR = 1;
                                                   >> 1014     G4cerr << "parameter name:"<<nam<<" not found."<< G4endl;
                                                   >> 1015     return 0;
                                                   >> 1016 }
                                                   >> 1017 
                                                   >> 1018 
                                                   >> 1019 unsigned G4UIcommand::
                                                   >> 1020 IsParameter(const char* nam)
                                                   >> 1021 {
                                                   >> 1022     G4String pname;
                                                   >> 1023     for(unsigned i=0;  i<parameter.size(); i++)  
                                                   >> 1024     {
                                                   >> 1025         pname = parameter[i]-> GetParameterName();
                                                   >> 1026         if( pname == nam ) return 1;
                                                   >> 1027     }
                                                   >> 1028     return 0;
                                                   >> 1029 }
                                                   >> 1030 
                                                   >> 1031 
                                                   >> 1032 // --------------------- utility functions --------------------------
                                                   >> 1033 
                                                   >> 1034 tokenNum G4UIcommand::
                                                   >> 1035 Yylex()         // reads input and returns token number, KR486
                                                   >> 1036 {               // (returns EOF)
                                                   >> 1037     G4int c;             
                                                   >> 1038     G4String buf;
                                                   >> 1039 
                                                   >> 1040     while(( c= G4UIpGetc())==' '|| c=='\t' || c== '\n' )
                                                   >> 1041         ;
                                                   >> 1042     if (c== EOF)
                                                   >> 1043         return (tokenNum)EOF;            // KR488 
                                                   >> 1044     buf= "";
                                                   >> 1045     if (isdigit(c) || c== '.') {         // I or D
                                                   >> 1046         do {
                                                   >> 1047              buf += G4String((unsigned char)c);
                                                   >> 1048              c=G4UIpGetc();
                                                   >> 1049          }  while (c=='.' || isdigit(c) || 
                                                   >> 1050                    c=='e' || c=='E' || c=='+' || c=='-');
                                                   >> 1051          G4UIpUngetc(c);
                                                   >> 1052          const char* t = buf;
                                                   >> 1053    std::istrstream is((char*)t);
                                                   >> 1054          if ( IsInt(buf.data(),20) ) {
                                                   >> 1055              is >> yylval.I;
                                                   >> 1056              return  CONSTINT;
                                                   >> 1057          } else 
                                                   >> 1058          if ( IsDouble(buf.data()) ) {
                                                   >> 1059              is >> yylval.D;
                                                   >> 1060              return  CONSTDOUBLE;
                                                   >> 1061          } else {
                                                   >> 1062              G4cerr << buf<<": numeric format error."<<G4endl;
                                                   >> 1063          }
                                                   >> 1064     }
                                                   >> 1065     buf="";
                                                   >> 1066     if (isalpha(c)|| c=='_') {           // IDENTIFIER
                                                   >> 1067         do {
                                                   >> 1068             buf += G4String((unsigned char)c); 
                                                   >> 1069         } while ((c=G4UIpGetc()) != EOF && (isalnum(c) || c=='_'));
                                                   >> 1070         G4UIpUngetc(c);
                                                   >> 1071         if( IsParameter(buf) ) {
                                                   >> 1072             yylval.S =buf;
                                                   >> 1073             return IDENTIFIER;
                                                   >> 1074         } else {
                                                   >> 1075             G4cerr << buf << " is not a parameter name."<< G4endl;
                                                   >> 1076             paramERR = 1;
                                                   >> 1077        }
                                                   >> 1078     }
                                                   >> 1079     switch (c) {
                                                   >> 1080       case '>':   return (tokenNum) Follow('=', GE,        GT);
                                                   >> 1081       case '<':   return (tokenNum) Follow('=', LE,        LT);
                                                   >> 1082       case '=':   return (tokenNum) Follow('=', EQ,        '=');
                                                   >> 1083       case '!':   return (tokenNum) Follow('=', NE,        '!');
                                                   >> 1084       case '|':   return (tokenNum) Follow('|', LOGICALOR, '|');
                                                   >> 1085       case '&':   return (tokenNum) Follow('&', LOGICALAND, '&');
                                                   >> 1086       default:
                                                   >> 1087           return (tokenNum) c;
                                                   >> 1088     }
                                                   >> 1089 }
                                                   >> 1090 
                                                   >> 1091 
                                                   >> 1092 G4int G4UIcommand::
                                                   >> 1093 Follow(G4int expect, G4int ifyes, G4int ifno)
                                                   >> 1094 {
                                                   >> 1095     G4int c = G4UIpGetc();
                                                   >> 1096     if ( c== expect)
                                                   >> 1097           return ifyes;
                                                   >> 1098     G4UIpUngetc(c);
                                                   >> 1099     return ifno;
                                                   >> 1100 }
                                                   >> 1101 
                                                   >> 1102 //------------------ low level routines -----------------------------
                                                   >> 1103 G4int G4UIcommand::
                                                   >> 1104 G4UIpGetc() {                        // emulation of getc() 
                                                   >> 1105     G4int length = rangeString.length();
                                                   >> 1106     if( bp < length)
                                                   >> 1107         return  rangeString(bp++);
                                                   >> 1108     else 
                                                   >> 1109         return EOF;
                                                   >> 1110 }
                                                   >> 1111 G4int G4UIcommand::
                                                   >> 1112 G4UIpUngetc(G4int c) {                 // emulation of ungetc() 
                                                   >> 1113     if (c<0) return -1;
                                                   >> 1114     if (bp >0 && c == rangeString(bp-1)) {
                                                   >> 1115          --bp;
                                                   >> 1116     } else {
                                                   >> 1117          G4cerr << "G4UIpUngetc() failed." << G4endl;
                                                   >> 1118          G4cerr << "bp="<<bp <<" c="<<c
                                                   >> 1119               << " pR(bp-1)=" << rangeString(bp-1)
                                                   >> 1120               << G4endl;
                                                   >> 1121          paramERR = 1;
                                                   >> 1122          return -1;
                                                   >> 1123     }
                                                   >> 1124     return 0;
482 }                                                 1125 }
483                                                   1126