Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 232 of file G4VBasicShell.cc.

237 {
239  if(UI==NULL) return;
240 
241  G4String command = a_string;
242  command.strip(G4String::leading);
243 
244  if( command(0) == '#' ) {
245 
246  G4cout << command << G4endl;
247 
248  } else if( command == "ls" || command(0,3) == "ls " ) {
249 
250  ListDirectory( command );
251 
252  } else if( command == "pwd" ) {
253 
254  G4cout << "Current Working Directory : "
256 
257  } else if( command == "cd" || command(0,3) == "cd ") {
258 
259  ChangeDirectoryCommand ( command );
260 
261  } else if( command == "help" || command(0,5) == "help ") {
262 
263  TerminalHelp( command );
264 
265  } else if( command(0) == '?' ) {
266 
267  ShowCurrent( command );
268 
269  } else if( command == "hist" || command == "history") {
270 
271  G4int nh = UI->GetNumberOfHistory();
272  for(G4int i=0;i<nh;i++) {
273  G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl;
274  }
275 
276  } else if( command(0) == '!' ) {
277 
278  G4String ss = command(1,command.length()-1);
279  G4int vl;
280  const char* tt = ss;
281  std::istringstream is(tt);
282  is >> vl;
283  G4int nh = UI->GetNumberOfHistory();
284  if(vl>=0 && vl<nh) {
285  G4String prev = UI->GetPreviousCommand(vl);
286  G4cout << prev << G4endl;
288  } else {
289  G4cerr << "history " << vl << " is not found." << G4endl;
290  }
291 
292  } else if( command == "exit" ) {
293 
294  if( exitPause == false) { //In a secondary loop.
295  G4cout << "You are now processing RUN." << G4endl;
296  G4cout << "Please abort it using \"/run/abort\" command first" << G4endl;
297  G4cout << " and use \"continue\" command until the application" << G4endl;
298  G4cout << " becomes to Idle." << G4endl;
299  } else {
300  exitSession = true;
301  }
302 
303  } else if( command == "cont" || command == "continue"){
304 
305  exitPause = true;
306 
307  } else {
308 
310 
311  }
312 }
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 326 of file G4VBasicShell.cc.

327 {
329  if( newCommand.length() <= 3 ) {
330  prefix = "/";
331  } else {
332  G4String aNewPrefix = newCommand.substr(3, newCommand.length()-3);
333  prefix = aNewPrefix.strip(G4String::both);
334  }
335  if(!ChangeDirectory(prefix)) {
336  G4cout << "directory <" << prefix << "> not found." << G4endl;
337  }
338 }
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 181 of file G4VBasicShell.cc.

182 {
183  G4String rawCommandLine = commandName;
184  G4String commandLine = rawCommandLine.strip(G4String::both);
185  size_t i = commandLine.index(" ");
186  if( i != std::string::npos ) return rawCommandLine; // Already entering parameters,
187  // assume command path is correct.
188  G4String commandString = commandLine;
189  G4String targetCom = ModifyPath(commandString);
191  G4String value = FindMatchingPath(tree,targetCom);
192  if(value=="") return rawCommandLine;
193  return value;
194 }
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
tuple tree
Definition: gammaraytel.py:4
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 206 of file G4VBasicShell.cc.

210 {
211  if(aCommand.length()<2) return;
213  if(UI==NULL) return;
214  G4int commandStatus = UI->ApplyCommand(aCommand);
215  switch(commandStatus) {
216  case fCommandSucceeded:
217  break;
218  case fCommandNotFound:
219  G4cerr << "command not found: " << "\"" << aCommand << "\"" << G4endl;
220  break;
222  G4cerr << "illegal application state -- command refused:" << "\"" << aCommand << "\"" << G4endl;
223  break;
227  default:
228  G4cerr << "command refused (" << commandStatus << "):" << "\"" << aCommand << "\"" << G4endl;
229  }
230 }
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

Implemented in G4VMPIsession.

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:

Here is the caller 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 196 of file G4VBasicShell.cc.

198 {
199  return aTree-> CompleteCommandPath(aCommandPath);
200 }

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

Implemented in G4VMPIsession.

Here is the caller graph for this function:

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

Definition at line 340 of file G4VBasicShell.cc.

341 {
342  G4String targetDir;
343  if( newCommand.length() <= 3 ) {
344  targetDir = GetCurrentWorkingDirectory();
345  } else {
346  G4String newPrefix = newCommand.substr(3, newCommand.length()-3);
347  targetDir = newPrefix.strip(G4String::both);
348  }
349  G4UIcommandTree* commandTree = FindDirectory( targetDir );
350  if( commandTree == NULL ) {
351  G4cout << "Directory <" << targetDir << "> is not found." << G4endl;
352  } else {
353  commandTree->ListCurrent();
354  }
355 }
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, G4UIterminal, and G4VMPIsession.

virtual G4UIsession* G4VBasicShell::SessionStart ( )
pure virtual

Reimplemented from G4UIsession.

Implemented in G4UIGainServer, G4UIterminal, G4MPIsession, and G4MPIbatch.

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

Definition at line 314 of file G4VBasicShell.cc.

315 {
317  if(UI==NULL) return;
318  G4String comString = newCommand.substr(1,newCommand.length()-1);
319  G4String theCommand = ModifyToFullPathCommand(comString);
320  G4String curV = UI->GetCurrentValues(theCommand);
321  if( ! curV.isNull() ) {
322  G4cout << "Current value(s) of the parameter(s) : " << curV << G4endl;
323  }
324 }
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 356 of file G4VBasicShell.cc.

357 {
359  if(UI==NULL) return;
360  G4UIcommandTree * treeTop = UI->GetTree();
361  size_t i = newCommand.index(" ");
362  if( i != std::string::npos )
363  {
364  G4String newValue = newCommand.substr(i+1, newCommand.length()-(i+1));
365  newValue.strip(G4String::both);
366  G4String targetCom = ModifyToFullPathCommand(newValue);
367  G4UIcommand* theCommand = treeTop->FindPath(targetCom);
368  if( theCommand != NULL )
369  {
370  theCommand->List();
371  return;
372  }
373  else
374  {
375  G4cout << "Command <" << newValue << " is not found." << G4endl;
376  return;
377  }
378  }
379 
380  G4UIcommandTree * floor[10];
381  floor[0] = treeTop;
382  size_t iFloor = 0;
383  size_t prefixIndex = 1;
385  while( prefixIndex < prefix.length()-1 )
386  {
387  size_t ii = prefix.index("/",prefixIndex);
388  floor[iFloor+1] =
389  floor[iFloor]->GetTree(G4String(prefix(0,ii+1)));
390  prefixIndex = ii+1;
391  iFloor++;
392  }
393  floor[iFloor]->ListCurrentWithNum();
394  // 1998 Oct 2 non-number input
395  while(1){
396  //G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<std::flush;
397  G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<G4endl;
398  G4int j;
399  if(!GetHelpChoice(j)){
400  G4cout << G4endl << "Not a number, once more" << G4endl;
401  continue;
402  } else if( j < 0 ){
403  if( iFloor < (size_t)-j ) iFloor = 0;
404  else iFloor += j;
405  //iFloor += j;
406  //if( iFloor < 0 ) iFloor = 0;
407  floor[iFloor]->ListCurrentWithNum();
408  continue;
409  } else if(j == 0) {
410  break;
411  } else if( j > 0 ) {
412  G4int n_tree = floor[iFloor]->GetTreeEntry();
413  if( j > n_tree )
414  {
415  if( j <= n_tree + floor[iFloor]->GetCommandEntry() )
416  {
417  floor[iFloor]->GetCommand(j-n_tree)->List();
418  }
419  }
420  else
421  {
422  floor[iFloor+1] = floor[iFloor]->GetTree(j);
423  iFloor++;
424  floor[iFloor]->ListCurrentWithNum();
425  }
426  }
427  }
428  G4cout << "Exit from HELP." << G4endl << G4endl;
429  //G4cout << G4endl;
430  ExitHelp();
431 }
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: