Geant4-11
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Private Attributes
G4UIterminal Class Reference

#include <G4UIterminal.hh>

Inheritance diagram for G4UIterminal:
G4VBasicShell G4UIsession G4coutDestination

Public Types

using Transformer = std::function< G4bool(G4String &)>
 

Public Member Functions

void AddCerrTransformer (const Transformer &t)
 
void AddCerrTransformer (Transformer &&t)
 
void AddCoutTransformer (const Transformer &t)
 
void AddCoutTransformer (Transformer &&t)
 
 G4UIterminal (G4VUIshell *aShell=0, G4bool qsig=true)
 
G4int GetLastReturnCode () const
 
virtual void PauseSessionStart (const G4String &msg)
 
virtual G4int ReceiveG4cerr (const G4String &cerrString)
 
G4int ReceiveG4cerr_ (const G4String &msg)
 
virtual G4int ReceiveG4cout (const G4String &coutString)
 
G4int ReceiveG4cout_ (const G4String &msg)
 
virtual void ResetTransformers ()
 
virtual G4UIsessionSessionStart ()
 
void SetPrompt (const G4String &prompt)
 
 ~G4UIterminal ()
 

Static Public Member Functions

static G4int InSession ()
 

Protected Member Functions

void ApplyShellCommand (const G4String &, G4bool &, G4bool &)
 
G4bool ChangeDirectory (const char *newDir)
 
void ChangeDirectoryCommand (const G4String &)
 
G4String Complete (const G4String &)
 
G4UIcommandFindCommand (const char *commandName) const
 
G4UIcommandTreeFindDirectory (const char *dirName) const
 
G4String FindMatchingPath (G4UIcommandTree *, const G4String &)
 
G4String GetCurrentWorkingDirectory () const
 
void ListDirectory (const G4String &) const
 
G4String ModifyToFullPathCommand (const char *aCommandLine) const
 
void ShowCurrent (const G4String &) const
 
void TerminalHelp (const G4String &)
 

Protected Attributes

G4int ifBatch = 0
 
G4int lastRC = 0
 
std::vector< TransformertransformersCerr
 
std::vector< TransformertransformersCout
 

Static Protected Attributes

static G4ICOMS_DLL G4int inSession = 0
 
static G4MTGLOB_DLL G4coutDestinationmasterG4coutDestination = nullptr
 

Private Member Functions

virtual void ExecuteCommand (const G4String &aCommand)
 
virtual void ExitHelp () const
 
G4String GetCommand (const char *msg=0)
 
virtual G4bool GetHelpChoice (G4int &aInt)
 
G4String ModifyPath (const G4String &tempPath) const
 

Private Attributes

G4String currentDirectory
 
G4bool iCont
 
G4bool iExit
 
G4VUIshellshell
 
G4UImanagerUI
 

Detailed Description

Definition at line 70 of file G4UIterminal.hh.

Member Typedef Documentation

◆ Transformer

Definition at line 61 of file G4coutDestination.hh.

Constructor & Destructor Documentation

◆ G4UIterminal()

G4UIterminal::G4UIterminal ( G4VUIshell aShell = 0,
G4bool  qsig = true 
)

Definition at line 90 of file G4UIterminal.cc.

92{
94 UI-> SetSession(this);
95 UI-> SetCoutDestination(this);
96
97 iExit= FALSE;
98 iCont= FALSE;
99
100 if(aShell) shell= aShell;
101 else shell= new G4UIcsh;
102 theshell= shell; // locally stored for the signal handler
103
104 // add signal handler
105 if(qsig) {
106#ifndef WIN32
107 signal(SIGINT, SignalHandler);
108#endif
109 }
110}
static G4ThreadLocal G4VUIshell * theshell
Definition: G4UIterminal.cc:49
static void SignalHandler(G4int)
Definition: G4UIterminal.cc:56
#define FALSE
Definition: Globals.hh:23
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
G4VUIshell * shell
Definition: G4UIterminal.hh:74
G4UImanager * UI
Definition: G4UIterminal.hh:72

References FALSE, G4UImanager::GetUIpointer(), iCont, iExit, shell, SignalHandler(), theshell, and UI.

◆ ~G4UIterminal()

G4UIterminal::~G4UIterminal ( )

Definition at line 113 of file G4UIterminal.cc.

115{
116 if(shell) delete shell;
117
119 UI-> SetSession(NULL);
120 UI-> SetCoutDestination(NULL);
121 }
122}

References G4UImanager::GetUIpointer(), shell, and UI.

Member Function Documentation

◆ AddCerrTransformer() [1/2]

void G4coutDestination::AddCerrTransformer ( const Transformer t)
inlineinherited

Definition at line 67 of file G4coutDestination.hh.

68 {
69 transformersCerr.push_back(t);
70 }
std::vector< Transformer > transformersCerr

References G4coutDestination::transformersCerr.

Referenced by G4MTcoutDestination::HandleFileCerr().

◆ AddCerrTransformer() [2/2]

void G4coutDestination::AddCerrTransformer ( Transformer &&  t)
inlineinherited

Definition at line 71 of file G4coutDestination.hh.

71{ transformersCerr.push_back(t); }

References G4coutDestination::transformersCerr.

◆ AddCoutTransformer() [1/2]

void G4coutDestination::AddCoutTransformer ( const Transformer t)
inlineinherited

◆ AddCoutTransformer() [2/2]

void G4coutDestination::AddCoutTransformer ( Transformer &&  t)
inlineinherited

Definition at line 66 of file G4coutDestination.hh.

66{ transformersCout.push_back(t); }

References G4coutDestination::transformersCout.

◆ ApplyShellCommand()

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

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

Definition at line 232 of file G4VBasicShell.cc.

237{
239 if(UI==NULL) return;
240
241 G4String command = G4StrUtil::lstrip_copy(a_string);
242
243 if( command[0] == '#' ) {
244
245 G4cout << command << G4endl;
246
247 } else if( command == "ls" || command.substr(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.substr(0,3) == "cd ") {
257
258 ChangeDirectoryCommand ( command );
259
260 } else if( command == "help" || command.substr(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.substr(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
static G4bool exitSession
Definition: G4UIQt.cc:92
static G4bool exitPause
Definition: G4UIQt.cc:93
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfHistory() const
Definition: G4UImanager.hh:201
G4String GetPreviousCommand(G4int i) const
Definition: G4UImanager.hh:202
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 &)
G4String lstrip_copy(G4String str, char c=' ')
Return copy of string with leading characters removed.

References G4VBasicShell::ChangeDirectoryCommand(), G4VBasicShell::ExecuteCommand(), exitPause, exitSession, G4cerr, G4cout, G4endl, G4VBasicShell::GetCurrentWorkingDirectory(), G4UImanager::GetNumberOfHistory(), G4UImanager::GetPreviousCommand(), G4UImanager::GetUIpointer(), G4VBasicShell::ListDirectory(), G4StrUtil::lstrip_copy(), G4VBasicShell::ModifyToFullPathCommand(), G4VBasicShell::ShowCurrent(), and G4VBasicShell::TerminalHelp().

Referenced by G4UIQt::ButtonCallback(), G4UIXm::ButtonCallback(), G4UIQt::CommandEnteredCallback(), G4UIXm::CommandEnteredCallback(), G4UIWin32::DoOpenMacro(), G4UIWin32::DoSaveViewer(), G4UIWin32::ProcessDefaultCommands(), and G4UIWin32::ProcessEnterKey().

◆ ChangeDirectory()

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

Definition at line 74 of file G4VBasicShell.cc.

75{
76 G4String newPrefix = G4StrUtil::strip_copy(newDir);
77
78 G4String newDirectory = ModifyPath( newPrefix );
79 if( newDirectory.back() != '/' )
80 { newDirectory += "/"; }
81 if( FindDirectory( newDirectory.c_str() ) == NULL )
82 { return false; }
83 currentDirectory = newDirectory;
84 return true;
85}
G4String ModifyPath(const G4String &tempPath) const
G4String currentDirectory
G4UIcommandTree * FindDirectory(const char *dirName) const
G4String strip_copy(G4String str, char c=' ')
Return copy of string with leading and trailing characters removed.

References G4VBasicShell::currentDirectory, G4VBasicShell::FindDirectory(), G4VBasicShell::ModifyPath(), and G4StrUtil::strip_copy().

Referenced by G4VBasicShell::ChangeDirectoryCommand().

◆ ChangeDirectoryCommand()

void G4VBasicShell::ChangeDirectoryCommand ( const G4String newCommand)
protectedinherited

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 = G4StrUtil::strip_copy(aNewPrefix);
333 }
334 if(!ChangeDirectory(prefix)) {
335 G4cout << "directory <" << prefix << "> not found." << G4endl;
336 }
337}
G4bool ChangeDirectory(const char *newDir)

References G4VBasicShell::ChangeDirectory(), G4cout, G4endl, and G4StrUtil::strip_copy().

Referenced by G4VBasicShell::ApplyShellCommand(), GetCommand(), and G4ZMQServer::GetCommand().

◆ Complete()

G4String G4VBasicShell::Complete ( const G4String commandName)
protectedinherited

Definition at line 180 of file G4VBasicShell.cc.

181{
182 G4String rawCommandLine = commandName;
183 G4String commandLine = G4StrUtil::strip_copy(rawCommandLine);
184
185 size_t i = commandLine.find(" ");
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}
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:186
G4String FindMatchingPath(G4UIcommandTree *, const G4String &)

References G4VBasicShell::FindMatchingPath(), G4UImanager::GetTree(), G4UImanager::GetUIpointer(), G4VBasicShell::ModifyPath(), and G4StrUtil::strip_copy().

Referenced by G4UIQt::eventFilter(), G4UIXm::keyHandler(), and G4UIWin32::ProcessTabKey().

◆ ExecuteCommand()

void G4UIterminal::ExecuteCommand ( const G4String aCommand)
privatevirtual

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

Reimplemented from G4VBasicShell.

Definition at line 160 of file G4UIterminal.cc.

162{
163 if(aCommand.length()<2) return;
164
165 G4int returnVal = UI-> ApplyCommand(aCommand);
166
167 G4int paramIndex = returnVal % 100;
168 // 0 - 98 : paramIndex-th parameter is invalid
169 // 99 : convination of parameters is invalid
170 G4int commandStatus = returnVal - paramIndex;
171
172 G4UIcommand* cmd = 0;
173 if(commandStatus!=fCommandSucceeded)
174 { cmd = FindCommand(aCommand); }
175
176 switch(commandStatus) {
178 break;
179 case fCommandNotFound:
180 G4cerr << "command <" << UI->SolveAlias(aCommand) << "> not found" << G4endl;
181 if( aCommand.find("@@") != G4String::npos) {
182 G4cout << "@@G4UIterminal" << G4endl;
183 }
184 break;
186 G4cerr << "illegal application state -- command refused" << G4endl;
187 break;
189 // if(paramIndex<99) {
190 // G4cerr << "Parameter is out of range (index " << paramIndex << ")" << G4endl;
191 // G4cerr << "Allowed range : " << cmd->GetParameter(paramIndex)->GetParameterRange() << G4endl;
192 // } else {
193 // G4cerr << "Parameter is out of range" << G4endl;
194 // G4cerr << "Allowed range : " << cmd->GetRange() << G4endl;
195 // }
196 break;
198 G4cerr << "Parameter is out of candidate list (index " << paramIndex << ")" << G4endl;
199 G4cerr << "Candidates : " << cmd->GetParameter(paramIndex)->GetParameterCandidates() << G4endl;
200 break;
202 G4cerr << "Parameter is wrong type and/or is not omittable (index " << paramIndex << ")" << G4endl;
203 break;
204 case fAliasNotFound:
205 default:
206 G4cerr << "command refused (" << commandStatus << ")" << G4endl;
207 }
208}
@ fParameterOutOfCandidates
@ fCommandNotFound
@ fAliasNotFound
@ fIllegalApplicationState
@ fParameterUnreadable
@ fCommandSucceeded
@ fParameterOutOfRange
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:139
G4String SolveAlias(const char *aCmd)
Definition: G4UImanager.cc:424
const G4String & GetParameterCandidates() const
G4UIcommand * FindCommand(const char *commandName) const

References fAliasNotFound, fCommandNotFound, fCommandSucceeded, fIllegalApplicationState, G4VBasicShell::FindCommand(), fParameterOutOfCandidates, fParameterOutOfRange, fParameterUnreadable, G4cerr, G4cout, G4endl, G4UIcommand::GetParameter(), G4UIparameter::GetParameterCandidates(), G4UImanager::SolveAlias(), and UI.

Referenced by PauseSessionStart(), and SessionStart().

◆ ExitHelp()

void G4UIterminal::ExitHelp ( ) const
privatevirtual

Implements G4VBasicShell.

Definition at line 334 of file G4UIterminal.cc.

336{
337 char temp[100];
338 G4cin.getline(temp, 100);
339}
#define G4cin
Definition: G4ios.hh:56

References G4cin.

◆ FindCommand()

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

Definition at line 109 of file G4VBasicShell.cc.

110{
111 G4String commandLine = G4StrUtil::strip_copy(commandName);
112
113 G4String commandString;
114 size_t i = commandLine.find(" ");
115 if( i != std::string::npos )
116 { commandString = commandLine.substr(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

References G4UIcommandTree::FindPath(), G4UImanager::GetTree(), G4UImanager::GetUIpointer(), G4VBasicShell::ModifyPath(), and G4StrUtil::strip_copy().

Referenced by ExecuteCommand(), and G4ZMQServer::ExecuteCommand().

◆ FindDirectory()

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

Definition at line 87 of file G4VBasicShell.cc.

88{
89 G4String theDir = G4StrUtil::strip_copy(dirName);
90
91 G4String targetDir = ModifyPath( theDir );
92 if( targetDir.back() != '/' )
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.find("/",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)

References G4UImanager::GetTree(), G4UIcommandTree::GetTree(), G4UImanager::GetUIpointer(), G4VBasicShell::ModifyPath(), and G4StrUtil::strip_copy().

Referenced by G4VBasicShell::ChangeDirectory(), G4VBasicShell::ListDirectory(), and G4ZMQServer::SessionStart().

◆ FindMatchingPath()

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

Definition at line 196 of file G4VBasicShell.cc.

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

Referenced by G4VBasicShell::Complete().

◆ GetCommand()

G4String G4UIterminal::GetCommand ( const char *  msg = 0)
private

Definition at line 211 of file G4UIterminal.cc.

213{
214 G4String newCommand = shell->GetCommandLineString(msg);
215 G4String nullString = "";
216
217 G4String nC = G4StrUtil::lstrip_copy(newCommand);
218
219 if( nC.length() == 0 ) {
220 newCommand= nullString;
221
222 } else if( nC[0] == '#' ) {
223 G4cout << nC << G4endl;
224 newCommand= nullString;
225
226 } else if(nC=="ls" || nC.substr(0,3)=="ls " ) { // list commands
227 ListDirectory(nC);
228 newCommand= nullString;
229
230 } else if(nC=="lc" || nC.substr(0,3)=="lc " ) { // ... by shell
231 shell-> ListCommand(nC.erase(0,2));
232 newCommand= nullString;
233
234 } else if(nC == "pwd") { // show current directory
235 G4cout << "Current Command Directory : "
237 newCommand= nullString;
238
239 } else if(nC == "cwd") { // ... by shell
240 shell-> ShowCurrentDirectory();
241 newCommand= nullString;
242
243 } else if(nC == "cd" || nC.substr(0,3) == "cd ") { // "cd"
245 shell-> SetCurrentDirectory(GetCurrentWorkingDirectory());
246 newCommand= nullString;
247
248 } else if(nC == "help" || nC.substr(0,5) == "help ") { // "help"
249 TerminalHelp(nC);
250 newCommand= nullString;
251
252 } else if(nC[0] == '?') { // "show current value of a parameter"
253 ShowCurrent(nC);
254 newCommand= nullString;
255
256 } else if(nC == "hist" || nC == "history") { // "hist/history"
257 G4int nh= UI-> GetNumberOfHistory();
258 for (G4int i=0; i<nh; i++) {
259 G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl;
260 }
261 newCommand= nullString;
262
263 } else if(nC[0] == '!') { // "!"
264 G4String ss= nC.substr(1, nC.length()-1);
265 G4int vl;
266 const char* tt= ss;
267 std::istringstream is(tt);
268 is >> vl;
269 G4int nh= UI-> GetNumberOfHistory();
270 if(vl>=0 && vl<nh) {
271 newCommand= UI-> GetPreviousCommand(vl);
272 G4cout << newCommand << G4endl;
273 } else {
274 G4cerr << "history " << vl << " is not found." << G4endl;
275 newCommand= nullString;
276 }
277
278 } else if(nC == "exit") { // "exit"
279 if(iCont) {
280 G4cout << "You are now processing RUN." << G4endl;
281 G4cout << "Please abort it using \"/run/abort\" command first" << G4endl;
282 G4cout << " and use \"continue\" command until the application"
283 << G4endl;
284 G4cout << " becomes to Idle." << G4endl;
285 } else {
286 iExit= FALSE;
287 newCommand= nullString;
288 }
289
290 } else if( nC == "cont" || nC == "continue"){ // "cont/continu"
291 iCont= FALSE;
292 newCommand= nullString;
293
294 } else if( nC.empty() ){ // NULL command
295 newCommand= nullString;
296
297 } else {
298 }
299
300 return ModifyToFullPathCommand(newCommand);
301}
virtual G4String GetCommandLineString(const char *msg=0)=0

References G4VBasicShell::ChangeDirectoryCommand(), FALSE, G4cerr, G4cout, G4endl, G4VUIshell::GetCommandLineString(), G4VBasicShell::GetCurrentWorkingDirectory(), G4UImanager::GetPreviousCommand(), iCont, iExit, G4VBasicShell::ListDirectory(), G4StrUtil::lstrip_copy(), G4VBasicShell::ModifyToFullPathCommand(), shell, G4VBasicShell::ShowCurrent(), G4VBasicShell::TerminalHelp(), and UI.

Referenced by PauseSessionStart(), and SessionStart().

◆ GetCurrentWorkingDirectory()

G4String G4VBasicShell::GetCurrentWorkingDirectory ( ) const
protectedinherited

◆ GetHelpChoice()

G4bool G4UIterminal::GetHelpChoice ( G4int aInt)
privatevirtual

Implements G4VBasicShell.

Definition at line 321 of file G4UIterminal.cc.

323{
324 G4cin >> aInt;
325 if(!G4cin.good()){
326 G4cin.clear();
327 G4cin.ignore(30,'\n');
328 return FALSE;
329 }
330 return TRUE;
331}
#define TRUE
Definition: Globals.hh:27

References FALSE, G4cin, and TRUE.

◆ GetLastReturnCode()

G4int G4UIsession::GetLastReturnCode ( ) const
inlineinherited

Definition at line 63 of file G4UIsession.hh.

63{ return lastRC; }
G4int lastRC
Definition: G4UIsession.hh:69

References G4UIsession::lastRC.

◆ InSession()

G4int G4UIsession::InSession ( )
staticinherited

Definition at line 68 of file G4UIsession.cc.

69{
70 return inSession;
71}
static G4ICOMS_DLL G4int inSession
Definition: G4UIsession.hh:67

References G4UIsession::inSession.

Referenced by G4UIcontrolMessenger::SetNewValue().

◆ ListDirectory()

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

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 = G4StrUtil::strip_copy(newPrefix);
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

References G4VBasicShell::FindDirectory(), G4cout, G4endl, G4VBasicShell::GetCurrentWorkingDirectory(), G4UIcommandTree::ListCurrent(), and G4StrUtil::strip_copy().

Referenced by G4VBasicShell::ApplyShellCommand(), GetCommand(), and G4ZMQServer::GetCommand().

◆ ModifyPath()

G4String G4VBasicShell::ModifyPath ( const G4String tempPath) const
privateinherited

Definition at line 124 of file G4VBasicShell.cc.

125{
126 if( tempPath.length() == 0 ) return tempPath;
127
128 G4String newPath = "";
129
130 // temporal full path
131 if( tempPath[0] == '/') newPath = tempPath;
132 else newPath = currentDirectory + tempPath;
133
134 // body of path...
135 while(1){
136 size_t idx = newPath.find("/./");
137 if( idx == G4String::npos) break;
138 newPath.erase(idx,2);
139 }
140
141 while(1) {
142 size_t idx = newPath.find("/../");
143 if( idx == G4String::npos) break;
144 if( idx == 0) {
145 newPath.erase(1,3);
146 continue;
147 }
148 size_t idx2 = newPath.find_last_of('/', idx-1);
149 if(idx2 != G4String::npos) newPath.erase(idx2, idx-idx2+3);
150 }
151
152 // end of path...
153 if ( newPath.size() >= 3 ) {
154 if(newPath.substr(newPath.size()-3,3) == "/..") {
155 if( newPath.size() == 3) {
156 newPath = "/";
157 } else {
158 size_t idx = newPath.find_last_of('/', newPath.size()-4);
159 if(idx != G4String::npos) newPath.erase(idx+1);
160 }
161 }
162 }
163
164 if ( newPath.size() >= 2 ) {
165 if(newPath.substr(newPath.size()-2,2) == "/.") newPath.erase(newPath.size()-1,1);
166 }
167
168 // truncate "/////" to "/"
169 while(1) {
170 size_t idx = newPath.find("//");
171 if( idx == G4String::npos) break;
172 newPath.erase(idx,1);
173 }
174
175 return newPath;
176}

References G4VBasicShell::currentDirectory.

Referenced by G4VBasicShell::ChangeDirectory(), G4VBasicShell::Complete(), G4VBasicShell::FindCommand(), G4VBasicShell::FindDirectory(), and G4VBasicShell::ModifyToFullPathCommand().

◆ ModifyToFullPathCommand()

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

Definition at line 47 of file G4VBasicShell.cc.

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

References G4VBasicShell::ModifyPath(), and G4StrUtil::strip_copy().

Referenced by G4UIQt::ActivateCommand(), G4VBasicShell::ApplyShellCommand(), GetCommand(), G4ZMQServer::GetCommand(), G4VBasicShell::ShowCurrent(), and G4VBasicShell::TerminalHelp().

◆ PauseSessionStart()

void G4UIterminal::PauseSessionStart ( const G4String msg)
virtual

Implements G4VBasicShell.

Definition at line 147 of file G4UIterminal.cc.

149{
150 iCont= TRUE;
151
152 G4String newCommand= GetCommand(msg);
153 while(iCont){
154 ExecuteCommand(newCommand);
155 newCommand= GetCommand(msg);
156 }
157}
G4String GetCommand(const char *msg=0)
virtual void ExecuteCommand(const G4String &aCommand)

References ExecuteCommand(), GetCommand(), iCont, and TRUE.

◆ ReceiveG4cerr()

G4int G4UIterminal::ReceiveG4cerr ( const G4String cerrString)
virtual

Reimplemented from G4UIsession.

Definition at line 313 of file G4UIterminal.cc.

315{
316 std::cerr << cerrString << std::flush;
317 return 0;
318}

◆ ReceiveG4cerr_()

G4int G4coutDestination::ReceiveG4cerr_ ( const G4String msg)
inherited

Definition at line 84 of file G4coutDestination.cc.

85{
86 if(transformersCout.size() > 0)
87 {
88 G4String m = msg;
89 std::for_each(transformersCerr.begin(), transformersCerr.end(),
90 [&m](const Transformer& t) { t(m); }
91 // Call transforming function on message
92 );
93 return ReceiveG4cerr(m);
94 }
95 else
96 {
97 return ReceiveG4cerr(msg);
98 }
99}
static constexpr double m
Definition: G4SIunits.hh:109
virtual G4int ReceiveG4cerr(const G4String &msg)
std::function< G4bool(G4String &)> Transformer

References m, G4coutDestination::ReceiveG4cerr(), G4coutDestination::transformersCerr, and G4coutDestination::transformersCout.

Referenced by G4MasterForwardcoutDestination::ReceiveG4cerr().

◆ ReceiveG4cout()

G4int G4UIterminal::ReceiveG4cout ( const G4String coutString)
virtual

Reimplemented from G4UIsession.

Definition at line 305 of file G4UIterminal.cc.

307{
308 std::cout << coutString << std::flush;
309 return 0;
310}

◆ ReceiveG4cout_()

G4int G4coutDestination::ReceiveG4cout_ ( const G4String msg)
inherited

Definition at line 62 of file G4coutDestination.cc.

63{
64 // Avoid copy of string if not necessary
65 if(transformersCout.size() > 0)
66 {
67 G4String m = msg;
68 G4bool result = true;
69 for(const auto& el : transformersCout)
70 {
71 result &= el(m);
72 if(!result)
73 break;
74 }
75 return (result ? ReceiveG4cout(m) : 0);
76 }
77 else
78 {
79 return ReceiveG4cout(msg);
80 }
81}
bool G4bool
Definition: G4Types.hh:86
virtual G4int ReceiveG4cout(const G4String &msg)

References m, G4coutDestination::ReceiveG4cout(), and G4coutDestination::transformersCout.

Referenced by G4MasterForwardcoutDestination::ReceiveG4cout().

◆ ResetTransformers()

void G4coutDestination::ResetTransformers ( )
virtualinherited

Definition at line 41 of file G4coutDestination.cc.

42{
43 transformersCout.clear();
44 transformersCerr.clear();
45}

References G4coutDestination::transformersCerr, and G4coutDestination::transformersCout.

◆ SessionStart()

G4UIsession * G4UIterminal::SessionStart ( )
virtual

Implements G4VBasicShell.

Definition at line 133 of file G4UIterminal.cc.

135{
136 iExit= TRUE;
137
138 G4String newCommand= GetCommand();
139 while(iExit){
140 ExecuteCommand(newCommand);
141 newCommand= GetCommand();
142 }
143 return NULL;
144}

References ExecuteCommand(), GetCommand(), iExit, and TRUE.

◆ SetPrompt()

void G4UIterminal::SetPrompt ( const G4String prompt)

Definition at line 126 of file G4UIterminal.cc.

128{
129 shell-> SetPrompt(prompt);
130}
void SetPrompt(const G4String &prompt)

References SetPrompt(), and shell.

Referenced by SetPrompt().

◆ ShowCurrent()

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

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.empty() ) {
321 G4cout << "Current value(s) of the parameter(s) : " << curV << G4endl;
322 }
323}
G4String GetCurrentValues(const char *aCommand)
Definition: G4UImanager.cc:164

References G4cout, G4endl, G4UImanager::GetCurrentValues(), G4UImanager::GetUIpointer(), and G4VBasicShell::ModifyToFullPathCommand().

Referenced by G4VBasicShell::ApplyShellCommand(), GetCommand(), and G4ZMQServer::GetCommand().

◆ TerminalHelp()

void G4VBasicShell::TerminalHelp ( const G4String newCommand)
protectedinherited

Definition at line 355 of file G4VBasicShell.cc.

356{
358 if(UI==NULL) return;
359 G4UIcommandTree * treeTop = UI->GetTree();
360 size_t i = newCommand.find(" ");
361 if( i != std::string::npos )
362 {
363 G4String newValue = newCommand.substr(i+1, newCommand.length()-(i+1));
364 G4StrUtil::strip(newValue);
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.find("/",prefixIndex);
387 floor[iFloor+1] =
388 floor[iFloor]->GetTree(G4String(prefix.substr(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:410
virtual void ExitHelp() const =0
virtual G4bool GetHelpChoice(G4int &)=0
void strip(G4String &str, char c=' ')
Remove leading and trailing characters from string.

References G4VBasicShell::ExitHelp(), G4UIcommandTree::FindPath(), G4cout, G4endl, G4UIcommandTree::GetCommand(), G4VBasicShell::GetCurrentWorkingDirectory(), G4VBasicShell::GetHelpChoice(), G4UImanager::GetTree(), G4UIcommandTree::GetTree(), G4UIcommandTree::GetTreeEntry(), G4UImanager::GetUIpointer(), G4UIcommand::List(), G4UIcommandTree::ListCurrentWithNum(), G4VBasicShell::ModifyToFullPathCommand(), and G4StrUtil::strip().

Referenced by G4VBasicShell::ApplyShellCommand(), GetCommand(), G4ZMQServer::GetCommand(), and G4UIQt::ShowHelpCallback().

Field Documentation

◆ currentDirectory

G4String G4VBasicShell::currentDirectory
privateinherited

◆ iCont

G4bool G4UIterminal::iCont
private

Definition at line 78 of file G4UIterminal.hh.

Referenced by G4UIterminal(), GetCommand(), and PauseSessionStart().

◆ iExit

G4bool G4UIterminal::iExit
private

Definition at line 77 of file G4UIterminal.hh.

Referenced by G4UIterminal(), GetCommand(), and SessionStart().

◆ ifBatch

G4int G4UIsession::ifBatch = 0
protectedinherited

Definition at line 68 of file G4UIsession.hh.

Referenced by G4UIsession::~G4UIsession().

◆ inSession

G4int G4UIsession::inSession = 0
staticprotectedinherited

◆ lastRC

G4int G4UIsession::lastRC = 0
protectedinherited

◆ masterG4coutDestination

G4coutDestination * G4coutDestination::masterG4coutDestination = nullptr
staticprotectedinherited

◆ shell

G4VUIshell* G4UIterminal::shell
private

Definition at line 74 of file G4UIterminal.hh.

Referenced by G4UIterminal(), GetCommand(), SetPrompt(), and ~G4UIterminal().

◆ transformersCerr

std::vector<Transformer> G4coutDestination::transformersCerr
protectedinherited

◆ transformersCout

std::vector<Transformer> G4coutDestination::transformersCout
protectedinherited

◆ UI

G4UImanager* G4UIterminal::UI
private

Definition at line 72 of file G4UIterminal.hh.

Referenced by ExecuteCommand(), G4UIterminal(), GetCommand(), and ~G4UIterminal().


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