Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 //
27 // $Id: G4UIcommand.hh 108081 2017-12-21 07:53:54Z 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:
200 
201  public:
202  inline void CommandFailed( G4int errCode, G4ExceptionDescription& ed )
203  { commandFailureCode = errCode; failureDescription = ed.str(); }
205  { commandFailureCode = 1; failureDescription = ed.str(); }
207  { return commandFailureCode; }
209  { return failureDescription; }
210  inline void ResetFailure()
212 
213  protected:
214  G4int CheckNewValue(const char* newValue);
215 
216  // --- the following is used by CheckNewValue() --------
217  private:
218  G4int TypeCheck(const char* t);
219  G4int RangeCheck(const char* t);
220  G4int IsInt(const char* str, short maxLength);
221  G4int IsDouble(const char* str);
222  G4int ExpectExponent(const char* str);
223  // syntax nodes
224  yystype Expression( void );
227  yystype EqualityExpression ( void );
229  yystype AdditiveExpression( void );
231  yystype UnaryExpression( void );
232  yystype PrimaryExpression( void );
233  // semantics routines
234  G4int Eval2( yystype arg1, G4int op, yystype arg2 );
235  G4int CompareInt( G4int arg1, G4int op, G4int arg2);
236  G4int CompareDouble( G4double arg1, G4int op, G4double arg2);
237  // utility
238  tokenNum Yylex( void ); // returns next token
239  unsigned IndexOf( const char* ); // returns the index of the var name
240  unsigned IsParameter( const char* ); // returns 1 or 0
241  G4int G4UIpGetc( void ); // read one char from rangeBuf
242  G4int G4UIpUngetc( G4int c ); // put back
243  G4int Backslash( G4int c );
244  G4int Follow( G4int expect, G4int ifyes, G4int ifno );
246  void PrintToken(void); // for debug
247  // data
249  G4int bp; // buffer pointer for rangeBuf
252  std::vector<yystype> newVal;
254 };
255 
256 #endif
257 
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:311
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:318
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
G4int Follow(G4int expect, G4int ifyes, G4int ifno)
G4int G4UIpUngetc(G4int c)
const G4String GetTitle() const
Definition: G4UIcommand.hh:170
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:202
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:457
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
G4int TypeCheck(const char *t)
Definition: G4UIcommand.cc:522
G4bool ToBeFlushed() const
Definition: G4UIcommand.hh:190
G4String failureDescription
Definition: G4UIcommand.hh:199
yystype EqualityExpression(void)
Definition: G4UIcommand.cc:769
G4int operator!=(const G4UIcommand &right) const
Definition: G4UIcommand.cc:118
yystype yylval
Definition: G4UIcommand.hh:251
G4UImessenger * GetMessenger() const
Definition: G4UIcommand.hh:149
unsigned IndexOf(const char *)
virtual G4int DoIt(G4String parameterList)
Definition: G4UIcommand.cc:125
G4int CompareDouble(G4double arg1, G4int op, G4double arg2)
const G4String & GetGuidanceLine(G4int i) const
Definition: G4UIcommand.hh:137
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:439
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:145
yystype RelationalExpression(void)
Definition: G4UIcommand.cc:800
virtual ~G4UIcommand()
Definition: G4UIcommand.cc:102
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
G4String rangeString
Definition: G4UIcommand.hh:119
G4int IfCommandFailed()
Definition: G4UIcommand.hh:206
yystype LogicalANDExpression(void)
Definition: G4UIcommand.cc:733
G4int GetGuidanceEntries() const
Definition: G4UIcommand.hh:135
G4int commandFailureCode
Definition: G4UIcommand.hh:198
G4String TokenToStr(G4int token)
G4int G4UIpGetc(void)
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:141
G4int Eval2(yystype arg1, G4int op, yystype arg2)
Definition: G4UIcommand.cc:927
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:449
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
G4int IsInt(const char *str, short maxLength)
Definition: G4UIcommand.cc:563
tokenNum token
Definition: G4UIcommand.hh:250
G4int Backslash(G4int c)
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
std::vector< G4String > commandGuidance
Definition: G4UIcommand.hh:121
void PrintToken(void)
yystype PrimaryExpression(void)
Definition: G4UIcommand.cc:890
G4int CompareInt(G4int arg1, G4int op, G4int arg2)
Definition: G4UIcommand.cc:985
std::vector< G4ApplicationState > * GetStateList()
Definition: G4UIcommand.hh:147
G4int RangeCheck(const char *t)
Definition: G4UIcommand.cc:656
yystype AdditiveExpression(void)
Definition: G4UIcommand.cc:829
yystype Expression(void)
Definition: G4UIcommand.cc:687
yystype MultiplicativeExpression(void)
Definition: G4UIcommand.cc:841
G4String rangeBuf
Definition: G4UIcommand.hh:248
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:139
static G4ThreeVector ConvertTo3Vector(const char *st)
Definition: G4UIcommand.cc:477
G4bool ToBeBroadcasted() const
Definition: G4UIcommand.hh:186
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:374
G4int IsDouble(const char *str)
Definition: G4UIcommand.cc:596
tokenNum
Definition: G4UItokenNum.hh:36
virtual void List()
Definition: G4UIcommand.cc:351
int G4int
Definition: G4Types.hh:78
void G4UIcommandCommonConstructorCode(const char *theCommandPath)
Definition: G4UIcommand.cc:82
unsigned IsParameter(const char *)
std::vector< G4UIparameter * > parameter
Definition: G4UIcommand.hh:120
G4UImessenger * messenger
Definition: G4UIcommand.hh:116
void SetWorkerThreadOnly(G4bool val=true)
Definition: G4UIcommand.hh:192
void SetToBeFlushed(G4bool val)
Definition: G4UIcommand.hh:188
tokenNum Yylex(void)
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
void CommandFailed(G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:204
G4ApplicationState
G4bool IsWorkerThreadOnly() const
Definition: G4UIcommand.hh:194
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
Definition: G4UIcommand.cc:487
yystype LogicalORExpression(void)
Definition: G4UIcommand.cc:698
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:323
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:465
G4String GetCurrentValue()
Definition: G4UIcommand.cc:237
std::vector< G4ApplicationState > availabelStateList
Definition: G4UIcommand.hh:122
G4String & GetFailureDescription()
Definition: G4UIcommand.hh:208
G4bool toBeBroadcasted
Definition: G4UIcommand.hh:179
G4int paramERR
Definition: G4UIcommand.hh:253
G4bool IsAvailable()
Definition: G4UIcommand.cc:292
G4bool workerThreadOnly
Definition: G4UIcommand.hh:181
G4int CheckNewValue(const char *newValue)
Definition: G4UIcommand.cc:510
std::vector< yystype > newVal
Definition: G4UIcommand.hh:252
yystype UnaryExpression(void)
Definition: G4UIcommand.cc:853
G4bool toBeFlushed
Definition: G4UIcommand.hh:180
G4int ExpectExponent(const char *str)
Definition: G4UIcommand.cc:587
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:242
const G4String & GetRange() const
Definition: G4UIcommand.hh:133
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:184
G4String commandName
Definition: G4UIcommand.hh:118
G4int operator==(const G4UIcommand &right) const
Definition: G4UIcommand.cc:113
G4String commandPath
Definition: G4UIcommand.hh:117
void ResetFailure()
Definition: G4UIcommand.hh:210