Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/intercoms/src/G4UIparameter.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/G4UIparameter.cc (Version 11.3.0) and /intercoms/src/G4UIparameter.cc (Version 7.0.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 // G4UIparameter                               << 
 27 //                                                 23 //
 28 // Author: Makoto Asai, 1997                   <<  24 // $Id: G4UIparameter.cc,v 1.12 2003/06/16 16:55:47 gunter Exp $
 29 // ------------------------------------------- <<  25 // GEANT4 tag $Name: geant4-07-00-patch-01 $
                                                   >>  26 //
 30                                                    27 
 31 #include "G4UIparameter.hh"                        28 #include "G4UIparameter.hh"
                                                   >>  29 #include "G4UIcommandStatus.hh"
 32                                                    30 
 33 #include "G4Tokenizer.hh"                          31 #include "G4Tokenizer.hh"
 34 #include "G4UIcommand.hh"                      <<  32 
 35 #include "G4UIcommandStatus.hh"                << 
 36 #include "G4UIparsing.hh"                      << 
 37 #include "G4ios.hh"                                33 #include "G4ios.hh"
                                                   >>  34 G4UIparameter::G4UIparameter():paramERR(0)
                                                   >>  35 {
                                                   >>  36   G4String nullString;
                                                   >>  37   parameterName = nullString;
                                                   >>  38   parameterType = '\0';
                                                   >>  39   omittable = false;
                                                   >>  40   parameterGuidance = nullString;
                                                   >>  41   defaultValue = nullString;
                                                   >>  42   parameterRange = nullString;
                                                   >>  43   currentAsDefaultFlag = false;
                                                   >>  44   parameterCandidate = nullString;
                                                   >>  45   widget = 0;
                                                   >>  46 }
 38                                                    47 
 39 // ------------------------------------------- <<  48 G4UIparameter::G4UIparameter(char theType):paramERR(0)
 40 G4UIparameter::G4UIparameter(char theType)     << 
 41 {                                                  49 {
                                                   >>  50   G4String nullString;
                                                   >>  51   parameterName = nullString;
 42   parameterType = theType;                         52   parameterType = theType;
                                                   >>  53   omittable = false;
                                                   >>  54   parameterGuidance = nullString;
                                                   >>  55   defaultValue = nullString;
                                                   >>  56   parameterRange = nullString;
                                                   >>  57   currentAsDefaultFlag = false;
                                                   >>  58   parameterCandidate = nullString;
                                                   >>  59   widget = 0;
 43 }                                                  60 }
 44                                                    61 
 45 // ------------------------------------------- <<  62 G4UIparameter::G4UIparameter(const char * theName, char theType, G4bool theOmittable):paramERR(0)
 46 G4UIparameter::G4UIparameter(const char* theNa << 
 47 {                                                  63 {
 48   parameterName = theName;                         64   parameterName = theName;
 49   parameterType = theType;                         65   parameterType = theType;
 50   omittable = theOmittable;                        66   omittable = theOmittable;
                                                   >>  67   G4String nullString;
                                                   >>  68   parameterGuidance = nullString;
                                                   >>  69   defaultValue = nullString;
                                                   >>  70   parameterRange = nullString;
                                                   >>  71   currentAsDefaultFlag = false;
                                                   >>  72   parameterCandidate = nullString;
                                                   >>  73   widget = 0;
 51 }                                                  74 }
 52                                                    75 
 53 // ------------------------------------------- <<  76 G4UIparameter::~G4UIparameter()
 54 G4UIparameter::~G4UIparameter() = default;     <<  77 { }
                                                   >>  78 
                                                   >>  79 G4int G4UIparameter::operator==(const G4UIparameter &right) const
                                                   >>  80 {
                                                   >>  81   return ( this == &right );
                                                   >>  82 }
                                                   >>  83 
                                                   >>  84 G4int G4UIparameter::operator!=(const G4UIparameter &right) const
                                                   >>  85 {
                                                   >>  86   return ( this != &right );
                                                   >>  87 }
 55                                                    88 
 56 // ------------------------------------------- << 
 57 void G4UIparameter::List()                         89 void G4UIparameter::List()
 58 {                                                  90 {
 59   G4cout << G4endl << "Parameter : " << parame     91   G4cout << G4endl << "Parameter : " << parameterName << G4endl;
 60   if (!parameterGuidance.empty()) {            <<  92   if( ! parameterGuidance.isNull() )
 61     G4cout << parameterGuidance << G4endl;     <<  93   G4cout << parameterGuidance << G4endl ;
 62   }                                            << 
 63   G4cout << " Parameter type  : " << parameter     94   G4cout << " Parameter type  : " << parameterType << G4endl;
 64   if (omittable) {                             <<  95   if(omittable)
 65     G4cout << " Omittable       : True" << G4e <<  96   { G4cout << " Omittable       : True" << G4endl; }
 66   }                                            <<  97   else
 67   else {                                       <<  98   { G4cout << " Omittable       : False" << G4endl; }
 68     G4cout << " Omittable       : False" << G4 <<  99   if( currentAsDefaultFlag )
 69   }                                            << 100   { G4cout << " Default value   : taken from the current value" << G4endl; }
 70   if (currentAsDefaultFlag) {                  << 101   else if( ! defaultValue.isNull() )
 71     G4cout << " Default value   : taken from t << 102   { G4cout << " Default value   : " << defaultValue << G4endl; }
 72   }                                            << 103   if( ! parameterRange.isNull() )
 73   else if (!defaultValue.empty()) {            << 104   G4cout << " Parameter range : " << parameterRange << G4endl;
 74     G4cout << " Default value   : " << default << 105   if( ! parameterCandidate.isNull() )
 75   }                                            << 106   G4cout << " Candidates      : " << parameterCandidate << G4endl;
 76   if (!rangeExpression.empty()) {              << 
 77     G4cout << " Parameter range : " << rangeEx << 
 78   }                                            << 
 79   if (!parameterCandidate.empty()) {           << 
 80     G4cout << " Candidates      : " << paramet << 
 81   }                                            << 
 82 }                                                 107 }
 83                                                   108 
 84 // ------------------------------------------- << 
 85 void G4UIparameter::SetDefaultValue(G4int theD    109 void G4UIparameter::SetDefaultValue(G4int theDefaultValue)
 86 {                                                 110 {
 87   defaultValue = G4UIparsing::TtoS(theDefaultV << 111   char defVal[20];
                                                   >> 112   std::ostrstream os(defVal,20);
                                                   >> 113   os << theDefaultValue << '\0';
                                                   >> 114   defaultValue = defVal;
 88 }                                                 115 }
 89                                                   116 
 90 // ------------------------------------------- << 117 void G4UIparameter::SetDefaultValue(G4double theDefaultValue)
 91 void G4UIparameter::SetDefaultValue(G4long the << 
 92 {                                                 118 {
 93   defaultValue = G4UIparsing::TtoS(theDefaultV << 119   char defVal[20];
                                                   >> 120   std::ostrstream os(defVal,20);
                                                   >> 121   os << theDefaultValue << '\0';
                                                   >> 122   defaultValue = defVal;
 94 }                                                 123 }
 95                                                   124 
 96 // ------------------------------------------- << 125 
 97 void G4UIparameter::SetDefaultValue(G4double t << 126 // ---------- CheckNewValue() related routines -----------
                                                   >> 127 #include <ctype.h>
                                                   >> 128 #include "G4UItokenNum.hh"
                                                   >> 129 
                                                   >> 130 //#include "checkNewValue_debug.icc"
                                                   >> 131 //#define DEBUG 1
                                                   >> 132 
                                                   >> 133 G4int G4UIparameter::
                                                   >> 134 CheckNewValue(const char* newValue ) {
                                                   >> 135     if( TypeCheck(newValue) == 0) return fParameterUnreadable;
                                                   >> 136     if( ! parameterRange.isNull() )
                                                   >> 137     { if( RangeCheck(newValue) == 0 ) return fParameterOutOfRange; }
                                                   >> 138     if( ! parameterCandidate.isNull() )
                                                   >> 139     { if( CandidateCheck(newValue) == 0 ) return fParameterOutOfCandidates; }
                                                   >> 140     return 0;   // succeeded
                                                   >> 141 }
                                                   >> 142 
                                                   >> 143 G4int G4UIparameter::
                                                   >> 144 CandidateCheck(const char* newValue) {
                                                   >> 145     G4Tokenizer candidateTokenizer(parameterCandidate);
                                                   >> 146     G4String aToken;
                                                   >> 147     G4int iToken = 0;
                                                   >> 148     while( ! (aToken=candidateTokenizer()).isNull() )
                                                   >> 149     {
                                                   >> 150       iToken++;
                                                   >> 151       if(aToken==newValue) return iToken;
                                                   >> 152     } 
                                                   >> 153     G4cerr << "parameter value is not listed in the candidate List." << G4endl;
                                                   >> 154     return 0;
                                                   >> 155 }
                                                   >> 156 
                                                   >> 157 G4int G4UIparameter::
                                                   >> 158 RangeCheck(const char* newValue) {
                                                   >> 159     yystype result;
                                                   >> 160     bp = 0;                   // reset buffer pointer for G4UIpGetc()
                                                   >> 161     std::istrstream is((char*)newValue); 
                                                   >> 162     char type = toupper( parameterType );
                                                   >> 163     switch (type) {
                                                   >> 164         case 'D': { is >> newVal.D; } break;
                                                   >> 165         case 'I': { is >> newVal.I; } break;
                                                   >> 166         default:   ;
                                                   >> 167     }
                                                   >> 168    // PrintToken();          // Print tokens (consumes all tokens)
                                                   >> 169    token= Yylex();
                                                   >> 170    result = Expression();
                                                   >> 171    if( paramERR == 1 ) return 0;
                                                   >> 172    if( result.type != CONSTINT) {
                                                   >> 173       G4cerr << "Illegal Expression in parameter range." << G4endl;
                                                   >> 174       return 0;
                                                   >> 175    }
                                                   >> 176    if ( result.I ) return 1;
                                                   >> 177    G4cerr << "parameter out of range: "<< parameterRange << G4endl;
                                                   >> 178    return 0;
                                                   >> 179 }
                                                   >> 180 
                                                   >> 181 
                                                   >> 182 G4int G4UIparameter::
                                                   >> 183 TypeCheck(const char* newValue)
 98 {                                                 184 {
 99   defaultValue = G4UIparsing::TtoS(theDefaultV << 185     G4String newValueString(newValue);
                                                   >> 186     char type = toupper( parameterType );
                                                   >> 187     switch(type) {
                                                   >> 188         case 'D':
                                                   >> 189             if( IsDouble(newValueString.data())== 0) {
                                                   >> 190                 G4cerr<<newValue<<": double value expected."
                                                   >> 191                     << G4endl;
                                                   >> 192                 return 0;
                                                   >> 193              } break;
                                                   >> 194         case 'I':
                                                   >> 195             if( IsInt(newValueString.data(),20)== 0) {
                                                   >> 196                 G4cerr<<newValue<<": integer expected."
                                                   >> 197                     << G4endl;
                                                   >> 198                 return 0;
                                                   >> 199              } break;
                                                   >> 200         case 'S': break;
                                                   >> 201         case 'B':
                                                   >> 202              newValueString.toUpper();
                                                   >> 203              if (  newValueString == "Y" || newValueString == "N"
                                                   >> 204                   ||newValueString == "YES" || newValueString == "NO"
                                                   >> 205                   ||newValueString == "1"   || newValueString == "0"
                                                   >> 206                   ||newValueString == "T" || newValueString == "F"
                                                   >> 207                   ||newValueString == "TRUE" || newValueString == "FALSE") 
                                                   >> 208                   return 1;
                                                   >> 209              else {
                                                   >> 210                     G4cerr<<newValue<<": bool expected." << G4endl;
                                                   >> 211                     return 0; 
                                                   >> 212              } 
                                                   >> 213         default: ;
                                                   >> 214     }
                                                   >> 215     return 1;
100 }                                                 216 }
101                                                   217 
102 // ------------------------------------------- << 218 
103 void G4UIparameter::SetDefaultUnit(const char* << 219 G4int G4UIparameter::
                                                   >> 220 IsInt(const char* buf, short maxDigits)  // do not allow any std::ws
104 {                                                 221 {
105   char type = (char)std::toupper(parameterType << 222     const char* p= buf;
106   if (type != 'S') {                           << 223     G4int length=0;
107     G4ExceptionDescription ed;                 << 224     if( *p == '+' || *p == '-') { ++p; }
108     ed << "This method can be used only for a  << 225     if( isdigit( (G4int)(*p) )) {
109           "used to specify a unit.\n"          << 226         while( isdigit( (G4int)(*p) )) { ++p;  ++length; }
110        << "This parameter <" << parameterName  << 227         if( *p == '\0' ) {
111     switch (type) {                            << 228             if( length > maxDigits) {
112       case 'D':                                << 229                 G4cerr <<"digit length exceeds"<<G4endl;
113         ed << "double.";                       << 230                 return 0;
114         break;                                 << 231             }
115       case 'I':                                << 232             return 1;
116         ed << "integer.";                      << 233         } else {
117         break;                                 << 234             // G4cerr <<"illegal character after int:"<<buf<<G4endl;
118       case 'L':                                << 235         }
119         ed << "long int.";                     << 236     } else {
120         break;                                 << 237         // G4cerr <<"illegal int:"<<buf<<G4endl;
121       case 'B':                                << 238     }
122         ed << "bool.";                         << 239     return 0;
123         break;                                 << 240 }
                                                   >> 241 
                                                   >> 242 
                                                   >> 243 G4int G4UIparameter::
                                                   >> 244 ExpectExponent(const char* str)   // used only by IsDouble()
                                                   >> 245 {
                                                   >> 246     G4int maxExplength;
                                                   >> 247     if( IsInt( str, maxExplength=7 )) return 1;
                                                   >> 248     else return 0;
                                                   >> 249 }
                                                   >> 250 
                                                   >> 251 G4int G4UIparameter::
                                                   >> 252 IsDouble(const char* buf)  // see state diagram for this spec.
                                                   >> 253 {
                                                   >> 254     const char* p= buf;
                                                   >> 255     switch( *p) {
                                                   >> 256         case '+':  case '-': ++p;
                                                   >> 257             if( isdigit(*p) ) {
                                                   >> 258                  while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 259                  switch ( *p ) {
                                                   >> 260                      case '\0':    return 1;  //break;
                                                   >> 261                      case 'E':  case 'e':
                                                   >> 262                          return ExpectExponent(++p );  //break;
                                                   >> 263                      case '.':  ++p;
                                                   >> 264                          if( *p == '\0' )  return 1;
                                                   >> 265                          if( *p == 'e' || *p =='E' ) return ExpectExponent(++p );
                                                   >> 266                          if( isdigit(*p) ) {
                                                   >> 267                              while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 268                              if( *p == '\0' )  return 1;
                                                   >> 269                              if( *p == 'e' || *p =='E') return ExpectExponent(++p);
                                                   >> 270                          } else return 0;   break;
                                                   >> 271                      default: return 0;
                                                   >> 272                  }
                                                   >> 273             }
                                                   >> 274             if( *p == '.' ) { ++p;
                                                   >> 275                  if( isdigit(*p) ) {
                                                   >> 276                      while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 277                      if( *p == '\0' )  return 1;
                                                   >> 278                      if( *p == 'e' || *p =='E')  return ExpectExponent(++p);
                                                   >> 279                  }
                                                   >> 280             }
                                                   >> 281             break;
                                                   >> 282         case '.':  ++p;
                                                   >> 283             if( isdigit(*p) ) {
                                                   >> 284                  while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 285                  if( *p == '\0' )  return 1;
                                                   >> 286                  if( *p == 'e' || *p =='E' )  return ExpectExponent(++p);
                                                   >> 287             }    break;
                                                   >> 288         default: // digit is expected
                                                   >> 289             if( isdigit(*p) ) {
                                                   >> 290                  while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 291                  if( *p == '\0' )  return 1;
                                                   >> 292                  if( *p == 'e' || *p =='E')  return ExpectExponent(++p);
                                                   >> 293                  if( *p == '.' ) { ++p;
                                                   >> 294                       if( *p == '\0' )  return 1;
                                                   >> 295                       if( *p == 'e' || *p =='E')  return ExpectExponent(++p);
                                                   >> 296                       if( isdigit(*p) ) {
                                                   >> 297                           while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 298                           if( *p == '\0' )  return 1;
                                                   >> 299                           if( *p == 'e' || *p =='E') return ExpectExponent(++p);
                                                   >> 300                       }
                                                   >> 301                  }
                                                   >> 302             }
                                                   >> 303      }
                                                   >> 304      return 0;
                                                   >> 305 }
                                                   >> 306 
                                                   >> 307 
                                                   >> 308 // ------------------ syntax node functions  ------------------
                                                   >> 309 
                                                   >> 310 yystype G4UIparameter:: 
                                                   >> 311 Expression(void)
                                                   >> 312 {
                                                   >> 313     yystype result;
                                                   >> 314     #ifdef DEBUG
                                                   >> 315         G4cerr << " Expression()" << G4endl;
                                                   >> 316     #endif
                                                   >> 317     result = LogicalORExpression();
                                                   >> 318     return result;
                                                   >> 319 }
                                                   >> 320 
                                                   >> 321 yystype G4UIparameter:: 
                                                   >> 322 LogicalORExpression(void)
                                                   >> 323 {
                                                   >> 324     yystype result;
                                                   >> 325     yystype p;
                                                   >> 326     p = LogicalANDExpression();
                                                   >> 327     if( token != LOGICALOR)  return p;
                                                   >> 328     if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
                                                   >> 329         G4cerr << "Parameter range: illegal type at '||'" << G4endl;
                                                   >> 330         paramERR = 1;
                                                   >> 331     }
                                                   >> 332     result.I = p.I;
                                                   >> 333     while (token == LOGICALOR) 
                                                   >> 334     {  
                                                   >> 335         token = Yylex();
                                                   >> 336         p = LogicalANDExpression();
                                                   >> 337         if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
                                                   >> 338             G4cerr << "Parameter range: illegal type at '||'" <<G4endl;
                                                   >> 339             paramERR = 1;
                                                   >> 340         }
                                                   >> 341         switch (p.type) {
                                                   >> 342             case CONSTINT: 
                                                   >> 343                 result.I  += p.I; 
                                                   >> 344                 result.type = CONSTINT;      break;
                                                   >> 345             case CONSTDOUBLE:
                                                   >> 346                 result.I += (p.D != 0.0); 
                                                   >> 347                 result.type = CONSTINT;      break;
                                                   >> 348             default: 
                                                   >> 349                 G4cerr << "Parameter range: unknown type"<<G4endl; 
                                                   >> 350                 paramERR = 1;
                                                   >> 351         } 
                                                   >> 352     }
                                                   >> 353     return result;
                                                   >> 354 }
                                                   >> 355 
                                                   >> 356 yystype G4UIparameter:: 
                                                   >> 357 LogicalANDExpression(void)
                                                   >> 358 {
                                                   >> 359     yystype result;
                                                   >> 360     yystype p;
                                                   >> 361     p = EqualityExpression();
                                                   >> 362     if( token != LOGICALAND)  return p;
                                                   >> 363     if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
                                                   >> 364         G4cerr << "Parameter range: illegal type at '&&'" << G4endl;
                                                   >> 365         paramERR = 1;
                                                   >> 366     }
                                                   >> 367     result.I = p.I;
                                                   >> 368     while (token == LOGICALAND)
                                                   >> 369     {
                                                   >> 370         token = Yylex();
                                                   >> 371         p = EqualityExpression();
                                                   >> 372         if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
                                                   >> 373             G4cerr << "Parameter range: illegal type at '&&'" << G4endl;
                                                   >> 374             paramERR = 1;
                                                   >> 375         }
                                                   >> 376         switch (p.type) {
                                                   >> 377             case CONSTINT:
                                                   >> 378                 result.I  *= p.I;
                                                   >> 379                 result.type = CONSTINT;      break;
                                                   >> 380             case CONSTDOUBLE:
                                                   >> 381                 result.I *= (p.D != 0.0);
                                                   >> 382                 result.type = CONSTINT;      break;
                                                   >> 383             default:
                                                   >> 384                 G4cerr << "Parameter range: unknown type."<< G4endl;
                                                   >> 385                 paramERR = 1;
                                                   >> 386         } 
                                                   >> 387     }
                                                   >> 388     return result;
                                                   >> 389 }
                                                   >> 390 
                                                   >> 391 
                                                   >> 392 yystype G4UIparameter:: 
                                                   >> 393 EqualityExpression(void)
                                                   >> 394 { 
                                                   >> 395     yystype  arg1, arg2;
                                                   >> 396     G4int operat;
                                                   >> 397     yystype result;
                                                   >> 398     #ifdef DEBUG
                                                   >> 399         G4cerr << " EqualityExpression()" <<G4endl;
                                                   >> 400     #endif
                                                   >> 401     result = RelationalExpression();
                                                   >> 402     if( token==EQ || token==NE ) {
                                                   >> 403         operat = token;
                                                   >> 404         token =  Yylex();
                                                   >> 405         arg1 = result;
                                                   >> 406         arg2 = RelationalExpression();
                                                   >> 407         result.I = Eval2( arg1, operat, arg2 );   // semantic action
                                                   >> 408         result.type = CONSTINT;
                                                   >> 409         #ifdef DEBUG
                                                   >> 410             G4cerr << " return code of Eval2(): " << result.I <<G4endl;
                                                   >> 411         #endif
                                                   >> 412     } else {
                                                   >> 413         if (result.type != CONSTINT && result.type != CONSTDOUBLE) {  
                                                   >> 414             G4cerr << "Parameter range: error at EqualityExpression"
                                                   >> 415                  << G4endl;
                                                   >> 416             paramERR = 1;
                                                   >> 417         }
                                                   >> 418     }
                                                   >> 419     return  result;
                                                   >> 420 }
                                                   >> 421 
                                                   >> 422 
                                                   >> 423 yystype G4UIparameter:: 
                                                   >> 424 RelationalExpression(void)
                                                   >> 425 { 
                                                   >> 426     yystype  arg1, arg2;
                                                   >> 427     G4int operat;
                                                   >> 428     yystype result;
                                                   >> 429     #ifdef DEBUG
                                                   >> 430         G4cerr << " RelationalExpression()" <<G4endl;
                                                   >> 431     #endif
                                                   >> 432 
                                                   >> 433     arg1 = AdditiveExpression();
                                                   >> 434     if( token==GT || token==GE || token==LT || token==LE  ) {
                                                   >> 435         operat = token;
                                                   >> 436         token =  Yylex();
                                                   >> 437         arg2 = AdditiveExpression();
                                                   >> 438         result.I = Eval2( arg1, operat, arg2 );    // semantic action
                                                   >> 439         result.type = CONSTINT;
                                                   >> 440         #ifdef DEBUG
                                                   >> 441             G4cerr << " return  Eval2(): " << G4endl;
                                                   >> 442         #endif
                                                   >> 443     } else {
                                                   >> 444         result = arg1;
                                                   >> 445     }
                                                   >> 446     #ifdef DEBUG
                                                   >> 447        G4cerr <<" return RelationalExpression()" <<G4endl;
                                                   >> 448     #endif
                                                   >> 449     return  result;
                                                   >> 450 }
                                                   >> 451 
                                                   >> 452 yystype G4UIparameter::
                                                   >> 453 AdditiveExpression(void)
                                                   >> 454 {   yystype result;
                                                   >> 455     result = MultiplicativeExpression();
                                                   >> 456     if( token != '+' && token != '-' )  return result;
                                                   >> 457     G4cerr << "Parameter range: operator " 
                                                   >> 458          << (char)token 
                                                   >> 459          << " is not supported." << G4endl;
                                                   >> 460     paramERR = 1;
                                                   >> 461     return  result;
                                                   >> 462 }
                                                   >> 463 
                                                   >> 464 yystype G4UIparameter::
                                                   >> 465 MultiplicativeExpression(void)
                                                   >> 466 {   yystype result;
                                                   >> 467     result = UnaryExpression();
                                                   >> 468     if( token != '*' && token != '/' && token != '%' ) return result;
                                                   >> 469     G4cerr << "Parameter range: operator "
                                                   >> 470          << (char)token
                                                   >> 471          << " is not supported." << G4endl;
                                                   >> 472     paramERR = 1;
                                                   >> 473     return  result;
                                                   >> 474 }
                                                   >> 475 
                                                   >> 476 yystype G4UIparameter::
                                                   >> 477 UnaryExpression(void)
                                                   >> 478 {
                                                   >> 479     yystype result;
                                                   >> 480     yystype p;
                                                   >> 481     #ifdef DEBUG
                                                   >> 482         G4cerr <<" UnaryExpression"<< G4endl;
                                                   >> 483     #endif
                                                   >> 484     switch(token) {
                                                   >> 485         case '-':
                                                   >> 486             token = Yylex();
                                                   >> 487             p = UnaryExpression();
                                                   >> 488             if (p.type == CONSTINT) {
                                                   >> 489                 result.I = - p.I;
                                                   >> 490                 result.type = CONSTINT;
                                                   >> 491             }
                                                   >> 492             if (p.type == CONSTDOUBLE) {
                                                   >> 493                 result.D = - p.D;
                                                   >> 494                 result.type = CONSTDOUBLE;
                                                   >> 495             }                              break;
                                                   >> 496         case '+':
                                                   >> 497             token = Yylex();
                                                   >> 498             result = UnaryExpression();   break;
                                                   >> 499         case '!':
                                                   >> 500             token = Yylex();
                                                   >> 501             G4cerr << "Parameter range error: "
                                                   >> 502                  << "operator '!' is not supported (sorry)."
                                                   >> 503                  << G4endl;
                                                   >> 504             paramERR = 1;
                                                   >> 505             result = UnaryExpression();   break;
                                                   >> 506         default:
                                                   >> 507             result = PrimaryExpression();
                                                   >> 508     }
                                                   >> 509     return result;
                                                   >> 510 }
                                                   >> 511 
                                                   >> 512 
                                                   >> 513 yystype G4UIparameter:: 
                                                   >> 514 PrimaryExpression(void)
                                                   >> 515 {
                                                   >> 516      yystype result;
                                                   >> 517      #ifdef DEBUG
                                                   >> 518          G4cerr <<" PrimaryExpression" << G4endl;
                                                   >> 519      #endif
                                                   >> 520      switch (token) {
                                                   >> 521          case IDENTIFIER:
                                                   >> 522               result.S = yylval.S;
                                                   >> 523               result.type =  token;
                                                   >> 524               token = Yylex();           break;
                                                   >> 525          case CONSTINT:
                                                   >> 526               result.I = yylval.I;
                                                   >> 527               result.type =  token;
                                                   >> 528               token= Yylex();            break;
                                                   >> 529          case CONSTDOUBLE:
                                                   >> 530               result.D = yylval.D;
                                                   >> 531               result.type =  token;
                                                   >> 532               token = Yylex();           break;
                                                   >> 533          case '(' :
                                                   >> 534               token= Yylex();
                                                   >> 535               result = Expression();
                                                   >> 536               if( token !=  ')'  ) {
                                                   >> 537                   G4cerr << " ')' expected" << G4endl;
                                                   >> 538                   paramERR = 1;
                                                   >> 539               }
                                                   >> 540               token = Yylex();
                                                   >> 541                                          break;
                                                   >> 542          default:
                                                   >> 543          return result;
                                                   >> 544     }
                                                   >> 545     return result; // never executed
                                                   >> 546 }
                                                   >> 547 
                                                   >> 548 //---------------- semantic routines ---------------------------------
                                                   >> 549 
                                                   >> 550 G4int G4UIparameter::
                                                   >> 551 Eval2(yystype arg1, G4int op, yystype arg2)
                                                   >> 552 {
                                                   >> 553     if( (arg1.type != IDENTIFIER) && (arg2.type != IDENTIFIER)) {
                                                   >> 554         G4cerr << parameterName
                                                   >> 555              << ": meaningless comparison "
                                                   >> 556              << G4int(arg1.type) << " " << G4int(arg2.type) << G4endl;
                                                   >> 557         paramERR = 1;
                                                   >> 558     }
                                                   >> 559     char type = toupper( parameterType );
                                                   >> 560     if( arg1.type == IDENTIFIER) {
                                                   >> 561         switch (type) {
                                                   >> 562             case 'I':
                                                   >> 563                 if ( arg2.type == CONSTINT ) {
                                                   >> 564                     return CompareInt( newVal.I, op, arg2.I );
                                                   >> 565                 } else {
                                                   >> 566                     G4cerr << "integer operand expected for "
                                                   >> 567                          << parameterRange << '.' 
                                                   >> 568                          << G4endl; 
                                                   >> 569                 }
                                                   >> 570                  break;
                                                   >> 571             case 'D': 
                                                   >> 572                 if ( arg2.type == CONSTDOUBLE ) {
                                                   >> 573                     return CompareDouble( newVal.D, op, arg2.D );
                                                   >> 574                 } else
                                                   >> 575                 if ( arg2.type == CONSTINT ) { // integral promotion
                                                   >> 576                     return CompareDouble( newVal.D, op, arg2.I );
                                                   >> 577                 } break;
                                                   >> 578             default: ;
                                                   >> 579         }
                                                   >> 580     }
                                                   >> 581     if( arg2.type == IDENTIFIER) {
                                                   >> 582         switch (type) {
                                                   >> 583             case 'I':
                                                   >> 584                 if ( arg1.type == CONSTINT ) {
                                                   >> 585                     return CompareInt( arg1.I, op, newVal.I );
                                                   >> 586                 } else {
                                                   >> 587                     G4cerr << "integer operand expected for "
                                                   >> 588                          << parameterRange << '.' 
                                                   >> 589                          << G4endl; 
                                                   >> 590                 }
                                                   >> 591                  break;
                                                   >> 592             case 'D': 
                                                   >> 593                 if ( arg1.type == CONSTDOUBLE ) {
                                                   >> 594                     return CompareDouble( arg1.D, op, newVal.D );
                                                   >> 595                 } else
                                                   >> 596                 if ( arg1.type == CONSTINT ) { // integral promotion
                                                   >> 597                     return CompareDouble( arg1.I, op, newVal.D );
                                                   >> 598                 } break;
                                                   >> 599             default: ;
                                                   >> 600         }
                                                   >> 601     }
                                                   >> 602     G4cerr << "no param name is specified at the param range."<<G4endl;
                                                   >> 603     return 0;
                                                   >> 604 }
                                                   >> 605 
                                                   >> 606 G4int G4UIparameter::
                                                   >> 607 CompareInt(G4int arg1, G4int op, G4int arg2)
                                                   >> 608 {   
                                                   >> 609     G4int result=-1;
                                                   >> 610     G4String opr;
                                                   >> 611     switch (op) {
                                                   >> 612        case GT:  result = ( arg1 >  arg2); opr= ">" ;  break;
                                                   >> 613        case GE:  result = ( arg1 >= arg2); opr= ">=";  break;
                                                   >> 614        case LT:  result = ( arg1 <  arg2); opr= "<" ;  break;
                                                   >> 615        case LE:  result = ( arg1 <= arg2); opr= "<=";  break;
                                                   >> 616        case EQ:  result = ( arg1 == arg2); opr= "==";  break;
                                                   >> 617        case NE:  result = ( arg1 != arg2); opr= "!=";  break;
                                                   >> 618        default: 
                                                   >> 619            G4cerr << "Parameter range: error at CompareInt" << G4endl;
                                                   >> 620            paramERR = 1;
                                                   >> 621     }
                                                   >> 622     #ifdef DEBUG
                                                   >> 623         G4cerr << "CompareInt "
                                                   >> 624              << arg1 << " " << opr << arg2 
                                                   >> 625              << " result: " << result
                                                   >> 626              << G4endl;
                                                   >> 627     #endif
                                                   >> 628     return result;
                                                   >> 629 }
                                                   >> 630 
                                                   >> 631 G4int G4UIparameter::
                                                   >> 632 CompareDouble(G4double arg1, G4int op, G4double arg2)
                                                   >> 633 {   
                                                   >> 634     G4int result=-1;
                                                   >> 635     G4String opr;
                                                   >> 636     switch (op) {
                                                   >> 637         case GT:  result = ( arg1 >  arg2); opr= ">";   break;
                                                   >> 638         case GE:  result = ( arg1 >= arg2); opr= ">=";  break;
                                                   >> 639         case LT:  result = ( arg1 <  arg2); opr= "<";   break;
                                                   >> 640         case LE:  result = ( arg1 <= arg2); opr= "<=";  break;
                                                   >> 641         case EQ:  result = ( arg1 == arg2); opr= "==";  break;
                                                   >> 642         case NE:  result = ( arg1 != arg2); opr= "!=";  break;
                                                   >> 643         default:
                                                   >> 644            G4cerr << "Parameter range: error at CompareDouble" << G4endl;
                                                   >> 645            paramERR = 1;
                                                   >> 646     }
                                                   >> 647     #ifdef DEBUG
                                                   >> 648         G4cerr << "CompareDouble " 
                                                   >> 649              << arg1 <<" " << opr << " "<< arg2
                                                   >> 650              << " result: " << result
                                                   >> 651              << G4endl;
                                                   >> 652     #endif
                                                   >> 653     return result;
                                                   >> 654 }
                                                   >> 655 
                                                   >> 656 // --------------------- utility functions --------------------------
                                                   >> 657 
                                                   >> 658 tokenNum G4UIparameter::
                                                   >> 659 Yylex()         // reads input and returns token number KR486
                                                   >> 660 {               // (returns EOF)
                                                   >> 661     G4int c;             
                                                   >> 662     G4String buf;
                                                   >> 663 
                                                   >> 664     while(( c= G4UIpGetc())==' '|| c=='\t' || c== '\n' )
                                                   >> 665         ;
                                                   >> 666     if (c== EOF)
                                                   >> 667         return (tokenNum)EOF;            // KR488 
                                                   >> 668     buf= "";
                                                   >> 669     if (isdigit(c) || c== '.') {         // I or D
                                                   >> 670         do {
                                                   >> 671              buf += G4String((unsigned char)c);
                                                   >> 672              c=G4UIpGetc();
                                                   >> 673          }  while (c=='.' || isdigit(c) || 
                                                   >> 674                    c=='e' || c=='E' || c=='+' || c=='-');
                                                   >> 675          G4UIpUngetc(c);
                                                   >> 676    const char* t = buf;
                                                   >> 677    std::istrstream is((char*)t);
                                                   >> 678          if ( IsInt(buf.data(),20) ) {
                                                   >> 679              is >> yylval.I;
                                                   >> 680              return  CONSTINT;
                                                   >> 681          } else 
                                                   >> 682          if ( IsDouble(buf.data()) ) {
                                                   >> 683              is >> yylval.D;
                                                   >> 684              return  CONSTDOUBLE;
                                                   >> 685          } else {
                                                   >> 686              G4cerr << buf<<": numeric format error."<<G4endl;
                                                   >> 687          }
                                                   >> 688     }
                                                   >> 689     buf="";
                                                   >> 690     if (isalpha(c)|| c=='_') {           // IDENTIFIER
                                                   >> 691         do {
                                                   >> 692             buf += G4String((unsigned char)c); 
                                                   >> 693         } while ((c=G4UIpGetc()) != EOF && (isalnum(c) || c=='_'));
                                                   >> 694         G4UIpUngetc(c);
                                                   >> 695         if( buf == parameterName ) {
                                                   >> 696             yylval.S =buf;
                                                   >> 697             return IDENTIFIER;
                                                   >> 698         } else {
                                                   >> 699             G4cerr << buf << " is not a parameter name."<< G4endl;
                                                   >> 700             paramERR = 1;
                                                   >> 701        }
                                                   >> 702     }
                                                   >> 703     switch (c) {
                                                   >> 704       case '>':   return (tokenNum) Follow('=', GE,        GT);
                                                   >> 705       case '<':   return (tokenNum) Follow('=', LE,        LT);
                                                   >> 706       case '=':   return (tokenNum) Follow('=', EQ,        '=');
                                                   >> 707       case '!':   return (tokenNum) Follow('=', NE,        '!');
                                                   >> 708       case '|':   return (tokenNum) Follow('|', LOGICALOR, '|');
                                                   >> 709       case '&':   return (tokenNum) Follow('&', LOGICALAND, '&');
124       default:                                    710       default:
125         ed << "undefined.";                    << 711           return (tokenNum) c;
                                                   >> 712     }
                                                   >> 713 }
                                                   >> 714 
                                                   >> 715 
                                                   >> 716 G4int G4UIparameter::
                                                   >> 717 Follow(G4int expect, G4int ifyes, G4int ifno)
                                                   >> 718 {
                                                   >> 719     G4int c = G4UIpGetc();
                                                   >> 720     if ( c== expect)
                                                   >> 721           return ifyes;
                                                   >> 722     G4UIpUngetc(c);
                                                   >> 723     return ifno;
                                                   >> 724 }
                                                   >> 725 
                                                   >> 726 //------------------ low level routines -----------------------------
                                                   >> 727 G4int G4UIparameter::
                                                   >> 728 G4UIpGetc() {                        // emulation of getc() 
                                                   >> 729     G4int length = parameterRange.length();
                                                   >> 730     if( bp < length)
                                                   >> 731         return  parameterRange(bp++);
                                                   >> 732     else 
                                                   >> 733         return EOF;
                                                   >> 734 }
                                                   >> 735 G4int G4UIparameter::
                                                   >> 736 G4UIpUngetc(G4int c) {                 // emulation of ungetc() 
                                                   >> 737     if (c<0) return -1;
                                                   >> 738     if (bp >0 && c == parameterRange(bp-1)) {
                                                   >> 739          --bp;
                                                   >> 740     } else {
                                                   >> 741          G4cerr << "G4UIpUngetc() failed." << G4endl;
                                                   >> 742          G4cerr << "bp="<<bp <<" c="<<c
                                                   >> 743               << " pR(bp-1)=" << parameterRange(bp-1)
                                                   >> 744               << G4endl;
                                                   >> 745          paramERR = 1;
                                                   >> 746          return -1;
126     }                                             747     }
127     G4Exception("G4UIparameter::SetDefaultUnit << 748     return 0;
128   }                                            << 
129   SetDefaultValue(theDefaultUnit);             << 
130   SetParameterCandidates(G4UIcommand::UnitsLis << 
131 }                                              << 
132                                                << 
133 // ---------- CheckNewValue() related routines << 
134                                                << 
135 G4int G4UIparameter::CheckNewValue(const char* << 
136 {                                              << 
137   if (!TypeCheck(newValue)) {                  << 
138     return fParameterUnreadable;               << 
139   }                                            << 
140   if (!G4UIparsing::RangeCheck(*this, newValue << 
141     return fParameterOutOfRange;               << 
142   }                                            << 
143   if (!CandidateCheck(newValue)) {             << 
144     return fParameterOutOfCandidates;          << 
145   }                                            << 
146   return 0;  // succeeded                      << 
147 }                                              << 
148                                                << 
149 // ------------------------------------------- << 
150 G4bool G4UIparameter::CandidateCheck(const cha << 
151 {                                              << 
152   if (parameterCandidate.empty()) {            << 
153     return true;                               << 
154   }                                            << 
155                                                << 
156   G4Tokenizer candidateTokenizer(parameterCand << 
157   G4String aToken;                             << 
158   while (!(aToken = candidateTokenizer()).empt << 
159     if (aToken == newValue) {                  << 
160       return true;                             << 
161     }                                          << 
162   }                                            << 
163   G4cerr << "parameter value (" << newValue << << 
164   G4cerr << "  Candidates are:";               << 
165   G4Tokenizer candidateListTokenizer(parameter << 
166   while (!(aToken = candidateListTokenizer()). << 
167     G4cerr << ' ' << aToken;                   << 
168   }                                            << 
169   G4cerr << G4endl;                            << 
170                                                << 
171   return false;                                << 
172 }                                              << 
173                                                << 
174 // ------------------------------------------- << 
175 G4bool G4UIparameter::TypeCheck(const char* ne << 
176 {                                              << 
177   G4String newValueString(newValue);           << 
178   char type = (char)std::toupper(parameterType << 
179   switch (type) {                              << 
180     case 'D':                                  << 
181       if (!G4UIparsing::IsDouble(newValueStrin << 
182         G4cerr << newValue << ": double value  << 
183         return false;                          << 
184       }                                        << 
185       break;                                   << 
186     case 'I':                                  << 
187       if (!G4UIparsing::IsInt(newValueString.d << 
188         G4cerr << newValue << ": integer expec << 
189         return false;                          << 
190       }                                        << 
191       break;                                   << 
192     case 'L':                                  << 
193       if (!G4UIparsing::IsInt(newValueString.d << 
194         G4cerr << newValue << ": long int expe << 
195         return false;                          << 
196       }                                        << 
197       break;                                   << 
198     case 'S':                                  << 
199       break;                                   << 
200     case 'B':                                  << 
201       G4StrUtil::to_upper(newValueString);     << 
202       if (newValueString == "Y" || newValueStr << 
203           || newValueString == "NO" || newValu << 
204           || newValueString == "T" || newValue << 
205           || newValueString == "FALSE")        << 
206       {                                        << 
207         return true;                           << 
208       }                                        << 
209                                                << 
210       G4cerr << newValue << ": bool expected." << 
211       return false;                            << 
212                                                << 
213     default:;                                  << 
214   }                                            << 
215   return true;                                 << 
216 }                                                 749 }
                                                   >> 750 // *****  end of CheckNewValue() related code  ******
                                                   >> 751 
217                                                   752