Geant4 11.2.2
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 "G4ApplicationState.hh"
42#include "G4ThreeVector.hh"
43#include "G4UIparameter.hh"
44#include "G4UItokenNum.hh"
45#include "globals.hh"
46
47#include <vector>
48
49class G4UImessenger;
50
52{
53 public:
54 // Dummy default constructor
55 G4UIcommand() = default;
56
57 // Constructor. The command string with full path directory
58 // and the pointer to the messenger must be given.
59 // If tBB is set to false, this command won't be sent to worker threads.
60 // This tBB parameter could be changed with SetToBeBroadcasted() method
61 // except for G4UIdirectory
62 G4UIcommand(const char* theCommandPath, G4UImessenger* theMessenger, G4bool tBB = true);
63
64 virtual ~G4UIcommand();
65
66 G4bool operator==(const G4UIcommand& right) const;
67 G4bool operator!=(const G4UIcommand& right) const;
68
69 virtual G4int DoIt(G4String parameterList);
70
72
73 // These methods define the states where the command is available.
74 // Once one of these commands is invoked, the command application will
75 // be denied when Geant4 is NOT in the assigned states
83
85
86 virtual void List();
87
88 // Static methods for conversion from value(s) to a string.
89 // These methods are to be used by GetCurrentValues() methods
90 // of concrete messengers
91 static G4String ConvertToString(G4bool boolVal);
92 static G4String ConvertToString(G4int intValue);
93 static G4String ConvertToString(G4long longValue);
94 static G4String ConvertToString(G4double doubleValue);
95 static G4String ConvertToString(G4double doubleValue, const char* unitName);
96 static G4String ConvertToString(const G4ThreeVector& vec);
97 static G4String ConvertToString(const G4ThreeVector& vec, const char* unitName);
98
99 // Static methods for conversion from a string to a value of the returning
100 // type. These methods are to be used directly by SetNewValues() methods
101 // of concrete messengers, or GetNewXXXValue() of classes derived from
102 // this G4UIcommand class
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
111 // Static methods for unit and its category
112 static G4double ValueOf(const char* unitName);
113 static G4String CategoryOf(const char* unitName);
114 static G4String UnitsList(const char* unitCategory);
115
116 // Defines the range the command parameter(s) can take.
117 // The variable name(s) appear in the range expression must be the same
118 // as the name(s) of the parameter(s).
119 // All the C++ syntax of relational operators are allowed for the
120 // range expression
121 inline void SetRange(const char* rs) { rangeExpression = rs; }
122
123 inline const G4String& GetRange() const { return rangeExpression; }
124 inline std::size_t GetGuidanceEntries() const { return commandGuidance.size(); }
125 inline const G4String& GetGuidanceLine(G4int i) const { return commandGuidance[i]; }
126 inline const G4String& GetCommandPath() const { return commandPath; }
127 inline const G4String& GetCommandName() const { return commandName; }
128 inline std::size_t GetParameterEntries() const { return parameter.size(); }
129 inline G4UIparameter* GetParameter(G4int i) const { return parameter[i]; }
130 inline std::vector<G4ApplicationState>* GetStateList() { return &availabelStateList; }
131 inline G4UImessenger* GetMessenger() const { return messenger; }
132
133 // Defines a parameter. This method is used by the derived command
134 // classes but the user can directly use this command when defining
135 // a command, without using the derived class. For this case, the order
136 // of the parameters is the order of invoking this method
137 inline void SetParameter(G4UIparameter* const newParameter)
138 {
139 parameter.push_back(newParameter);
140 newVal.resize(parameter.size());
141 }
142
143 // Adds a guidance line. Unlimited times of invokation of this method is
144 // allowed. The given lines of guidance will appear for the help.
145 // The first line of the guidance will be used as the title of the
146 // command, i.e. one line list of the commands
147 inline void SetGuidance(const char* aGuidance) { commandGuidance.emplace_back(aGuidance); }
148
149 inline const G4String GetTitle() const
150 {
151 return (commandGuidance.empty()) ? G4String("...Title not available...") : commandGuidance[0];
152 }
153
154 inline void SetToBeBroadcasted(G4bool val) { toBeBroadcasted = val; }
155 inline G4bool ToBeBroadcasted() const { return toBeBroadcasted; }
156 inline void SetToBeFlushed(G4bool val) { toBeFlushed = val; }
157 inline G4bool ToBeFlushed() const { return toBeFlushed; }
158 inline void SetWorkerThreadOnly(G4bool val = true) { workerThreadOnly = val; }
159 inline G4bool IsWorkerThreadOnly() const { return workerThreadOnly; }
160
162 {
163 commandFailureCode = errCode;
164 failureDescription = ed.str();
165 }
167 {
169 failureDescription = ed.str();
170 }
173 inline void ResetFailure()
174 {
177 }
178
179 public:
194
195 inline CommandType GetCommandType() const { return commandType; }
197
198 inline void SetDefaultSortFlag(G4bool val) { ifSort = val; }
199
200 protected:
201 // --- the following is used by CheckNewValue() --------
204
205 G4int CheckNewValue(const char* newValue);
206
210
213
214 G4bool ifSort = false;
215
216 private:
217 void G4UIcommandCommonConstructorCode(const char* theCommandPath);
218
219 G4bool RangeCheck(const char* t);
220
221 // syntax nodes
222 yystype Expression();
223 yystype LogicalORExpression();
224 yystype LogicalANDExpression();
225 yystype EqualityExpression();
226 yystype RelationalExpression();
227 yystype AdditiveExpression();
228 yystype MultiplicativeExpression();
229 yystype UnaryExpression();
230 yystype PrimaryExpression();
231 // semantics routines
232 G4int Eval2(const yystype& arg1, G4int op, const yystype& arg2);
233 // utility
234 tokenNum Yylex(); // returns next token
235 unsigned IndexOf(const char*); // returns the index of the var name
236 unsigned IsParameter(const char*); // returns 1 or 0
237 G4int G4UIpGetc(); // read one char from rangeBuf
238 G4int G4UIpUngetc(G4int c); // put back
239 G4int Backslash(G4int c);
240 G4int Follow(G4int expect, G4int ifyes, G4int ifno);
241
242 // Data -----------------------------------------------------------
243
244 private:
245 CommandType commandType = BaseClassCmd;
246 G4UImessenger* messenger = nullptr;
247 G4String commandPath;
248 G4String commandName;
249 G4String rangeExpression;
250 std::vector<G4UIparameter*> parameter;
251 std::vector<G4String> commandGuidance;
252 std::vector<G4ApplicationState> availabelStateList;
253
254 G4int bp = 0; // current index into rangeExpression
256 yystype yylval;
257 std::vector<yystype> newVal;
258 G4int paramERR = 0;
259};
260
261#endif
G4ApplicationState
std::ostringstream G4ExceptionDescription
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)
G4bool IsWorkerThreadOnly() const
G4UIcommand()=default
G4UImessenger * GetMessenger() const
std::size_t GetParameterEntries() const
const G4String & GetGuidanceLine(G4int i) const
static G4ThreeVector ConvertTo3Vector(const char *st)
G4UIparameter * GetParameter(G4int i) const
G4bool toBeBroadcasted
G4int commandFailureCode
static G4String CategoryOf(const char *unitName)
static G4double ValueOf(const char *unitName)
virtual ~G4UIcommand()
void SetCommandType(CommandType)
G4bool ToBeBroadcasted() const
G4int IfCommandFailed()
static G4long ConvertToLongInt(const char *st)
virtual G4int DoIt(G4String parameterList)
const G4String GetTitle() const
G4bool operator==(const G4UIcommand &right) const
static G4String ConvertToString(G4bool boolVal)
const G4String & GetCommandPath() const
void SetParameter(G4UIparameter *const newParameter)
void SetGuidance(const char *aGuidance)
CommandType GetCommandType() const
void ResetFailure()
G4int CheckNewValue(const char *newValue)
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
G4bool IsAvailable()
std::size_t GetGuidanceEntries() const
static G4int ConvertToInt(const char *st)
static G4String UnitsList(const char *unitCategory)
void SetToBeFlushed(G4bool val)
G4bool toBeFlushed
static G4bool ConvertToBool(const char *st)
std::vector< G4ApplicationState > * GetStateList()
void SetRange(const char *rs)
void SetWorkerThreadOnly(G4bool val=true)
static G4double ConvertToDouble(const char *st)
static G4double ConvertToDimensionedDouble(const char *st)
const G4String & GetFailureDescription()
G4bool ToBeFlushed() const
virtual void List()
G4bool workerThreadOnly
void AvailableForStates(G4ApplicationState s1)
const G4String & GetCommandName() const
G4bool operator!=(const G4UIcommand &right) const
const G4String & GetRange() const
G4String failureDescription
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
void SetDefaultSortFlag(G4bool val)
void CommandFailed(G4ExceptionDescription &ed)
G4String GetCurrentValue()