| [821] | 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4UIparameter.hh,v 1.9 2006/06/29 19:08:21 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // ---------------------------------------------------------------------
|
|---|
| 32 |
|
|---|
| 33 | #ifndef G4UIparameter_h
|
|---|
| 34 | #define G4UIparameter_h 1
|
|---|
| 35 |
|
|---|
| 36 | #include "globals.hh"
|
|---|
| 37 | #include "G4UItokenNum.hh"
|
|---|
| 38 |
|
|---|
| 39 | // class description:
|
|---|
| 40 | //
|
|---|
| 41 | // This class represents a parameter which will be taken by a G4UIcommand
|
|---|
| 42 | // object. In case a command is defined by constructing G4UIcmdXXX class,
|
|---|
| 43 | // it automatically creates necessary parameter objects, thus the user needs
|
|---|
| 44 | // not to create parameter object(s) by him/herself. In case the user wants
|
|---|
| 45 | // to create a command directly instansiated by G4UIcommand class, he/she
|
|---|
| 46 | // must create parameter object(s) by him/herself.
|
|---|
| 47 |
|
|---|
| 48 | class G4UIparameter
|
|---|
| 49 | {
|
|---|
| 50 | public: // with description
|
|---|
| 51 | G4UIparameter();
|
|---|
| 52 | G4UIparameter(char theType);
|
|---|
| 53 | G4UIparameter(const char * theName, char theType, G4bool theOmittable);
|
|---|
| 54 | // Constructors, where "theName" is the name of the parameter which will
|
|---|
| 55 | // be used by the range checking, "theType" is the type of the parameter
|
|---|
| 56 | // (currently "b" (boolean), "i" (integer), "d" (double), and "s" (string)
|
|---|
| 57 | // are supported), and "theOmittable" is a boolean flag to set whether
|
|---|
| 58 | // the user of the command can ommit the parameter or not. If "theOmittable"
|
|---|
| 59 | // is true, the default value must be given.
|
|---|
| 60 | ~G4UIparameter();
|
|---|
| 61 | // Destructor. When a command is destructed, the delete operator(s) for
|
|---|
| 62 | // associating parameter(s) are AUTOMATICALLY invoked. Thus the user needs
|
|---|
| 63 | // NOT to invoke this by him/herself.
|
|---|
| 64 |
|
|---|
| 65 | public:
|
|---|
| 66 | G4int operator==(const G4UIparameter &right) const;
|
|---|
| 67 | G4int operator!=(const G4UIparameter &right) const;
|
|---|
| 68 |
|
|---|
| 69 | G4int CheckNewValue(const char* newValue);
|
|---|
| 70 | void List();
|
|---|
| 71 |
|
|---|
| 72 | private:
|
|---|
| 73 | G4String parameterName;
|
|---|
| 74 | G4String parameterGuidance;
|
|---|
| 75 | G4String defaultValue;
|
|---|
| 76 | G4String parameterRange;
|
|---|
| 77 | G4String parameterCandidate;
|
|---|
| 78 | char parameterType;
|
|---|
| 79 | G4bool omittable;
|
|---|
| 80 | G4bool currentAsDefaultFlag;
|
|---|
| 81 | G4int widget;
|
|---|
| 82 |
|
|---|
| 83 | public: // with description
|
|---|
| 84 | inline void SetDefaultValue(const char * theDefaultValue)
|
|---|
| 85 | { defaultValue = theDefaultValue; }
|
|---|
| 86 | void SetDefaultValue(G4int theDefaultValue);
|
|---|
| 87 | void SetDefaultValue(G4double theDefaultValue);
|
|---|
| 88 | // These methods set the default value of the parameter.
|
|---|
| 89 | public:
|
|---|
| 90 | inline G4String GetDefaultValue() const
|
|---|
| 91 | { return defaultValue; }
|
|---|
| 92 | inline char GetParameterType() const
|
|---|
| 93 | { return parameterType; }
|
|---|
| 94 |
|
|---|
| 95 | public: // with description
|
|---|
| 96 | inline void SetParameterRange(const char * theRange)
|
|---|
| 97 | { parameterRange = theRange; }
|
|---|
| 98 | // Defines the range the parameter can take.
|
|---|
| 99 | // The variable name appear in the range expression must be same
|
|---|
| 100 | // as the name of the parameter.
|
|---|
| 101 | // All the C++ syntax of relational operators are allowed for the
|
|---|
| 102 | // range expression.
|
|---|
| 103 | public:
|
|---|
| 104 | inline G4String GetParameterRange() const
|
|---|
| 105 | { return parameterRange; }
|
|---|
| 106 |
|
|---|
| 107 | // parameterName
|
|---|
| 108 | inline void SetParameterName(const char * theName)
|
|---|
| 109 | { parameterName = theName; }
|
|---|
| 110 | inline G4String GetParameterName() const
|
|---|
| 111 | { return parameterName; }
|
|---|
| 112 |
|
|---|
| 113 | public: // with description
|
|---|
| 114 | inline void SetParameterCandidates(const char * theString)
|
|---|
| 115 | { parameterCandidate = theString; }
|
|---|
| 116 | // This method is meaningful if the type of the parameter is string.
|
|---|
| 117 | // The candidates listed in the argument must be separated by space(s).
|
|---|
| 118 | public:
|
|---|
| 119 | inline G4String GetParameterCandidates() const
|
|---|
| 120 | { return parameterCandidate; }
|
|---|
| 121 |
|
|---|
| 122 | // omittable
|
|---|
| 123 | inline void SetOmittable(G4bool om)
|
|---|
| 124 | { omittable = om; }
|
|---|
| 125 | inline G4bool IsOmittable() const
|
|---|
| 126 | { return omittable; }
|
|---|
| 127 |
|
|---|
| 128 | // currentAsDefaultFlag
|
|---|
| 129 | inline void SetCurrentAsDefault(G4bool val)
|
|---|
| 130 | { currentAsDefaultFlag = val; }
|
|---|
| 131 | inline G4bool GetCurrentAsDefault() const
|
|---|
| 132 | { return currentAsDefaultFlag; }
|
|---|
| 133 |
|
|---|
| 134 | // out of date methods
|
|---|
| 135 | inline void SetWidget(G4int theWidget)
|
|---|
| 136 | { widget = theWidget; }
|
|---|
| 137 | inline const G4String GetParameterGuidance() const
|
|---|
| 138 | { return parameterGuidance; }
|
|---|
| 139 | inline void SetGuidance(const char * theGuidance)
|
|---|
| 140 | { parameterGuidance = theGuidance; }
|
|---|
| 141 |
|
|---|
| 142 | private:
|
|---|
| 143 | // --- the following is used by CheckNewValue() -------
|
|---|
| 144 | G4int TypeCheck(const char* newValue );
|
|---|
| 145 | G4int RangeCheck(const char* newValue );
|
|---|
| 146 | G4int CandidateCheck(const char* newValue );
|
|---|
| 147 | G4int IsInt(const char* str, short maxDigit);
|
|---|
| 148 | G4int IsDouble(const char* str);
|
|---|
| 149 | G4int ExpectExponent(const char* str);
|
|---|
| 150 | // syntax nodes
|
|---|
| 151 | yystype Expression( void );
|
|---|
| 152 | yystype LogicalORExpression( void );
|
|---|
| 153 | yystype LogicalANDExpression( void );
|
|---|
| 154 | yystype EqualityExpression ( void );
|
|---|
| 155 | yystype RelationalExpression( void );
|
|---|
| 156 | yystype AdditiveExpression( void );
|
|---|
| 157 | yystype MultiplicativeExpression( void );
|
|---|
| 158 | yystype UnaryExpression( void );
|
|---|
| 159 | yystype PrimaryExpression( void );
|
|---|
| 160 | // semantics routines
|
|---|
| 161 | G4int Eval2( yystype arg1, G4int op, yystype arg2 );
|
|---|
| 162 | G4int CompareInt( G4int arg1, G4int op, G4int arg2);
|
|---|
| 163 | G4int CompareDouble( double arg1, G4int op, double arg2);
|
|---|
| 164 | // utility
|
|---|
| 165 | tokenNum Yylex( void ); // returns next token
|
|---|
| 166 | G4int G4UIpGetc( void ); // read one char from rangeBuf
|
|---|
| 167 | G4int G4UIpUngetc( G4int c ); // put back
|
|---|
| 168 | G4int Backslash( G4int c );
|
|---|
| 169 | G4int Follow( G4int expect, G4int ifyes, G4int ifno );
|
|---|
| 170 | G4String TokenToStr(G4int token);
|
|---|
| 171 | //void PrintToken(void); // debug
|
|---|
| 172 | // data
|
|---|
| 173 | G4String rangeBuf;
|
|---|
| 174 | G4int bp; // buffer pointer for rangeBuf
|
|---|
| 175 | tokenNum token;
|
|---|
| 176 | yystype yylval;
|
|---|
| 177 | yystype newVal;
|
|---|
| 178 | G4int paramERR;
|
|---|
| 179 | //------------ end of CheckNewValue() related member --------------
|
|---|
| 180 |
|
|---|
| 181 | };
|
|---|
| 182 |
|
|---|
| 183 | #endif
|
|---|
| 184 |
|
|---|