ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UIcommand.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4UIcommand.hh
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 // Author: Makoto Asai (SLAC)
29 // --------------------------------------------------------------------
30 #ifndef G4UIcommand_hh
31 #define G4UIcommand_hh 1
32 
33 #include "G4UIparameter.hh"
34 class G4UImessenger;
35 #include "globals.hh"
36 #include "G4ApplicationState.hh"
37 #include <vector>
38 #include "G4UItokenNum.hh"
39 #include "G4ThreeVector.hh"
40 
41 // class description:
42 //
43 // This G4UIcommand is the "concrete" base class which represents a command
44 // used by Geant4 (G)UI. The user can use this class in case the parameter
45 // arguments of a command are not suitable with respect to the derived command
46 // classes.
47 // Some methods defined in this base class are used by the derived classes.
48 //
49 
51 {
52  public:
53  G4UIcommand();
54  public: // with description
55  G4UIcommand(const char * theCommandPath, G4UImessenger * theMessenger,
56  G4bool tBB = true);
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 
63  public:
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);
71  public: // with description
81  // These methods define the states where the command is available.
82  // Once one of these commands is invoked, the command application will
83  // be denied when Geant4 is NOT in the assigned states.
84  public:
86  virtual void List();
87 
88  public: // with description
89  static G4String ConvertToString(G4bool boolVal);
90  static G4String ConvertToString(G4int intValue);
91  static G4String ConvertToString(G4double doubleValue);
92  static G4String ConvertToString(G4double doubleValue,const char* unitName);
94  static G4String ConvertToString(G4ThreeVector vec,const char* unitName);
95  // Static methods for conversion from value(s) to a string. These methods are to be
96  // used by GetCurrentValues() methods of concrete messengers.
97 
98  static G4bool ConvertToBool(const char* st);
99  static G4int ConvertToInt(const char* st);
100  static G4double ConvertToDouble(const char* st);
101  static G4double ConvertToDimensionedDouble(const char* st);
102  static G4ThreeVector ConvertTo3Vector(const char* st);
103  static G4ThreeVector ConvertToDimensioned3Vector(const char* st);
104  // Static methods for conversion from a string to a value of the returning type.
105  // These methods are to be used directly by SetNewValues() methods of concrete
106  // messengers, or GetNewXXXValue() of classes derived from this G4UIcommand class.
107 
108  static G4double ValueOf(const char* unitName);
109  static G4String CategoryOf(const char* unitName);
110  static G4String UnitsList(const char* unitCategory);
111  // Static methods for unit and its category.
112 
113  private:
114  void G4UIcommandCommonConstructorCode (const char * theCommandPath);
119  std::vector<G4UIparameter*> parameter;
120  std::vector<G4String> commandGuidance;
121  std::vector<G4ApplicationState> availabelStateList;
122 
123  public: // with description
124  inline void SetRange(const char* rs)
125  { rangeString = rs; }
126  // Defines the range the command parameter(s) can take.
127  // The variable name(s) appear in the range expression must be same
128  // as the name(s) of the parameter(s).
129  // All the C++ syntax of relational operators are allowed for the
130  // range expression.
131  public:
132  inline const G4String & GetRange() const
133  { return rangeString; };
134  inline size_t GetGuidanceEntries() const
135  { return commandGuidance.size(); }
136  inline const G4String & GetGuidanceLine(G4int i) const
137  { return commandGuidance[i]; }
138  inline const G4String & GetCommandPath() const
139  { return commandPath; }
140  inline const G4String & GetCommandName() const
141  { return commandName; }
142  inline size_t GetParameterEntries() const
143  { return parameter.size(); }
144  inline G4UIparameter * GetParameter(G4int i) const
145  { return parameter[i]; }
146  inline std::vector<G4ApplicationState>* GetStateList()
147  { return &availabelStateList; }
148  inline G4UImessenger * GetMessenger() const
149  { return messenger; }
150  public: // with description
151  inline void SetParameter(G4UIparameter *const newParameter)
152  {
153  parameter.push_back( newParameter );
154  newVal.resize( parameter.size() );
155  }
156  // Defines a parameter. This method is used by the derived command classes
157  // but the user can directly use this command when he/she defines a command
158  // by hem(her)self without using the derived class. For this case, the order
159  // of the parameters is the order of invoking this method.
160  inline void SetGuidance(const char * aGuidance)
161  {
162  commandGuidance.push_back( G4String( aGuidance ) );
163  }
164  // Adds a guidance line. Unlimitted number of invokation of this method is
165  // allowed. The given lines of guidance will appear for the help. The first
166  // line of the guidance will be used as the title of the command, i.e. one
167  // line list of the commands.
168  public:
169  inline const G4String GetTitle() const
170  {
171  if(commandGuidance.size() == 0)
172  { return G4String("...Title not available..."); }
173  else
174  { return commandGuidance[0]; }
175  }
176 
177  protected:
181 
182  public:
183  inline void SetToBeBroadcasted(G4bool val)
184  { toBeBroadcasted = val; }
185  inline G4bool ToBeBroadcasted() const
186  { return toBeBroadcasted; }
187  inline void SetToBeFlushed(G4bool val)
188  { toBeFlushed = val; }
189  inline G4bool ToBeFlushed() const
190  { return toBeFlushed; }
191  inline void SetWorkerThreadOnly(G4bool val=true)
192  { workerThreadOnly = val; }
193  inline G4bool IsWorkerThreadOnly() const
194  { return workerThreadOnly; }
195 
196  protected:
199 
200  public:
201  inline void CommandFailed( G4int errCode, G4ExceptionDescription& ed )
202  { commandFailureCode = errCode; failureDescription = ed.str(); }
204  { commandFailureCode = 1; failureDescription = ed.str(); }
206  { return commandFailureCode; }
208  { return failureDescription; }
209  inline void ResetFailure()
211 
212  protected:
213  G4int CheckNewValue(const char* newValue);
214 
215  // --- the following is used by CheckNewValue() --------
216  protected:
219  private:
220  G4int TypeCheck(const char* t);
221  G4int RangeCheck(const char* t);
222  G4int IsInt(const char* str, short maxLength);
223  G4int IsDouble(const char* str);
224  G4int ExpectExponent(const char* str);
225  // syntax nodes
226  yystype Expression( void );
229  yystype EqualityExpression ( void );
231  yystype AdditiveExpression( void );
233  yystype UnaryExpression( void );
234  yystype PrimaryExpression( void );
235  // semantics routines
236  G4int Eval2( yystype arg1, G4int op, yystype arg2 );
237  G4int CompareInt( G4int arg1, G4int op, G4int arg2);
238  G4int CompareDouble( G4double arg1, G4int op, G4double arg2);
239  // utility
240  tokenNum Yylex( void ); // returns next token
241  unsigned IndexOf( const char* ); // returns the index of the var name
242  unsigned IsParameter( const char* ); // returns 1 or 0
243  G4int G4UIpGetc( void ); // read one char from rangeBuf
244  G4int G4UIpUngetc( G4int c ); // put back
245  G4int Backslash( G4int c );
246  G4int Follow( G4int expect, G4int ifyes, G4int ifno );
248  void PrintToken(void); // for debug
249  // data
251  G4int bp; // buffer pointer for rangeBuf
254  std::vector<yystype> newVal;
256 };
257 
258 #endif
259