Geant4 11.2.2
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 ()
 
 ~G4VBasicShell () override
 
G4UIsessionSessionStart () override=0
 
void PauseSessionStart (const G4String &Prompt) override=0
 
- Public Member Functions inherited from G4UIsession
 G4UIsession ()
 
 G4UIsession (G4int iBatch)
 
 ~G4UIsession () override
 
G4int ReceiveG4debug (const G4String &debugString) override
 
G4int ReceiveG4cout (const G4String &coutString) override
 
G4int ReceiveG4cerr (const G4String &cerrString) override
 
G4int GetLastReturnCode () const
 
- Public Member Functions inherited from G4coutDestination
 G4coutDestination ()=default
 
virtual ~G4coutDestination ()=default
 
void AddDebugTransformer (const Transformer &t)
 
void AddDebugTransformer (Transformer &&t)
 
void AddCoutTransformer (const Transformer &t)
 
void AddCoutTransformer (Transformer &&t)
 
void AddCerrTransformer (const Transformer &t)
 
void AddCerrTransformer (Transformer &&t)
 
virtual void ResetTransformers ()
 
G4int ReceiveG4debug_ (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< TransformertransformersDebug
 
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 40 of file G4VBasicShell.cc.

40: currentDirectory("/") {}

◆ ~G4VBasicShell()

G4VBasicShell::~G4VBasicShell ( )
overridedefault

Member Function Documentation

◆ ApplyShellCommand()

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

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

Definition at line 237 of file G4VBasicShell.cc.

241{
243 if (UI == nullptr) return;
244
245 G4String command = G4StrUtil::lstrip_copy(a_string);
246
247 if (command[0] == '#') {
248 G4cout << command << G4endl;
249 }
250 else if (command == "ls" || command.substr(0, 3) == "ls ") {
251 ListDirectory(command);
252 }
253 else if (command == "pwd") {
254 G4cout << "Current Working Directory : " << GetCurrentWorkingDirectory() << G4endl;
255 }
256 else if (command == "cd" || command.substr(0, 3) == "cd ") {
257 ChangeDirectoryCommand(command);
258 }
259 else if (command == "help" || command.substr(0, 5) == "help ") {
260 TerminalHelp(command);
261 }
262 else if (command[0] == '?') {
263 ShowCurrent(command);
264 }
265 else if (command == "hist" || command == "history") {
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 G4String ss = command.substr(1, command.length() - 1);
273 G4int vl;
274 const char* tt = ss;
275 std::istringstream is(tt);
276 is >> vl;
277 G4int nh = UI->GetNumberOfHistory();
278 if (vl >= 0 && vl < nh) {
279 G4String prev = UI->GetPreviousCommand(vl);
280 G4cout << prev << G4endl;
282 }
283 else {
284 G4cerr << "history " << vl << " is not found." << G4endl;
285 }
286 }
287 else if (command == "exit") {
288 if (!exitPause) { // In a secondary loop.
289 G4cout << "You are now processing RUN." << G4endl;
290 G4cout << "Please abort it using \"/run/abort\" command first" << G4endl;
291 G4cout << " and use \"continue\" command until the application" << G4endl;
292 G4cout << " becomes to Idle." << G4endl;
293 }
294 else {
295 exitSession = true;
296 }
297 }
298 else if (command == "cont" || command == "continue") {
299 exitPause = true;
300 }
301 else {
303 }
304}
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfHistory() const
G4String GetPreviousCommand(G4int i) const
static G4UImanager * GetUIpointer()
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 67 of file G4VBasicShell.cc.

68{
69 G4String newPrefix = G4StrUtil::strip_copy(newDir);
70
71 G4String newDirectory = ModifyPath(newPrefix);
72 if (newDirectory.back() != '/') {
73 newDirectory += "/";
74 }
75 if (FindDirectory(newDirectory.c_str()) == nullptr) {
76 return false;
77 }
78 currentDirectory = newDirectory;
79 return true;
80}
G4UIcommandTree * FindDirectory(const char *dirName) const

Referenced by ChangeDirectoryCommand().

◆ ChangeDirectoryCommand()

void G4VBasicShell::ChangeDirectoryCommand ( const G4String & newCommand)
protected

Definition at line 318 of file G4VBasicShell.cc.

319{
321 if (newCommand.length() <= 3) {
322 prefix = "/";
323 }
324 else {
325 G4String aNewPrefix = newCommand.substr(3, newCommand.length() - 3);
326 prefix = G4StrUtil::strip_copy(aNewPrefix);
327 }
328 if (! ChangeDirectory(prefix)) {
329 G4cout << "directory <" << prefix << "> not found." << G4endl;
330 }
331}
G4bool ChangeDirectory(const char *newDir)

Referenced by ApplyShellCommand().

◆ Complete()

G4String G4VBasicShell::Complete ( const G4String & commandName)
protected

Definition at line 182 of file G4VBasicShell.cc.

183{
184 G4String rawCommandLine = commandName;
185 G4String commandLine = G4StrUtil::strip_copy(rawCommandLine);
186
187 size_t i = commandLine.find(' ');
188 if (i != std::string::npos)
189 return rawCommandLine; // Already entering parameters,
190 // assume command path is correct.
191 G4String commandString = commandLine;
192 G4String targetCom = ModifyPath(commandString);
194 G4String value = FindMatchingPath(tree, targetCom);
195 if (value.empty()) return rawCommandLine;
196 return value;
197}
G4UIcommandTree * GetTree() const
G4String FindMatchingPath(G4UIcommandTree *, const G4String &)

◆ ExecuteCommand()

void G4VBasicShell::ExecuteCommand ( const G4String & aCommand)
protectedvirtual

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

Definition at line 208 of file G4VBasicShell.cc.

212{
213 if (aCommand.length() < 2) return;
215 if (UI == nullptr) return;
216 G4int commandStatus = UI->ApplyCommand(aCommand);
217 switch (commandStatus) {
219 break;
220 case fCommandNotFound:
221 G4cerr << "command not found: "
222 << "\"" << aCommand << "\"" << G4endl;
223 break;
225 G4cerr << "illegal application state -- command refused:"
226 << "\"" << aCommand << "\"" << G4endl;
227 break;
231 default:
232 G4cerr << "command refused (" << commandStatus << "):"
233 << "\"" << aCommand << "\"" << G4endl;
234 }
235}
@ fParameterOutOfCandidates
@ fCommandNotFound
@ fIllegalApplicationState
@ fParameterUnreadable
@ fCommandSucceeded
@ fParameterOutOfRange
G4int ApplyCommand(const char *aCommand)

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

107{
108 G4String commandLine = G4StrUtil::strip_copy(commandName);
109
110 G4String commandString;
111 size_t i = commandLine.find(' ');
112 if (i != std::string::npos) {
113 commandString = commandLine.substr(0, i);
114 }
115 else {
116 commandString = commandLine;
117 }
118
119 G4String targetCom = ModifyPath(commandString);
120 return G4UImanager::GetUIpointer()->GetTree()->FindPath(targetCom);
121}
G4UIcommand * FindPath(const char *commandPath) const

◆ FindDirectory()

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

Definition at line 82 of file G4VBasicShell.cc.

83{
84 G4String theDir = G4StrUtil::strip_copy(dirName);
85
86 G4String targetDir = ModifyPath(theDir);
87 if (targetDir.back() != '/') {
88 targetDir += "/";
89 }
91 if (targetDir == "/") {
92 return comTree;
93 }
94 size_t idx = 1;
95 while (idx < targetDir.length() - 1) {
96 size_t i = targetDir.find('/', idx);
97 comTree = comTree->GetTree(targetDir.substr(0, i + 1).c_str());
98 if (comTree == nullptr) {
99 return nullptr;
100 }
101 idx = i + 1;
102 }
103 return comTree;
104}
G4UIcommandTree * GetTree(G4int i)

Referenced by ChangeDirectory(), and ListDirectory().

◆ FindMatchingPath()

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

Definition at line 199 of file G4VBasicShell.cc.

200{
201 return aTree->CompleteCommandPath(aCommandPath);
202}
G4String CompleteCommandPath(const G4String &commandPath)

Referenced by Complete().

◆ GetCurrentWorkingDirectory()

G4String G4VBasicShell::GetCurrentWorkingDirectory ( ) const
protected

Definition at line 65 of file G4VBasicShell.cc.

65{ return currentDirectory; }

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

334{
335 G4String targetDir;
336 if (newCommand.length() <= 3) {
337 targetDir = GetCurrentWorkingDirectory();
338 }
339 else {
340 G4String newPrefix = newCommand.substr(3, newCommand.length() - 3);
341 targetDir = G4StrUtil::strip_copy(newPrefix);
342 }
343 G4UIcommandTree* commandTree = FindDirectory(targetDir);
344 if (commandTree == nullptr) {
345 G4cout << "Directory <" << targetDir << "> is not found." << G4endl;
346 }
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 44 of file G4VBasicShell.cc.

45{
46 G4String rawCommandLine = aCommandLine;
47 if (rawCommandLine.empty() || rawCommandLine[0] == '\0') return rawCommandLine;
48 G4String commandLine = G4StrUtil::strip_copy(rawCommandLine);
49 G4String commandString;
50 G4String parameterString;
51 size_t i = commandLine.find(' ');
52 if (i != std::string::npos) {
53 commandString = commandLine.substr(0, i);
54 parameterString = " ";
55 parameterString += commandLine.substr(i + 1, commandLine.length() - (i + 1));
56 }
57 else {
58 commandString = commandLine;
59 }
60
61 G4String fullPathCommandLine = ModifyPath(commandString) + parameterString;
62 return fullPathCommandLine;
63}

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

◆ PauseSessionStart()

void G4VBasicShell::PauseSessionStart ( const G4String & Prompt)
overridepure virtual

Reimplemented from G4UIsession.

Implemented in G4UIQt, G4UIterminal, G4UIWin32, and G4UIXm.

◆ SessionStart()

G4UIsession * G4VBasicShell::SessionStart ( )
overridepure virtual

Reimplemented from G4UIsession.

Implemented in G4UIQt, G4UIterminal, G4UIWin32, and G4UIXm.

◆ ShowCurrent()

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

Definition at line 306 of file G4VBasicShell.cc.

307{
309 if (UI == nullptr) return;
310 G4String comString = newCommand.substr(1, newCommand.length() - 1);
311 G4String theCommand = ModifyToFullPathCommand(comString);
312 G4String curV = UI->GetCurrentValues(theCommand);
313 if (! curV.empty()) {
314 G4cout << "Current value(s) of the parameter(s) : " << curV << G4endl;
315 }
316}
G4String GetCurrentValues(const char *aCommand)

Referenced by ApplyShellCommand().

◆ TerminalHelp()

void G4VBasicShell::TerminalHelp ( const G4String & newCommand)
protected

Definition at line 351 of file G4VBasicShell.cc.

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

Referenced by ApplyShellCommand().


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