Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UIparameter.hh
Go to the documentation of this file.
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// G4UIparameter
27//
28// Class description:
29//
30// This class represents a parameter which will be taken by a G4UIcommand
31// object. In case a command is defined by constructing G4UIcmdXXX class,
32// it automatically creates necessary parameter objects, thus the user needs
33// not to create parameter object(s). In case the user wants to create a
34// command directly instantiated by G4UIcommand class, he/she must create
35// a parameter object(s)
36
37// Author: Makoto Asai, 1997
38// --------------------------------------------------------------------
39#ifndef G4UIparameter_hh
40#define G4UIparameter_hh 1
41
42#include "G4UItokenNum.hh"
43#include "globals.hh"
44
46{
47 public:
48 // Default constructor
49 G4UIparameter() = default;
50
51 // Constructors, where "theName" is the name of the parameter which will
52 // be used by the range checking, "theType" is the type of the parameter
53 // (currently "b" (Boolean), "i" (integer), "l" (long int), "d" (double)
54 // and "s" (string) are supported).
55 // "theOmittable" is a Boolean flag to set whether
56 // the user of the command can omit the parameter or not.
57 // If "theOmittable" is true, the default value must be given
58 G4UIparameter(char theType);
59 G4UIparameter(const char* theName, char theType, G4bool theOmittable);
60
61 // Destructor. When a command is destructed, the delete operator(s) of the
62 // associated parameter(s) are AUTOMATICALLY invoked
64
65 G4int CheckNewValue(const char* newValue);
66 void List();
67
68 // These methods set the default value of the parameter
69 inline void SetDefaultValue(const char* theDefaultValue) { defaultValue = theDefaultValue; }
70 void SetDefaultValue(G4int theDefaultValue);
71 void SetDefaultValue(G4long theDefaultValue);
72 void SetDefaultValue(G4double theDefaultValue);
73
74 // This method can be used for a string-type parameter that is
75 // used to specify a unit. This method is valid only for a
76 // string-type parameter
77 void SetDefaultUnit(const char* theDefaultUnit);
78
79 inline const G4String& GetDefaultValue() const { return defaultValue; }
80 inline char GetParameterType() const { return parameterType; }
81
82 // Defines the range the parameter can take.
83 // The variable name appearing in the range expression must be the
84 // same as the name of the parameter.
85 // All the C++ syntax of relational operators are allowed for the
86 // range expression
87 inline void SetParameterRange(const char* theRange) { rangeExpression = theRange; }
88
89 inline const G4String& GetParameterRange() const { return rangeExpression; }
90
91 inline void SetParameterName(const char* pName) { parameterName = pName; }
92 inline const G4String& GetParameterName() const { return parameterName; }
93
94 // This method is meaningful if the type of the parameter is string.
95 // The candidates listed in the argument must be separated by space(s)
96 inline void SetParameterCandidates(const char* theString) { parameterCandidate = theString; }
97
98 inline const G4String& GetParameterCandidates() const { return parameterCandidate; }
99
100 inline void SetOmittable(G4bool om) { omittable = om; }
101 inline G4bool IsOmittable() const { return omittable; }
102
103 inline void SetCurrentAsDefault(G4bool val) { currentAsDefaultFlag = val; }
104 inline G4bool GetCurrentAsDefault() const { return currentAsDefaultFlag; }
105
106 // Obsolete methods
107 //
108 inline const G4String& GetParameterGuidance() const { return parameterGuidance; }
109 inline void SetGuidance(const char* theGuidance) { parameterGuidance = theGuidance; }
110
111 protected:
114
115 private:
116 // --- the following is used by CheckNewValue() -------
117 G4bool TypeCheck(const char* newValue);
118 G4bool RangeCheck(const char* newValue);
119 G4bool CandidateCheck(const char* newValue);
120 // syntax nodes
121 yystype Expression();
122 yystype LogicalORExpression();
123 yystype LogicalANDExpression();
124 yystype EqualityExpression();
125 yystype RelationalExpression();
126 yystype AdditiveExpression();
127 yystype MultiplicativeExpression();
128 yystype UnaryExpression();
129 yystype PrimaryExpression();
130 // semantics routines
131 G4int Eval2(const yystype& arg1, G4int op, const yystype& arg2);
132 // utility
133 tokenNum Yylex(); // returns next token
134 G4int G4UIpGetc(); // read one char from rangeBuf
135 G4int G4UIpUngetc(G4int c); // put back
136 G4int Backslash(G4int c);
137 G4int Follow(G4int expect, G4int ifyes, G4int ifno);
138
139 // data -----------------------------------------------------------
140
141 G4String parameterName;
142 G4String parameterGuidance;
143 G4String defaultValue;
144 G4String rangeExpression;
145 G4String parameterCandidate;
146 char parameterType = '\0';
147 G4bool omittable = false;
148 G4bool currentAsDefaultFlag = false;
149
150 //------------ CheckNewValue() related data members ---------------
151 G4int bp = 0; // current index in rangeExpression
153 yystype yylval;
154 yystype newVal;
155 G4int paramERR = 0;
156};
157
158#endif
double G4double
Definition G4Types.hh:83
long G4long
Definition G4Types.hh:87
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
const G4String & GetParameterCandidates() const
void SetDefaultValue(const char *theDefaultValue)
G4int CheckNewValue(const char *newValue)
void SetParameterName(const char *pName)
const G4String & GetParameterGuidance() const
G4UIparameter()=default
G4bool IsOmittable() const
void SetOmittable(G4bool om)
const G4String & GetParameterRange() const
void SetGuidance(const char *theGuidance)
void SetParameterRange(const char *theRange)
G4bool GetCurrentAsDefault() const
void SetParameterCandidates(const char *theString)
char GetParameterType() const
void SetCurrentAsDefault(G4bool val)
const G4String & GetParameterName() const
const G4String & GetDefaultValue() const
void SetDefaultUnit(const char *theDefaultUnit)