42 : messenger(0), bp(0), token(
IDENTIFIER), paramERR(0)
48:messenger(theMessenger),token(
IDENTIFIER),paramERR(0)
53 if(comStr(comStr.length()-1)!=
'/')
56 G4cerr <<
" <" << theCommandPath <<
"> must be a directory." <<
G4endl;
61 G4UIcommandCommonConstructorCode (comStr);
63 availabelStateList.clear();
72void G4UIcommand::G4UIcommandCommonConstructorCode
73(
const char * theCommandPath)
75 commandPath = theCommandPath;
76 commandName = theCommandPath;
77 G4int commandNameIndex = commandName.
last(
'/');
78 commandName.
remove(0,commandNameIndex+1);
88 G4int n_parameterEntry = parameter.size();
89 for(
G4int i_thParameter=0; i_thParameter < n_parameterEntry; i_thParameter++ )
90 {
delete parameter[i_thParameter]; }
107 G4int n_parameterEntry = parameter.size();
108 if( n_parameterEntry != 0 )
113 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
115 if(i_thParameter > 0)
117 correctParameters.
append(
" ");
119 aToken = parameterToken();
120 if( aToken.length()>0 && aToken(0)==
'"' )
122 while( aToken(aToken.length()-1) !=
'"'
123 || ( aToken.length()==1 && aToken(0)==
'"' ))
125 G4String additionalToken = parameterToken();
126 if( additionalToken.
isNull() )
129 aToken += additionalToken;
132 else if(i_thParameter==n_parameterEntry-1 && parameter[i_thParameter]->GetParameterType()==
's')
135 while(!((anotherToken=parameterToken()).isNull()))
138 if(idxs==
G4int(std::string::npos))
141 aToken += anotherToken;
146 aToken += anotherToken(0,idxs);
154 if( aToken.
isNull() || aToken ==
"!" )
156 if(parameter[i_thParameter]->IsOmittable())
158 if(parameter[i_thParameter]->GetCurrentAsDefault())
162 for(
G4int ii=0;ii<i_thParameter;ii++)
167 while( parVal(parVal.length()-1) !=
'"' )
170 if( additionalToken.
isNull() )
173 parVal += additionalToken;
178 if (aCVToken(0)==
'"')
180 while( aCVToken(aCVToken.length()-1) !=
'"' )
183 if( additionalToken.
isNull() )
186 aCVToken += additionalToken;
190 correctParameters.
append(aCVToken);
193 { correctParameters.
append(parameter[i_thParameter]->GetDefaultValue()); }
200 G4int stat = parameter[i_thParameter]->CheckNewValue( aToken );
201 if(stat)
return stat+i_thParameter;
202 correctParameters.
append(aToken);
221 availabelStateList.clear();
222 availabelStateList.push_back(s1);
228 availabelStateList.clear();
229 availabelStateList.push_back(s1);
230 availabelStateList.push_back(s2);
237 availabelStateList.clear();
238 availabelStateList.push_back(s1);
239 availabelStateList.push_back(s2);
240 availabelStateList.push_back(s3);
248 availabelStateList.clear();
249 availabelStateList.push_back(s1);
250 availabelStateList.push_back(s2);
251 availabelStateList.push_back(s3);
252 availabelStateList.push_back(s4);
261 availabelStateList.clear();
262 availabelStateList.push_back(s1);
263 availabelStateList.push_back(s2);
264 availabelStateList.push_back(s3);
265 availabelStateList.push_back(s4);
266 availabelStateList.push_back(s5);
275 G4int nState = availabelStateList.size();
276 for(
G4int i=0;i<nState;i++)
278 if(availabelStateList[i]==currentState)
305 for(i=0;i<UTbl.size();i++)
306 {
if(UTbl[i]->GetName()==unitCategory)
break; }
309 G4cerr <<
"Unit category <" << unitCategory <<
"> is not defined." <<
G4endl;
313 retStr = UCnt[0]->GetSymbol();
314 G4int je = UCnt.size();
315 for(
G4int j=1;j<je;j++)
318 retStr += UCnt[j]->GetSymbol();
320 for(
G4int k=0;k<je;k++)
323 retStr += UCnt[k]->GetName();
332 if(commandPath(commandPath.length()-1)!=
'/')
335 G4int n_guidanceEntry = commandGuidance.size();
336 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ )
338 if( ! rangeString.
isNull() )
339 {
G4cout <<
" Range of parameters : " << rangeString <<
G4endl; }
340 G4int n_parameterEntry = parameter.size();
341 if( n_parameterEntry > 0 )
343 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
344 { parameter[i_thParameter]->List(); }
352 if(boolVal) vl =
"1";
358 std::ostringstream os;
366 std::ostringstream os;
377 std::ostringstream os;
378 os << doubleValue/uv <<
" " << unitName;
385 std::ostringstream os;
386 os << vec.
x() <<
" " << vec.
y() <<
" " << vec.
z();
396 std::ostringstream os;
397 os << vec.
x()/uv <<
" " << vec.
y()/uv <<
" " << vec.
z()/uv
408 if( v==
"Y" || v==
"YES" || v==
"1" || v==
"T" || v==
"TRUE" )
416 std::istringstream is(st);
424 std::istringstream is(st);
434 std::istringstream is(st);
446 std::istringstream is(st);
447 is >> vx >> vy >> vz;
457 std::istringstream is(st);
458 is >> vx >> vy >> vz >> unts;
478 if( ! rangeString.
isNull() )
486TypeCheck(
const char * t)
490 std::istringstream is(t);
491 for (
unsigned i=0; i< parameter.size(); i++) {
493 type = toupper(parameter[i]->GetParameterType());
496 if( IsDouble(aNewValue)==0 ){
497 G4cerr << aNewValue <<
": double value expected."
502 if( IsInt(aNewValue,20)==0 ){
503 G4cerr <<aNewValue<<
": integer expected."
511 if (aNewValue ==
"Y" || aNewValue ==
"N"
512 ||aNewValue ==
"YES" || aNewValue ==
"NO"
513 ||aNewValue ==
"1" || aNewValue ==
"0"
514 ||aNewValue ==
"T" || aNewValue ==
"F"
515 ||aNewValue ==
"TRUE" || aNewValue ==
"FALSE")
527IsInt(
const char* buf,
short maxDigits)
531 if( *p ==
'+' || *p ==
'-') { ++p; }
532 if( isdigit( (
G4int)(*p) )) {
533 while( isdigit( (
G4int)(*p) )) { ++p; ++length; }
535 if( length > maxDigits) {
551ExpectExponent(
const char* str)
554 if( IsInt( str, maxExplength=7 ))
return 1;
560IsDouble(
const char* buf)
564 case '+':
case '-': ++p;
566 while( isdigit( (
G4int)(*p) )) { ++p; }
571 return ExpectExponent(++p );
574 if( *p ==
'\0' )
return 1;
575 if( *p ==
'e' || *p ==
'E' )
return ExpectExponent(++p );
577 while( isdigit( (
G4int)(*p) )) { ++p; }
578 if( *p ==
'\0' )
return 1;
579 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
580 }
else return 0;
break;
584 if( *p ==
'.' ) { ++p;
586 while( isdigit( (
G4int)(*p) )) { ++p; }
587 if( *p ==
'\0' )
return 1;
588 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
594 while( isdigit( (
G4int)(*p) )) { ++p; }
595 if( *p ==
'\0' )
return 1;
596 if( *p ==
'e' || *p ==
'E' )
return ExpectExponent(++p);
600 while( isdigit( (
G4int)(*p) )) { ++p; }
601 if( *p ==
'\0' )
return 1;
602 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
603 if( *p ==
'.' ) { ++p;
604 if( *p ==
'\0' )
return 1;
605 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
607 while( isdigit( (
G4int)(*p) )) { ++p; }
608 if( *p ==
'\0' )
return 1;
609 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
620RangeCheck(
const char* t) {
624 std::istringstream is(t);
625 for (
unsigned i=0; i< parameter.size(); i++) {
626 type= toupper(parameter[i]->GetParameterType());
628 case 'D': is >> newVal[i].D;
break;
629 case 'I': is >> newVal[i].I;
break;
637 result = Expression();
639 if( paramERR == 1 )
return 0;
641 G4cerr <<
"Illegal Expression in parameter range." <<
G4endl;
644 if ( result.
I )
return 1;
645 G4cerr <<
"parameter out of range: "<< rangeString <<
G4endl;
657 result = LogicalORExpression();
662LogicalORExpression(
void)
666 p = LogicalANDExpression();
669 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
676 p = LogicalANDExpression();
678 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
686 result.
I += (p.
D != 0.0);
697LogicalANDExpression(
void)
701 p = EqualityExpression();
704 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
711 p = EqualityExpression();
713 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
721 result.
I *= (p.
D != 0.0);
733EqualityExpression(
void)
741 result = RelationalExpression();
742 if( token==
EQ || token==
NE ) {
746 arg2 = RelationalExpression();
747 result.
I = Eval2( arg1, operat, arg2 );
754 G4cerr <<
"Parameter range: error at EqualityExpression"
764RelationalExpression(
void)
773 arg1 = AdditiveExpression();
774 if( token==
GT || token==
GE || token==
LT || token==
LE ) {
777 arg2 = AdditiveExpression();
778 result.
I = Eval2( arg1, operat, arg2 );
793AdditiveExpression(
void)
795 result = MultiplicativeExpression();
796 if( token !=
'+' && token !=
'-' )
return result;
797 G4cerr <<
"Parameter range: operator "
799 <<
" is not supported." <<
G4endl;
805MultiplicativeExpression(
void)
807 result = UnaryExpression();
808 if( token !=
'*' && token !=
'/' && token !=
'%' )
return result;
809 G4cerr <<
"Parameter range: operator "
811 <<
" is not supported." <<
G4endl;
827 p = UnaryExpression();
838 result = UnaryExpression();
break;
841 G4cerr <<
"Parameter range error: "
842 <<
"operator '!' is not supported (sorry)."
845 result = UnaryExpression();
break;
847 result = PrimaryExpression();
854PrimaryExpression(
void)
864 token = Yylex();
break;
868 token= Yylex();
break;
872 token = Yylex();
break;
875 result = Expression();
896 <<
": meaningless comparison"
902 unsigned i = IndexOf( arg1.
S );
903 newValtype = toupper(parameter[i]->GetParameterType());
904 switch ( newValtype ) {
907 return CompareInt( newVal[i].I, op, arg2.
I );
909 G4cerr <<
"integer operand expected for "
915 return CompareDouble( newVal[i].D, op, arg2.
D );
918 return CompareDouble( newVal[i].D, op, arg2.
I );
924 unsigned i = IndexOf( arg2.
S );
925 newValtype = toupper(parameter[i]->GetParameterType());
926 switch ( newValtype ) {
929 return CompareInt( arg1.
I, op, newVal[i].I );
931 G4cerr <<
"integer operand expected for "
937 return CompareDouble( arg1.
D, op, newVal[i].D );
940 return CompareDouble( arg1.
I, op, newVal[i].D );
954 case GT: result = ( arg1 > arg2); opr=
">" ;
break;
955 case GE: result = ( arg1 >= arg2); opr=
">=";
break;
956 case LT: result = ( arg1 < arg2); opr=
"<" ;
break;
957 case LE: result = ( arg1 <= arg2); opr=
"<=";
break;
958 case EQ: result = ( arg1 == arg2); opr=
"==";
break;
959 case NE: result = ( arg1 != arg2); opr=
"!=";
break;
961 G4cerr <<
"Parameter range: error at CompareInt" <<
G4endl;
966 << arg1 <<
" " << opr << arg2
967 <<
" result: " << result
979 case GT: result = ( arg1 > arg2); opr=
">";
break;
980 case GE: result = ( arg1 >= arg2); opr=
">=";
break;
981 case LT: result = ( arg1 < arg2); opr=
"<";
break;
982 case LE: result = ( arg1 <= arg2); opr=
"<=";
break;
983 case EQ: result = ( arg1 == arg2); opr=
"==";
break;
984 case NE: result = ( arg1 != arg2); opr=
"!=";
break;
986 G4cerr <<
"Parameter range: error at CompareDouble"
991 G4cerr <<
"CompareDouble "
992 << arg1 <<
" " << opr <<
" "<< arg2
993 <<
" result: " << result
999unsigned G4UIcommand::
1000IndexOf(
const char* nam)
1004 for( i=0; i<parameter.size(); i++)
1006 pname = parameter[i]-> GetParameterName();
1007 if( pname == nam ) {
1012 G4cerr <<
"parameter name:"<<nam<<
" not found."<<
G4endl;
1017unsigned G4UIcommand::
1018IsParameter(
const char* nam)
1021 for(
unsigned i=0; i<parameter.size(); i++)
1023 pname = parameter[i]-> GetParameterName();
1024 if( pname == nam )
return 1;
1038 while(( c= G4UIpGetc())==
' '|| c==
'\t' || c==
'\n' )
1043 if (isdigit(c) || c==
'.') {
1047 }
while (c==
'.' || isdigit(c) ||
1048 c==
'e' || c==
'E' || c==
'+' || c==
'-');
1050 const char* t = buf;
1051 std::istringstream is(t);
1052 if ( IsInt(buf.
data(),20) ) {
1056 if ( IsDouble(buf.
data()) ) {
1064 if (isalpha(c)|| c==
'_') {
1067 }
while ((c=G4UIpGetc()) != EOF && (isalnum(c) || c==
'_'));
1069 if( IsParameter(buf) ) {
1080 case '=':
return (
tokenNum) Follow(
'=',
EQ,
'=');
1081 case '!':
return (
tokenNum) Follow(
'=',
NE,
'!');
1093 G4int c = G4UIpGetc();
1103 G4int length = rangeString.length();
1105 return rangeString(bp++);
1110G4UIpUngetc(
G4int c) {
1112 if (bp >0 && c == rangeString(bp-1)) {
1116 G4cerr <<
"bp="<<bp <<
" c="<<c
1117 <<
" pR(bp-1)=" << rangeString(bp-1)
CLHEP::Hep3Vector G4ThreeVector
std::vector< G4UnitsCategory * > G4UnitsTable
std::vector< G4UnitDefinition * > G4UnitsContainer
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
G4ApplicationState GetCurrentState() const
static G4StateManager * GetStateManager()
G4String & remove(str_size)
G4String & append(const G4String &)
str_size index(const char *, G4int pos=0) const
const char * data() const
static G4ThreeVector ConvertTo3Vector(const char *st)
G4int operator==(const G4UIcommand &right) const
static G4String CategoryOf(const char *unitName)
static G4double ValueOf(const char *unitName)
virtual G4int DoIt(G4String parameterList)
static G4String ConvertToString(G4bool boolVal)
const G4String & GetCommandPath() const
G4int operator!=(const G4UIcommand &right) const
G4int CheckNewValue(const char *newValue)
static G4int ConvertToInt(const char *st)
static G4String UnitsList(const char *unitCategory)
static G4bool ConvertToBool(const char *st)
static G4double ConvertToDouble(const char *st)
static G4double ConvertToDimensionedDouble(const char *st)
void AvailableForStates(G4ApplicationState s1)
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
G4String GetCurrentValue()
void AddNewCommand(G4UIcommand *newCommand)
void RemoveCommand(G4UIcommand *aCommand)
static G4UImanager * GetUIpointer()
virtual G4String GetCurrentValue(G4UIcommand *command)
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
static G4double GetValueOf(const G4String &)
static G4String GetCategory(const G4String &)
static G4UnitsTable & GetUnitsTable()