Geant4  10.02.p03
G4UIterminal Class Reference

#include <G4UIterminal.hh>

Inheritance diagram for G4UIterminal:
Collaboration diagram for G4UIterminal:

Public Member Functions

 G4UIterminal (G4VUIshell *aShell=0, G4bool qsig=true)
 
 ~G4UIterminal ()
 
void SetPrompt (const G4String &prompt)
 
virtual G4UIsessionSessionStart ()
 
virtual void PauseSessionStart (const G4String &msg)
 
virtual G4int ReceiveG4cout (const G4String &coutString)
 
virtual G4int ReceiveG4cerr (const G4String &cerrString)
 
- Public Member Functions inherited from G4VBasicShell
 G4VBasicShell ()
 
virtual ~G4VBasicShell ()
 
- Public Member Functions inherited from G4UIsession
 G4UIsession ()
 
virtual ~G4UIsession ()
 
- Public Member Functions inherited from G4coutDestination
 G4coutDestination ()
 
virtual ~G4coutDestination ()
 

Private Member Functions

virtual void ExecuteCommand (const G4String &aCommand)
 
virtual G4bool GetHelpChoice (G4int &aInt)
 
virtual void ExitHelp () const
 
G4String GetCommand (const char *msg=0)
 

Private Attributes

G4UImanagerUI
 
G4VUIshellshell
 
G4bool iExit
 
G4bool iCont
 

Additional Inherited Members

- Protected Member Functions inherited from G4VBasicShell
G4String ModifyToFullPathCommand (const char *aCommandLine) const
 
G4String GetCurrentWorkingDirectory () const
 
G4bool ChangeDirectory (const char *newDir)
 
G4UIcommandTreeFindDirectory (const char *dirName) const
 
G4UIcommandFindCommand (const char *commandName) const
 
G4String Complete (const G4String &)
 
G4String FindMatchingPath (G4UIcommandTree *, const G4String &)
 
void ApplyShellCommand (const G4String &, G4bool &, G4bool &)
 
void ShowCurrent (const G4String &) const
 
void ChangeDirectoryCommand (const G4String &)
 
void ListDirectory (const G4String &) const
 
void TerminalHelp (const G4String &)
 
- Static Protected Attributes inherited from G4coutDestination
static G4coutDestinationmasterG4coutDestination = 0
 

Detailed Description

Definition at line 71 of file G4UIterminal.hh.

Constructor & Destructor Documentation

◆ G4UIterminal()

G4UIterminal::G4UIterminal ( G4VUIshell aShell = 0,
G4bool  qsig = true 
)

Definition at line 91 of file G4UIterminal.cc.

93 {
95  UI-> SetSession(this);
96  UI-> SetCoutDestination(this);
97 
98  iExit= FALSE;
99  iCont= FALSE;
100 
101  if(aShell) shell= aShell;
102  else shell= new G4UIcsh;
103  theshell= shell; // locally stored for the signal handler
104 
105  // add signal handler
106  if(qsig) {
107 #ifndef WIN32
108  signal(SIGINT, SignalHandler);
109 #endif
110  }
111 }
static G4ThreadLocal G4VUIshell * theshell
Definition: G4UIterminal.cc:50
static void SignalHandler(G4int)
Definition: G4UIterminal.cc:57
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
#define FALSE
Definition: globals.hh:52
G4UImanager * UI
Definition: G4UIterminal.hh:73
G4VUIshell * shell
Definition: G4UIterminal.hh:75
Here is the call graph for this function:

◆ ~G4UIterminal()

G4UIterminal::~G4UIterminal ( )

Definition at line 114 of file G4UIterminal.cc.

116 {
117  if(shell) delete shell;
118 
120  UI-> SetSession(NULL);
121  UI-> SetCoutDestination(NULL);
122  }
123 }
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4UImanager * UI
Definition: G4UIterminal.hh:73
G4VUIshell * shell
Definition: G4UIterminal.hh:75
Here is the call graph for this function:

Member Function Documentation

◆ ExecuteCommand()

void G4UIterminal::ExecuteCommand ( const G4String aCommand)
privatevirtual

Reimplemented from G4VBasicShell.

Definition at line 161 of file G4UIterminal.cc.

163 {
164  if(aCommand.length()<2) return;
165 
166  G4int returnVal = UI-> ApplyCommand(aCommand);
167 
168  G4int paramIndex = returnVal % 100;
169  // 0 - 98 : paramIndex-th parameter is invalid
170  // 99 : convination of parameters is invalid
171  G4int commandStatus = returnVal - paramIndex;
172 
173  G4UIcommand* cmd = 0;
174  if(commandStatus!=fCommandSucceeded)
175  { cmd = FindCommand(aCommand); }
176 
177  switch(commandStatus) {
178  case fCommandSucceeded:
179  break;
180  case fCommandNotFound:
181  G4cerr << "command <" << UI->SolveAlias(aCommand) << "> not found" << G4endl;
182  if( aCommand.index("@@") != G4String::npos) {
183  G4cout << "@@G4UIterminal" << G4endl;
184  }
185  break;
187  G4cerr << "illegal application state -- command refused" << G4endl;
188  break;
190  // if(paramIndex<99) {
191  // G4cerr << "Parameter is out of range (index " << paramIndex << ")" << G4endl;
192  // G4cerr << "Allowed range : " << cmd->GetParameter(paramIndex)->GetParameterRange() << G4endl;
193  // } else {
194  // G4cerr << "Parameter is out of range" << G4endl;
195  // G4cerr << "Allowed range : " << cmd->GetRange() << G4endl;
196  // }
197  break;
199  G4cerr << "Parameter is out of candidate list (index " << paramIndex << ")" << G4endl;
200  G4cerr << "Candidates : " << cmd->GetParameter(paramIndex)->GetParameterCandidates() << G4endl;
201  break;
203  G4cerr << "Parameter is wrong type and/or is not omittable (index " << paramIndex << ")" << G4endl;
204  break;
205  case fAliasNotFound:
206  default:
207  G4cerr << "command refused (" << commandStatus << ")" << G4endl;
208  }
209 }
G4UIcommand * FindCommand(const char *commandName) const
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:145
str_size index(const char *, G4int pos=0) const
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
G4String GetParameterCandidates() const
G4String SolveAlias(const char *aCmd)
Definition: G4UImanager.cc:391
#define G4endl
Definition: G4ios.hh:61
G4UImanager * UI
Definition: G4UIterminal.hh:73
G4GLOB_DLL std::ostream G4cerr
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExitHelp()

void G4UIterminal::ExitHelp ( ) const
privatevirtual

Implements G4VBasicShell.

Definition at line 336 of file G4UIterminal.cc.

338 {
339  char temp[100];
340  G4cin.getline(temp, 100);
341 }
#define G4cin
Definition: G4ios.hh:60

◆ GetCommand()

G4String G4UIterminal::GetCommand ( const char *  msg = 0)
private

Definition at line 212 of file G4UIterminal.cc.

214 {
215  G4String newCommand;
216  G4String nullString;
217 
218  newCommand= shell-> GetCommandLineString(msg);
219 
220  G4String nC = newCommand.strip(G4String::leading);
221  if( nC.length() == 0 ) {
222  newCommand= nullString;
223 
224  } else if( nC(0) == '#' ) {
225  G4cout << nC << G4endl;
226  newCommand= nullString;
227 
228  } else if(nC=="ls" || nC.substr(0,3)=="ls " ) { // list commands
229  ListDirectory(nC);
230  newCommand= nullString;
231 
232  } else if(nC=="lc" || nC.substr(0,3)=="lc " ) { // ... by shell
233  shell-> ListCommand(nC.remove(0,2));
234  newCommand= nullString;
235 
236  } else if(nC == "pwd") { // show current directory
237  G4cout << "Current Command Directory : "
239  newCommand= nullString;
240 
241  } else if(nC == "cwd") { // ... by shell
242  shell-> ShowCurrentDirectory();
243  newCommand= nullString;
244 
245  } else if(nC == "cd" || nC.substr(0,3) == "cd ") { // "cd"
247  shell-> SetCurrentDirectory(GetCurrentWorkingDirectory());
248  newCommand= nullString;
249 
250  } else if(nC == "help" || nC.substr(0,5) == "help ") { // "help"
251  TerminalHelp(nC);
252  newCommand= nullString;
253 
254  } else if(nC(0) == '?') { // "show current value of a parameter"
255  ShowCurrent(nC);
256  newCommand= nullString;
257 
258  } else if(nC == "hist" || nC == "history") { // "hist/history"
259  G4int nh= UI-> GetNumberOfHistory();
260  for (G4int i=0; i<nh; i++) {
261  G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl;
262  }
263  newCommand= nullString;
264 
265  } else if(nC(0) == '!') { // "!"
266  G4String ss= nC(1, nC.length()-1);
267  G4int vl;
268  const char* tt= ss;
269  std::istringstream is(tt);
270  is >> vl;
271  G4int nh= UI-> GetNumberOfHistory();
272  if(vl>=0 && vl<nh) {
273  newCommand= UI-> GetPreviousCommand(vl);
274  G4cout << newCommand << G4endl;
275  } else {
276  G4cerr << "history " << vl << " is not found." << G4endl;
277  newCommand= nullString;
278  }
279 
280  } else if(nC == "exit") { // "exit"
281  if(iCont) {
282  G4cout << "You are now processing RUN." << G4endl;
283  G4cout << "Please abort it using \"/run/abort\" command first" << G4endl;
284  G4cout << " and use \"continue\" command until the application"
285  << G4endl;
286  G4cout << " becomes to Idle." << G4endl;
287  } else {
288  iExit= FALSE;
289  newCommand= nullString;
290  }
291 
292  } else if( nC == "cont" || nC == "continue"){ // "cont/continu"
293  iCont= FALSE;
294  newCommand= nullString;
295 
296  } else if( nC.empty() ){ // NULL command
297  newCommand= nullString;
298 
299  } else {
300  }
301 
302  return ModifyToFullPathCommand(newCommand);
303 }
void ChangeDirectoryCommand(const G4String &)
void TerminalHelp(const G4String &)
G4String & remove(str_size)
G4String strip(G4int strip_Type=trailing, char c=' ')
void ShowCurrent(const G4String &) const
int G4int
Definition: G4Types.hh:78
G4String GetCurrentWorkingDirectory() const
G4GLOB_DLL std::ostream G4cout
G4String ModifyToFullPathCommand(const char *aCommandLine) const
#define FALSE
Definition: globals.hh:52
#define G4endl
Definition: G4ios.hh:61
G4UImanager * UI
Definition: G4UIterminal.hh:73
void ListDirectory(const G4String &) const
G4String GetPreviousCommand(G4int i) const
Definition: G4UImanager.hh:231
G4GLOB_DLL std::ostream G4cerr
G4VUIshell * shell
Definition: G4UIterminal.hh:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetHelpChoice()

G4bool G4UIterminal::GetHelpChoice ( G4int aInt)
privatevirtual

Implements G4VBasicShell.

Definition at line 323 of file G4UIterminal.cc.

325 {
326  G4cin >> aInt;
327  if(!G4cin.good()){
328  G4cin.clear();
329  G4cin.ignore(30,'\n');
330  return FALSE;
331  }
332  return TRUE;
333 }
#define G4cin
Definition: G4ios.hh:60
#define FALSE
Definition: globals.hh:52
#define TRUE
Definition: globals.hh:55

◆ PauseSessionStart()

void G4UIterminal::PauseSessionStart ( const G4String msg)
virtual

Implements G4VBasicShell.

Definition at line 148 of file G4UIterminal.cc.

150 {
151  iCont= TRUE;
152 
153  G4String newCommand= GetCommand(msg);
154  while(iCont){
155  ExecuteCommand(newCommand);
156  newCommand= GetCommand(msg);
157  }
158 }
G4String GetCommand(const char *msg=0)
#define TRUE
Definition: globals.hh:55
virtual void ExecuteCommand(const G4String &aCommand)
Here is the call graph for this function:

◆ ReceiveG4cerr()

G4int G4UIterminal::ReceiveG4cerr ( const G4String cerrString)
virtual

Reimplemented from G4UIsession.

Definition at line 315 of file G4UIterminal.cc.

317 {
318  std::cerr << cerrString << std::flush;
319  return 0;
320 }

◆ ReceiveG4cout()

G4int G4UIterminal::ReceiveG4cout ( const G4String coutString)
virtual

Reimplemented from G4UIsession.

Definition at line 307 of file G4UIterminal.cc.

309 {
310  std::cout << coutString << std::flush;
311  return 0;
312 }

◆ SessionStart()

G4UIsession * G4UIterminal::SessionStart ( )
virtual

Implements G4VBasicShell.

Definition at line 134 of file G4UIterminal.cc.

136 {
137  iExit= TRUE;
138 
139  G4String newCommand= GetCommand();
140  while(iExit){
141  ExecuteCommand(newCommand);
142  newCommand= GetCommand();
143  }
144  return NULL;
145 }
G4String GetCommand(const char *msg=0)
#define TRUE
Definition: globals.hh:55
virtual void ExecuteCommand(const G4String &aCommand)
Here is the call graph for this function:

◆ SetPrompt()

void G4UIterminal::SetPrompt ( const G4String prompt)

Definition at line 127 of file G4UIterminal.cc.

129 {
130  shell-> SetPrompt(prompt);
131 }
void SetPrompt(const G4String &prompt)
G4VUIshell * shell
Definition: G4UIterminal.hh:75

Member Data Documentation

◆ iCont

G4bool G4UIterminal::iCont
private

Definition at line 79 of file G4UIterminal.hh.

◆ iExit

G4bool G4UIterminal::iExit
private

Definition at line 78 of file G4UIterminal.hh.

◆ shell

G4VUIshell* G4UIterminal::shell
private

Definition at line 75 of file G4UIterminal.hh.

◆ UI

G4UImanager* G4UIterminal::UI
private

Definition at line 73 of file G4UIterminal.hh.


The documentation for this class was generated from the following files: