Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4VBasicShell Class Referenceabstract

#include <G4VBasicShell.hh>

Inheritance diagram for G4VBasicShell:
Collaboration diagram for G4VBasicShell:

Public Member Functions

 G4VBasicShell ()
 
virtual ~G4VBasicShell ()
 
virtual G4UIsessionSessionStart ()=0
 
virtual void PauseSessionStart (const G4String &Prompt)=0
 
- Public Member Functions inherited from G4UIsession
 G4UIsession ()
 
 G4UIsession (G4int iBatch)
 
virtual ~G4UIsession ()
 
virtual G4int ReceiveG4cout (const G4String &coutString)
 
virtual G4int ReceiveG4cerr (const G4String &cerrString)
 
- Public Member Functions inherited from G4coutDestination
 G4coutDestination ()
 
virtual ~G4coutDestination ()
 

Protected Member Functions

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 &)
 
virtual void ExecuteCommand (const G4String &)
 
virtual G4bool GetHelpChoice (G4int &)=0
 
virtual void ExitHelp () const =0
 
void ApplyShellCommand (const G4String &, G4bool &, G4bool &)
 
void ShowCurrent (const G4String &) const
 
void ChangeDirectoryCommand (const G4String &)
 
void ListDirectory (const G4String &) const
 
void TerminalHelp (const G4String &)
 

Additional Inherited Members

- Static Public Member Functions inherited from G4UIsession
static G4int InSession ()
 
- Protected Attributes inherited from G4UIsession
G4int ifBatch
 
- Static Protected Attributes inherited from G4UIsession
static G4int inSession = 0
 
- Static Protected Attributes inherited from G4coutDestination
static G4coutDestinationmasterG4coutDestination = 0
 

Detailed Description

Definition at line 52 of file G4VBasicShell.hh.

Constructor & Destructor Documentation

G4VBasicShell::G4VBasicShell ( )

Definition at line 39 of file G4VBasicShell.cc.

40 :currentDirectory("/")
41 {
42 }
G4VBasicShell::~G4VBasicShell ( )
virtual

Definition at line 44 of file G4VBasicShell.cc.

45 {
46 }

Member Function Documentation

void G4VBasicShell::ApplyShellCommand ( const G4String a_string,
G4bool exitSession,
G4bool exitPause 
)
protected

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Definition at line 227 of file G4VBasicShell.cc.

232 {
234  if(UI==NULL) return;
235 
236  G4String command = a_string;
237  command.strip(G4String::leading);
238 
239  if( command(0) == '#' ) {
240 
241  G4cout << command << G4endl;
242 
243  } else if( command == "ls" || command(0,3) == "ls " ) {
244 
245  ListDirectory( command );
246 
247  } else if( command == "pwd" ) {
248 
249  G4cout << "Current Working Directory : "
251 
252  } else if( command == "cd" || command(0,3) == "cd ") {
253 
254  ChangeDirectoryCommand ( command );
255 
256  } else if( command == "help" || command(0,5) == "help ") {
257 
258  TerminalHelp( command );
259 
260  } else if( command(0) == '?' ) {
261 
262  ShowCurrent( command );
263 
264  } else if( command == "hist" || command == "history") {
265 
266  G4int nh = UI->GetNumberOfHistory();
267  for(G4int i=0;i<nh;i++) {
268  G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl;
269  }
270 
271  } else if( command(0) == '!' ) {
272 
273  G4String ss = command(1,command.length()-1);
274  G4int vl;
275  const char* tt = ss;
276  std::istringstream is(tt);
277  is >> vl;
278  G4int nh = UI->GetNumberOfHistory();
279  if(vl>=0 && vl<nh) {
280  G4String prev = UI->GetPreviousCommand(vl);
281  G4cout << prev << G4endl;
283  } else {
284  G4cerr << "history " << vl << " is not found." << G4endl;
285  }
286 
287  } else if( command == "exit" ) {
288 
289  if( exitPause == false) { //In a secondary loop.
290  G4cout << "You are now processing RUN." << G4endl;
291  G4cout << "Please abort it using \"/run/abort\" command first" << G4endl;
292  G4cout << " and use \"continue\" command until the application" << G4endl;
293  G4cout << " becomes to Idle." << G4endl;
294  } else {
295  exitSession = true;
296  }
297 
298  } else if( command == "cont" || command == "continue"){
299 
300  exitPause = true;
301 
302  } else {
303 
305 
306  }
307 }
G4int GetNumberOfHistory() const
Definition: G4UImanager.hh:229
G4String GetPreviousCommand(G4int i) const
Definition: G4UImanager.hh:231
void ChangeDirectoryCommand(const G4String &)
void TerminalHelp(const G4String &)
G4String strip(G4int strip_Type=trailing, char c=' ')
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
G4GLOB_DLL std::ostream G4cout
virtual void ExecuteCommand(const G4String &)
G4String ModifyToFullPathCommand(const char *aCommandLine) const
void ShowCurrent(const G4String &) const
void ListDirectory(const G4String &) const
#define G4endl
Definition: G4ios.hh:61
G4String GetCurrentWorkingDirectory() const
G4GLOB_DLL std::ostream G4cerr

Here is the call graph for this function:

G4bool G4VBasicShell::ChangeDirectory ( const char *  newDir)
protected

Definition at line 75 of file G4VBasicShell.cc.

76 {
77  G4String aNewPrefix = newDir;
78  G4String newPrefix = aNewPrefix.strip(G4String::both);
79  G4String newDirectory = ModifyPath( newPrefix );
80  if( newDirectory( newDirectory.length() - 1 ) != '/' )
81  { newDirectory += "/"; }
82  if( FindDirectory( newDirectory.c_str() ) == NULL )
83  { return false; }
84  currentDirectory = newDirectory;
85  return true;
86 }
G4UIcommandTree * FindDirectory(const char *dirName) const
G4String strip(G4int strip_Type=trailing, char c=' ')

Here is the call graph for this function:

Here is the caller graph for this function:

void G4VBasicShell::ChangeDirectoryCommand ( const G4String newCommand)
protected

Definition at line 321 of file G4VBasicShell.cc.

322 {
324  if( newCommand.length() <= 3 ) {
325  prefix = "/";
326  } else {
327  G4String aNewPrefix = newCommand.substr(3, newCommand.length()-3);
328  prefix = aNewPrefix.strip(G4String::both);
329  }
330  if(!ChangeDirectory(prefix)) {
331  G4cout << "directory <" << prefix << "> not found." << G4endl;
332  }
333 }
G4String strip(G4int strip_Type=trailing, char c=' ')
G4GLOB_DLL std::ostream G4cout
G4bool ChangeDirectory(const char *newDir)
const XML_Char * prefix
Definition: expat.h:380
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

Here is the caller graph for this function:

G4String G4VBasicShell::Complete ( const G4String commandName)
protected

Definition at line 176 of file G4VBasicShell.cc.

177 {
178  G4String rawCommandLine = commandName;
179  G4String commandLine = rawCommandLine.strip(G4String::both);
180  size_t i = commandLine.index(" ");
181  if( i != std::string::npos ) return rawCommandLine; // Already entering parameters,
182  // assume command path is correct.
183  G4String commandString = commandLine;
184  G4String targetCom = ModifyPath(commandString);
186  G4String value = FindMatchingPath(tree,targetCom);
187  if(value=="") return rawCommandLine;
188  return value;
189 }
G4String strip(G4int strip_Type=trailing, char c=' ')
G4String FindMatchingPath(G4UIcommandTree *, const G4String &)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
str_size index(const char *, G4int pos=0) const
const XML_Char int const XML_Char * value
Definition: expat.h:331
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:206

Here is the call graph for this function:

void G4VBasicShell::ExecuteCommand ( const G4String aCommand)
protectedvirtual

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Definition at line 201 of file G4VBasicShell.cc.

205 {
206  if(aCommand.length()<2) return;
208  if(UI==NULL) return;
209  G4int commandStatus = UI->ApplyCommand(aCommand);
210  switch(commandStatus) {
211  case fCommandSucceeded:
212  break;
213  case fCommandNotFound:
214  G4cerr << "command not found: " << "\"" << aCommand << "\"" << G4endl;
215  break;
217  G4cerr << "illegal application state -- command refused:" << "\"" << aCommand << "\"" << G4endl;
218  break;
222  default:
223  G4cerr << "command refused (" << commandStatus << "):" << "\"" << aCommand << "\"" << G4endl;
224  }
225 }
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
#define G4endl
Definition: G4ios.hh:61
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:447
G4GLOB_DLL std::ostream G4cerr

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void G4VBasicShell::ExitHelp ( ) const
protectedpure virtual

Here is the caller graph for this function:

G4UIcommand * G4VBasicShell::FindCommand ( const char *  commandName) const
protected

Definition at line 110 of file G4VBasicShell.cc.

111 {
112  G4String rawCommandLine = commandName;
113  G4String commandLine = rawCommandLine.strip(G4String::both);
114  G4String commandString;
115  size_t i = commandLine.index(" ");
116  if( i != std::string::npos )
117  { commandString = commandLine(0,i); }
118  else
119  { commandString = commandLine; }
120 
121  G4String targetCom = ModifyPath(commandString);
122  return G4UImanager::GetUIpointer()->GetTree()->FindPath(targetCom);
123 }
G4UIcommand * FindPath(const char *commandPath) const
G4String strip(G4int strip_Type=trailing, char c=' ')
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
str_size index(const char *, G4int pos=0) const
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:206

Here is the call graph for this function:

G4UIcommandTree * G4VBasicShell::FindDirectory ( const char *  dirName) const
protected

Definition at line 88 of file G4VBasicShell.cc.

89 {
90  G4String aDirName = dirName;
91  G4String theDir = aDirName.strip(G4String::both);
92  G4String targetDir = ModifyPath( theDir );
93  if( targetDir( targetDir.length()-1 ) != '/' )
94  { targetDir += "/"; }
96  if( targetDir == "/" )
97  { return comTree; }
98  size_t idx = 1;
99  while( idx < targetDir.length()-1 )
100  {
101  size_t i = targetDir.index("/",idx);
102  comTree = comTree->GetTree(targetDir.substr(0,i+1).c_str());
103  if( comTree == NULL )
104  { return NULL; }
105  idx = i+1;
106  }
107  return comTree;
108 }
G4String strip(G4int strip_Type=trailing, char c=' ')
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
str_size index(const char *, G4int pos=0) const
G4UIcommandTree * GetTree(G4int i)
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:206

Here is the call graph for this function:

Here is the caller graph for this function:

G4String G4VBasicShell::FindMatchingPath ( G4UIcommandTree aTree,
const G4String aCommandPath 
)
protected

Definition at line 191 of file G4VBasicShell.cc.

193 {
194  return aTree-> CompleteCommandPath(aCommandPath);
195 }

Here is the caller graph for this function:

G4String G4VBasicShell::GetCurrentWorkingDirectory ( ) const
protected

Definition at line 70 of file G4VBasicShell.cc.

71 {
72  return currentDirectory;
73 }

Here is the caller graph for this function:

virtual G4bool G4VBasicShell::GetHelpChoice ( G4int )
protectedpure virtual

Here is the caller graph for this function:

void G4VBasicShell::ListDirectory ( const G4String newCommand) const
protected

Definition at line 335 of file G4VBasicShell.cc.

336 {
337  G4String targetDir;
338  if( newCommand.length() <= 3 ) {
339  targetDir = GetCurrentWorkingDirectory();
340  } else {
341  G4String newPrefix = newCommand.substr(3, newCommand.length()-3);
342  targetDir = newPrefix.strip(G4String::both);
343  }
344  G4UIcommandTree* commandTree = FindDirectory( targetDir );
345  if( commandTree == NULL ) {
346  G4cout << "Directory <" << targetDir << "> is not found." << G4endl;
347  } else {
348  commandTree->ListCurrent();
349  }
350 }
G4UIcommandTree * FindDirectory(const char *dirName) const
G4String strip(G4int strip_Type=trailing, char c=' ')
void ListCurrent() const
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4String GetCurrentWorkingDirectory() const

Here is the call graph for this function:

Here is the caller graph for this function:

G4String G4VBasicShell::ModifyToFullPathCommand ( const char *  aCommandLine) const
protected

Definition at line 48 of file G4VBasicShell.cc.

49 {
50  G4String rawCommandLine = aCommandLine;
51  if(rawCommandLine.isNull()||rawCommandLine(0)=='\0') return rawCommandLine;
52  G4String commandLine = rawCommandLine.strip(G4String::both);
53  G4String commandString;
54  G4String parameterString;
55  size_t i = commandLine.index(" ");
56  if( i != std::string::npos )
57  {
58  commandString = commandLine(0,i);
59  parameterString = " ";
60  parameterString += commandLine(i+1,commandLine.length()-(i+1));
61  }
62  else
63  { commandString = commandLine; }
64 
65  G4String fullPathCommandLine
66  = ModifyPath( commandString )+parameterString;
67  return fullPathCommandLine;
68 }
G4String strip(G4int strip_Type=trailing, char c=' ')
str_size index(const char *, G4int pos=0) const
G4bool isNull() const

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void G4VBasicShell::PauseSessionStart ( const G4String Prompt)
pure virtual

Reimplemented from G4UIsession.

Implemented in G4UIGainServer, and G4UIterminal.

virtual G4UIsession* G4VBasicShell::SessionStart ( )
pure virtual

Reimplemented from G4UIsession.

Implemented in G4UIGainServer, and G4UIterminal.

void G4VBasicShell::ShowCurrent ( const G4String newCommand) const
protected

Definition at line 309 of file G4VBasicShell.cc.

310 {
312  if(UI==NULL) return;
313  G4String comString = newCommand.substr(1,newCommand.length()-1);
314  G4String theCommand = ModifyToFullPathCommand(comString);
315  G4String curV = UI->GetCurrentValues(theCommand);
316  if( ! curV.isNull() ) {
317  G4cout << "Current value(s) of the parameter(s) : " << curV << G4endl;
318  }
319 }
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
G4GLOB_DLL std::ostream G4cout
G4String GetCurrentValues(const char *aCommand)
Definition: G4UImanager.cc:171
G4String ModifyToFullPathCommand(const char *aCommandLine) const
#define G4endl
Definition: G4ios.hh:61
G4bool isNull() const

Here is the call graph for this function:

Here is the caller graph for this function:

void G4VBasicShell::TerminalHelp ( const G4String newCommand)
protected

Definition at line 351 of file G4VBasicShell.cc.

352 {
354  if(UI==NULL) return;
355  G4UIcommandTree * treeTop = UI->GetTree();
356  size_t i = newCommand.index(" ");
357  if( i != std::string::npos )
358  {
359  G4String newValue = newCommand.substr(i+1, newCommand.length()-(i+1));
360  newValue.strip(G4String::both);
361  G4String targetCom = ModifyToFullPathCommand(newValue);
362  G4UIcommand* theCommand = treeTop->FindPath(targetCom);
363  if( theCommand != NULL )
364  {
365  theCommand->List();
366  return;
367  }
368  else
369  {
370  G4cout << "Command <" << newValue << " is not found." << G4endl;
371  return;
372  }
373  }
374 
375  G4UIcommandTree * floor[10];
376  floor[0] = treeTop;
377  size_t iFloor = 0;
378  size_t prefixIndex = 1;
380  while( prefixIndex < prefix.length()-1 )
381  {
382  size_t ii = prefix.index("/",prefixIndex);
383  floor[iFloor+1] =
384  floor[iFloor]->GetTree(G4String(prefix(0,ii+1)));
385  prefixIndex = ii+1;
386  iFloor++;
387  }
388  floor[iFloor]->ListCurrentWithNum();
389  // 1998 Oct 2 non-number input
390  while(1){
391  //G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<std::flush;
392  G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<G4endl;
393  G4int j;
394  if(!GetHelpChoice(j)){
395  G4cout << G4endl << "Not a number, once more" << G4endl;
396  continue;
397  } else if( j < 0 ){
398  if( iFloor < (size_t)-j ) iFloor = 0;
399  else iFloor += j;
400  //iFloor += j;
401  //if( iFloor < 0 ) iFloor = 0;
402  floor[iFloor]->ListCurrentWithNum();
403  continue;
404  } else if(j == 0) {
405  break;
406  } else if( j > 0 ) {
407  G4int n_tree = floor[iFloor]->GetTreeEntry();
408  if( j > n_tree )
409  {
410  if( j <= n_tree + floor[iFloor]->GetCommandEntry() )
411  {
412  floor[iFloor]->GetCommand(j-n_tree)->List();
413  }
414  }
415  else
416  {
417  floor[iFloor+1] = floor[iFloor]->GetTree(j);
418  iFloor++;
419  floor[iFloor]->ListCurrentWithNum();
420  }
421  }
422  }
423  G4cout << "Exit from HELP." << G4endl << G4endl;
424  //G4cout << G4endl;
425  ExitHelp();
426 }
virtual G4bool GetHelpChoice(G4int &)=0
virtual void ExitHelp() const =0
G4UIcommand * FindPath(const char *commandPath) const
G4String strip(G4int strip_Type=trailing, char c=' ')
G4UIcommand * GetCommand(G4int i)
G4int GetTreeEntry() const
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
G4GLOB_DLL std::ostream G4cout
str_size index(const char *, G4int pos=0) const
G4UIcommandTree * GetTree(G4int i)
void ListCurrentWithNum() const
const XML_Char * prefix
Definition: expat.h:380
G4String ModifyToFullPathCommand(const char *aCommandLine) const
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:206
#define G4endl
Definition: G4ios.hh:61
virtual void List()
Definition: G4UIcommand.cc:349
G4String GetCurrentWorkingDirectory() const

Here is the call graph for this function:

Here is the caller graph for this function:


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