Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4UIcommand 26 // G4UIcommand 27 // 27 // 28 // Class description: 28 // Class description: 29 // 29 // 30 // This G4UIcommand is the "concrete" base cla 30 // This G4UIcommand is the "concrete" base class which represents a command 31 // used by Geant4 (G)UI. The user can use this 31 // used by Geant4 (G)UI. The user can use this class in case the parameter 32 // arguments of a command are not suitable wit 32 // arguments of a command are not suitable with respect to the derived command 33 // classes. 33 // classes. 34 // Some methods defined in this base class are 34 // Some methods defined in this base class are used by the derived classes 35 35 36 // Author: Makoto Asai (SLAC), 1998 36 // Author: Makoto Asai (SLAC), 1998 37 // ------------------------------------------- 37 // -------------------------------------------------------------------- 38 #ifndef G4UIcommand_hh 38 #ifndef G4UIcommand_hh 39 #define G4UIcommand_hh 1 39 #define G4UIcommand_hh 1 40 40 41 #include "G4ApplicationState.hh" << 41 #include <vector> 42 #include "G4ThreeVector.hh" << 42 43 #include "G4UIparameter.hh" 43 #include "G4UIparameter.hh" 44 #include "globals.hh" 44 #include "globals.hh" 45 << 45 #include "G4ApplicationState.hh" 46 #include <vector> << 46 #include "G4UItokenNum.hh" >> 47 #include "G4ThreeVector.hh" 47 48 48 class G4UImessenger; 49 class G4UImessenger; 49 50 50 class G4UIcommand 51 class G4UIcommand 51 { 52 { 52 public: 53 public: 53 // Dummy default constructor << 54 G4UIcommand() = default; << 55 54 56 // Constructor. The command string with fu << 55 G4UIcommand(); 57 // and the pointer to the messenger must b << 56 // Dummy default constructor 58 // If tBB is set to false, this command wo << 57 59 // This tBB parameter could be changed wit << 58 G4UIcommand(const char* theCommandPath, G4UImessenger* theMessenger, 60 // except for G4UIdirectory << 59 G4bool tBB = true); 61 G4UIcommand(const char* theCommandPath, G4 << 60 // Constructor. The command string with full path directory >> 61 // and the pointer to the messenger must be given. >> 62 // If tBB is set to false, this command won't be sent to worker threads. >> 63 // This tBB parameter could be changed with SetToBeBroadcasted() method >> 64 // except for G4UIdirectory 62 65 63 virtual ~G4UIcommand(); 66 virtual ~G4UIcommand(); 64 67 65 G4bool operator==(const G4UIcommand& right 68 G4bool operator==(const G4UIcommand& right) const; 66 G4bool operator!=(const G4UIcommand& right 69 G4bool operator!=(const G4UIcommand& right) const; 67 70 68 virtual G4int DoIt(const G4String& paramet << 71 virtual G4int DoIt(G4String parameterList); 69 72 70 G4String GetCurrentValue(); 73 G4String GetCurrentValue(); 71 74 72 // These methods define the states where t << 73 // Once one of these commands is invoked, << 74 // be denied when Geant4 is NOT in the ass << 75 void AvailableForStates(G4ApplicationState 75 void AvailableForStates(G4ApplicationState s1); 76 void AvailableForStates(G4ApplicationState 76 void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2); 77 void AvailableForStates(G4ApplicationState << 77 void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, 78 void AvailableForStates(G4ApplicationState << 78 G4ApplicationState s3); 79 G4ApplicationState << 79 void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, 80 void AvailableForStates(G4ApplicationState << 80 G4ApplicationState s3, G4ApplicationState s4); 81 G4ApplicationState << 81 void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, >> 82 G4ApplicationState s3, G4ApplicationState s4, >> 83 G4ApplicationState s5); >> 84 // These methods define the states where the command is available. >> 85 // Once one of these commands is invoked, the command application will >> 86 // be denied when Geant4 is NOT in the assigned states 82 87 83 G4bool IsAvailable(); 88 G4bool IsAvailable(); 84 89 85 virtual void List(); 90 virtual void List(); 86 91 87 // Static methods for conversion from valu << 88 // These methods are to be used by GetCurr << 89 // of concrete messengers << 90 static G4String ConvertToString(G4bool boo 92 static G4String ConvertToString(G4bool boolVal); 91 static G4String ConvertToString(G4int intV 93 static G4String ConvertToString(G4int intValue); 92 static G4String ConvertToString(G4long lon 94 static G4String ConvertToString(G4long longValue); 93 static G4String ConvertToString(G4double d 95 static G4String ConvertToString(G4double doubleValue); 94 static G4String ConvertToString(G4double d 96 static G4String ConvertToString(G4double doubleValue, const char* unitName); 95 static G4String ConvertToString(const G4Th << 97 static G4String ConvertToString(G4ThreeVector vec); 96 static G4String ConvertToString(const G4Th << 98 static G4String ConvertToString(G4ThreeVector vec, const char* unitName); >> 99 // Static methods for conversion from value(s) to a string. >> 100 // These methods are to be used by GetCurrentValues() methods >> 101 // of concrete messengers 97 102 98 // Static methods for conversion from a st << 99 // type. These methods are to be used dire << 100 // of concrete messengers, or GetNewXXXVal << 101 // this G4UIcommand class << 102 static G4bool ConvertToBool(const char* st 103 static G4bool ConvertToBool(const char* st); 103 static G4int ConvertToInt(const char* st); 104 static G4int ConvertToInt(const char* st); 104 static G4long ConvertToLongInt(const char* 105 static G4long ConvertToLongInt(const char* st); 105 static G4double ConvertToDouble(const char 106 static G4double ConvertToDouble(const char* st); 106 static G4double ConvertToDimensionedDouble 107 static G4double ConvertToDimensionedDouble(const char* st); 107 static G4ThreeVector ConvertTo3Vector(cons 108 static G4ThreeVector ConvertTo3Vector(const char* st); 108 static G4ThreeVector ConvertToDimensioned3 109 static G4ThreeVector ConvertToDimensioned3Vector(const char* st); >> 110 // Static methods for conversion from a string to a value of the returning >> 111 // type. These methods are to be used directly by SetNewValues() methods >> 112 // of concrete messengers, or GetNewXXXValue() of classes derived from >> 113 // this G4UIcommand class 109 114 110 // Static methods for unit and its categor << 111 static G4double ValueOf(const char* unitNa 115 static G4double ValueOf(const char* unitName); 112 static G4String CategoryOf(const char* uni 116 static G4String CategoryOf(const char* unitName); 113 static G4String UnitsList(const char* unit 117 static G4String UnitsList(const char* unitCategory); >> 118 // Static methods for unit and its category >> 119 >> 120 inline void SetRange(const char* rs) { rangeString = rs; } >> 121 // Defines the range the command parameter(s) can take. >> 122 // The variable name(s) appear in the range expression must be the same >> 123 // as the name(s) of the parameter(s). >> 124 // All the C++ syntax of relational operators are allowed for the >> 125 // range expression 114 126 115 // Defines the range the command parameter << 127 inline const G4String& GetRange() const { return rangeString; } 116 // The variable name(s) appear in the rang << 128 inline std::size_t GetGuidanceEntries() const 117 // as the name(s) of the parameter(s). << 129 { 118 // All the C++ syntax of relational operat << 130 return commandGuidance.size(); 119 // range expression << 131 } 120 inline void SetRange(const char* rs) { ran << 132 inline const G4String& GetGuidanceLine(G4int i) const 121 << 133 { 122 inline const G4String& GetRange() const { << 134 return commandGuidance[i]; 123 inline std::size_t GetGuidanceEntries() co << 135 } 124 inline const G4String& GetGuidanceLine(G4i << 125 inline const G4String& GetCommandPath() co 136 inline const G4String& GetCommandPath() const { return commandPath; } 126 inline const G4String& GetCommandName() co 137 inline const G4String& GetCommandName() const { return commandName; } 127 inline std::size_t GetParameterEntries() c 138 inline std::size_t GetParameterEntries() const { return parameter.size(); } 128 inline G4UIparameter* GetParameter(G4int i 139 inline G4UIparameter* GetParameter(G4int i) const { return parameter[i]; } 129 inline std::vector<G4ApplicationState>* Ge << 140 inline std::vector<G4ApplicationState>* GetStateList() >> 141 { >> 142 return &availabelStateList; >> 143 } 130 inline G4UImessenger* GetMessenger() const 144 inline G4UImessenger* GetMessenger() const { return messenger; } 131 145 132 // Defines a parameter. This method is use << 133 // classes but the user can directly use t << 134 // a command, without using the derived cl << 135 // of the parameters is the order of invok << 136 inline void SetParameter(G4UIparameter* co 146 inline void SetParameter(G4UIparameter* const newParameter) >> 147 // Defines a parameter. This method is used by the derived command >> 148 // classes but the user can directly use this command when defining >> 149 // a command, without using the derived class. For this case, the order >> 150 // of the parameters is the order of invoking this method 137 { 151 { 138 parameter.push_back(newParameter); 152 parameter.push_back(newParameter); >> 153 newVal.resize(parameter.size()); 139 } 154 } 140 155 141 // Adds a guidance line. Unlimited times o << 156 inline void SetGuidance(const char* aGuidance) 142 // allowed. The given lines of guidance wi << 157 // Adds a guidance line. Unlimited times of invokation of this method is 143 // The first line of the guidance will be << 158 // allowed. The given lines of guidance will appear for the help. 144 // command, i.e. one line list of the comm << 159 // The first line of the guidance will be used as the title of the 145 inline void SetGuidance(const char* aGuida << 160 // command, i.e. one line list of the commands >> 161 { >> 162 commandGuidance.push_back(G4String(aGuidance)); >> 163 } 146 164 147 inline const G4String GetTitle() const 165 inline const G4String GetTitle() const 148 { 166 { 149 return (commandGuidance.empty()) ? G4Str << 167 return (commandGuidance.size() == 0) >> 168 ? G4String("...Title not available...") >> 169 : commandGuidance[0]; 150 } 170 } 151 171 152 inline void SetToBeBroadcasted(G4bool val) 172 inline void SetToBeBroadcasted(G4bool val) { toBeBroadcasted = val; } 153 inline G4bool ToBeBroadcasted() const { re 173 inline G4bool ToBeBroadcasted() const { return toBeBroadcasted; } 154 inline void SetToBeFlushed(G4bool val) { t 174 inline void SetToBeFlushed(G4bool val) { toBeFlushed = val; } 155 inline G4bool ToBeFlushed() const { return 175 inline G4bool ToBeFlushed() const { return toBeFlushed; } 156 inline void SetWorkerThreadOnly(G4bool val << 176 inline void SetWorkerThreadOnly(G4bool val = true) { workerThreadOnly=val; } 157 inline G4bool IsWorkerThreadOnly() const { 177 inline G4bool IsWorkerThreadOnly() const { return workerThreadOnly; } 158 178 159 inline void CommandFailed(G4int errCode, G 179 inline void CommandFailed(G4int errCode, G4ExceptionDescription& ed) 160 { 180 { 161 commandFailureCode = errCode; 181 commandFailureCode = errCode; 162 failureDescription = ed.str(); 182 failureDescription = ed.str(); 163 } 183 } 164 inline void CommandFailed(G4ExceptionDescr 184 inline void CommandFailed(G4ExceptionDescription& ed) 165 { 185 { 166 commandFailureCode = 1; 186 commandFailureCode = 1; 167 failureDescription = ed.str(); 187 failureDescription = ed.str(); 168 } 188 } 169 inline G4int IfCommandFailed() { return co 189 inline G4int IfCommandFailed() { return commandFailureCode; } 170 inline const G4String& GetFailureDescripti << 190 inline const G4String& GetFailureDescription() {return failureDescription;} 171 inline void ResetFailure() 191 inline void ResetFailure() 172 { 192 { 173 commandFailureCode = 0; 193 commandFailureCode = 0; 174 failureDescription = ""; 194 failureDescription = ""; 175 } 195 } 176 196 177 public: 197 public: 178 enum CommandType << 198 enum CommandType 179 { << 199 { BaseClassCmd, WithoutParameterCmd, 180 BaseClassCmd, << 200 WithABoolCmd, WithAnIntegerCmd, WithALongIntCmd, 181 WithoutParameterCmd, << 201 WithADoubleCmd, WithADoubleAndUnitCmd, With3VectorCmd, With3VectorAndUnitCmd, 182 WithABoolCmd, << 202 WithAStringCmd, CmdDirectory = -1 }; 183 WithAnIntegerCmd, << 203 184 WithALongIntCmd, << 204 inline CommandType GetCommandType() const 185 WithADoubleCmd, << 205 { return commandType; } 186 WithADoubleAndUnitCmd, << 187 With3VectorCmd, << 188 With3VectorAndUnitCmd, << 189 WithAStringCmd, << 190 CmdDirectory = -1 << 191 }; << 192 << 193 inline CommandType GetCommandType() const << 194 void SetCommandType(CommandType); 206 void SetCommandType(CommandType); 195 207 196 inline void SetDefaultSortFlag(G4bool val) << 208 inline void SetDefaultSortFlag(G4bool val) >> 209 { ifSort = val; } 197 210 198 protected: 211 protected: >> 212 >> 213 // --- the following is used by CheckNewValue() -------- >> 214 using yystype = G4UItokenNum::yystype; >> 215 using tokenNum = G4UItokenNum::tokenNum; >> 216 199 G4int CheckNewValue(const char* newValue); 217 G4int CheckNewValue(const char* newValue); 200 218 201 G4bool toBeBroadcasted = false; 219 G4bool toBeBroadcasted = false; 202 G4bool toBeFlushed = false; 220 G4bool toBeFlushed = false; 203 G4bool workerThreadOnly = false; 221 G4bool workerThreadOnly = false; 204 222 205 G4int commandFailureCode = 0; 223 G4int commandFailureCode = 0; 206 G4String failureDescription = ""; 224 G4String failureDescription = ""; 207 225 208 G4bool ifSort = false; 226 G4bool ifSort = false; 209 227 210 private: 228 private: >> 229 211 void G4UIcommandCommonConstructorCode(cons 230 void G4UIcommandCommonConstructorCode(const char* theCommandPath); 212 231 >> 232 G4int TypeCheck(const char* t); >> 233 G4int RangeCheck(const char* t); >> 234 G4int IsInt(const char* str, short maxLength); // used for both int and long int >> 235 G4int IsDouble(const char* str); >> 236 G4int ExpectExponent(const char* str); >> 237 // syntax nodes >> 238 yystype Expression(void); >> 239 yystype LogicalORExpression(void); >> 240 yystype LogicalANDExpression(void); >> 241 yystype EqualityExpression(void); >> 242 yystype RelationalExpression(void); >> 243 yystype AdditiveExpression(void); >> 244 yystype MultiplicativeExpression(void); >> 245 yystype UnaryExpression(void); >> 246 yystype PrimaryExpression(void); >> 247 // semantics routines >> 248 G4int Eval2(yystype arg1, G4int op, yystype arg2); >> 249 G4int CompareInt(G4int arg1, G4int op, G4int arg2); >> 250 G4int CompareLong(G4long arg1, G4int op, G4long arg2); >> 251 G4int CompareDouble(G4double arg1, G4int op, G4double arg2); >> 252 // utility >> 253 tokenNum Yylex(void); // returns next token >> 254 unsigned IndexOf(const char*); // returns the index of the var name >> 255 unsigned IsParameter(const char*); // returns 1 or 0 >> 256 G4int G4UIpGetc(void); // read one char from rangeBuf >> 257 G4int G4UIpUngetc(G4int c); // put back >> 258 G4int Backslash(G4int c); >> 259 G4int Follow(G4int expect, G4int ifyes, G4int ifno); >> 260 //G4String TokenToStr(G4int token); >> 261 //void PrintToken(void); // for debug >> 262 >> 263 // Data ----------------------------------------------------------- >> 264 213 private: 265 private: 214 CommandType commandType = BaseClassCmd; 266 CommandType commandType = BaseClassCmd; 215 G4UImessenger* messenger = nullptr; 267 G4UImessenger* messenger = nullptr; 216 G4String commandPath; 268 G4String commandPath; 217 G4String commandName; 269 G4String commandName; 218 G4String rangeExpression; << 270 G4String rangeString; 219 std::vector<G4UIparameter*> parameter; 271 std::vector<G4UIparameter*> parameter; 220 std::vector<G4String> commandGuidance; 272 std::vector<G4String> commandGuidance; 221 std::vector<G4ApplicationState> availabelS 273 std::vector<G4ApplicationState> availabelStateList; >> 274 >> 275 G4String rangeBuf; >> 276 G4int bp = 0; // buffer pointer for rangeBuf >> 277 tokenNum token = G4UItokenNum::IDENTIFIER; >> 278 yystype yylval; >> 279 std::vector<yystype> newVal; >> 280 G4int paramERR = 0; 222 }; 281 }; 223 282 224 #endif 283 #endif 225 284