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 4.0)


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