Geant4  10.00.p01
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: G4UIcommand.hh 77563 2013-11-26 09:03:18Z gcosmo $
28 //
29 //
30 
31 #ifndef G4UIcommand_h
32 #define G4UIcommand_h 1
33 
34 #include "G4UIparameter.hh"
35 class 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:
54  G4UIcommand();
55  public: // with description
56  G4UIcommand(const char * theCommandPath, G4UImessenger * theMessenger,
57  G4bool tBB = true);
58  // Constructor. The command string with full path directory
59  // and the pointer to the messenger must be given.
60  // If tBB is set to false, this command won't be sent to worker threads.
61  // This tBB parameter could be changed with SetToBeBroadcasted() method
62  // except for G4UIdirectory.
63 
64  public:
65  virtual ~G4UIcommand();
66 
67  G4int operator==(const G4UIcommand &right) const;
68  G4int operator!=(const G4UIcommand &right) const;
69 
70  virtual G4int DoIt(G4String parameterList);
72  public: // with description
82  // These methods define the states where the command is available.
83  // Once one of these commands is invoked, the command application will
84  // be denied when Geant4 is NOT in the assigned states.
85  public:
87  virtual void List();
88 
89  public: // with description
90  static G4String ConvertToString(G4bool boolVal);
91  static G4String ConvertToString(G4int intValue);
92  static G4String ConvertToString(G4double doubleValue);
93  static G4String ConvertToString(G4double doubleValue,const char* unitName);
95  static G4String ConvertToString(G4ThreeVector vec,const char* unitName);
96  // Static methods for conversion from value(s) to a string. These methods are to be
97  // used by GetCurrentValues() methods of concrete messengers.
98 
99  static G4bool ConvertToBool(const char* st);
100  static G4int ConvertToInt(const char* st);
101  static G4double ConvertToDouble(const char* st);
102  static G4double ConvertToDimensionedDouble(const char* st);
103  static G4ThreeVector ConvertTo3Vector(const char* st);
104  static G4ThreeVector ConvertToDimensioned3Vector(const char* st);
105  // Static methods for conversion from a string to a value of the returning type.
106  // These methods are to be used directly by SetNewValues() methods of concrete
107  // messengers, or GetNewXXXValue() of classes derived from this G4UIcommand class.
108 
109  static G4double ValueOf(const char* unitName);
110  static G4String CategoryOf(const char* unitName);
111  static G4String UnitsList(const char* unitCategory);
112  // Static methods for unit and its category.
113 
114  private:
115  void G4UIcommandCommonConstructorCode (const char * theCommandPath);
120  std::vector<G4UIparameter*> parameter;
121  std::vector<G4String> commandGuidance;
122  std::vector<G4ApplicationState> availabelStateList;
123 
124  public: // with description
125  inline void SetRange(const char* rs)
126  { rangeString = rs; }
127  // Defines the range the command parameter(s) can take.
128  // The variable name(s) appear in the range expression must be same
129  // as the name(s) of the parameter(s).
130  // All the C++ syntax of relational operators are allowed for the
131  // range expression.
132  public:
133  inline const G4String & GetRange() const
134  { return rangeString; };
135  inline G4int GetGuidanceEntries() const
136  { return commandGuidance.size(); }
137  inline const G4String & GetGuidanceLine(G4int i) const
138  { return commandGuidance[i]; }
139  inline const G4String & GetCommandPath() const
140  { return commandPath; }
141  inline const G4String & GetCommandName() const
142  { return commandName; }
143  inline G4int GetParameterEntries() const
144  { return parameter.size(); }
145  inline G4UIparameter * GetParameter(G4int i) const
146  { return parameter[i]; }
147  inline std::vector<G4ApplicationState>* GetStateList()
148  { return &availabelStateList; }
149  inline G4UImessenger * GetMessenger() const
150  { return messenger; }
151  public: // with description
152  inline void SetParameter(G4UIparameter *const newParameter)
153  {
154  parameter.push_back( newParameter );
155  newVal.resize( parameter.size() );
156  }
157  // Defines a parameter. This method is used by the derived command classes
158  // but the user can directly use this command when he/she defines a command
159  // by hem(her)self without using the derived class. For this case, the order
160  // of the parameters is the order of invoking this method.
161  inline void SetGuidance(const char * aGuidance)
162  {
163  commandGuidance.push_back( G4String( aGuidance ) );
164  }
165  // Adds a guidance line. Unlimitted number of invokation of this method is
166  // allowed. The given lines of guidance will appear for the help. The first
167  // line of the guidance will be used as the title of the command, i.e. one
168  // line list of the commands.
169  public:
170  inline const G4String GetTitle() const
171  {
172  if(commandGuidance.size() == 0)
173  { return G4String("...Title not available..."); }
174  else
175  { return commandGuidance[0]; }
176  }
177 
178  protected:
182 
183  public:
184  inline void SetToBeBroadcasted(G4bool val)
185  { toBeBroadcasted = val; }
186  inline G4bool ToBeBroadcasted() const
187  { return toBeBroadcasted; }
188  inline void SetToBeFlushed(G4bool val)
189  { toBeFlushed = val; }
190  inline G4bool ToBeFlushed() const
191  { return toBeFlushed; }
192  inline void SetWorkerThreadOnly(G4bool val=true)
193  { workerThreadOnly = val; }
194  inline G4bool IsWorkerThreadOnly() const
195  { return workerThreadOnly; }
196 
197  protected:
198  G4int CheckNewValue(const char* newValue);
199 
200  // --- the following is used by CheckNewValue() --------
201  private:
202  G4int TypeCheck(const char* t);
203  G4int RangeCheck(const char* t);
204  G4int IsInt(const char* str, short maxLength);
205  G4int IsDouble(const char* str);
206  G4int ExpectExponent(const char* str);
207  // syntax nodes
208  yystype Expression( void );
211  yystype EqualityExpression ( void );
213  yystype AdditiveExpression( void );
215  yystype UnaryExpression( void );
216  yystype PrimaryExpression( void );
217  // semantics routines
218  G4int Eval2( yystype arg1, G4int op, yystype arg2 );
219  G4int CompareInt( G4int arg1, G4int op, G4int arg2);
220  G4int CompareDouble( G4double arg1, G4int op, G4double arg2);
221  // utility
222  tokenNum Yylex( void ); // returns next token
223  unsigned IndexOf( const char* ); // returns the index of the var name
224  unsigned IsParameter( const char* ); // returns 1 or 0
225  G4int G4UIpGetc( void ); // read one char from rangeBuf
226  G4int G4UIpUngetc( G4int c ); // put back
227  G4int Backslash( G4int c );
228  G4int Follow( G4int expect, G4int ifyes, G4int ifno );
230  void PrintToken(void); // for debug
231  // data
233  G4int bp; // buffer pointer for rangeBuf
236  std::vector<yystype> newVal;
238 };
239 
240 #endif
241 
G4UImessenger * messenger
Definition: G4UIcommand.hh:116
yystype MultiplicativeExpression(void)
Definition: G4UIcommand.cc:813
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
std::vector< yystype > newVal
Definition: G4UIcommand.hh:236
tokenNum
Definition: G4UItokenNum.hh:36
G4int Eval2(yystype arg1, G4int op, yystype arg2)
Definition: G4UIcommand.cc:899
G4String commandName
Definition: G4UIcommand.hh:118
G4bool IsAvailable()
Definition: G4UIcommand.cc:275
const G4String & GetRange() const
Definition: G4UIcommand.hh:133
G4bool IsWorkerThreadOnly() const
Definition: G4UIcommand.hh:194
G4int G4UIpGetc(void)
CLHEP::Hep3Vector G4ThreeVector
G4int operator!=(const G4UIcommand &right) const
Definition: G4UIcommand.cc:101
void PrintToken(void)
G4int IsInt(const char *str, short maxLength)
Definition: G4UIcommand.cc:535
unsigned IndexOf(const char *)
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:184
yystype PrimaryExpression(void)
Definition: G4UIcommand.cc:862
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:357
G4bool toBeFlushed
Definition: G4UIcommand.hh:180
G4int CompareDouble(G4double arg1, G4int op, G4double arg2)
Definition: G4UIcommand.cc:982
tokenNum Yylex(void)
G4int TypeCheck(const char *t)
Definition: G4UIcommand.cc:494
G4String rangeString
Definition: G4UIcommand.hh:119
std::vector< G4ApplicationState > availabelStateList
Definition: G4UIcommand.hh:122
const G4String GetTitle() const
Definition: G4UIcommand.hh:170
yystype UnaryExpression(void)
Definition: G4UIcommand.cc:825
int G4int
Definition: G4Types.hh:78
G4int paramERR
Definition: G4UIcommand.hh:237
const G4String & GetGuidanceLine(G4int i) const
Definition: G4UIcommand.hh:137
static G4ThreeVector ConvertTo3Vector(const char *st)
Definition: G4UIcommand.cc:449
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:437
G4int Follow(G4int expect, G4int ifyes, G4int ifno)
G4int ExpectExponent(const char *str)
Definition: G4UIcommand.cc:559
tokenNum token
Definition: G4UIcommand.hh:234
G4bool ToBeBroadcasted() const
Definition: G4UIcommand.hh:186
yystype LogicalANDExpression(void)
Definition: G4UIcommand.cc:705
G4bool workerThreadOnly
Definition: G4UIcommand.hh:181
G4int CheckNewValue(const char *newValue)
Definition: G4UIcommand.cc:482
yystype LogicalORExpression(void)
Definition: G4UIcommand.cc:670
void G4UIcommandCommonConstructorCode(const char *theCommandPath)
Definition: G4UIcommand.cc:75
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:306
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:411
yystype Expression(void)
Definition: G4UIcommand.cc:659
G4bool toBeBroadcasted
Definition: G4UIcommand.hh:179
unsigned IsParameter(const char *)
bool G4bool
Definition: G4Types.hh:79
G4int IsDouble(const char *str)
Definition: G4UIcommand.cc:568
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:145
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:429
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:139
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
G4bool ToBeFlushed() const
Definition: G4UIcommand.hh:190
yystype AdditiveExpression(void)
Definition: G4UIcommand.cc:801
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:421
G4int operator==(const G4UIcommand &right) const
Definition: G4UIcommand.cc:96
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:141
void SetWorkerThreadOnly(G4bool val=true)
Definition: G4UIcommand.hh:192
yystype yylval
Definition: G4UIcommand.hh:235
G4int G4UIpUngetc(G4int c)
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:294
G4String rangeBuf
Definition: G4UIcommand.hh:232
std::vector< G4ApplicationState > * GetStateList()
Definition: G4UIcommand.hh:147
yystype EqualityExpression(void)
Definition: G4UIcommand.cc:741
G4UImessenger * GetMessenger() const
Definition: G4UIcommand.hh:149
yystype RelationalExpression(void)
Definition: G4UIcommand.cc:772
G4String commandPath
Definition: G4UIcommand.hh:117
G4String TokenToStr(G4int token)
double G4double
Definition: G4Types.hh:76
std::vector< G4String > commandGuidance
Definition: G4UIcommand.hh:121
virtual void List()
Definition: G4UIcommand.cc:334
G4int GetGuidanceEntries() const
Definition: G4UIcommand.hh:135
virtual ~G4UIcommand()
Definition: G4UIcommand.cc:85
std::vector< G4UIparameter * > parameter
Definition: G4UIcommand.hh:120
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:301
virtual G4int DoIt(G4String parameterList)
Definition: G4UIcommand.cc:108
G4int CompareInt(G4int arg1, G4int op, G4int arg2)
Definition: G4UIcommand.cc:957
G4ApplicationState
G4String GetCurrentValue()
Definition: G4UIcommand.cc:220
G4int RangeCheck(const char *t)
Definition: G4UIcommand.cc:628
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
Definition: G4UIcommand.cc:459
void SetToBeFlushed(G4bool val)
Definition: G4UIcommand.hh:188
G4int Backslash(G4int c)