Geant4 10.7.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 ()
 
 G4UIsession (G4int iBatch)
 
virtual ~G4UIsession ()
 
virtual G4UIsessionSessionStart ()
 
virtual void PauseSessionStart (const G4String &Prompt)
 
virtual G4int ReceiveG4cout (const G4String &coutString)
 
virtual G4int ReceiveG4cerr (const G4String &cerrString)
 
G4int GetLastReturnCode () const
 
- Public Member Functions inherited from G4coutDestination
 G4coutDestination ()=default
 
virtual ~G4coutDestination ()
 
void AddCoutTransformer (const Transformer &t)
 
void AddCoutTransformer (Transformer &&t)
 
void AddCerrTransformer (const Transformer &t)
 
void AddCerrTransformer (Transformer &&t)
 
virtual void ResetTransformers ()
 
virtual G4int ReceiveG4cout (const G4String &msg)
 
virtual G4int ReceiveG4cerr (const G4String &msg)
 
G4int ReceiveG4cout_ (const G4String &msg)
 
G4int ReceiveG4cerr_ (const G4String &msg)
 

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

- Public Types inherited from G4coutDestination
using Transformer = std::function< G4bool(G4String &)>
 
- Static Public Member Functions inherited from G4UIsession
static G4int InSession ()
 
- Protected Attributes inherited from G4UIsession
G4int ifBatch = 0
 
G4int lastRC = 0
 
- Protected Attributes inherited from G4coutDestination
std::vector< TransformertransformersCout
 
std::vector< TransformertransformersCerr
 
- Static Protected Attributes inherited from G4UIsession
static G4ICOMS_DLL G4int inSession = 0
 
- Static Protected Attributes inherited from G4coutDestination
static G4MTGLOB_DLL G4coutDestinationmasterG4coutDestination = nullptr
 

Detailed Description

Definition at line 51 of file G4VBasicShell.hh.

Constructor & Destructor Documentation

◆ G4VBasicShell()

G4VBasicShell::G4VBasicShell ( )

Definition at line 38 of file G4VBasicShell.cc.

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

◆ ~G4VBasicShell()

G4VBasicShell::~G4VBasicShell ( )
virtual

Definition at line 43 of file G4VBasicShell.cc.

44{
45}

Member Function Documentation

◆ ApplyShellCommand()

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

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

Definition at line 231 of file G4VBasicShell.cc.

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

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

Referenced by ChangeDirectoryCommand().

◆ ChangeDirectoryCommand()

void G4VBasicShell::ChangeDirectoryCommand ( const G4String newCommand)
protected

Definition at line 325 of file G4VBasicShell.cc.

326{
328 if( newCommand.length() <= 3 ) {
329 prefix = "/";
330 } else {
331 G4String aNewPrefix = newCommand.substr(3, newCommand.length()-3);
332 prefix = aNewPrefix.strip(G4String::both);
333 }
334 if(!ChangeDirectory(prefix)) {
335 G4cout << "directory <" << prefix << "> not found." << G4endl;
336 }
337}
G4bool ChangeDirectory(const char *newDir)

Referenced by ApplyShellCommand().

◆ Complete()

G4String G4VBasicShell::Complete ( const G4String commandName)
protected

Definition at line 180 of file G4VBasicShell.cc.

181{
182 G4String rawCommandLine = commandName;
183 G4String commandLine = rawCommandLine.strip(G4String::both);
184 size_t i = commandLine.index(" ");
185 if( i != std::string::npos ) return rawCommandLine; // Already entering parameters,
186 // assume command path is correct.
187 G4String commandString = commandLine;
188 G4String targetCom = ModifyPath(commandString);
190 G4String value = FindMatchingPath(tree,targetCom);
191 if(value=="") return rawCommandLine;
192 return value;
193}
str_size index(const char *, G4int pos=0) const
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:179
G4String FindMatchingPath(G4UIcommandTree *, const G4String &)

◆ ExecuteCommand()

void G4VBasicShell::ExecuteCommand ( const G4String aCommand)
protectedvirtual

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

Definition at line 205 of file G4VBasicShell.cc.

209{
210 if(aCommand.length()<2) return;
212 if(UI==NULL) return;
213 G4int commandStatus = UI->ApplyCommand(aCommand);
214 switch(commandStatus) {
216 break;
217 case fCommandNotFound:
218 G4cerr << "command not found: " << "\"" << aCommand << "\"" << G4endl;
219 break;
221 G4cerr << "illegal application state -- command refused:" << "\"" << aCommand << "\"" << G4endl;
222 break;
226 default:
227 G4cerr << "command refused (" << commandStatus << "):" << "\"" << aCommand << "\"" << G4endl;
228 }
229}
@ fParameterOutOfCandidates
@ fCommandNotFound
@ fIllegalApplicationState
@ fParameterUnreadable
@ fCommandSucceeded
@ fParameterOutOfRange
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485

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 109 of file G4VBasicShell.cc.

110{
111 G4String rawCommandLine = commandName;
112 G4String commandLine = rawCommandLine.strip(G4String::both);
113 G4String commandString;
114 size_t i = commandLine.index(" ");
115 if( i != std::string::npos )
116 { commandString = commandLine(0,i); }
117 else
118 { commandString = commandLine; }
119
120 G4String targetCom = ModifyPath(commandString);
121 return G4UImanager::GetUIpointer()->GetTree()->FindPath(targetCom);
122}
G4UIcommand * FindPath(const char *commandPath) const

◆ FindDirectory()

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

Definition at line 87 of file G4VBasicShell.cc.

88{
89 G4String aDirName = dirName;
90 G4String theDir = aDirName.strip(G4String::both);
91 G4String targetDir = ModifyPath( theDir );
92 if( targetDir( targetDir.length()-1 ) != '/' )
93 { targetDir += "/"; }
95 if( targetDir == "/" )
96 { return comTree; }
97 size_t idx = 1;
98 while( idx < targetDir.length()-1 )
99 {
100 size_t i = targetDir.index("/",idx);
101 comTree = comTree->GetTree(targetDir.substr(0,i+1).c_str());
102 if( comTree == NULL )
103 { return NULL; }
104 idx = i+1;
105 }
106 return comTree;
107}
G4UIcommandTree * GetTree(G4int i)

Referenced by ChangeDirectory(), and ListDirectory().

◆ FindMatchingPath()

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

Definition at line 195 of file G4VBasicShell.cc.

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

Referenced by Complete().

◆ GetCurrentWorkingDirectory()

G4String G4VBasicShell::GetCurrentWorkingDirectory ( ) const
protected

Definition at line 69 of file G4VBasicShell.cc.

70{
71 return currentDirectory;
72}

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 339 of file G4VBasicShell.cc.

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

Referenced by ApplyShellCommand().

◆ ModifyToFullPathCommand()

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

Definition at line 47 of file G4VBasicShell.cc.

48{
49 G4String rawCommandLine = aCommandLine;
50 if(rawCommandLine.isNull()||rawCommandLine(0)=='\0') return rawCommandLine;
51 G4String commandLine = rawCommandLine.strip(G4String::both);
52 G4String commandString;
53 G4String parameterString;
54 size_t i = commandLine.index(" ");
55 if( i != std::string::npos )
56 {
57 commandString = commandLine(0,i);
58 parameterString = " ";
59 parameterString += commandLine(i+1,commandLine.length()-(i+1));
60 }
61 else
62 { commandString = commandLine; }
63
64 G4String fullPathCommandLine
65 = ModifyPath( commandString )+parameterString;
66 return fullPathCommandLine;
67}
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 313 of file G4VBasicShell.cc.

314{
316 if(UI==NULL) return;
317 G4String comString = newCommand.substr(1,newCommand.length()-1);
318 G4String theCommand = ModifyToFullPathCommand(comString);
319 G4String curV = UI->GetCurrentValues(theCommand);
320 if( ! curV.isNull() ) {
321 G4cout << "Current value(s) of the parameter(s) : " << curV << G4endl;
322 }
323}
G4String GetCurrentValues(const char *aCommand)
Definition: G4UImanager.cc:164

Referenced by ApplyShellCommand().

◆ TerminalHelp()

void G4VBasicShell::TerminalHelp ( const G4String newCommand)
protected

Definition at line 355 of file G4VBasicShell.cc.

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

Referenced by ApplyShellCommand().


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