Geant4 9.6.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//
27// $Id$
28//
29//
30
31#ifndef G4UIcommand_h
32#define G4UIcommand_h 1
33
34#include "G4UIparameter.hh"
35class G4UImessenger;
36#include "globals.hh"
37#include "G4ApplicationState.hh"
38#include <vector>
39#include "G4UItokenNum.hh"
40#include "G4ThreeVector.hh"
41
42// class description:
43//
44// This G4UIcommand is the "concrete" base class which represents a command
45// used by Geant4 (G)UI. The user can use this class in case the parameter
46// arguments of a command are not suitable with respect to the derived command
47// classes.
48// Some methods defined in this base class are used by the derived classes.
49//
50
52{
53 public:
55 public: // with description
56 G4UIcommand(const char * theCommandPath, G4UImessenger * theMessenger);
57 // Constructor. The command string with full path directory
58 // and the pointer to the messenger must be given.
59 public:
60 virtual ~G4UIcommand();
61
62 G4int operator==(const G4UIcommand &right) const;
63 G4int operator!=(const G4UIcommand &right) const;
64
65 virtual G4int DoIt(G4String parameterList);
67 public: // with description
77 // These methods define the states where the command is available.
78 // Once one of these commands is invoked, the command application will
79 // be denied when Geant4 is NOT in the assigned states.
80 public:
82 virtual void List();
83
84 public: // with description
85 static G4String ConvertToString(G4bool boolVal);
86 static G4String ConvertToString(G4int intValue);
87 static G4String ConvertToString(G4double doubleValue);
88 static G4String ConvertToString(G4double doubleValue,const char* unitName);
90 static G4String ConvertToString(G4ThreeVector vec,const char* unitName);
91 // Static methods for conversion from value(s) to a string. These methods are to be
92 // used by GetCurrentValues() methods of concrete messengers.
93
94 static G4bool ConvertToBool(const char* st);
95 static G4int ConvertToInt(const char* st);
96 static G4double ConvertToDouble(const char* st);
97 static G4double ConvertToDimensionedDouble(const char* st);
98 static G4ThreeVector ConvertTo3Vector(const char* st);
99 static G4ThreeVector ConvertToDimensioned3Vector(const char* st);
100 // Static methods for conversion from a string to a value of the returning type.
101 // These methods are to be used directly by SetNewValues() methods of concrete
102 // messengers, or GetNewXXXValue() of classes derived from this G4UIcommand class.
103
104 static G4double ValueOf(const char* unitName);
105 static G4String CategoryOf(const char* unitName);
106 static G4String UnitsList(const char* unitCategory);
107 // Static methods for unit and its category.
108
109 private:
110 void G4UIcommandCommonConstructorCode (const char * theCommandPath);
111 G4UImessenger *messenger;
112 G4String commandPath;
113 G4String commandName;
114 G4String rangeString;
115 std::vector<G4UIparameter*> parameter;
116 std::vector<G4String> commandGuidance;
117 std::vector<G4ApplicationState> availabelStateList;
118
119 public: // with description
120 inline void SetRange(const char* rs)
121 { rangeString = rs; }
122 // Defines the range the command parameter(s) can take.
123 // The variable name(s) appear in the range expression must be 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 public:
128 inline const G4String & GetRange() const
129 { return rangeString; };
131 { return commandGuidance.size(); }
132 inline const G4String & GetGuidanceLine(G4int i) const
133 { return commandGuidance[i]; }
134 inline const G4String & GetCommandPath() const
135 { return commandPath; }
136 inline const G4String & GetCommandName() const
137 { return commandName; }
139 { return parameter.size(); }
141 { return parameter[i]; }
142 inline std::vector<G4ApplicationState>* GetStateList()
143 { return &availabelStateList; }
145 { return messenger; }
146 public: // with description
147 inline void SetParameter(G4UIparameter *const newParameter)
148 {
149 parameter.push_back( newParameter );
150 newVal.resize( parameter.size() );
151 }
152 // Defines a parameter. This method is used by the derived command classes
153 // but the user can directly use this command when he/she defines a command
154 // by hem(her)self without using the derived class. For this case, the order
155 // of the parameters is the order of invoking this method.
156 inline void SetGuidance(const char * aGuidance)
157 {
158 commandGuidance.push_back( G4String( aGuidance ) );
159 }
160 // Adds a guidance line. Unlimitted number of invokation of this method is
161 // allowed. The given lines of guidance will appear for the help. The first
162 // line of the guidance will be used as the title of the command, i.e. one
163 // line list of the commands.
164 public:
165 inline const G4String GetTitle() const
166 {
167 if(commandGuidance.size() == 0)
168 { return G4String("...Title not available..."); }
169 else
170 { return commandGuidance[0]; }
171 }
172
173 protected:
174 G4int CheckNewValue(const char* newValue);
175
176 // --- the following is used by CheckNewValue() --------
177 private:
178 G4int TypeCheck(const char* t);
179 G4int RangeCheck(const char* t);
180 G4int IsInt(const char* str, short maxLength);
181 G4int IsDouble(const char* str);
182 G4int ExpectExponent(const char* str);
183 // syntax nodes
184 yystype Expression( void );
185 yystype LogicalORExpression( void );
186 yystype LogicalANDExpression( void );
187 yystype EqualityExpression ( void );
188 yystype RelationalExpression( void );
189 yystype AdditiveExpression( void );
190 yystype MultiplicativeExpression( void );
191 yystype UnaryExpression( void );
192 yystype PrimaryExpression( void );
193 // semantics routines
194 G4int Eval2( yystype arg1, G4int op, yystype arg2 );
195 G4int CompareInt( G4int arg1, G4int op, G4int arg2);
196 G4int CompareDouble( G4double arg1, G4int op, G4double arg2);
197 // utility
198 tokenNum Yylex( void ); // returns next token
199 unsigned IndexOf( const char* ); // returns the index of the var name
200 unsigned IsParameter( const char* ); // returns 1 or 0
201 G4int G4UIpGetc( void ); // read one char from rangeBuf
202 G4int G4UIpUngetc( G4int c ); // put back
203 G4int Backslash( G4int c );
204 G4int Follow( G4int expect, G4int ifyes, G4int ifno );
205 G4String TokenToStr(G4int token);
206 void PrintToken(void); // for debug
207 // data
208 G4String rangeBuf;
209 G4int bp; // buffer pointer for rangeBuf
210 tokenNum token;
211 yystype yylval;
212 std::vector<yystype> newVal;
213 G4int paramERR;
214};
215
216#endif
217
G4ApplicationState
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
tokenNum
Definition: G4UItokenNum.hh:37
G4UImessenger * GetMessenger() const
Definition: G4UIcommand.hh:144
const G4String & GetGuidanceLine(G4int i) const
Definition: G4UIcommand.hh:132
static G4ThreeVector ConvertTo3Vector(const char *st)
Definition: G4UIcommand.cc:441
G4int operator==(const G4UIcommand &right) const
Definition: G4UIcommand.cc:94
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:140
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:295
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:288
virtual ~G4UIcommand()
Definition: G4UIcommand.cc:83
G4int GetGuidanceEntries() const
Definition: G4UIcommand.hh:130
virtual G4int DoIt(G4String parameterList)
Definition: G4UIcommand.cc:104
const G4String GetTitle() const
Definition: G4UIcommand.hh:165
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:349
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:134
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:138
G4int operator!=(const G4UIcommand &right) const
Definition: G4UIcommand.cc:99
G4int CheckNewValue(const char *newValue)
Definition: G4UIcommand.cc:474
G4bool IsAvailable()
Definition: G4UIcommand.cc:269
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:413
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:300
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:403
std::vector< G4ApplicationState > * GetStateList()
Definition: G4UIcommand.hh:142
void SetRange(const char *rs)
Definition: G4UIcommand.hh:120
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:421
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:429
virtual void List()
Definition: G4UIcommand.cc:328
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:219
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:136
const G4String & GetRange() const
Definition: G4UIcommand.hh:128
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
Definition: G4UIcommand.cc:451
G4String GetCurrentValue()
Definition: G4UIcommand.cc:214