56 : toBeBroadcasted(tBB)
57 , messenger(theMessenger)
62 if(comStr(comStr.length() - 1) !=
'/')
65 G4cerr <<
" <" << theCommandPath <<
"> must be a directory." <<
G4endl;
70 G4UIcommandCommonConstructorCode(comStr);
72 availabelStateList.clear();
82void G4UIcommand::G4UIcommandCommonConstructorCode(
const char* theCommandPath)
84 commandPath = theCommandPath;
85 commandName = theCommandPath;
86 G4int commandNameIndex = commandName.
last(
'/');
87 commandName.
remove(0, commandNameIndex + 1);
113 G4int n_parameterEntry = parameter.size();
114 for(
G4int i_thParameter = 0; i_thParameter < n_parameterEntry;
117 delete parameter[i_thParameter];
138 G4int n_parameterEntry = parameter.size();
139 if(n_parameterEntry != 0)
144 for(
G4int i_thParameter = 0; i_thParameter < n_parameterEntry;
147 if(i_thParameter > 0)
149 correctParameters.
append(
" ");
151 aToken = parameterToken();
152 if(aToken.length() > 0 && aToken(0) ==
'"')
154 while(aToken(aToken.length() - 1) !=
'"' ||
155 (aToken.length() == 1 && aToken(0) ==
'"'))
157 G4String additionalToken = parameterToken();
158 if(additionalToken.
isNull())
163 aToken += additionalToken;
166 else if(i_thParameter == n_parameterEntry - 1 &&
167 parameter[i_thParameter]->GetParameterType() ==
's')
170 while(!((anotherToken = parameterToken()).isNull()))
173 if(idxs ==
G4int(std::string::npos))
176 aToken += anotherToken;
181 aToken += anotherToken(0, idxs);
191 if(aToken.
isNull() || aToken ==
"!")
193 if(parameter[i_thParameter]->IsOmittable())
195 if(parameter[i_thParameter]->GetCurrentAsDefault())
199 for(
G4int ii = 0; ii < i_thParameter; ++ii)
204 while(parVal(parVal.length() - 1) !=
'"')
207 if(additionalToken.
isNull())
212 parVal += additionalToken;
217 if(aCVToken(0) ==
'"')
219 while(aCVToken(aCVToken.length() - 1) !=
'"')
222 if(additionalToken.
isNull())
227 aCVToken += additionalToken;
231 correctParameters.
append(aCVToken);
236 parameter[i_thParameter]->GetDefaultValue());
246 G4int stat = parameter[i_thParameter]->CheckNewValue(aToken);
248 return stat + i_thParameter;
249 correctParameters.
append(aToken);
275 availabelStateList.clear();
276 availabelStateList.push_back(s1);
283 availabelStateList.clear();
284 availabelStateList.push_back(s1);
285 availabelStateList.push_back(s2);
293 availabelStateList.clear();
294 availabelStateList.push_back(s1);
295 availabelStateList.push_back(s2);
296 availabelStateList.push_back(s3);
305 availabelStateList.clear();
306 availabelStateList.push_back(s1);
307 availabelStateList.push_back(s2);
308 availabelStateList.push_back(s3);
309 availabelStateList.push_back(s4);
319 availabelStateList.clear();
320 availabelStateList.push_back(s1);
321 availabelStateList.push_back(s2);
322 availabelStateList.push_back(s3);
323 availabelStateList.push_back(s4);
324 availabelStateList.push_back(s5);
334 G4int nState = availabelStateList.size();
335 for(
G4int i = 0; i < nState; ++i)
337 if(availabelStateList[i] == currentState)
367 for(i = 0; i < UTbl.size(); ++i)
369 if(UTbl[i]->GetName() == unitCategory)
374 G4cerr <<
"Unit category <" << unitCategory <<
"> is not defined."
379 retStr = UCnt[0]->GetSymbol();
380 G4int je = UCnt.size();
381 for(
G4int j = 1; j < je; ++j)
384 retStr += UCnt[j]->GetSymbol();
386 for(
G4int k = 0; k < je; ++k)
389 retStr += UCnt[k]->GetName();
399 if(commandPath(commandPath.length() - 1) !=
'/')
405 G4cout <<
" ---- available only in worker thread" <<
G4endl;
408 G4int n_guidanceEntry = commandGuidance.size();
409 for(
G4int i_thGuidance = 0; i_thGuidance < n_guidanceEntry; ++i_thGuidance)
415 G4cout <<
" Range of parameters : " << rangeString <<
G4endl;
417 G4int n_parameterEntry = parameter.size();
418 if(n_parameterEntry > 0)
420 for(
G4int i_thParameter = 0; i_thParameter < n_parameterEntry;
423 parameter[i_thParameter]->List();
441 std::ostringstream os;
450 std::ostringstream os;
459 std::ostringstream os;
462 os << std::setprecision(17) << doubleValue;
474 const char* unitName)
479 std::ostringstream os;
482 os << std::setprecision(17) << doubleValue / uv <<
" " << unitName;
486 os << doubleValue / uv <<
" " << unitName;
495 std::ostringstream os;
498 os << std::setprecision(17) << vec.
x() <<
" " << vec.
y() <<
" " << vec.
z();
502 os << vec.
x() <<
" " << vec.
y() <<
" " << vec.
z();
514 std::ostringstream os;
517 os << std::setprecision(17) << vec.
x() / uv <<
" " << vec.
y() / uv <<
" "
518 << vec.
z() / uv <<
" " << unitName;
522 os << vec.
x() / uv <<
" " << vec.
y() / uv <<
" " << vec.
z() / uv <<
" "
535 if(v ==
"Y" || v ==
"YES" || v ==
"1" || v ==
"T" || v ==
"TRUE")
546 std::istringstream is(st);
555 std::istringstream is(st);
564 std::istringstream is(st);
575 std::istringstream is(st);
588 std::istringstream is(st);
589 is >> vx >> vy >> vz;
600 std::istringstream is(st);
601 is >> vx >> vy >> vz >> unts;
617 if(RangeCheck(newValue) == 0)
624G4int G4UIcommand::TypeCheck(
const char* t)
628 std::istringstream is(t);
629 for(
unsigned i = 0; i < parameter.size(); ++i)
632 type = toupper(parameter[i]->GetParameterType());
636 if(IsDouble(aNewValue) == 0)
638 G4cerr << aNewValue <<
": double value expected." <<
G4endl;
643 if(IsInt(aNewValue, 10) == 0)
650 if(IsInt(aNewValue, 20) == 0)
652 G4cerr << aNewValue <<
": long int expected." <<
G4endl;
660 if(aNewValue ==
"Y" || aNewValue ==
"N" || aNewValue ==
"YES" ||
661 aNewValue ==
"NO" || aNewValue ==
"1" || aNewValue ==
"0" ||
662 aNewValue ==
"T" || aNewValue ==
"F" || aNewValue ==
"TRUE" ||
663 aNewValue ==
"FALSE")
675G4int G4UIcommand::IsInt(
const char* buf,
short maxDigits)
679 if(*p ==
'+' || *p ==
'-')
683 if(isdigit((
G4int)(*p)))
685 while(isdigit((
G4int)(*p)))
692 if(length > maxDigits)
712G4int G4UIcommand::ExpectExponent(
const char* str)
715 if(IsInt(str, maxExplength = 7))
722G4int G4UIcommand::IsDouble(
const char* buf)
732 while(isdigit((
G4int)(*p)))
743 return ExpectExponent(++p);
749 if(*p ==
'e' || *p ==
'E')
750 return ExpectExponent(++p);
753 while(isdigit((
G4int)(*p)))
759 if(*p ==
'e' || *p ==
'E')
760 return ExpectExponent(++p);
774 while(isdigit((
G4int)(*p)))
780 if(*p ==
'e' || *p ==
'E')
781 return ExpectExponent(++p);
789 while(isdigit((
G4int)(*p)))
795 if(*p ==
'e' || *p ==
'E')
796 return ExpectExponent(++p);
802 while(isdigit((
G4int)(*p)))
808 if(*p ==
'e' || *p ==
'E')
809 return ExpectExponent(++p);
815 if(*p ==
'e' || *p ==
'E')
816 return ExpectExponent(++p);
819 while(isdigit((
G4int)(*p)))
825 if(*p ==
'e' || *p ==
'E')
826 return ExpectExponent(++p);
835G4int G4UIcommand::RangeCheck(
const char* t)
840 std::istringstream is(t);
841 for(
unsigned i = 0; i < parameter.size(); ++i)
843 type = toupper(parameter[i]->GetParameterType());
866 result = Expression();
872 G4cerr <<
"Illegal Expression in parameter range." <<
G4endl;
877 G4cerr <<
"parameter out of range: " << rangeString <<
G4endl;
883yystype G4UIcommand::Expression(
void)
889 result = LogicalORExpression();
894yystype G4UIcommand::LogicalORExpression(
void)
898 p = LogicalANDExpression();
903 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
910 p = LogicalANDExpression();
913 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
923 result.
I += (p.
L != 0L);
927 result.
I += (p.
D != 0.0);
939yystype G4UIcommand::LogicalANDExpression(
void)
943 p = EqualityExpression();
948 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
955 p = EqualityExpression();
958 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
968 result.
I *= (p.
L != 0L);
972 result.
I *= (p.
D != 0.0);
984yystype G4UIcommand::EqualityExpression(
void)
992 result = RelationalExpression();
993 if(token ==
EQ || token ==
NE)
998 arg2 = RelationalExpression();
999 result.
I = Eval2(arg1, operat, arg2);
1002 G4cerr <<
" return code of Eval2(): " << result.
I <<
G4endl;
1009 G4cerr <<
"Parameter range: error at EqualityExpression" <<
G4endl;
1017yystype G4UIcommand::RelationalExpression(
void)
1026 arg1 = AdditiveExpression();
1027 if(token ==
GT || token ==
GE || token ==
LT || token ==
LE)
1031 arg2 = AdditiveExpression();
1032 result.
I = Eval2(arg1, operat, arg2);
1035 G4cerr <<
" return code of Eval2(): " << result.
I <<
G4endl;
1049yystype G4UIcommand::AdditiveExpression(
void)
1052 result = MultiplicativeExpression();
1053 if(token !=
'+' && token !=
'-')
1055 G4cerr <<
"Parameter range: operator " << (char) token <<
" is not supported."
1062yystype G4UIcommand::MultiplicativeExpression(
void)
1065 result = UnaryExpression();
1066 if(token !=
'*' && token !=
'/' && token !=
'%')
1068 G4cerr <<
"Parameter range: operator " << (char) token <<
" is not supported."
1075yystype G4UIcommand::UnaryExpression(
void)
1086 p = UnaryExpression();
1105 result = UnaryExpression();
1109 G4cerr <<
"Parameter range error: "
1110 <<
"operator '!' is not supported (sorry)." <<
G4endl;
1112 result = UnaryExpression();
1115 result = PrimaryExpression();
1121yystype G4UIcommand::PrimaryExpression(
void)
1130 result.
S = yylval.
S;
1131 result.
type = token;
1135 result.
I = yylval.
I;
1136 result.
type = token;
1140 result.
L = yylval.
L;
1141 result.
type = token;
1145 result.
D = yylval.
D;
1146 result.
type = token;
1151 result = Expression();
1172 G4cerr << commandName <<
": meaningless comparison" <<
G4endl;
1178 unsigned i = IndexOf(arg1.
S);
1179 newValtype = toupper(parameter[i]->GetParameterType());
1185 return CompareInt(newVal[i].I, op, arg2.
I);
1191 unsigned iii = IndexOf(arg2.
S);
1192 char newValtype2 = toupper(parameter[iii]->GetParameterType());
1193 if(newValtype2 ==
'I')
1195 return CompareInt(newVal[i].I, op, newVal[iii].I);
1197 else if(newValtype2 ==
'L')
1199 G4cerr <<
"Warning : Integer is compared with long int : "
1200 << rangeString <<
G4endl;
1201 return CompareLong(newVal[i].I, op, newVal[iii].L);
1203 else if(newValtype2 ==
'D')
1205 G4cerr <<
"Warning : Integer is compared with double : "
1206 << rangeString <<
G4endl;
1207 return CompareDouble(newVal[i].I, op, newVal[iii].
D);
1213 G4cerr <<
"integer operand expected for " << rangeString <<
'.'
1220 return CompareLong(newVal[i].L, op, arg2.
I);
1224 return CompareLong(newVal[i].L, op, arg2.
L);
1228 unsigned iii = IndexOf(arg2.
S);
1229 char newValtype2 = toupper(parameter[iii]->GetParameterType());
1230 if(newValtype2 ==
'I')
1232 return CompareLong(newVal[i].L, op, newVal[iii].I);
1234 if(newValtype2 ==
'L')
1236 return CompareLong(newVal[i].L, op, newVal[iii].L);
1238 else if(newValtype2 ==
'D')
1240 G4cerr <<
"Warning : Long int is compared with double : "
1241 << rangeString <<
G4endl;
1242 return CompareDouble(newVal[i].L, op, newVal[iii].
D);
1248 G4cerr <<
"integer operand expected for " << rangeString <<
'.'
1255 return CompareDouble(newVal[i].
D, op, arg2.
D);
1259 return CompareDouble(newVal[i].
D, op, arg2.
I);
1265 return CompareDouble(newVal[i].
D, op, arg2.
L);
1269 unsigned iii = IndexOf(arg2.
S);
1270 char newValtype2 = toupper(parameter[iii]->GetParameterType());
1271 if(newValtype2 ==
'I')
1273 return CompareDouble(newVal[i].
D, op, newVal[iii].I);
1275 else if(newValtype2 ==
'L')
1277 return CompareDouble(newVal[i].
D, op, newVal[iii].L);
1279 else if(newValtype2 ==
'D')
1281 return CompareDouble(newVal[i].
D, op, newVal[iii].
D);
1291 unsigned i = IndexOf(arg2.
S);
1292 newValtype = toupper(parameter[i]->GetParameterType());
1298 return CompareInt(arg1.
I, op, newVal[i].I);
1302 G4cerr <<
"integer operand expected for " << rangeString <<
'.'
1309 return CompareLong(arg1.
L, op, newVal[i].L);
1313 G4cerr <<
"long int operand expected for " << rangeString <<
'.'
1320 return CompareDouble(arg1.
D, op, newVal[i].D);
1324 return CompareDouble(arg1.
I, op, newVal[i].D);
1341 result = (arg1 > arg2);
1345 result = (arg1 >= arg2);
1349 result = (arg1 < arg2);
1353 result = (arg1 <= arg2);
1357 result = (arg1 == arg2);
1361 result = (arg1 != arg2);
1365 G4cerr <<
"Parameter range: error at CompareInt" <<
G4endl;
1369 G4cerr <<
"CompareInt " << arg1 <<
" " << opr << arg2 <<
" result: " << result
1383 result = (arg1 > arg2);
1387 result = (arg1 >= arg2);
1391 result = (arg1 < arg2);
1395 result = (arg1 <= arg2);
1399 result = (arg1 == arg2);
1403 result = (arg1 != arg2);
1407 G4cerr <<
"Parameter range: error at CompareInt" <<
G4endl;
1411 G4cerr <<
"CompareInt " << arg1 <<
" " << opr << arg2 <<
" result: " << result
1425 result = (arg1 > arg2);
1429 result = (arg1 >= arg2);
1433 result = (arg1 < arg2);
1437 result = (arg1 <= arg2);
1441 result = (arg1 == arg2);
1445 result = (arg1 != arg2);
1449 G4cerr <<
"Parameter range: error at CompareDouble" <<
G4endl;
1453 G4cerr <<
"CompareDouble " << arg1 <<
" " << opr <<
" " << arg2
1454 <<
" result: " << result <<
G4endl;
1460unsigned G4UIcommand::IndexOf(
const char* nam)
1464 for(i = 0; i < parameter.size(); ++i)
1466 pname = parameter[i]->GetParameterName();
1473 G4cerr <<
"parameter name:" << nam <<
" not found." <<
G4endl;
1478unsigned G4UIcommand::IsParameter(
const char* nam)
1481 for(
unsigned i = 0; i < parameter.size(); ++i)
1483 pname = parameter[i]->GetParameterName();
1497 while((c = G4UIpGetc()) ==
' ' || c ==
'\t' || c ==
'\n')
1502 if(isdigit(c) || c ==
'.')
1506 buf +=
G4String((
unsigned char) c);
1508 }
while(c ==
'.' || isdigit(c) || c ==
'e' || c ==
'E' || c ==
'+' ||
1511 const char* t = buf;
1512 std::istringstream is(t);
1513 if(IsInt(buf.
data(), 20))
1518 else if(IsDouble(buf.
data()))
1529 if(isalpha(c) || c ==
'_')
1533 buf +=
G4String((
unsigned char) c);
1534 }
while((c = G4UIpGetc()) != EOF && (isalnum(c) || c ==
'_'));
1536 if(IsParameter(buf))
1543 G4cerr << buf <<
" is not a parameter name." <<
G4endl;
1569 G4int c = G4UIpGetc();
1578G4int G4UIcommand::G4UIpGetc()
1580 G4int length = rangeString.length();
1582 return rangeString(bp++);
1592 if(bp > 0 && c == rangeString(bp - 1))
1599 G4cerr <<
"bp=" << bp <<
" c=" << c <<
" pR(bp-1)=" << rangeString(bp - 1)
CLHEP::Hep3Vector G4ThreeVector
std::vector< G4UnitDefinition * > G4UnitsContainer
std::vector< G4UnitsCategory * > G4UnitsTable
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4String & remove(str_size)
G4String & append(const G4String &)
str_size index(const char *, G4int pos=0) const
std::size_t last(char) const
const char * data() const
static G4ThreeVector ConvertTo3Vector(const char *st)
static G4String CategoryOf(const char *unitName)
static G4double ValueOf(const char *unitName)
static G4long ConvertToLongInt(const char *st)
virtual G4int DoIt(G4String parameterList)
G4bool operator==(const G4UIcommand &right) const
static G4String ConvertToString(G4bool boolVal)
const G4String & GetCommandPath() const
G4int CheckNewValue(const char *newValue)
static G4int ConvertToInt(const char *st)
static G4String UnitsList(const char *unitCategory)
static G4bool ConvertToBool(const char *st)
static G4double ConvertToDouble(const char *st)
static G4double ConvertToDimensionedDouble(const char *st)
void AvailableForStates(G4ApplicationState s1)
G4bool operator!=(const G4UIcommand &right) const
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
G4String GetCurrentValue()
static G4bool DoublePrecisionStr()
static G4UImanager * GetMasterUIpointer()
void AddNewCommand(G4UIcommand *newCommand)
void RemoveCommand(G4UIcommand *aCommand)
static G4UImanager * GetUIpointer()
virtual G4String GetCurrentValue(G4UIcommand *command)
G4bool CommandsShouldBeInMaster() const
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
static G4double GetValueOf(const G4String &)
static G4String GetCategory(const G4String &)
static G4UnitsTable & GetUnitsTable()