Geant4-11
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 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(void);
247 // semantics routines
248 G4int Eval2(yystype arg1, G4int op, 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(void); // 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(void); // read one char from rangeBuf
257 G4int G4UIpUngetc(G4int c); // put back
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:
271 std::vector<G4UIparameter*> parameter;
272 std::vector<G4String> commandGuidance;
273 std::vector<G4ApplicationState> availabelStateList;
274
276 G4int bp = 0; // buffer pointer for rangeBuf
279 std::vector<yystype> newVal;
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
G4String commandName
Definition: G4UIcommand.hh:269
G4bool IsWorkerThreadOnly() const
Definition: G4UIcommand.hh:177
void G4UIcommandCommonConstructorCode(const char *theCommandPath)
Definition: G4UIcommand.cc:71
G4int TypeCheck(const char *t)
Definition: G4UIcommand.cc:638
G4UImessenger * GetMessenger() const
Definition: G4UIcommand.hh:144
std::size_t GetParameterEntries() const
Definition: G4UIcommand.hh:138
yystype MultiplicativeExpression(void)
yystype yylval
Definition: G4UIcommand.hh:278
G4int Backslash(G4int c)
unsigned IndexOf(const char *)
const G4String & GetGuidanceLine(G4int i) const
Definition: G4UIcommand.hh:132
G4int CompareDouble(G4double arg1, G4int op, G4double arg2)
static G4ThreeVector ConvertTo3Vector(const char *st)
Definition: G4UIcommand.cc:597
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:139
G4bool toBeBroadcasted
Definition: G4UIcommand.hh:219
G4int commandFailureCode
Definition: G4UIcommand.hh:223
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:371
yystype EqualityExpression(void)
Definition: G4UIcommand.cc:998
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:363
unsigned IsParameter(const char *)
virtual ~G4UIcommand()
Definition: G4UIcommand.cc:121
yystype AdditiveExpression(void)
G4int Follow(G4int expect, G4int ifyes, G4int ifno)
void SetCommandType(CommandType)
Definition: G4UIcommand.cc:94
G4bool ToBeBroadcasted() const
Definition: G4UIcommand.hh:173
G4int IfCommandFailed()
Definition: G4UIcommand.hh:189
std::vector< G4ApplicationState > availabelStateList
Definition: G4UIcommand.hh:273
yystype PrimaryExpression(void)
static G4long ConvertToLongInt(const char *st)
Definition: G4UIcommand.cc:566
virtual G4int DoIt(G4String parameterList)
Definition: G4UIcommand.cc:151
std::vector< G4UIparameter * > parameter
Definition: G4UIcommand.hh:271
const G4String GetTitle() const
Definition: G4UIcommand.hh:165
G4bool operator==(const G4UIcommand &right) const
Definition: G4UIcommand.cc:139
tokenNum Yylex(void)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:445
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:136
G4int paramERR
Definition: G4UIcommand.hh:280
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:146
G4String rangeString
Definition: G4UIcommand.hh:270
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
G4int IsDouble(const char *str)
Definition: G4UIcommand.cc:736
yystype LogicalANDExpression(void)
Definition: G4UIcommand.cc:953
G4int G4UIpUngetc(G4int c)
yystype RelationalExpression(void)
G4int CompareInt(G4int arg1, G4int op, G4int arg2)
CommandType GetCommandType() const
Definition: G4UIcommand.hh:204
void ResetFailure()
Definition: G4UIcommand.hh:191
G4String rangeBuf
Definition: G4UIcommand.hh:275
G4int CheckNewValue(const char *newValue)
Definition: G4UIcommand.cc:625
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:343
std::size_t GetGuidanceEntries() const
Definition: G4UIcommand.hh:128
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:557
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:377
void SetToBeFlushed(G4bool val)
Definition: G4UIcommand.hh:174
G4UImessenger * messenger
Definition: G4UIcommand.hh:267
yystype LogicalORExpression(void)
Definition: G4UIcommand.cc:908
yystype Expression(void)
Definition: G4UIcommand.cc:897
tokenNum token
Definition: G4UIcommand.hh:277
G4bool toBeFlushed
Definition: G4UIcommand.hh:220
G4int IsInt(const char *str, short maxLength)
Definition: G4UIcommand.cc:689
G4int ExpectExponent(const char *str)
Definition: G4UIcommand.cc:726
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:545
G4bool ifSort
Definition: G4UIcommand.hh:226
yystype UnaryExpression(void)
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:575
G4int CompareLong(G4long arg1, G4int op, G4long arg2)
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:584
std::vector< G4String > commandGuidance
Definition: G4UIcommand.hh:272
const G4String & GetFailureDescription()
Definition: G4UIcommand.hh:190
G4bool ToBeFlushed() const
Definition: G4UIcommand.hh:175
virtual void List()
Definition: G4UIcommand.cc:410
G4bool workerThreadOnly
Definition: G4UIcommand.hh:221
G4int RangeCheck(const char *t)
Definition: G4UIcommand.cc:849
G4String commandPath
Definition: G4UIcommand.hh:268
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:288
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:137
G4bool operator!=(const G4UIcommand &right) const
Definition: G4UIcommand.cc:145
std::vector< yystype > newVal
Definition: G4UIcommand.hh:279
const G4String & GetRange() const
Definition: G4UIcommand.hh:127
G4String failureDescription
Definition: G4UIcommand.hh:224
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
Definition: G4UIcommand.cc:608
CommandType commandType
Definition: G4UIcommand.hh:266
G4int G4UIpGetc(void)
void SetDefaultSortFlag(G4bool val)
Definition: G4UIcommand.hh:208
void CommandFailed(G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:184
G4String GetCurrentValue()
Definition: G4UIcommand.cc:282
G4int Eval2(yystype arg1, G4int op, yystype arg2)
struct G4UItokenNum::yystype yystype