47 parameterType = theType;
53 parameterName = theName;
54 parameterType = theType;
55 omittable = theOmittable;
65 if (!parameterGuidance.empty()) {
68 G4cout <<
" Parameter type : " << parameterType <<
G4endl;
75 if (currentAsDefaultFlag) {
76 G4cout <<
" Default value : taken from the current value" <<
G4endl;
78 else if (!defaultValue.empty()) {
81 if (!rangeExpression.empty()) {
82 G4cout <<
" Parameter range : " << rangeExpression <<
G4endl;
84 if (!parameterCandidate.empty()) {
85 G4cout <<
" Candidates : " << parameterCandidate <<
G4endl;
110 char type = (char)std::toupper(parameterType);
113 ed <<
"This method can be used only for a string-type parameter that is "
114 "used to specify a unit.\n"
115 <<
"This parameter <" << parameterName <<
"> is defined as ";
142 if (!TypeCheck(newValue)) {
145 if (!RangeCheck(newValue)) {
148 if (!CandidateCheck(newValue)) {
155G4bool G4UIparameter::CandidateCheck(
const char* newValue)
157 if (parameterCandidate.empty()) {
161 G4Tokenizer candidateTokenizer(parameterCandidate);
163 while (!(aToken = candidateTokenizer()).empty()) {
164 if (aToken == newValue) {
168 G4cerr <<
"parameter value (" << newValue <<
") is not listed in the candidate List." <<
G4endl;
169 G4cerr <<
" Candidates are:";
170 G4Tokenizer candidateListTokenizer(parameterCandidate);
171 while (!(aToken = candidateListTokenizer()).empty()) {
180G4bool G4UIparameter::TypeCheck(
const char* newValue)
183 char type = (char)std::toupper(parameterType);
187 G4cerr << newValue <<
": double value expected." <<
G4endl;
206 G4StrUtil::to_upper(newValueString);
207 if (newValueString ==
"Y" || newValueString ==
"N" || newValueString ==
"YES"
208 || newValueString ==
"NO" || newValueString ==
"1" || newValueString ==
"0"
209 || newValueString ==
"T" || newValueString ==
"F" || newValueString ==
"TRUE"
210 || newValueString ==
"FALSE")
224G4bool G4UIparameter::RangeCheck(
const char* newValue)
226 if (rangeExpression.empty()) {
232 std::istringstream is(newValue);
233 char type = (char)std::toupper(parameterType);
253 result = Expression();
258 G4cerr <<
"Illegal Expression in parameter range." <<
G4endl;
264 G4cerr <<
"parameter out of range: " << rangeExpression <<
G4endl;
270yystype G4UIparameter::Expression()
272 return LogicalORExpression();
276yystype G4UIparameter::LogicalORExpression()
280 p = LogicalANDExpression();
285 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
291 p = LogicalANDExpression();
293 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
302 result.
I +=
static_cast<int>(p.
L != 0L);
306 result.
I +=
static_cast<int>(p.
D != 0.0);
318yystype G4UIparameter::LogicalANDExpression()
322 p = EqualityExpression();
327 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
333 p = EqualityExpression();
335 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
344 result.
I *=
static_cast<int>(p.
L != 0L);
348 result.
I *=
static_cast<int>(p.
D != 0.0);
360yystype G4UIparameter::EqualityExpression()
365 result = RelationalExpression();
366 if (token ==
EQ || token ==
NE) {
370 arg2 = RelationalExpression();
371 result.
I = Eval2(arg1, operat, arg2);
376 G4cerr <<
"Parameter range: error at EqualityExpression" <<
G4endl;
384yystype G4UIparameter::RelationalExpression()
390 arg1 = AdditiveExpression();
391 if (token ==
GT || token ==
GE || token ==
LT || token ==
LE) {
394 arg2 = AdditiveExpression();
395 result.
I = Eval2(arg1, operat, arg2);
405yystype G4UIparameter::AdditiveExpression()
407 yystype result = MultiplicativeExpression();
408 if (token !=
'+' && token !=
'-') {
411 G4cerr <<
"Parameter range: operator " << (char)token <<
" is not supported." <<
G4endl;
417yystype G4UIparameter::MultiplicativeExpression()
419 yystype result = UnaryExpression();
420 if (token !=
'*' && token !=
'/' && token !=
'%') {
423 G4cerr <<
"Parameter range: operator " << (char)token <<
" is not supported." <<
G4endl;
429yystype G4UIparameter::UnaryExpression()
436 p = UnaryExpression();
452 result = UnaryExpression();
456 G4cerr <<
"Parameter range error: "
457 <<
"operator '!' is not supported (sorry)." <<
G4endl;
459 result = UnaryExpression();
462 result = PrimaryExpression();
468yystype G4UIparameter::PrimaryExpression()
494 result = Expression();
512 G4cerr << parameterName <<
": meaningless comparison " <<
G4int(arg1.
type) <<
" "
516 char type = (char)std::toupper(parameterType);
524 G4cerr <<
"integer operand expected for " << rangeExpression <<
'.' <<
G4endl;
532 G4cerr <<
"long int operand expected for " << rangeExpression <<
'.' <<
G4endl;
556 G4cerr <<
"integer operand expected for " << rangeExpression <<
'.' <<
G4endl;
564 G4cerr <<
"long int operand expected for " << rangeExpression <<
'.' <<
G4endl;
581 G4cerr <<
"no param name is specified at the param range." <<
G4endl;
592 while ((c = G4UIpGetc()) ==
' ' || c ==
'\t' || c ==
'\n') {
599 if ((isdigit(c) != 0) || c ==
'.') {
601 buf += (
unsigned char)c;
603 }
while (c ==
'.' || (isdigit(c) != 0) || c ==
'e' || c ==
'E' || c ==
'+' || c ==
'-');
606 std::istringstream is(t);
619 if ((isalpha(c) != 0) || c ==
'_') {
621 buf += (
unsigned char)c;
622 }
while ((c = G4UIpGetc()) != EOF && ((isalnum(c) != 0) || c ==
'_'));
624 if (buf == parameterName) {
653 G4int c = G4UIpGetc();
663G4int G4UIparameter::G4UIpGetc()
665 auto length = (
G4int)rangeExpression.length();
667 return rangeExpression[bp++];
679 if (bp > 0 && c == rangeExpression[bp - 1]) {
684 G4cerr <<
"bp=" << bp <<
" c=" << c <<
" pR(bp-1)=" << rangeExpression[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)
void SetDefaultUnit(const char *theDefaultUnit)
G4bool IsDouble(const char *str)
G4int CompareLong(G4long arg1, G4int op, G4long arg2, G4int &errCode)
G4int CompareDouble(G4double arg1, G4int op, G4double arg2, G4int &errCode)
G4bool IsInt(const char *str, short maxDigits)
G4int CompareInt(G4int arg1, G4int op, G4int arg2, G4int &errCode)