50 parameterType = theType;
57 parameterName = theName;
58 parameterType = theType;
59 omittable = theOmittable;
70 return (
this == &right);
76 return (
this != &right);
83 if(!parameterGuidance.
isNull())
85 G4cout <<
" Parameter type : " << parameterType <<
G4endl;
94 if(currentAsDefaultFlag)
96 G4cout <<
" Default value : taken from the current value" <<
G4endl;
98 else if(!defaultValue.
isNull())
100 G4cout <<
" Default value : " << defaultValue <<
G4endl;
102 if(!parameterRange.
isNull())
103 G4cout <<
" Parameter range : " << parameterRange <<
G4endl;
104 if(!parameterCandidate.
isNull())
105 G4cout <<
" Candidates : " << parameterCandidate <<
G4endl;
111 std::ostringstream os;
112 os << theDefaultValue;
113 defaultValue = os.str();
119 std::ostringstream os;
120 os << theDefaultValue;
121 defaultValue = os.str();
127 std::ostringstream os;
128 os << theDefaultValue;
129 defaultValue = os.str();
135 char type = toupper(parameterType);
139 ed <<
"This method can be used only for a string-type parameter that is "
140 "used to specify a unit.\n"
141 <<
"This parameter <" << parameterName <<
"> is defined as ";
175 if(TypeCheck(newValue) == 0)
177 if(!parameterRange.
isNull())
179 if(RangeCheck(newValue) == 0)
182 if(!parameterCandidate.
isNull())
184 if(CandidateCheck(newValue) == 0)
191G4int G4UIparameter::CandidateCheck(
const char* newValue)
193 G4Tokenizer candidateTokenizer(parameterCandidate);
196 while(!(aToken = candidateTokenizer()).isNull())
199 if(aToken == newValue)
202 G4cerr <<
"parameter value (" << newValue
203 <<
") is not listed in the candidate List." <<
G4endl;
208G4int G4UIparameter::RangeCheck(
const char* newValue)
212 std::istringstream is(newValue);
213 char type = toupper(parameterType);
229 result = Expression();
230 if(paramERR == 1)
return 0;
233 G4cerr <<
"Illegal Expression in parameter range." <<
G4endl;
236 if(result.
I)
return 1;
237 G4cerr <<
"parameter out of range: " << parameterRange <<
G4endl;
242G4int G4UIparameter::TypeCheck(
const char* newValue)
245 char type = toupper(parameterType);
249 if(IsDouble(newValueString.data()) == 0)
251 G4cerr << newValue <<
": double value expected." <<
G4endl;
256 if(IsInt(newValueString.data(), 10) == 0)
263 if(IsInt(newValueString.data(), 20) == 0)
272 newValueString.toUpper();
273 if(newValueString ==
"Y" || newValueString ==
"N" ||
274 newValueString ==
"YES" || newValueString ==
"NO" ||
275 newValueString ==
"1" || newValueString ==
"0" ||
276 newValueString ==
"T" || newValueString ==
"F" ||
277 newValueString ==
"TRUE" || newValueString ==
"FALSE")
290G4int G4UIparameter::IsInt(
const char* buf,
295 if(*p ==
'+' || *p ==
'-')
299 if(isdigit((
G4int)(*p)))
301 while(isdigit((
G4int)(*p)))
308 if(length > maxDigits)
328G4int G4UIparameter::ExpectExponent(
const char* str)
331 if(IsInt(str, maxExplength = 7))
338G4int G4UIparameter::IsDouble(
349 while(isdigit((
G4int)(*p)))
359 return ExpectExponent(++p);
364 if(*p ==
'e' || *p ==
'E')
365 return ExpectExponent(++p);
368 while(isdigit((
G4int)(*p)))
374 if(*p ==
'e' || *p ==
'E')
375 return ExpectExponent(++p);
389 while(isdigit((
G4int)(*p)))
395 if(*p ==
'e' || *p ==
'E')
396 return ExpectExponent(++p);
404 while(isdigit((
G4int)(*p)))
410 if(*p ==
'e' || *p ==
'E')
411 return ExpectExponent(++p);
417 while(isdigit((
G4int)(*p)))
423 if(*p ==
'e' || *p ==
'E')
424 return ExpectExponent(++p);
430 if(*p ==
'e' || *p ==
'E')
431 return ExpectExponent(++p);
434 while(isdigit((
G4int)(*p)))
440 if(*p ==
'e' || *p ==
'E')
441 return ExpectExponent(++p);
451yystype G4UIparameter::Expression(
void)
457 result = LogicalORExpression();
462yystype G4UIparameter::LogicalORExpression(
void)
466 p = LogicalANDExpression();
471 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
478 p = LogicalANDExpression();
481 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
491 result.
I += (p.
L != 0L);
495 result.
I += (p.
D != 0.0);
507yystype G4UIparameter::LogicalANDExpression(
void)
511 p = EqualityExpression();
516 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
523 p = EqualityExpression();
526 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
536 result.
I *= (p.
L != 0L);
540 result.
I *= (p.
D != 0.0);
552yystype G4UIparameter::EqualityExpression(
void)
560 result = RelationalExpression();
561 if(token ==
EQ || token ==
NE)
566 arg2 = RelationalExpression();
567 result.
I = Eval2(arg1, operat, arg2);
577 G4cerr <<
"Parameter range: error at EqualityExpression" <<
G4endl;
585yystype G4UIparameter::RelationalExpression(
void)
594 arg1 = AdditiveExpression();
595 if(token ==
GT || token ==
GE || token ==
LT || token ==
LE)
599 arg2 = AdditiveExpression();
600 result.
I = Eval2(arg1, operat, arg2);
617yystype G4UIparameter::AdditiveExpression(
void)
620 result = MultiplicativeExpression();
621 if(token !=
'+' && token !=
'-')
623 G4cerr <<
"Parameter range: operator " << (char) token <<
" is not supported."
630yystype G4UIparameter::MultiplicativeExpression(
void)
633 result = UnaryExpression();
634 if(token !=
'*' && token !=
'/' && token !=
'%')
636 G4cerr <<
"Parameter range: operator " << (char) token <<
" is not supported."
643yystype G4UIparameter::UnaryExpression(
void)
654 p = UnaryExpression();
673 result = UnaryExpression();
677 G4cerr <<
"Parameter range error: "
678 <<
"operator '!' is not supported (sorry)." <<
G4endl;
680 result = UnaryExpression();
683 result = PrimaryExpression();
689yystype G4UIparameter::PrimaryExpression(
void)
719 result = Expression();
739 G4cerr << parameterName <<
": meaningless comparison " <<
G4int(arg1.
type)
743 char type = toupper(parameterType);
751 return CompareInt(newVal.
I, op, arg2.
I);
755 G4cerr <<
"integer operand expected for " << parameterRange <<
'.'
762 return CompareLong(newVal.
L, op, arg2.
L);
766 G4cerr <<
"long int operand expected for " << parameterRange <<
'.'
773 return CompareDouble(newVal.
D, op, arg2.
D);
777 return CompareDouble(newVal.
D, op, arg2.
I);
781 return CompareDouble(newVal.
D, op, arg2.
L);
794 return CompareInt(arg1.
I, op, newVal.
I);
798 G4cerr <<
"integer operand expected for " << parameterRange <<
'.'
805 return CompareLong(arg1.
L, op, newVal.
L);
809 G4cerr <<
"long int operand expected for " << parameterRange <<
'.'
816 return CompareDouble(arg1.
D, op, newVal.
D);
820 return CompareDouble(arg1.
I, op, newVal.
D);
824 return CompareDouble(arg1.
L, op, newVal.
D);
830 G4cerr <<
"no param name is specified at the param range." <<
G4endl;
842 result = (arg1 > arg2);
846 result = (arg1 >= arg2);
850 result = (arg1 < arg2);
854 result = (arg1 <= arg2);
858 result = (arg1 == arg2);
862 result = (arg1 != arg2);
866 G4cerr <<
"Parameter range: error at CompareInt" <<
G4endl;
870 G4cerr <<
"CompareInt " << arg1 <<
" " << opr << arg2 <<
" result: " << result
884 result = (arg1 > arg2);
888 result = (arg1 >= arg2);
892 result = (arg1 < arg2);
896 result = (arg1 <= arg2);
900 result = (arg1 == arg2);
904 result = (arg1 != arg2);
908 G4cerr <<
"Parameter range: error at CompareInt" <<
G4endl;
912 G4cerr <<
"CompareInt " << arg1 <<
" " << opr << arg2 <<
" result: " << result
926 result = (arg1 > arg2);
930 result = (arg1 >= arg2);
934 result = (arg1 < arg2);
938 result = (arg1 <= arg2);
942 result = (arg1 == arg2);
946 result = (arg1 != arg2);
950 G4cerr <<
"Parameter range: error at CompareDouble" <<
G4endl;
954 G4cerr <<
"CompareDouble " << arg1 <<
" " << opr <<
" " << arg2
955 <<
" result: " << result <<
G4endl;
967 while((c = G4UIpGetc()) ==
' ' || c ==
'\t' || c ==
'\n')
972 if(isdigit(c) || c ==
'.')
978 }
while(c ==
'.' || isdigit(c) || c ==
'e' || c ==
'E' || c ==
'+' ||
982 std::istringstream is(t);
983 if(IsInt(buf.
data(), 20))
988 else if(IsDouble(buf.
data()))
999 if(isalpha(c) || c ==
'_')
1003 buf +=
G4String((
unsigned char) c);
1004 }
while((c = G4UIpGetc()) != EOF && (isalnum(c) || c ==
'_'));
1006 if(buf == parameterName)
1013 G4cerr << buf <<
" is not a parameter name." <<
G4endl;
1039 G4int c = G4UIpGetc();
1048G4int G4UIparameter::G4UIpGetc()
1050 G4int length = parameterRange.length();
1052 return parameterRange(bp++);
1062 if(bp > 0 && c == parameterRange(bp - 1))
1069 G4cerr <<
"bp=" << bp <<
" c=" << c
1070 <<
" 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
const char * data() const
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)