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 // G4UIparameter << 27 // 26 // 28 // Class description: << 29 // 27 // 30 // This class represents a parameter which wil << 28 // 31 // object. In case a command is defined by con << 29 // --------------------------------------------------------------------- 32 // it automatically creates necessary paramete << 30 33 // not to create parameter object(s). In case << 31 #ifndef G4UIparameter_h 34 // command directly instantiated by G4UIcomman << 32 #define G4UIparameter_h 1 35 // a parameter object(s) << 36 << 37 // Author: Makoto Asai, 1997 << 38 // ------------------------------------------- << 39 #ifndef G4UIparameter_hh << 40 #define G4UIparameter_hh 1 << 41 33 42 #include "globals.hh" 34 #include "globals.hh" >> 35 #include "G4UItokenNum.hh" >> 36 >> 37 // class description: >> 38 // >> 39 // This class represents a parameter which will be taken by a G4UIcommand >> 40 // object. In case a command is defined by constructing G4UIcmdXXX class, >> 41 // it automatically creates necessary parameter objects, thus the user needs >> 42 // not to create parameter object(s) by him/herself. In case the user wants >> 43 // to create a command directly instansiated by G4UIcommand class, he/she >> 44 // must create parameter object(s) by him/herself. 43 45 44 class G4UIparameter << 46 class G4UIparameter 45 { 47 { >> 48 public: // with description >> 49 G4UIparameter(); >> 50 G4UIparameter(char theType); >> 51 G4UIparameter(const char * theName, char theType, G4bool theOmittable); >> 52 // Constructors, where "theName" is the name of the parameter which will >> 53 // be used by the range checking, "theType" is the type of the parameter >> 54 // (currently "b" (boolean), "i" (integer), "d" (double), and "s" (string) >> 55 // are supported), and "theOmittable" is a boolean flag to set whether >> 56 // the user of the command can ommit the parameter or not. If "theOmittable" >> 57 // is true, the default value must be given. >> 58 ~G4UIparameter(); >> 59 // Destructor. When a command is destructed, the delete operator(s) for >> 60 // associating parameter(s) are AUTOMATICALLY invoked. Thus the user needs >> 61 // NOT to invoke this by him/herself. >> 62 46 public: 63 public: 47 // Default constructor << 64 G4bool operator==(const G4UIparameter &right) const; 48 G4UIparameter() = default; << 65 G4bool operator!=(const G4UIparameter &right) const; 49 66 50 // Constructors, where "theName" is the na << 67 G4int CheckNewValue(const char* newValue); 51 // be used by the range checking, "theType << 68 void List(); 52 // (currently "b" (Boolean), "i" (integer) << 53 // and "s" (string) are supported). << 54 // "theOmittable" is a Boolean flag to set << 55 // the user of the command can omit the pa << 56 // If "theOmittable" is true, the default << 57 G4UIparameter(char theType); << 58 G4UIparameter(const char* theName, char th << 59 << 60 // Destructor. When a command is destructe << 61 // associated parameter(s) are AUTOMATICAL << 62 ~G4UIparameter(); << 63 << 64 G4int CheckNewValue(const char* newValue); << 65 void List(); << 66 << 67 // These methods set the default value of << 68 inline void SetDefaultValue(const char* th << 69 void SetDefaultValue(G4int theDefaultValue << 70 void SetDefaultValue(G4long theDefaultValu << 71 void SetDefaultValue(G4double theDefaultVa << 72 << 73 // This method can be used for a string-ty << 74 // used to specify a unit. This method is << 75 // string-type parameter << 76 void SetDefaultUnit(const char* theDefault << 77 << 78 inline const G4String& GetDefaultValue() c << 79 inline char GetParameterType() const { ret << 80 << 81 // Defines the range the parameter can tak << 82 // The variable name appearing in the rang << 83 // same as the name of the parameter. << 84 // All the C++ syntax of relational operat << 85 // range expression << 86 inline void SetParameterRange(const char* << 87 << 88 inline const G4String& GetParameterRange() << 89 << 90 inline void SetParameterName(const char* p << 91 inline const G4String& GetParameterName() << 92 << 93 // This method is meaningful if the type o << 94 // The candidates listed in the argument m << 95 inline void SetParameterCandidates(const c << 96 << 97 inline const G4String& GetParameterCandida << 98 << 99 inline void SetOmittable(G4bool om) { omit << 100 inline G4bool IsOmittable() const { return << 101 << 102 inline void SetCurrentAsDefault(G4bool val << 103 inline G4bool GetCurrentAsDefault() const << 104 << 105 // Obsolete methods << 106 // << 107 inline const G4String& GetParameterGuidanc << 108 inline void SetGuidance(const char* theGui << 109 69 110 private: 70 private: 111 G4bool TypeCheck(const char* newValue); << 71 G4String parameterName; 112 G4bool CandidateCheck(const char* newValue << 72 G4String parameterGuidance; 113 << 73 G4String defaultValue; >> 74 G4String parameterRange; >> 75 G4String parameterCandidate; >> 76 char parameterType; >> 77 G4bool omittable; >> 78 G4bool currentAsDefaultFlag; >> 79 G4int widget; >> 80 >> 81 public: // with description >> 82 inline void SetDefaultValue(const char * theDefaultValue) >> 83 { defaultValue = theDefaultValue; } >> 84 void SetDefaultValue(G4int theDefaultValue); >> 85 void SetDefaultValue(G4double theDefaultValue); >> 86 // These methods set the default value of the parameter. >> 87 void SetDefaultUnit(const char * theDefaultUnit); >> 88 // This method can be used for a string-type parameter that is >> 89 // used to specify a unit. This method is valid only for a >> 90 // string-type parameter. With this set-method, not only the >> 91 // default unit but also candidate units that belong to the >> 92 // same unit category (a.k.a. dimension) as the default unit. >> 93 public: >> 94 inline G4String GetDefaultValue() const >> 95 { return defaultValue; } >> 96 inline char GetParameterType() const >> 97 { return parameterType; } >> 98 >> 99 public: // with description >> 100 inline void SetParameterRange(const char * theRange) >> 101 { parameterRange = theRange; } >> 102 // Defines the range the parameter can take. >> 103 // The variable name appear in the range expression must be same >> 104 // as the name of the parameter. >> 105 // All the C++ syntax of relational operators are allowed for the >> 106 // range expression. >> 107 public: >> 108 inline G4String GetParameterRange() const >> 109 { return parameterRange; } >> 110 >> 111 // parameterName >> 112 inline void SetParameterName(const char * theName) >> 113 { parameterName = theName; } >> 114 inline G4String GetParameterName() const >> 115 { return parameterName; } >> 116 >> 117 public: // with description >> 118 inline void SetParameterCandidates(const char * theString) >> 119 { parameterCandidate = theString; } >> 120 // This method is meaningful if the type of the parameter is string. >> 121 // The candidates listed in the argument must be separated by space(s). >> 122 public: >> 123 inline G4String GetParameterCandidates() const >> 124 { return parameterCandidate; } >> 125 >> 126 // omittable >> 127 inline void SetOmittable(G4bool om) >> 128 { omittable = om; } >> 129 inline G4bool IsOmittable() const >> 130 { return omittable; } >> 131 >> 132 // currentAsDefaultFlag >> 133 inline void SetCurrentAsDefault(G4bool val) >> 134 { currentAsDefaultFlag = val; } >> 135 inline G4bool GetCurrentAsDefault() const >> 136 { return currentAsDefaultFlag; } >> 137 >> 138 // out of date methods >> 139 inline void SetWidget(G4int theWidget) >> 140 { widget = theWidget; } >> 141 inline const G4String GetParameterGuidance() const >> 142 { return parameterGuidance; } >> 143 inline void SetGuidance(const char * theGuidance) >> 144 { parameterGuidance = theGuidance; } >> 145 >> 146 protected: >> 147 using yystype = G4UItokenNum::yystype; >> 148 using tokenNum = G4UItokenNum::tokenNum; 114 private: 149 private: 115 G4String parameterName; << 150 // --- the following is used by CheckNewValue() ------- 116 G4String parameterGuidance; << 151 G4int TypeCheck(const char* newValue ); 117 G4String defaultValue; << 152 G4int RangeCheck(const char* newValue ); 118 G4String rangeExpression; << 153 G4int CandidateCheck(const char* newValue ); 119 G4String parameterCandidate; << 154 G4int IsInt(const char* str, short maxDigit); 120 char parameterType = '\0'; << 155 G4int IsDouble(const char* str); 121 G4bool omittable = false; << 156 G4int ExpectExponent(const char* str); 122 G4bool currentAsDefaultFlag = false; << 157 // syntax nodes >> 158 yystype Expression( void ); >> 159 yystype LogicalORExpression( void ); >> 160 yystype LogicalANDExpression( void ); >> 161 yystype EqualityExpression ( void ); >> 162 yystype RelationalExpression( void ); >> 163 yystype AdditiveExpression( void ); >> 164 yystype MultiplicativeExpression( void ); >> 165 yystype UnaryExpression( void ); >> 166 yystype PrimaryExpression( void ); >> 167 // semantics routines >> 168 G4int Eval2( yystype arg1, G4int op, yystype arg2 ); >> 169 G4int CompareInt( G4int arg1, G4int op, G4int arg2); >> 170 G4int CompareDouble( double arg1, G4int op, double arg2); >> 171 // utility >> 172 tokenNum Yylex( void ); // returns next token >> 173 G4int G4UIpGetc( void ); // read one char from rangeBuf >> 174 G4int G4UIpUngetc( G4int c ); // put back >> 175 G4int Backslash( G4int c ); >> 176 G4int Follow( G4int expect, G4int ifyes, G4int ifno ); >> 177 G4String TokenToStr(G4int token); >> 178 //void PrintToken(void); // debug >> 179 // data >> 180 G4String rangeBuf; >> 181 G4int bp; // buffer pointer for rangeBuf >> 182 tokenNum token; >> 183 yystype yylval; >> 184 yystype newVal; >> 185 G4int paramERR; >> 186 //------------ end of CheckNewValue() related member -------------- >> 187 123 }; 188 }; 124 189 125 #endif 190 #endif >> 191 126 192