File indexing completed on 2025-01-18 09:59:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #ifndef G4UIcommand_hh
0039 #define G4UIcommand_hh 1
0040
0041 #include "G4ApplicationState.hh"
0042 #include "G4ThreeVector.hh"
0043 #include "G4UIparameter.hh"
0044 #include "G4UItokenNum.hh"
0045 #include "globals.hh"
0046
0047 #include <vector>
0048
0049 class G4UImessenger;
0050
0051 class G4UIcommand
0052 {
0053 public:
0054
0055 G4UIcommand() = default;
0056
0057
0058
0059
0060
0061
0062 G4UIcommand(const char* theCommandPath, G4UImessenger* theMessenger, G4bool tBB = true);
0063
0064 virtual ~G4UIcommand();
0065
0066 G4bool operator==(const G4UIcommand& right) const;
0067 G4bool operator!=(const G4UIcommand& right) const;
0068
0069 virtual G4int DoIt(G4String parameterList);
0070
0071 G4String GetCurrentValue();
0072
0073
0074
0075
0076 void AvailableForStates(G4ApplicationState s1);
0077 void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2);
0078 void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3);
0079 void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3,
0080 G4ApplicationState s4);
0081 void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3,
0082 G4ApplicationState s4, G4ApplicationState s5);
0083
0084 G4bool IsAvailable();
0085
0086 virtual void List();
0087
0088
0089
0090
0091 static G4String ConvertToString(G4bool boolVal);
0092 static G4String ConvertToString(G4int intValue);
0093 static G4String ConvertToString(G4long longValue);
0094 static G4String ConvertToString(G4double doubleValue);
0095 static G4String ConvertToString(G4double doubleValue, const char* unitName);
0096 static G4String ConvertToString(const G4ThreeVector& vec);
0097 static G4String ConvertToString(const G4ThreeVector& vec, const char* unitName);
0098
0099
0100
0101
0102
0103 static G4bool ConvertToBool(const char* st);
0104 static G4int ConvertToInt(const char* st);
0105 static G4long ConvertToLongInt(const char* st);
0106 static G4double ConvertToDouble(const char* st);
0107 static G4double ConvertToDimensionedDouble(const char* st);
0108 static G4ThreeVector ConvertTo3Vector(const char* st);
0109 static G4ThreeVector ConvertToDimensioned3Vector(const char* st);
0110
0111
0112 static G4double ValueOf(const char* unitName);
0113 static G4String CategoryOf(const char* unitName);
0114 static G4String UnitsList(const char* unitCategory);
0115
0116
0117
0118
0119
0120
0121 inline void SetRange(const char* rs) { rangeExpression = rs; }
0122
0123 inline const G4String& GetRange() const { return rangeExpression; }
0124 inline std::size_t GetGuidanceEntries() const { return commandGuidance.size(); }
0125 inline const G4String& GetGuidanceLine(G4int i) const { return commandGuidance[i]; }
0126 inline const G4String& GetCommandPath() const { return commandPath; }
0127 inline const G4String& GetCommandName() const { return commandName; }
0128 inline std::size_t GetParameterEntries() const { return parameter.size(); }
0129 inline G4UIparameter* GetParameter(G4int i) const { return parameter[i]; }
0130 inline std::vector<G4ApplicationState>* GetStateList() { return &availabelStateList; }
0131 inline G4UImessenger* GetMessenger() const { return messenger; }
0132
0133
0134
0135
0136
0137 inline void SetParameter(G4UIparameter* const newParameter)
0138 {
0139 parameter.push_back(newParameter);
0140 newVal.resize(parameter.size());
0141 }
0142
0143
0144
0145
0146
0147 inline void SetGuidance(const char* aGuidance) { commandGuidance.emplace_back(aGuidance); }
0148
0149 inline const G4String GetTitle() const
0150 {
0151 return (commandGuidance.empty()) ? G4String("...Title not available...") : commandGuidance[0];
0152 }
0153
0154 inline void SetToBeBroadcasted(G4bool val) { toBeBroadcasted = val; }
0155 inline G4bool ToBeBroadcasted() const { return toBeBroadcasted; }
0156 inline void SetToBeFlushed(G4bool val) { toBeFlushed = val; }
0157 inline G4bool ToBeFlushed() const { return toBeFlushed; }
0158 inline void SetWorkerThreadOnly(G4bool val = true) { workerThreadOnly = val; }
0159 inline G4bool IsWorkerThreadOnly() const { return workerThreadOnly; }
0160
0161 inline void CommandFailed(G4int errCode, G4ExceptionDescription& ed)
0162 {
0163 commandFailureCode = errCode;
0164 failureDescription = ed.str();
0165 }
0166 inline void CommandFailed(G4ExceptionDescription& ed)
0167 {
0168 commandFailureCode = 1;
0169 failureDescription = ed.str();
0170 }
0171 inline G4int IfCommandFailed() { return commandFailureCode; }
0172 inline const G4String& GetFailureDescription() { return failureDescription; }
0173 inline void ResetFailure()
0174 {
0175 commandFailureCode = 0;
0176 failureDescription = "";
0177 }
0178
0179 public:
0180 enum CommandType
0181 {
0182 BaseClassCmd,
0183 WithoutParameterCmd,
0184 WithABoolCmd,
0185 WithAnIntegerCmd,
0186 WithALongIntCmd,
0187 WithADoubleCmd,
0188 WithADoubleAndUnitCmd,
0189 With3VectorCmd,
0190 With3VectorAndUnitCmd,
0191 WithAStringCmd,
0192 CmdDirectory = -1
0193 };
0194
0195 inline CommandType GetCommandType() const { return commandType; }
0196 void SetCommandType(CommandType);
0197
0198 inline void SetDefaultSortFlag(G4bool val) { ifSort = val; }
0199
0200 protected:
0201
0202 using yystype = G4UItokenNum::yystype;
0203 using tokenNum = G4UItokenNum::tokenNum;
0204
0205 G4int CheckNewValue(const char* newValue);
0206
0207 G4bool toBeBroadcasted = false;
0208 G4bool toBeFlushed = false;
0209 G4bool workerThreadOnly = false;
0210
0211 G4int commandFailureCode = 0;
0212 G4String failureDescription = "";
0213
0214 G4bool ifSort = false;
0215
0216 private:
0217 void G4UIcommandCommonConstructorCode(const char* theCommandPath);
0218
0219 G4bool RangeCheck(const char* t);
0220
0221
0222 yystype Expression();
0223 yystype LogicalORExpression();
0224 yystype LogicalANDExpression();
0225 yystype EqualityExpression();
0226 yystype RelationalExpression();
0227 yystype AdditiveExpression();
0228 yystype MultiplicativeExpression();
0229 yystype UnaryExpression();
0230 yystype PrimaryExpression();
0231
0232 G4int Eval2(const yystype& arg1, G4int op, const yystype& arg2);
0233
0234 tokenNum Yylex();
0235 unsigned IndexOf(const char*);
0236 unsigned IsParameter(const char*);
0237 G4int G4UIpGetc();
0238 G4int G4UIpUngetc(G4int c);
0239 G4int Backslash(G4int c);
0240 G4int Follow(G4int expect, G4int ifyes, G4int ifno);
0241
0242
0243
0244 private:
0245 CommandType commandType = BaseClassCmd;
0246 G4UImessenger* messenger = nullptr;
0247 G4String commandPath;
0248 G4String commandName;
0249 G4String rangeExpression;
0250 std::vector<G4UIparameter*> parameter;
0251 std::vector<G4String> commandGuidance;
0252 std::vector<G4ApplicationState> availabelStateList;
0253
0254 G4int bp = 0;
0255 tokenNum token = G4UItokenNum::IDENTIFIER;
0256 yystype yylval;
0257 std::vector<yystype> newVal;
0258 G4int paramERR = 0;
0259 };
0260
0261 #endif