Geant4-11
G4UIparameter.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4UIparameter
27//
28// Author: Makoto Asai, 1997
29// --------------------------------------------------------------------
30
31#include "G4UIparameter.hh"
32#include "G4UIcommandStatus.hh"
33#include "G4Tokenizer.hh"
34#include "G4ios.hh"
35#include "G4UIcommand.hh"
36
37#include <sstream>
38#include <ctype.h> // for CheckNewValue()
39
40using namespace G4UItokenNum;
41
42// --------------------------------------------------------------------
44{
45}
46
47// --------------------------------------------------------------------
49{
50 parameterType = theType;
51}
52
53// --------------------------------------------------------------------
54G4UIparameter::G4UIparameter(const char* theName, char theType,
55 G4bool theOmittable)
56{
57 parameterName = theName;
58 parameterType = theType;
59 omittable = theOmittable;
60}
61
62// --------------------------------------------------------------------
64{
65}
66
67// --------------------------------------------------------------------
69{
70 return (this == &right);
71}
72
73// --------------------------------------------------------------------
75{
76 return (this != &right);
77}
78
79// --------------------------------------------------------------------
81{
82 G4cout << G4endl << "Parameter : " << parameterName << G4endl;
83 if(!parameterGuidance.empty())
85 G4cout << " Parameter type : " << parameterType << G4endl;
86 if(omittable)
87 {
88 G4cout << " Omittable : True" << G4endl;
89 }
90 else
91 {
92 G4cout << " Omittable : False" << G4endl;
93 }
95 {
96 G4cout << " Default value : taken from the current value" << G4endl;
97 }
98 else if(!defaultValue.empty())
99 {
100 G4cout << " Default value : " << defaultValue << G4endl;
101 }
102 if(!parameterRange.empty())
103 G4cout << " Parameter range : " << parameterRange << G4endl;
104 if(!parameterCandidate.empty())
105 G4cout << " Candidates : " << parameterCandidate << G4endl;
106}
107
108// --------------------------------------------------------------------
110{
111 std::ostringstream os;
112 os << theDefaultValue;
113 defaultValue = os.str();
114}
115
116// --------------------------------------------------------------------
118{
119 std::ostringstream os;
120 os << theDefaultValue;
121 defaultValue = os.str();
122}
123
124// --------------------------------------------------------------------
126{
127 std::ostringstream os;
128 os << theDefaultValue;
129 defaultValue = os.str();
130}
131
132// --------------------------------------------------------------------
133void G4UIparameter::SetDefaultUnit(const char* theDefaultUnit)
134{
135 char type = toupper(parameterType);
136 if(type != 'S')
137 {
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 ";
142 switch(type)
143 {
144 case 'D':
145 ed << "double.";
146 break;
147 case 'I':
148 ed << "integer.";
149 break;
150 case 'L':
151 ed << "long int.";
152 break;
153 case 'B':
154 ed << "bool.";
155 break;
156 default:
157 ed << "undefined.";
158 }
159 G4Exception("G4UIparameter::SetDefaultUnit", "INTERCOM2010", FatalException,
160 ed);
161 }
162 SetDefaultValue(theDefaultUnit);
165}
166
167// ---------- CheckNewValue() related routines ------------------------
168
169//#include "checkNewValue_debug.icc"
170//#define DEBUG 1
171
172// --------------------------------------------------------------------
174{
175 if(TypeCheck(newValue) == 0)
177 if(!parameterRange.empty())
178 {
179 if(RangeCheck(newValue) == 0)
181 }
182 if(!parameterCandidate.empty())
183 {
184 if(CandidateCheck(newValue) == 0)
186 }
187 return 0; // succeeded
188}
189
190// --------------------------------------------------------------------
192{
193 G4Tokenizer candidateTokenizer(parameterCandidate);
194 G4String aToken;
195 G4int iToken = 0;
196 while(!(aToken = candidateTokenizer()).empty())
197 {
198 ++iToken;
199 if(aToken == newValue)
200 return iToken;
201 }
202 G4cerr << "parameter value (" << newValue
203 << ") is not listed in the candidate List." << G4endl;
204 G4cerr << " Candidates are:";
205 G4Tokenizer candidateListTokenizer(parameterCandidate);
206 while(!(aToken = candidateListTokenizer()).empty())
207 {
208 G4cerr << ' ' << aToken;
209 }
210 G4cerr << G4endl;
211
212 return 0;
213}
214
215// --------------------------------------------------------------------
216G4int G4UIparameter::RangeCheck(const char* newValue)
217{
218 yystype result;
219 bp = 0; // reset buffer pointer for G4UIpGetc()
220 std::istringstream is(newValue);
221 char type = toupper(parameterType);
222 switch(type)
223 {
224 case 'D':
225 is >> newVal.D;
226 break;
227 case 'I':
228 is >> newVal.I;
229 break;
230 case 'L':
231 is >> newVal.L;
232 break;
233 default:;
234 }
235 // PrintToken(); // Print tokens (consumes all tokens)
236 token = Yylex();
237 result = Expression();
238 if(paramERR == 1) return 0;
239 if(result.type != CONSTINT)
240 {
241 G4cerr << "Illegal Expression in parameter range." << G4endl;
242 return 0;
243 }
244 if(result.I) return 1;
245 G4cerr << "parameter out of range: " << parameterRange << G4endl;
246 return 0;
247}
248
249// --------------------------------------------------------------------
250G4int G4UIparameter::TypeCheck(const char* newValue)
251{
252 G4String newValueString(newValue);
253 char type = toupper(parameterType);
254 switch(type)
255 {
256 case 'D':
257 if(IsDouble(newValueString.data()) == 0)
258 {
259 G4cerr << newValue << ": double value expected." << G4endl;
260 return 0;
261 }
262 break;
263 case 'I':
264 if(IsInt(newValueString.data(), 10) == 0)
265 {
266 G4cerr << newValue << ": integer expected." << G4endl;
267 return 0;
268 }
269 break;
270 case 'L':
271 if(IsInt(newValueString.data(), 20) == 0)
272 {
273 G4cerr << newValue << ": long int expected." << G4endl;
274 return 0;
275 }
276 break;
277 case 'S':
278 break;
279 case 'B':
280 G4StrUtil::to_upper(newValueString);
281 if(newValueString == "Y" || newValueString == "N" ||
282 newValueString == "YES" || newValueString == "NO" ||
283 newValueString == "1" || newValueString == "0" ||
284 newValueString == "T" || newValueString == "F" ||
285 newValueString == "TRUE" || newValueString == "FALSE")
286 return 1;
287 else
288 {
289 G4cerr << newValue << ": bool expected." << G4endl;
290 return 0;
291 }
292 default:;
293 }
294 return 1;
295}
296
297// --------------------------------------------------------------------
299 short maxDigits) // do not allow any std::ws
300{
301 const char* p = buf;
302 G4int length = 0;
303 if(*p == '+' || *p == '-')
304 {
305 ++p;
306 }
307 if(isdigit((G4int)(*p)))
308 {
309 while(isdigit((G4int)(*p)))
310 {
311 ++p;
312 ++length;
313 }
314 if(*p == '\0')
315 {
316 if(length > maxDigits)
317 {
318 G4cerr << "digit length exceeds" << G4endl;
319 return 0;
320 }
321 return 1;
322 }
323 else
324 {
325 // G4cerr <<"illegal character after int:"<<buf<<G4endl;
326 }
327 }
328 else
329 {
330 // G4cerr <<"illegal int:"<<buf<<G4endl;
331 }
332 return 0;
333}
334
335// --------------------------------------------------------------------
336G4int G4UIparameter::ExpectExponent(const char* str) // used only by IsDouble()
337{
338 G4int maxExplength;
339 if(IsInt(str, maxExplength = 7))
340 return 1;
341 else
342 return 0;
343}
344
345// --------------------------------------------------------------------
347 const char* buf) // see state diagram for this spec.
348{
349 const char* p = buf;
350 switch(*p)
351 {
352 case '+':
353 case '-':
354 ++p;
355 if(isdigit(*p))
356 {
357 while(isdigit((G4int)(*p)))
358 {
359 ++p;
360 }
361 switch(*p)
362 {
363 case '\0':
364 return 1; // break;
365 case 'E':
366 case 'e':
367 return ExpectExponent(++p); // break;
368 case '.':
369 ++p;
370 if(*p == '\0')
371 return 1;
372 if(*p == 'e' || *p == 'E')
373 return ExpectExponent(++p);
374 if(isdigit(*p))
375 {
376 while(isdigit((G4int)(*p)))
377 {
378 ++p;
379 }
380 if(*p == '\0')
381 return 1;
382 if(*p == 'e' || *p == 'E')
383 return ExpectExponent(++p);
384 }
385 else
386 return 0;
387 break;
388 default:
389 return 0;
390 }
391 }
392 if(*p == '.')
393 {
394 ++p;
395 if(isdigit(*p))
396 {
397 while(isdigit((G4int)(*p)))
398 {
399 ++p;
400 }
401 if(*p == '\0')
402 return 1;
403 if(*p == 'e' || *p == 'E')
404 return ExpectExponent(++p);
405 }
406 }
407 break;
408 case '.':
409 ++p;
410 if(isdigit(*p))
411 {
412 while(isdigit((G4int)(*p)))
413 {
414 ++p;
415 }
416 if(*p == '\0')
417 return 1;
418 if(*p == 'e' || *p == 'E')
419 return ExpectExponent(++p);
420 }
421 break;
422 default: // digit is expected
423 if(isdigit(*p))
424 {
425 while(isdigit((G4int)(*p)))
426 {
427 ++p;
428 }
429 if(*p == '\0')
430 return 1;
431 if(*p == 'e' || *p == 'E')
432 return ExpectExponent(++p);
433 if(*p == '.')
434 {
435 ++p;
436 if(*p == '\0')
437 return 1;
438 if(*p == 'e' || *p == 'E')
439 return ExpectExponent(++p);
440 if(isdigit(*p))
441 {
442 while(isdigit((G4int)(*p)))
443 {
444 ++p;
445 }
446 if(*p == '\0')
447 return 1;
448 if(*p == 'e' || *p == 'E')
449 return ExpectExponent(++p);
450 }
451 }
452 }
453 }
454 return 0;
455}
456
457// ------------------ syntax node functions ------------------
458
460{
461 yystype result;
462#ifdef DEBUG
463 G4cerr << " Expression()" << G4endl;
464#endif
465 result = LogicalORExpression();
466 return result;
467}
468
469// --------------------------------------------------------------------
471{
472 yystype result;
473 yystype p;
475 if(token != LOGICALOR)
476 return p;
477 if(p.type == CONSTSTRING || p.type == IDENTIFIER)
478 {
479 G4cerr << "Parameter range: illegal type at '||'" << G4endl;
480 paramERR = 1;
481 }
482 result.I = p.I;
483 while(token == LOGICALOR)
484 {
485 token = Yylex();
487 if(p.type == CONSTSTRING || p.type == IDENTIFIER)
488 {
489 G4cerr << "Parameter range: illegal type at '||'" << G4endl;
490 paramERR = 1;
491 }
492 switch(p.type)
493 {
494 case CONSTINT:
495 result.I += p.I;
496 result.type = CONSTINT;
497 break;
498 case CONSTLONG:
499 result.I += (p.L != 0L);
500 result.type = CONSTINT;
501 break;
502 case CONSTDOUBLE:
503 result.I += (p.D != 0.0);
504 result.type = CONSTINT;
505 break;
506 default:
507 G4cerr << "Parameter range: unknown type" << G4endl;
508 paramERR = 1;
509 }
510 }
511 return result;
512}
513
514// --------------------------------------------------------------------
516{
517 yystype result;
518 yystype p;
519 p = EqualityExpression();
520 if(token != LOGICALAND)
521 return p;
522 if(p.type == CONSTSTRING || p.type == IDENTIFIER)
523 {
524 G4cerr << "Parameter range: illegal type at '&&'" << G4endl;
525 paramERR = 1;
526 }
527 result.I = p.I;
528 while(token == LOGICALAND)
529 {
530 token = Yylex();
531 p = EqualityExpression();
532 if(p.type == CONSTSTRING || p.type == IDENTIFIER)
533 {
534 G4cerr << "Parameter range: illegal type at '&&'" << G4endl;
535 paramERR = 1;
536 }
537 switch(p.type)
538 {
539 case CONSTINT:
540 result.I *= p.I;
541 result.type = CONSTINT;
542 break;
543 case CONSTLONG:
544 result.I *= (p.L != 0L);
545 result.type = CONSTINT;
546 break;
547 case CONSTDOUBLE:
548 result.I *= (p.D != 0.0);
549 result.type = CONSTINT;
550 break;
551 default:
552 G4cerr << "Parameter range: unknown type." << G4endl;
553 paramERR = 1;
554 }
555 }
556 return result;
557}
558
559// --------------------------------------------------------------------
561{
562 yystype arg1, arg2;
563 G4int operat;
564 yystype result;
565#ifdef DEBUG
566 G4cerr << " EqualityExpression()" << G4endl;
567#endif
568 result = RelationalExpression();
569 if(token == EQ || token == NE)
570 {
571 operat = token;
572 token = Yylex();
573 arg1 = result;
574 arg2 = RelationalExpression();
575 result.I = Eval2(arg1, operat, arg2); // semantic action
576 result.type = CONSTINT;
577#ifdef DEBUG
578 G4cerr << " return code of Eval2(): " << result.I << G4endl;
579#endif
580 }
581 else
582 {
583 if(result.type != CONSTINT && result.type != CONSTDOUBLE)
584 {
585 G4cerr << "Parameter range: error at EqualityExpression" << G4endl;
586 paramERR = 1;
587 }
588 }
589 return result;
590}
591
592// --------------------------------------------------------------------
594{
595 yystype arg1, arg2;
596 G4int operat;
597 yystype result;
598#ifdef DEBUG
599 G4cerr << " RelationalExpression()" << G4endl;
600#endif
601
602 arg1 = AdditiveExpression();
603 if(token == GT || token == GE || token == LT || token == LE)
604 {
605 operat = token;
606 token = Yylex();
607 arg2 = AdditiveExpression();
608 result.I = Eval2(arg1, operat, arg2); // semantic action
609 result.type = CONSTINT;
610#ifdef DEBUG
611 G4cerr << " return Eval2(): " << G4endl;
612#endif
613 }
614 else
615 {
616 result = arg1;
617 }
618#ifdef DEBUG
619 G4cerr << " return RelationalExpression()" << G4endl;
620#endif
621 return result;
622}
623
624// --------------------------------------------------------------------
626{
627 yystype result;
628 result = MultiplicativeExpression();
629 if(token != '+' && token != '-')
630 return result;
631 G4cerr << "Parameter range: operator " << (char) token << " is not supported."
632 << G4endl;
633 paramERR = 1;
634 return result;
635}
636
637// --------------------------------------------------------------------
639{
640 yystype result;
641 result = UnaryExpression();
642 if(token != '*' && token != '/' && token != '%')
643 return result;
644 G4cerr << "Parameter range: operator " << (char) token << " is not supported."
645 << G4endl;
646 paramERR = 1;
647 return result;
648}
649
650// --------------------------------------------------------------------
652{
653 yystype result;
654 yystype p;
655#ifdef DEBUG
656 G4cerr << " UnaryExpression" << G4endl;
657#endif
658 switch(token)
659 {
660 case '-':
661 token = Yylex();
662 p = UnaryExpression();
663 if(p.type == CONSTINT)
664 {
665 result.I = -p.I;
666 result.type = CONSTINT;
667 }
668 if(p.type == CONSTLONG)
669 {
670 result.L = -p.L;
671 result.type = CONSTLONG;
672 }
673 if(p.type == CONSTDOUBLE)
674 {
675 result.D = -p.D;
676 result.type = CONSTDOUBLE;
677 }
678 break;
679 case '+':
680 token = Yylex();
681 result = UnaryExpression();
682 break;
683 case '!':
684 token = Yylex();
685 G4cerr << "Parameter range error: "
686 << "operator '!' is not supported (sorry)." << G4endl;
687 paramERR = 1;
688 result = UnaryExpression();
689 break;
690 default:
691 result = PrimaryExpression();
692 }
693 return result;
694}
695
696// --------------------------------------------------------------------
698{
699 yystype result;
700#ifdef DEBUG
701 G4cerr << " PrimaryExpression" << G4endl;
702#endif
703 switch(token)
704 {
705 case IDENTIFIER:
706 result.S = yylval.S;
707 result.type = token;
708 token = Yylex();
709 break;
710 case CONSTINT:
711 result.I = yylval.I;
712 result.type = token;
713 token = Yylex();
714 break;
715 case CONSTLONG:
716 result.L = yylval.L;
717 result.type = token;
718 token = Yylex();
719 break;
720 case CONSTDOUBLE:
721 result.D = yylval.D;
722 result.type = token;
723 token = Yylex();
724 break;
725 case '(':
726 token = Yylex();
727 result = Expression();
728 if(token != ')')
729 {
730 G4cerr << " ')' expected" << G4endl;
731 paramERR = 1;
732 }
733 token = Yylex();
734 break;
735 default:
736 return result;
737 }
738 return result; // never executed
739}
740
741//---------------- semantic routines ---------------------------------
742
744{
745 if((arg1.type != IDENTIFIER) && (arg2.type != IDENTIFIER))
746 {
747 G4cerr << parameterName << ": meaningless comparison " << G4int(arg1.type)
748 << " " << G4int(arg2.type) << G4endl;
749 paramERR = 1;
750 }
751 char type = toupper(parameterType);
752 if(arg1.type == IDENTIFIER)
753 {
754 switch(type)
755 {
756 case 'I':
757 if(arg2.type == CONSTINT)
758 {
759 return CompareInt(newVal.I, op, arg2.I);
760 }
761 else
762 {
763 G4cerr << "integer operand expected for " << parameterRange << '.'
764 << G4endl;
765 }
766 break;
767 case 'L':
768 if(arg2.type == CONSTLONG)
769 {
770 return CompareLong(newVal.L, op, arg2.L);
771 }
772 else
773 {
774 G4cerr << "long int operand expected for " << parameterRange << '.'
775 << G4endl;
776 }
777 break;
778 case 'D':
779 if(arg2.type == CONSTDOUBLE)
780 {
781 return CompareDouble(newVal.D, op, arg2.D);
782 }
783 else if(arg2.type == CONSTINT)
784 { // integral promotion
785 return CompareDouble(newVal.D, op, arg2.I);
786 }
787 else if(arg2.type == CONSTLONG)
788 {
789 return CompareDouble(newVal.D, op, arg2.L);
790 }
791 break;
792 default:;
793 }
794 }
795 if(arg2.type == IDENTIFIER)
796 {
797 switch(type)
798 {
799 case 'I':
800 if(arg1.type == CONSTINT)
801 {
802 return CompareInt(arg1.I, op, newVal.I);
803 }
804 else
805 {
806 G4cerr << "integer operand expected for " << parameterRange << '.'
807 << G4endl;
808 }
809 break;
810 case 'L':
811 if(arg1.type == CONSTLONG)
812 {
813 return CompareLong(arg1.L, op, newVal.L);
814 }
815 else
816 {
817 G4cerr << "long int operand expected for " << parameterRange << '.'
818 << G4endl;
819 }
820 break;
821 case 'D':
822 if(arg1.type == CONSTDOUBLE)
823 {
824 return CompareDouble(arg1.D, op, newVal.D);
825 }
826 else if(arg1.type == CONSTINT)
827 { // integral promotion
828 return CompareDouble(arg1.I, op, newVal.D);
829 }
830 else if(arg1.type == CONSTLONG)
831 { // integral promotion
832 return CompareDouble(arg1.L, op, newVal.D);
833 }
834 break;
835 default:;
836 }
837 }
838 G4cerr << "no param name is specified at the param range." << G4endl;
839 return 0;
840}
841
842// --------------------------------------------------------------------
844{
845 G4int result = -1;
846 G4String opr;
847 switch(op)
848 {
849 case GT:
850 result = (arg1 > arg2);
851 opr = ">";
852 break;
853 case GE:
854 result = (arg1 >= arg2);
855 opr = ">=";
856 break;
857 case LT:
858 result = (arg1 < arg2);
859 opr = "<";
860 break;
861 case LE:
862 result = (arg1 <= arg2);
863 opr = "<=";
864 break;
865 case EQ:
866 result = (arg1 == arg2);
867 opr = "==";
868 break;
869 case NE:
870 result = (arg1 != arg2);
871 opr = "!=";
872 break;
873 default:
874 G4cerr << "Parameter range: error at CompareInt" << G4endl;
875 paramERR = 1;
876 }
877#ifdef DEBUG
878 G4cerr << "CompareInt " << arg1 << " " << opr << arg2 << " result: " << result
879 << G4endl;
880#endif
881 return result;
882}
883
884// --------------------------------------------------------------------
886{
887 G4int result = -1;
888 G4String opr;
889 switch(op)
890 {
891 case GT:
892 result = (arg1 > arg2);
893 opr = ">";
894 break;
895 case GE:
896 result = (arg1 >= arg2);
897 opr = ">=";
898 break;
899 case LT:
900 result = (arg1 < arg2);
901 opr = "<";
902 break;
903 case LE:
904 result = (arg1 <= arg2);
905 opr = "<=";
906 break;
907 case EQ:
908 result = (arg1 == arg2);
909 opr = "==";
910 break;
911 case NE:
912 result = (arg1 != arg2);
913 opr = "!=";
914 break;
915 default:
916 G4cerr << "Parameter range: error at CompareInt" << G4endl;
917 paramERR = 1;
918 }
919#ifdef DEBUG
920 G4cerr << "CompareInt " << arg1 << " " << opr << arg2 << " result: " << result
921 << G4endl;
922#endif
923 return result;
924}
925
926// --------------------------------------------------------------------
928{
929 G4int result = -1;
930 G4String opr;
931 switch(op)
932 {
933 case GT:
934 result = (arg1 > arg2);
935 opr = ">";
936 break;
937 case GE:
938 result = (arg1 >= arg2);
939 opr = ">=";
940 break;
941 case LT:
942 result = (arg1 < arg2);
943 opr = "<";
944 break;
945 case LE:
946 result = (arg1 <= arg2);
947 opr = "<=";
948 break;
949 case EQ:
950 result = (arg1 == arg2);
951 opr = "==";
952 break;
953 case NE:
954 result = (arg1 != arg2);
955 opr = "!=";
956 break;
957 default:
958 G4cerr << "Parameter range: error at CompareDouble" << G4endl;
959 paramERR = 1;
960 }
961#ifdef DEBUG
962 G4cerr << "CompareDouble " << arg1 << " " << opr << " " << arg2
963 << " result: " << result << G4endl;
964#endif
965 return result;
966}
967
968// --------------------- utility functions --------------------------
969
970tokenNum G4UIparameter::Yylex() // reads input and returns token number KR486
971{ // (returns EOF)
972 G4int c;
973 G4String buf;
974
975 while((c = G4UIpGetc()) == ' ' || c == '\t' || c == '\n')
976 ;
977 if(c == EOF)
978 return (tokenNum) EOF; // KR488
979 buf = "";
980 if(isdigit(c) || c == '.')
981 { // I or D
982 do
983 {
984 buf += (unsigned char) c;
985 c = G4UIpGetc();
986 } while(c == '.' || isdigit(c) || c == 'e' || c == 'E' || c == '+' ||
987 c == '-');
988 G4UIpUngetc(c);
989 const char* t = buf;
990 std::istringstream is(t);
991 if(IsInt(buf.data(), 20))
992 {
993 is >> yylval.I;
994 return CONSTINT;
995 }
996 else if(IsDouble(buf.data()))
997 {
998 is >> yylval.D;
999 return CONSTDOUBLE;
1000 }
1001 else
1002 {
1003 G4cerr << buf << ": numeric format error." << G4endl;
1004 }
1005 }
1006 buf = "";
1007 if(isalpha(c) || c == '_')
1008 { // IDENTIFIER
1009 do
1010 {
1011 buf += (unsigned char) c;
1012 } while((c = G4UIpGetc()) != EOF && (isalnum(c) || c == '_'));
1013 G4UIpUngetc(c);
1014 if(buf == parameterName)
1015 {
1016 yylval.S = buf;
1017 return IDENTIFIER;
1018 }
1019 else
1020 {
1021 G4cerr << buf << " is not a parameter name." << G4endl;
1022 paramERR = 1;
1023 }
1024 }
1025 switch(c)
1026 {
1027 case '>':
1028 return (tokenNum) Follow('=', GE, GT);
1029 case '<':
1030 return (tokenNum) Follow('=', LE, LT);
1031 case '=':
1032 return (tokenNum) Follow('=', EQ, '=');
1033 case '!':
1034 return (tokenNum) Follow('=', NE, '!');
1035 case '|':
1036 return (tokenNum) Follow('|', LOGICALOR, '|');
1037 case '&':
1038 return (tokenNum) Follow('&', LOGICALAND, '&');
1039 default:
1040 return (tokenNum) c;
1041 }
1042}
1043
1044// --------------------------------------------------------------------
1046{
1047 G4int c = G4UIpGetc();
1048 if(c == expect)
1049 return ifyes;
1050 G4UIpUngetc(c);
1051 return ifno;
1052}
1053
1054//------------------ low level routines -----------------------------
1055
1057{ // emulation of getc()
1058 G4int length = parameterRange.length();
1059 if(bp < length)
1060 return parameterRange[bp++];
1061 else
1062 return EOF;
1063}
1064
1065// --------------------------------------------------------------------
1067{ // emulation of ungetc()
1068 if(c < 0)
1069 return -1;
1070 if(bp > 0 && c == parameterRange[bp - 1])
1071 {
1072 --bp;
1073 }
1074 else
1075 {
1076 G4cerr << "G4UIpUngetc() failed." << G4endl;
1077 G4cerr << "bp=" << bp << " c=" << c
1078 << " pR(bp-1)=" << parameterRange[bp - 1] << G4endl;
1079 paramERR = 1;
1080 return -1;
1081 }
1082 return 0;
1083}
1084// ***** end of CheckNewValue() related code ******
@ GT
Definition: Evaluator.cc:65
@ LT
Definition: Evaluator.cc:65
@ NE
Definition: Evaluator.cc:65
@ GE
Definition: Evaluator.cc:65
@ LE
Definition: Evaluator.cc:65
@ EQ
Definition: Evaluator.cc:65
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
static constexpr double L
Definition: G4SIunits.hh:104
double G4double
Definition: G4Types.hh:83
long G4long
Definition: G4Types.hh:87
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
@ fParameterOutOfCandidates
@ fParameterUnreadable
@ fParameterOutOfRange
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:371
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:377
void SetDefaultValue(const char *theDefaultValue)
G4int CheckNewValue(const char *newValue)
G4String defaultValue
yystype PrimaryExpression(void)
G4int CompareInt(G4int arg1, G4int op, G4int arg2)
yystype AdditiveExpression(void)
G4int CandidateCheck(const char *newValue)
G4String parameterRange
G4int TypeCheck(const char *newValue)
G4int RangeCheck(const char *newValue)
G4int CompareDouble(double arg1, G4int op, double arg2)
G4bool currentAsDefaultFlag
G4int Follow(G4int expect, G4int ifyes, G4int ifno)
yystype MultiplicativeExpression(void)
G4String parameterGuidance
G4int ExpectExponent(const char *str)
G4String parameterCandidate
G4int CompareLong(G4long arg1, G4int op, G4long arg2)
yystype RelationalExpression(void)
yystype EqualityExpression(void)
yystype Expression(void)
tokenNum Yylex(void)
G4int Eval2(yystype arg1, G4int op, yystype arg2)
G4int G4UIpGetc(void)
void SetParameterCandidates(const char *theString)
yystype LogicalANDExpression(void)
G4bool operator!=(const G4UIparameter &right) const
G4String parameterName
G4int IsInt(const char *str, short maxDigit)
yystype LogicalORExpression(void)
G4bool operator==(const G4UIparameter &right) const
G4int G4UIpUngetc(G4int c)
G4int IsDouble(const char *str)
yystype UnaryExpression(void)
void SetDefaultUnit(const char *theDefaultUnit)
void to_upper(G4String &str)
Convert string to uppercase.