45 parameterType = theType;
52 parameterName = theName;
53 parameterType = theType;
54 omittable = theOmittable;
63 return (
this == &right);
69 return (
this != &right);
76 if(!parameterGuidance.empty())
80 G4cout <<
" Parameter type : " << parameterType <<
G4endl;
89 if(currentAsDefaultFlag)
91 G4cout <<
" Default value : taken from the current value" <<
G4endl;
93 else if(!defaultValue.empty())
97 if(!parameterRange.empty())
99 G4cout <<
" Parameter range : " << parameterRange <<
G4endl;
101 if(!parameterCandidate.empty())
103 G4cout <<
" Candidates : " << parameterCandidate <<
G4endl;
110 std::ostringstream os;
111 os << theDefaultValue;
112 defaultValue = os.str();
118 std::ostringstream os;
119 os << theDefaultValue;
120 defaultValue = os.str();
126 std::ostringstream os;
127 os << theDefaultValue;
128 defaultValue = os.str();
134 char type = (char)std::toupper(parameterType);
138 ed <<
"This method can be used only for a string-type parameter that is "
139 "used to specify a unit.\n"
140 <<
"This parameter <" << parameterName <<
"> is defined as ";
174 if(TypeCheck(newValue) == 0)
178 if(!parameterRange.empty())
180 if(RangeCheck(newValue) == 0)
185 if(!parameterCandidate.empty())
187 if(CandidateCheck(newValue) == 0)
196G4int G4UIparameter::CandidateCheck(
const char* newValue)
198 G4Tokenizer candidateTokenizer(parameterCandidate);
201 while(!(aToken = candidateTokenizer()).empty())
204 if(aToken == newValue)
209 G4cerr <<
"parameter value (" << newValue
210 <<
") is not listed in the candidate List." <<
G4endl;
211 G4cerr <<
" Candidates are:";
212 G4Tokenizer candidateListTokenizer(parameterCandidate);
213 while(!(aToken = candidateListTokenizer()).empty())
223G4int G4UIparameter::RangeCheck(
const char* newValue)
227 std::istringstream is(newValue);
228 char type = (char)std::toupper(parameterType);
244 result = Expression();
251 G4cerr <<
"Illegal Expression in parameter range." <<
G4endl;
258 G4cerr <<
"parameter out of range: " << parameterRange <<
G4endl;
263G4int G4UIparameter::TypeCheck(
const char* newValue)
266 char type = (char)std::toupper(parameterType);
270 if(IsDouble(newValueString.data()) == 0)
272 G4cerr << newValue <<
": double value expected." <<
G4endl;
277 if(IsInt(newValueString.data(), 10) == 0)
284 if(IsInt(newValueString.data(), 20) == 0)
294 if(newValueString ==
"Y" || newValueString ==
"N" ||
295 newValueString ==
"YES" || newValueString ==
"NO" ||
296 newValueString ==
"1" || newValueString ==
"0" ||
297 newValueString ==
"T" || newValueString ==
"F" ||
298 newValueString ==
"TRUE" || newValueString ==
"FALSE")
313G4int G4UIparameter::IsInt(
const char* buf,
318 if(*p ==
'+' || *p ==
'-')
322 if(isdigit((
G4int) (*p)) != 0)
324 while(isdigit((
G4int) (*p)) != 0)
331 if(length > maxDigits)
351G4int G4UIparameter::ExpectExponent(
const char* str)
354 if(IsInt(str, maxExplength = 7) != 0)
365G4int G4UIparameter::IsDouble(
376 while(isdigit((
G4int) (*p)) != 0)
386 return ExpectExponent(++p);
393 if(*p ==
'e' || *p ==
'E')
395 return ExpectExponent(++p);
399 while(isdigit((
G4int) (*p)) != 0)
407 if(*p ==
'e' || *p ==
'E')
409 return ExpectExponent(++p);
426 while(isdigit((
G4int) (*p)) != 0)
434 if(*p ==
'e' || *p ==
'E')
436 return ExpectExponent(++p);
445 while(isdigit((
G4int) (*p)) != 0)
453 if(*p ==
'e' || *p ==
'E')
455 return ExpectExponent(++p);
462 while(isdigit((
G4int) (*p)) != 0)
470 if(*p ==
'e' || *p ==
'E')
472 return ExpectExponent(++p);
481 if(*p ==
'e' || *p ==
'E')
483 return ExpectExponent(++p);
487 while(isdigit((
G4int) (*p)) != 0)
495 if(*p ==
'e' || *p ==
'E')
497 return ExpectExponent(++p);
508yystype G4UIparameter::Expression()
514 result = LogicalORExpression();
519yystype G4UIparameter::LogicalORExpression()
523 p = LogicalANDExpression();
530 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
537 p = LogicalANDExpression();
540 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
550 result.I +=
static_cast<int>(p.L != 0
L);
554 result.I +=
static_cast<int>(p.D != 0.0);
566yystype G4UIparameter::LogicalANDExpression()
570 p = EqualityExpression();
577 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
584 p = EqualityExpression();
587 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
597 result.I *=
static_cast<int>(p.L != 0
L);
601 result.I *=
static_cast<int>(p.D != 0.0);
613yystype G4UIparameter::EqualityExpression()
621 result = RelationalExpression();
622 if(token ==
EQ || token ==
NE)
627 arg2 = RelationalExpression();
628 result.I = Eval2(arg1, operat, arg2);
631 G4cerr <<
" return code of Eval2(): " << result.I <<
G4endl;
638 G4cerr <<
"Parameter range: error at EqualityExpression" <<
G4endl;
646yystype G4UIparameter::RelationalExpression()
655 arg1 = AdditiveExpression();
656 if(token ==
GT || token ==
GE || token ==
LT || token ==
LE)
660 arg2 = AdditiveExpression();
661 result.I = Eval2(arg1, operat, arg2);
678yystype G4UIparameter::AdditiveExpression()
681 result = MultiplicativeExpression();
682 if(token !=
'+' && token !=
'-')
686 G4cerr <<
"Parameter range: operator " << (char) token <<
" is not supported."
693yystype G4UIparameter::MultiplicativeExpression()
696 result = UnaryExpression();
697 if(token !=
'*' && token !=
'/' && token !=
'%')
701 G4cerr <<
"Parameter range: operator " << (char) token <<
" is not supported."
708yystype G4UIparameter::UnaryExpression()
719 p = UnaryExpression();
738 result = UnaryExpression();
742 G4cerr <<
"Parameter range error: "
743 <<
"operator '!' is not supported (sorry)." <<
G4endl;
745 result = UnaryExpression();
748 result = PrimaryExpression();
754yystype G4UIparameter::PrimaryExpression()
784 result = Expression();
804 G4cerr << parameterName <<
": meaningless comparison " <<
G4int(arg1.type)
808 char type = (char)std::toupper(parameterType);
816 return CompareInt(newVal.I, op, arg2.I);
820 G4cerr <<
"integer operand expected for " << parameterRange <<
'.'
827 return CompareLong(newVal.L, op, arg2.L);
831 G4cerr <<
"long int operand expected for " << parameterRange <<
'.'
838 return CompareDouble(newVal.D, op, arg2.D);
842 return CompareDouble(newVal.D, op, arg2.I);
846 return CompareDouble(newVal.D, op, arg2.L);
859 return CompareInt(arg1.I, op, newVal.I);
863 G4cerr <<
"integer operand expected for " << parameterRange <<
'.'
870 return CompareLong(arg1.L, op, newVal.L);
874 G4cerr <<
"long int operand expected for " << parameterRange <<
'.'
881 return CompareDouble(arg1.D, op, newVal.D);
885 return CompareDouble(arg1.I, op, newVal.D);
889 return CompareDouble(arg1.L, op, newVal.D);
895 G4cerr <<
"no param name is specified at the param range." <<
G4endl;
907 result =
static_cast<G4int>(arg1 > arg2);
911 result =
static_cast<G4int>(arg1 >= arg2);
915 result =
static_cast<G4int>(arg1 < arg2);
919 result =
static_cast<G4int>(arg1 <= arg2);
923 result =
static_cast<G4int>(arg1 == arg2);
927 result =
static_cast<G4int>(arg1 != arg2);
931 G4cerr <<
"Parameter range: error at CompareInt" <<
G4endl;
935 G4cerr <<
"CompareInt " << arg1 <<
" " << opr << arg2 <<
" result: " << result
949 result =
static_cast<G4int>(arg1 > arg2);
953 result =
static_cast<G4int>(arg1 >= arg2);
957 result =
static_cast<G4int>(arg1 < arg2);
961 result =
static_cast<G4int>(arg1 <= arg2);
965 result =
static_cast<G4int>(arg1 == arg2);
969 result =
static_cast<G4int>(arg1 != arg2);
973 G4cerr <<
"Parameter range: error at CompareInt" <<
G4endl;
977 G4cerr <<
"CompareInt " << arg1 <<
" " << opr << arg2 <<
" result: " << result
991 result =
static_cast<G4int>(arg1 > arg2);
995 result =
static_cast<G4int>(arg1 >= arg2);
999 result =
static_cast<G4int>(arg1 < arg2);
1003 result =
static_cast<G4int>(arg1 <= arg2);
1007 result =
static_cast<G4int>(arg1 == arg2);
1011 result =
static_cast<G4int>(arg1 != arg2);
1015 G4cerr <<
"Parameter range: error at CompareDouble" <<
G4endl;
1019 G4cerr <<
"CompareDouble " << arg1 <<
" " << opr <<
" " << arg2
1020 <<
" result: " << result <<
G4endl;
1032 while((c = G4UIpGetc()) ==
' ' || c ==
'\t' || c ==
'\n')
1041 if((isdigit(c) != 0) || c ==
'.')
1045 buf += (
unsigned char) c;
1047 }
while(c ==
'.' || (isdigit(c) != 0) || c ==
'e' || c ==
'E' || c ==
'+' ||
1050 const char* t = buf;
1051 std::istringstream is(t);
1052 if(IsInt(buf.data(), 20) != 0)
1057 else if(IsDouble(buf.data()) != 0)
1068 if((isalpha(c) != 0) || c ==
'_')
1072 buf += (
unsigned char) c;
1073 }
while((c = G4UIpGetc()) != EOF && ((isalnum(c) != 0) || c ==
'_'));
1075 if(buf == parameterName)
1082 G4cerr << buf <<
" is not a parameter name." <<
G4endl;
1108 G4int c = G4UIpGetc();
1119G4int G4UIparameter::G4UIpGetc()
1121 G4int length = (
G4int)parameterRange.length();
1124 return parameterRange[bp++];
1139 if(bp > 0 && c == parameterRange[bp - 1])
1146 G4cerr <<
"bp=" << bp <<
" c=" << c
1147 <<
" pR(bp-1)=" << parameterRange[bp - 1] <<
G4endl;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
@ fParameterOutOfCandidates
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
static G4String CategoryOf(const char *unitName)
static G4String UnitsList(const char *unitCategory)
void SetDefaultValue(const char *theDefaultValue)
G4int CheckNewValue(const char *newValue)
void SetParameterCandidates(const char *theString)
G4bool operator!=(const G4UIparameter &right) const
G4bool operator==(const G4UIparameter &right) const
void SetDefaultUnit(const char *theDefaultUnit)
void to_upper(G4String &str)
Convert string to uppercase.
yystype { tokenNum type{ tokenNum::NONE } yystype