Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VBasicShell Class Referenceabstract

#include <G4VBasicShell.hh>

+ Inheritance 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 ()
 
virtual ~G4UIsession ()
 
virtual G4UIsessionSessionStart ()
 
virtual void PauseSessionStart (const G4String &Prompt)
 
virtual G4int ReceiveG4cout (const G4String &coutString)
 
virtual G4int ReceiveG4cerr (const G4String &cerrString)
 
- Public Member Functions inherited from G4coutDestination
 G4coutDestination ()
 
virtual ~G4coutDestination ()
 
virtual G4int ReceiveG4cout (const G4String &)
 
virtual G4int ReceiveG4cerr (const G4String &)
 

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 &)
 

Detailed Description

Definition at line 52 of file G4VBasicShell.hh.

Constructor & Destructor Documentation

◆ G4VBasicShell()

G4VBasicShell::G4VBasicShell ( )

Definition at line 39 of file G4VBasicShell.cc.

40:currentDirectory("/")
41{
42}

◆ ~G4VBasicShell()

G4VBasicShell::~G4VBasicShell ( )
virtual

Definition at line 44 of file G4VBasicShell.cc.

45{
46}

Member Function Documentation

◆ ApplyShellCommand()

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}
int G4int
Definition: G4Types.hh:66
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
G4String strip(G4int strip_Type=trailing, char c=' ')
G4int GetNumberOfHistory() const
Definition: G4UImanager.hh:220
G4String GetPreviousCommand(G4int i) const
Definition: G4UImanager.hh:222
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:51
G4String ModifyToFullPathCommand(const char *aCommandLine) const
void ShowCurrent(const G4String &) const
void TerminalHelp(const G4String &)
virtual void ExecuteCommand(const G4String &)
void ListDirectory(const G4String &) const
G4String GetCurrentWorkingDirectory() const
void ChangeDirectoryCommand(const G4String &)

◆ ChangeDirectory()

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

Referenced by ChangeDirectoryCommand().

◆ ChangeDirectoryCommand()

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}
G4bool ChangeDirectory(const char *newDir)

Referenced by ApplyShellCommand().

◆ Complete()

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}
str_size index(const char *, G4int pos=0) const
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:197
G4String FindMatchingPath(G4UIcommandTree *, const G4String &)

◆ ExecuteCommand()

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) {
212 break;
213 case fCommandNotFound:
214 G4cerr << "command not found" << G4endl;
215 break;
217 G4cerr << "illegal application state -- command refused" << G4endl;
218 break;
222 default:
223 G4cerr << "command refused (" << commandStatus << ")" << G4endl;
224 }
225}
@ fParameterOutOfCandidates
@ fCommandNotFound
@ fIllegalApplicationState
@ fParameterUnreadable
@ fCommandSucceeded
@ fParameterOutOfRange
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:369

Referenced by ApplyShellCommand().

◆ ExitHelp()

virtual void G4VBasicShell::ExitHelp ( ) const
protectedpure virtual

Referenced by TerminalHelp().

◆ FindCommand()

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

◆ FindDirectory()

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}
G4UIcommandTree * GetTree(G4int i)

Referenced by ChangeDirectory(), and ListDirectory().

◆ FindMatchingPath()

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

Definition at line 191 of file G4VBasicShell.cc.

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

Referenced by Complete().

◆ GetCurrentWorkingDirectory()

G4String G4VBasicShell::GetCurrentWorkingDirectory ( ) const
protected

Definition at line 70 of file G4VBasicShell.cc.

71{
72 return currentDirectory;
73}

Referenced by ApplyShellCommand(), ListDirectory(), and TerminalHelp().

◆ GetHelpChoice()

virtual G4bool G4VBasicShell::GetHelpChoice ( G4int )
protectedpure virtual

Referenced by TerminalHelp().

◆ ListDirectory()

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}
void ListCurrent() const

Referenced by ApplyShellCommand().

◆ ModifyToFullPathCommand()

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}
G4bool isNull() const

Referenced by ApplyShellCommand(), ShowCurrent(), and TerminalHelp().

◆ PauseSessionStart()

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

Reimplemented from G4UIsession.

Implemented in G4UIterminal, and G4UIGainServer.

◆ SessionStart()

virtual G4UIsession * G4VBasicShell::SessionStart ( )
pure virtual

Reimplemented from G4UIsession.

Implemented in G4UIterminal, and G4UIGainServer.

◆ ShowCurrent()

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}
G4String GetCurrentValues(const char *aCommand)
Definition: G4UImanager.cc:122

Referenced by ApplyShellCommand().

◆ TerminalHelp()

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}
G4UIcommand * GetCommand(G4int i)
G4int GetTreeEntry() const
void ListCurrentWithNum() const
virtual void List()
Definition: G4UIcommand.cc:328
virtual void ExitHelp() const =0
virtual G4bool GetHelpChoice(G4int &)=0

Referenced by ApplyShellCommand().


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