Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UIcommand.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// G4UIcommand
27//
28// Class description:
29//
30// This G4UIcommand is the "concrete" base class which represents a command
31// used by Geant4 (G)UI. The user can use this class in case the parameter
32// arguments of a command are not suitable with respect to the derived command
33// classes.
34// Some methods defined in this base class are used by the derived classes
35
36// Author: Makoto Asai (SLAC), 1998
37// --------------------------------------------------------------------
38#ifndef G4UIcommand_hh
39#define G4UIcommand_hh 1
40
41#include <vector>
42
43#include "G4UIparameter.hh"
44#include "globals.hh"
45#include "G4ApplicationState.hh"
46#include "G4UItokenNum.hh"
47#include "G4ThreeVector.hh"
48
49class G4UImessenger;
50
52{
53 public:
54
55 G4UIcommand() = default;
56 // Dummy default constructor
57
58 G4UIcommand(const char* theCommandPath, G4UImessenger* theMessenger,
59 G4bool tBB = true);
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
65
66 virtual ~G4UIcommand();
67
68 G4bool operator==(const G4UIcommand& right) const;
69 G4bool operator!=(const G4UIcommand& right) const;
70
71 virtual G4int DoIt(G4String parameterList);
72
74
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
87
89
90 virtual void List();
91
92 static G4String ConvertToString(G4bool boolVal);
93 static G4String ConvertToString(G4int intValue);
94 static G4String ConvertToString(G4long longValue);
95 static G4String ConvertToString(G4double doubleValue);
96 static G4String ConvertToString(G4double doubleValue, const char* unitName);
97 static G4String ConvertToString(const G4ThreeVector& vec);
98 static G4String ConvertToString(const G4ThreeVector& vec,
99 const char* unitName);
100 // Static methods for conversion from value(s) to a string.
101 // These methods are to be used by GetCurrentValues() methods
102 // of concrete messengers
103
104 static G4bool ConvertToBool(const char* st);
105 static G4int ConvertToInt(const char* st);
106 static G4long ConvertToLongInt(const char* st);
107 static G4double ConvertToDouble(const char* st);
108 static G4double ConvertToDimensionedDouble(const char* st);
109 static G4ThreeVector ConvertTo3Vector(const char* st);
110 static G4ThreeVector ConvertToDimensioned3Vector(const char* st);
111 // Static methods for conversion from a string to a value of the returning
112 // type. These methods are to be used directly by SetNewValues() methods
113 // of concrete messengers, or GetNewXXXValue() of classes derived from
114 // this G4UIcommand class
115
116 static G4double ValueOf(const char* unitName);
117 static G4String CategoryOf(const char* unitName);
118 static G4String UnitsList(const char* unitCategory);
119 // Static methods for unit and its category
120
121 inline void SetRange(const char* rs) { rangeString = rs; }
122 // Defines the range the command parameter(s) can take.
123 // The variable name(s) appear in the range expression must be the same
124 // as the name(s) of the parameter(s).
125 // All the C++ syntax of relational operators are allowed for the
126 // range expression
127
128 inline const G4String& GetRange() const { return rangeString; }
129 inline std::size_t GetGuidanceEntries() const
130 {
131 return commandGuidance.size();
132 }
133 inline const G4String& GetGuidanceLine(G4int i) const
134 {
135 return commandGuidance[i];
136 }
137 inline const G4String& GetCommandPath() const { return commandPath; }
138 inline const G4String& GetCommandName() const { return commandName; }
139 inline std::size_t GetParameterEntries() const { return parameter.size(); }
140 inline G4UIparameter* GetParameter(G4int i) const { return parameter[i]; }
141 inline std::vector<G4ApplicationState>* GetStateList()
142 {
143 return &availabelStateList;
144 }
145 inline G4UImessenger* GetMessenger() const { return messenger; }
146
147 inline void SetParameter(G4UIparameter* const newParameter)
148 // Defines a parameter. This method is used by the derived command
149 // classes but the user can directly use this command when defining
150 // a command, without using the derived class. For this case, the order
151 // of the parameters is the order of invoking this method
152 {
153 parameter.push_back(newParameter);
154 newVal.resize(parameter.size());
155 }
156
157 inline void SetGuidance(const char* aGuidance)
158 // Adds a guidance line. Unlimited times of invokation of this method is
159 // allowed. The given lines of guidance will appear for the help.
160 // The first line of the guidance will be used as the title of the
161 // command, i.e. one line list of the commands
162 {
163 commandGuidance.emplace_back(aGuidance);
164 }
165
166 inline const G4String GetTitle() const
167 {
168 return (commandGuidance.empty()) ? G4String("...Title not available...")
169 : commandGuidance[0];
170 }
171
172 inline void SetToBeBroadcasted(G4bool val) { toBeBroadcasted = val; }
173 inline G4bool ToBeBroadcasted() const { return toBeBroadcasted; }
174 inline void SetToBeFlushed(G4bool val) { toBeFlushed = val; }
175 inline G4bool ToBeFlushed() const { return toBeFlushed; }
176 inline void SetWorkerThreadOnly(G4bool val = true) { workerThreadOnly=val; }
177 inline G4bool IsWorkerThreadOnly() const { return workerThreadOnly; }
178
180 {
181 commandFailureCode = errCode;
182 failureDescription = ed.str();
183 }
185 {
187 failureDescription = ed.str();
188 }
191 inline void ResetFailure()
192 {
195 }
196
197 public:
203
205 { return commandType; }
207
208 inline void SetDefaultSortFlag(G4bool val)
209 { ifSort = val; }
210
211 protected:
212
213 // --- the following is used by CheckNewValue() --------
216
217 G4int CheckNewValue(const char* newValue);
218
222
225
226 G4bool ifSort = false;
227
228 private:
229
230 void G4UIcommandCommonConstructorCode(const char* theCommandPath);
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();
239 yystype LogicalORExpression();
240 yystype LogicalANDExpression();
241 yystype EqualityExpression();
242 yystype RelationalExpression();
243 yystype AdditiveExpression();
244 yystype MultiplicativeExpression();
245 yystype UnaryExpression();
246 yystype PrimaryExpression();
247 // semantics routines
248 G4int Eval2(const yystype& arg1, G4int op, const 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(); // 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(); // 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
265 private:
266 CommandType commandType = BaseClassCmd;
267 G4UImessenger* messenger = nullptr;
268 G4String commandPath;
269 G4String commandName;
270 G4String rangeString;
271 std::vector<G4UIparameter*> parameter;
272 std::vector<G4String> commandGuidance;
273 std::vector<G4ApplicationState> availabelStateList;
274
275 G4String rangeBuf;
276 G4int bp = 0; // buffer pointer for rangeBuf
278 yystype yylval;
279 std::vector<yystype> newVal;
280 G4int paramERR = 0;
281};
282
283#endif
G4ApplicationState
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
double G4double
Definition: G4Types.hh:83
long G4long
Definition: G4Types.hh:87
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:172
G4bool IsWorkerThreadOnly() const
Definition: G4UIcommand.hh:177
G4UIcommand()=default
G4UImessenger * GetMessenger() const
Definition: G4UIcommand.hh:145
std::size_t GetParameterEntries() const
Definition: G4UIcommand.hh:139
const G4String & GetGuidanceLine(G4int i) const
Definition: G4UIcommand.hh:133
static G4ThreeVector ConvertTo3Vector(const char *st)
Definition: G4UIcommand.cc:601
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:140
G4bool toBeBroadcasted
Definition: G4UIcommand.hh:219
G4int commandFailureCode
Definition: G4UIcommand.hh:223
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:370
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:362
virtual ~G4UIcommand()
Definition: G4UIcommand.cc:116
void SetCommandType(CommandType)
Definition: G4UIcommand.cc:89
G4bool ToBeBroadcasted() const
Definition: G4UIcommand.hh:173
G4int IfCommandFailed()
Definition: G4UIcommand.hh:189
static G4long ConvertToLongInt(const char *st)
Definition: G4UIcommand.cc:570
virtual G4int DoIt(G4String parameterList)
Definition: G4UIcommand.cc:146
G4UItokenNum::yystype yystype
Definition: G4UIcommand.hh:214
const G4String GetTitle() const
Definition: G4UIcommand.hh:166
G4bool operator==(const G4UIcommand &right) const
Definition: G4UIcommand.cc:134
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:446
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:137
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:157
CommandType GetCommandType() const
Definition: G4UIcommand.hh:204
void ResetFailure()
Definition: G4UIcommand.hh:191
G4int CheckNewValue(const char *newValue)
Definition: G4UIcommand.cc:629
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:179
@ WithADoubleAndUnitCmd
Definition: G4UIcommand.hh:201
@ With3VectorAndUnitCmd
Definition: G4UIcommand.hh:201
G4bool IsAvailable()
Definition: G4UIcommand.cc:342
std::size_t GetGuidanceEntries() const
Definition: G4UIcommand.hh:129
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:561
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:376
void SetToBeFlushed(G4bool val)
Definition: G4UIcommand.hh:174
G4bool toBeFlushed
Definition: G4UIcommand.hh:220
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:549
G4bool ifSort
Definition: G4UIcommand.hh:226
std::vector< G4ApplicationState > * GetStateList()
Definition: G4UIcommand.hh:141
void SetRange(const char *rs)
Definition: G4UIcommand.hh:121
void SetWorkerThreadOnly(G4bool val=true)
Definition: G4UIcommand.hh:176
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:579
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:588
const G4String & GetFailureDescription()
Definition: G4UIcommand.hh:190
G4bool ToBeFlushed() const
Definition: G4UIcommand.hh:175
virtual void List()
Definition: G4UIcommand.cc:411
G4bool workerThreadOnly
Definition: G4UIcommand.hh:221
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:287
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:138
G4bool operator!=(const G4UIcommand &right) const
Definition: G4UIcommand.cc:140
const G4String & GetRange() const
Definition: G4UIcommand.hh:128
G4String failureDescription
Definition: G4UIcommand.hh:224
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
Definition: G4UIcommand.cc:612
void SetDefaultSortFlag(G4bool val)
Definition: G4UIcommand.hh:208
void CommandFailed(G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:184
G4String GetCurrentValue()
Definition: G4UIcommand.cc:281
yystype { tokenNum type{ tokenNum::NONE } yystype
Definition: G4UItokenNum.hh:67