Geant4 10.7.0
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
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);
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
102
103 static G4bool ConvertToBool(const char* st);
104 static G4int ConvertToInt(const char* st);
105 static G4long ConvertToLongInt(const char* st);
106 static G4double ConvertToDouble(const char* st);
107 static G4double ConvertToDimensionedDouble(const char* st);
108 static G4ThreeVector ConvertTo3Vector(const char* st);
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
114
115 static G4double ValueOf(const char* unitName);
116 static G4String CategoryOf(const char* unitName);
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
126
127 inline const G4String& GetRange() const { return rangeString; }
128 inline std::size_t GetGuidanceEntries() const
129 {
130 return commandGuidance.size();
131 }
132 inline const G4String& GetGuidanceLine(G4int i) const
133 {
134 return commandGuidance[i];
135 }
136 inline const G4String& GetCommandPath() const { return commandPath; }
137 inline const G4String& GetCommandName() const { return commandName; }
138 inline std::size_t GetParameterEntries() const { return parameter.size(); }
139 inline G4UIparameter* GetParameter(G4int i) const { return parameter[i]; }
140 inline std::vector<G4ApplicationState>* GetStateList()
141 {
142 return &availabelStateList;
143 }
144 inline G4UImessenger* GetMessenger() const { return messenger; }
145
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
151 {
152 parameter.push_back(newParameter);
153 newVal.resize(parameter.size());
154 }
155
156 inline void SetGuidance(const char* aGuidance)
157 // Adds a guidance line. Unlimited times of invokation of this method is
158 // allowed. The given lines of guidance will appear for the help.
159 // The first line of the guidance will be used as the title of the
160 // command, i.e. one line list of the commands
161 {
162 commandGuidance.push_back(G4String(aGuidance));
163 }
164
165 inline const G4String GetTitle() const
166 {
167 return (commandGuidance.size() == 0)
168 ? 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 protected:
198
199 // --- the following is used by CheckNewValue() --------
202
203 G4int CheckNewValue(const char* newValue);
204
208
211
212 private:
213
214 void G4UIcommandCommonConstructorCode(const char* theCommandPath);
215
216 G4int TypeCheck(const char* t);
217 G4int RangeCheck(const char* t);
218 G4int IsInt(const char* str, short maxLength); // used for both int and long int
219 G4int IsDouble(const char* str);
220 G4int ExpectExponent(const char* str);
221 // syntax nodes
222 yystype Expression(void);
223 yystype LogicalORExpression(void);
224 yystype LogicalANDExpression(void);
225 yystype EqualityExpression(void);
226 yystype RelationalExpression(void);
227 yystype AdditiveExpression(void);
228 yystype MultiplicativeExpression(void);
229 yystype UnaryExpression(void);
230 yystype PrimaryExpression(void);
231 // semantics routines
232 G4int Eval2(yystype arg1, G4int op, yystype arg2);
233 G4int CompareInt(G4int arg1, G4int op, G4int arg2);
234 G4int CompareLong(G4long arg1, G4int op, G4long arg2);
235 G4int CompareDouble(G4double arg1, G4int op, G4double arg2);
236 // utility
237 tokenNum Yylex(void); // returns next token
238 unsigned IndexOf(const char*); // returns the index of the var name
239 unsigned IsParameter(const char*); // returns 1 or 0
240 G4int G4UIpGetc(void); // read one char from rangeBuf
241 G4int G4UIpUngetc(G4int c); // put back
242 G4int Backslash(G4int c);
243 G4int Follow(G4int expect, G4int ifyes, G4int ifno);
244 //G4String TokenToStr(G4int token);
245 //void PrintToken(void); // for debug
246
247 // Data -----------------------------------------------------------
248
249 G4UImessenger* messenger = nullptr;
250 G4String commandPath;
251 G4String commandName;
252 G4String rangeString;
253 std::vector<G4UIparameter*> parameter;
254 std::vector<G4String> commandGuidance;
255 std::vector<G4ApplicationState> availabelStateList;
256
257 G4String rangeBuf;
258 G4int bp = 0; // buffer pointer for rangeBuf
260 yystype yylval;
261 std::vector<yystype> newVal;
262 G4int paramERR = 0;
263};
264
265#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
G4UImessenger * GetMessenger() const
Definition: G4UIcommand.hh:144
std::size_t GetParameterEntries() const
Definition: G4UIcommand.hh:138
const G4String & GetGuidanceLine(G4int i) const
Definition: G4UIcommand.hh:132
static G4ThreeVector ConvertTo3Vector(const char *st)
Definition: G4UIcommand.cc:583
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:139
G4bool toBeBroadcasted
Definition: G4UIcommand.hh:205
G4int commandFailureCode
Definition: G4UIcommand.hh:209
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:356
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:348
virtual ~G4UIcommand()
Definition: G4UIcommand.cc:105
G4bool ToBeBroadcasted() const
Definition: G4UIcommand.hh:173
G4int IfCommandFailed()
Definition: G4UIcommand.hh:189
static G4long ConvertToLongInt(const char *st)
Definition: G4UIcommand.cc:552
virtual G4int DoIt(G4String parameterList)
Definition: G4UIcommand.cc:135
const G4String GetTitle() const
Definition: G4UIcommand.hh:165
G4bool operator==(const G4UIcommand &right) const
Definition: G4UIcommand.cc:123
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:430
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:136
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:146
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
void ResetFailure()
Definition: G4UIcommand.hh:191
G4int CheckNewValue(const char *newValue)
Definition: G4UIcommand.cc:611
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:179
G4bool IsAvailable()
Definition: G4UIcommand.cc:328
std::size_t GetGuidanceEntries() const
Definition: G4UIcommand.hh:128
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:543
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:362
void SetToBeFlushed(G4bool val)
Definition: G4UIcommand.hh:174
G4bool toBeFlushed
Definition: G4UIcommand.hh:206
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:530
std::vector< G4ApplicationState > * GetStateList()
Definition: G4UIcommand.hh:140
void SetRange(const char *rs)
Definition: G4UIcommand.hh:120
void SetWorkerThreadOnly(G4bool val=true)
Definition: G4UIcommand.hh:176
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:561
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:570
const G4String & GetFailureDescription()
Definition: G4UIcommand.hh:190
G4bool ToBeFlushed() const
Definition: G4UIcommand.hh:175
virtual void List()
Definition: G4UIcommand.cc:395
G4bool workerThreadOnly
Definition: G4UIcommand.hh:207
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:273
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:137
G4bool operator!=(const G4UIcommand &right) const
Definition: G4UIcommand.cc:129
const G4String & GetRange() const
Definition: G4UIcommand.hh:127
G4String failureDescription
Definition: G4UIcommand.hh:210
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
Definition: G4UIcommand.cc:594
void CommandFailed(G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:184
G4String GetCurrentValue()
Definition: G4UIcommand.cc:267