Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UIparsing Namespace Reference

Functions

template<typename T >
StoT (const G4String &s)
 
template<typename T >
G4String TtoS (T value)
 
G4bool ChkMax (const char *str, short maxDigits)
 
G4bool IsInt (const char *str, short maxDigits)
 
G4bool ExpectExponent (const char *str)
 
G4bool IsDouble (const char *str)
 
G4int CompareInt (G4int arg1, G4int op, G4int arg2, G4int &errCode)
 
G4int CompareLong (G4long arg1, G4int op, G4long arg2, G4int &errCode)
 
G4int CompareDouble (G4double arg1, G4int op, G4double arg2, G4int &errCode)
 

Function Documentation

◆ ChkMax()

G4bool G4UIparsing::ChkMax ( const char * str,
short maxDigits )
inline

Definition at line 60 of file G4UIparsing.hh.

61{
62 if(maxDigits > 10) {
63 // long int assumed
64 auto tmpval = std::stoll(str);
65 if(tmpval > LONG_MAX || tmpval < LONG_MIN) {
66 G4cerr << "input string '" << str << "' out-of-range for conversion to 'long int' value" << G4endl;
67 return false;
68 }
69 } else {
70 // int assumed
71 auto tmpval = std::stol(str);
72 if(tmpval > INT_MAX || tmpval < INT_MIN) {
73 G4cerr << "input string '" << str << "' out-of-range for conversion to 'int' value" << G4endl;
74 return false;
75 }
76 }
77 return true;
78}
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
#define INT_MIN
Definition templates.hh:94
#define INT_MAX
Definition templates.hh:90

Referenced by IsInt().

◆ CompareDouble()

G4int G4UIparsing::CompareDouble ( G4double arg1,
G4int op,
G4double arg2,
G4int & errCode )
inline

Definition at line 282 of file G4UIparsing.hh.

283{
284 G4int result = -1;
285 switch (op) {
286 case G4UItokenNum::GT:
287 result = static_cast<G4int>(arg1 > arg2);
288 break;
289 case G4UItokenNum::GE:
290 result = static_cast<G4int>(arg1 >= arg2);
291 break;
292 case G4UItokenNum::LT:
293 result = static_cast<G4int>(arg1 < arg2);
294 break;
295 case G4UItokenNum::LE:
296 result = static_cast<G4int>(arg1 <= arg2);
297 break;
298 case G4UItokenNum::EQ:
299 result = static_cast<G4int>(arg1 == arg2);
300 break;
301 case G4UItokenNum::NE:
302 result = static_cast<G4int>(arg1 != arg2);
303 break;
304 default:
305 G4cerr << "Parameter range: error at CompareDouble" << G4endl;
306 errCode = 1;
307 }
308 return result;
309}
int G4int
Definition G4Types.hh:85

◆ CompareInt()

G4int G4UIparsing::CompareInt ( G4int arg1,
G4int op,
G4int arg2,
G4int & errCode )
inline

Definition at line 222 of file G4UIparsing.hh.

223{
224 G4int result = -1;
225 switch (op) {
226 case G4UItokenNum::GT:
227 result = static_cast<G4int>(arg1 > arg2);
228 break;
229 case G4UItokenNum::GE:
230 result = static_cast<G4int>(arg1 >= arg2);
231 break;
232 case G4UItokenNum::LT:
233 result = static_cast<G4int>(arg1 < arg2);
234 break;
235 case G4UItokenNum::LE:
236 result = static_cast<G4int>(arg1 <= arg2);
237 break;
238 case G4UItokenNum::EQ:
239 result = static_cast<G4int>(arg1 == arg2);
240 break;
241 case G4UItokenNum::NE:
242 result = static_cast<G4int>(arg1 != arg2);
243 break;
244 default:
245 G4cerr << "Parameter range: error at CompareInt" << G4endl;
246 errCode = 1;
247 }
248 return result;
249}

◆ CompareLong()

G4int G4UIparsing::CompareLong ( G4long arg1,
G4int op,
G4long arg2,
G4int & errCode )
inline

Definition at line 252 of file G4UIparsing.hh.

253{
254 G4int result = -1;
255 switch (op) {
256 case G4UItokenNum::GT:
257 result = static_cast<G4int>(arg1 > arg2);
258 break;
259 case G4UItokenNum::GE:
260 result = static_cast<G4int>(arg1 >= arg2);
261 break;
262 case G4UItokenNum::LT:
263 result = static_cast<G4int>(arg1 < arg2);
264 break;
265 case G4UItokenNum::LE:
266 result = static_cast<G4int>(arg1 <= arg2);
267 break;
268 case G4UItokenNum::EQ:
269 result = static_cast<G4int>(arg1 == arg2);
270 break;
271 case G4UItokenNum::NE:
272 result = static_cast<G4int>(arg1 != arg2);
273 break;
274 default:
275 G4cerr << "Parameter range: error at CompareInt" << G4endl;
276 errCode = 1;
277 }
278 return result;
279}

◆ ExpectExponent()

G4bool G4UIparsing::ExpectExponent ( const char * str)
inline

Definition at line 107 of file G4UIparsing.hh.

108{
109 return IsInt(str, 7);
110}
G4bool IsInt(const char *str, short maxDigits)

Referenced by IsDouble().

◆ IsDouble()

G4bool G4UIparsing::IsDouble ( const char * str)
inline

Definition at line 112 of file G4UIparsing.hh.

113{
114 const char* p = str;
115 switch (*p) {
116 case '+':
117 case '-':
118 ++p;
119 if (isdigit(*p) != 0) {
120 while (isdigit((G4int)(*p)) != 0) {
121 ++p;
122 }
123 switch (*p) {
124 case '\0':
125 return true; // break;
126 case 'E':
127 case 'e':
128 return ExpectExponent(++p); // break;
129 case '.':
130 ++p;
131 if (*p == '\0') {
132 return true;
133 }
134 if (*p == 'e' || *p == 'E') {
135 return ExpectExponent(++p);
136 }
137 if (isdigit(*p) != 0) {
138 while (isdigit((G4int)(*p)) != 0) {
139 ++p;
140 }
141 if (*p == '\0') {
142 return true;
143 }
144 if (*p == 'e' || *p == 'E') {
145 return ExpectExponent(++p);
146 }
147 }
148 else {
149 return false;
150 }
151 break;
152 default:
153 return false;
154 }
155 }
156 if (*p == '.') {
157 ++p;
158 if (isdigit(*p) != 0) {
159 while (isdigit((G4int)(*p)) != 0) {
160 ++p;
161 }
162 if (*p == '\0') {
163 return true;
164 }
165 if (*p == 'e' || *p == 'E') {
166 return ExpectExponent(++p);
167 }
168 }
169 }
170 break;
171 case '.':
172 ++p;
173 if (isdigit(*p) != 0) {
174 while (isdigit((G4int)(*p)) != 0) {
175 ++p;
176 }
177 if (*p == '\0') {
178 return true;
179 }
180 if (*p == 'e' || *p == 'E') {
181 return ExpectExponent(++p);
182 }
183 }
184 break;
185 default: // digit is expected
186 if (isdigit(*p) != 0) {
187 while (isdigit((G4int)(*p)) != 0) {
188 ++p;
189 }
190 if (*p == '\0') {
191 return true;
192 }
193 if (*p == 'e' || *p == 'E') {
194 return ExpectExponent(++p);
195 }
196 if (*p == '.') {
197 ++p;
198 if (*p == '\0') {
199 return true;
200 }
201 if (*p == 'e' || *p == 'E') {
202 return ExpectExponent(++p);
203 }
204 if (isdigit(*p) != 0) {
205 while (isdigit((G4int)(*p)) != 0) {
206 ++p;
207 }
208 if (*p == '\0') {
209 return true;
210 }
211 if (*p == 'e' || *p == 'E') {
212 return ExpectExponent(++p);
213 }
214 }
215 }
216 }
217 }
218 return false;
219}
G4bool ExpectExponent(const char *str)

◆ IsInt()

G4bool G4UIparsing::IsInt ( const char * str,
short maxDigits )
inline

Definition at line 81 of file G4UIparsing.hh.

82{
83 const char* p = str;
84 G4int length = 0;
85 if (*p == '+' || *p == '-') {
86 ++p;
87 }
88 if (isdigit((G4int)(*p)) != 0) {
89 while (isdigit((G4int)(*p)) != 0) {
90 ++p;
91 ++length;
92 }
93 if (*p == '\0') {
94 if (length > maxDigits) {
95 G4cerr << "digit length exceeds" << G4endl;
96 return false;
97 }
98 return ChkMax(str,maxDigits);
99 }
100 }
101 return false;
102}
G4bool ChkMax(const char *str, short maxDigits)

Referenced by ExpectExponent().

◆ StoT()

template<typename T >
T G4UIparsing::StoT ( const G4String & s)
inline

Definition at line 42 of file G4UIparsing.hh.

43{
44 T vl;
45 std::istringstream is(s);
46 is >> vl;
47 return vl;
48}

Referenced by G4UIcommand::ConvertToDouble(), G4UIcommand::ConvertToInt(), G4UIcommand::ConvertToLongInt(), G4UImessenger::StoD(), G4UImessenger::StoI(), and G4UImessenger::StoL().

◆ TtoS()

template<typename T >
G4String G4UIparsing::TtoS ( T value)
inline

Definition at line 52 of file G4UIparsing.hh.

53{
54 std::ostringstream os;
55 os << value;
56 return os.str();
57}

Referenced by G4UIcommand::ConvertToString(), G4UIcommand::ConvertToString(), G4UIparameter::SetDefaultValue(), G4UIparameter::SetDefaultValue(), and G4UIparameter::SetDefaultValue().