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

#include <G4VUIshell.hh>

+ Inheritance diagram for G4VUIshell:

Public Member Functions

 G4VUIshell (const G4String &prompt="> ")
 
virtual ~G4VUIshell ()
 
void SetNColumn (G4int ncol)
 
void SetPrompt (const G4String &prompt)
 
void SetCurrentDirectory (const G4String &ccd)
 
virtual void SetLsColor (TermColorIndex, TermColorIndex)
 
virtual void ShowCurrentDirectory () const
 
virtual void ListCommand (const G4String &input, const G4String &candidate="") const
 
virtual G4String GetCommandLineString (const char *msg=0)=0
 
virtual void ResetTerminal ()
 

Protected Member Functions

virtual void MakePrompt (const char *msg=0)
 
G4UIcommandTreeGetCommandTree (const G4String &dir) const
 
G4String GetAbsCommandDirPath (const G4String &apath) const
 
G4String GetCommandPathTail (const G4String &apath) const
 

Protected Attributes

G4String promptSetting
 
G4String promptString
 
G4int nColumn
 
G4bool lsColorFlag
 
TermColorIndex directoryColor
 
TermColorIndex commandColor
 
G4String currentCommandDir
 

Detailed Description

Definition at line 58 of file G4VUIshell.hh.

Constructor & Destructor Documentation

◆ G4VUIshell()

G4VUIshell::G4VUIshell ( const G4String prompt = "> ")

Definition at line 45 of file G4VUIshell.cc.

46 : promptSetting(prompt), promptString(""), nColumn(80),
49///////////////////////////////////////////////////////////////////
50{
51}
@ BLACK
Definition: G4VUIshell.hh:53
#define FALSE
Definition: Globals.hh:23
TermColorIndex directoryColor
Definition: G4VUIshell.hh:68
G4int nColumn
Definition: G4VUIshell.hh:63
G4String currentCommandDir
Definition: G4VUIshell.hh:72
TermColorIndex commandColor
Definition: G4VUIshell.hh:69
G4String promptString
Definition: G4VUIshell.hh:61
G4bool lsColorFlag
Definition: G4VUIshell.hh:67
G4String promptSetting
Definition: G4VUIshell.hh:60

◆ ~G4VUIshell()

G4VUIshell::~G4VUIshell ( )
virtual

Definition at line 54 of file G4VUIshell.cc.

56{
57}

Member Function Documentation

◆ GetAbsCommandDirPath()

G4String G4VUIshell::GetAbsCommandDirPath ( const G4String apath) const
protected

Definition at line 146 of file G4VUIshell.cc.

148{
149 if(apath.empty()) return apath; // null string
150
151 // if "apath" does not start with "/",
152 // then it is treared as relative path
153 G4String bpath= apath;
154 if(apath[(size_t)0] != '/') bpath= currentCommandDir + apath;
155
156 // parsing...
157 G4String absPath= "/";
158 for(G4int indx=1; indx<=G4int(bpath.length())-1; ) {
159 G4int jslash= bpath.index("/", indx); // search index begin with "/"
160 if(indx == jslash) { // skip first '///'
161 indx++;
162 continue;
163 }
164 if(jslash != G4int(G4String::npos)) {
165 if(bpath.substr(indx,jslash-indx) == ".."){ // directory up
166 if(absPath == "/") {
167 indx = jslash+1;
168 continue;
169 }
170 if(absPath.length() >= 2) {
171 absPath.remove(absPath.length()-1); // remove last "/"
172 G4int jpre= absPath.last('/');
173 if(jpre != G4int(G4String::npos)) absPath.remove(jpre+1);
174 }
175 } else if(bpath.substr(indx,jslash-indx) == "."){ // nothing to do
176 } else { // add
177 if( !(jslash==indx && bpath(indx)=='/') ) // truncate "////"
178 absPath+= bpath(indx, jslash-indx+1);
179 // better to be check directory existence. (it costs!)
180 }
181 indx= jslash+1;
182 } else { // directory ONLY (ignore non-"/" terminated string)
183 break;
184 }
185 }
186
187 return absPath;
188}
int G4int
Definition: G4Types.hh:85
G4String & remove(str_size)
str_size index(const char *, G4int pos=0) const
std::size_t last(char) const

Referenced by G4UItcsh::CompleteCommand(), and G4UItcsh::ListMatchedCommand().

◆ GetCommandLineString()

virtual G4String G4VUIshell::GetCommandLineString ( const char *  msg = 0)
pure virtual

Implemented in G4UIcsh, and G4UItcsh.

◆ GetCommandPathTail()

G4String G4VUIshell::GetCommandPathTail ( const G4String apath) const
protected

Definition at line 192 of file G4VUIshell.cc.

194{ // xxx/xxx/zzz -> zzz, trancate /// -> /
195 if(apath.empty()) return apath;
196
197 G4int lstr= apath.length();
198
199 // for trancating "/"
200 G4bool Qsla= FALSE;
201 if(apath[(size_t)(lstr-1)]=='/') Qsla= TRUE;
202
203 // searching last '/' from tail
204 G4int indx= -1;
205 for(G4int i=lstr-1; i>=0; i--) {
206 if(Qsla && apath[(size_t)i]!='/') Qsla= FALSE; // break "/" flag!!
207 if(apath[(size_t)i]=='/' && !Qsla) {
208 indx= i;
209 break;
210 }
211 }
212
213 if(indx==-1) return apath; // not found
214
215 if(indx==0 && lstr==1) { // "/"
216 G4String nullStr;
217 return nullStr;
218 } else {
219 //G4String newPath= apath(indx+1,lstr-indx-1);
220 G4String newPath= apath;
221 newPath= newPath(indx+1,lstr-indx-1);
222 return newPath;
223 }
224}
bool G4bool
Definition: G4Types.hh:86
#define TRUE
Definition: Globals.hh:27

Referenced by G4UItcsh::CompleteCommand().

◆ GetCommandTree()

G4UIcommandTree * G4VUIshell::GetCommandTree ( const G4String dir) const
protected

Definition at line 117 of file G4VUIshell.cc.

119{
121
122 G4UIcommandTree* cmdTree= UI-> GetTree(); // root tree
123
124 G4String absPath= input; // G4String::strip() CONST !!
125 absPath= GetAbsCommandDirPath(absPath.strip(G4String::both));
126
127 // parsing absolute path ...
128 if(absPath.length()==0) return NULL;
129 if(absPath[absPath.length()-1] != '/') return NULL; // error??
130 if(absPath=="/") return cmdTree;
131
132 for(G4int indx=1; indx<G4int(absPath.length())-1; ) {
133 G4int jslash= absPath.index("/", indx); // search index begin with "/"
134 if(jslash != G4int(G4String::npos)) {
135 if(cmdTree != NULL)
136 cmdTree= cmdTree-> GetTree(G4String(absPath(0,jslash+1)));
137 }
138 indx= jslash+1;
139 }
140
141 if(cmdTree == NULL) return NULL;
142 else return cmdTree;
143}
G4String strip(G4int strip_Type=trailing, char c=' ')
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
G4String GetAbsCommandDirPath(const G4String &apath) const
Definition: G4VUIshell.cc:146

Referenced by G4UItcsh::CompleteCommand().

◆ ListCommand()

void G4VUIshell::ListCommand ( const G4String input,
const G4String candidate = "" 
) const
virtual

Definition at line 230 of file G4VUIshell.cc.

233{
234 // specified directpry
235 G4String input= dir; // ...
236 input= input.strip(G4String::both);
237
238 // command tree of "user specified directory"
240 G4String vcmd;
241
242 G4int len= input.length();
243 if(! input.empty()) {
244 G4int indx= -1;
245 for(G4int i=len-1; i>=0; i--) { // search last '/'
246 if(input[(size_t)i]=='/') {
247 indx= i;
248 break;
249 }
250 }
251 // get abs. path
252 if(indx != -1) vpath= GetAbsCommandDirPath(input(0,indx+1));
253 if(!(indx==0 && len==1)) vcmd= input(indx+1,len-indx-1); // care for "/"
254 }
255
256 // check "vcmd" is directory?
257 G4String inputpath= vpath+vcmd;
258 if(! vcmd.empty()){
259 G4String tmpstr= inputpath + "/";
260 if(GetCommandTree(tmpstr) != NULL) {
261 vpath= tmpstr;
262 vcmd= "";
263 }
264 }
265
266 // check "vpath" directory exists?
267 G4UIcommandTree* atree= GetCommandTree(vpath);
268 if(atree == NULL) {
269 G4cout << "<" << input << ">: No such directory" << G4endl;
270 return;
271 }
272
273 // list matched directories/commands
274 G4String stream;
275 G4bool isMatch= FALSE;
276
277 G4int Ndir= atree-> GetTreeEntry();
278 G4int Ncmd= atree-> GetCommandEntry();
279 if(Ndir==0 && Ncmd==0) return; // no contents
280
281 // directory ...
282 for(G4int idir=1; idir<=Ndir; idir++) {
283 if(idir==1 && lsColorFlag) stream+= TermColorString[directoryColor];
284 G4String fpdir= atree-> GetTree(idir)-> GetPathName();
285 // matching test
286 if(candidate.empty()) { // list all
287 if(vcmd=="" || fpdir==inputpath) {
288 stream+= GetCommandPathTail(fpdir); stream+= " ";
289 isMatch= TRUE;
290 }
291 } else { // list only matched with candidate
292 if( fpdir.index(candidate, 0) == 0) {
293 stream+= GetCommandPathTail(fpdir); stream+= " ";
294 }
295 }
296 }
297
298 // command ...
299 for(G4int icmd=1; icmd<=Ncmd; icmd++){
300 if(icmd==1 && lsColorFlag) stream+= TermColorString[commandColor];
301 G4String fpcmd= atree-> GetPathName() +
302 atree-> GetCommand(icmd) -> GetCommandName();
303 // matching test
304 if(candidate.empty()) { // list all
305 if(vcmd=="" || fpcmd==inputpath) {
306 stream+= GetCommandPathTail(fpcmd); stream+= "* ";
307 isMatch= TRUE;
308 }
309 } else { // list only matched with candidate
310 if( fpcmd.index(candidate, 0) == 0) {
311 stream+= GetCommandPathTail(fpcmd); stream+= "* ";
312 }
313 }
314 }
315
316 // waring : not matched
317 if(!isMatch && candidate.empty())
318 G4cout << "<" << input
319 << ">: No such directory or command" << std::flush;
320
321 // display
322 G4UIArrayString arrayString(stream);
323 arrayString.Show(nColumn);
324}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4UIcommandTree * GetCommandTree(const G4String &dir) const
Definition: G4VUIshell.cc:117
G4String GetCommandPathTail(const G4String &apath) const
Definition: G4VUIshell.cc:192

Referenced by G4UItcsh::ListMatchedCommand().

◆ MakePrompt()

void G4VUIshell::MakePrompt ( const char *  msg = 0)
protectedvirtual

Reimplemented in G4UItcsh.

Definition at line 60 of file G4VUIshell.cc.

62{
63 if(promptSetting.length()<=1) {
65 return;
66 }
67
68 promptString="";
69 G4int i;
70 for(i=0; i<G4int(promptSetting.length())-1; i++){
71 if(promptSetting[(size_t)i]=='%'){
72 switch (promptSetting[(size_t)(i+1)]) {
73 case 's': // current application status
74 {
75 G4String stateStr;
76 if(msg)
77 { stateStr = msg; }
78 else
79 {
81 stateStr= statM-> GetStateString(statM->GetCurrentState());
82 }
83 promptString.append(stateStr);
84 i++;
85 }
86 break;
87 case '/': // current working directory
89 i++;
90 break;
91 default:
93 break;
94 }
95 } else {
97 }
98 }
99
100 // append last chaacter
101 if(i == G4int(promptSetting.length())-1)
103}
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4String & append(const G4String &)

Referenced by G4UIcsh::GetCommandLineString().

◆ ResetTerminal()

void G4VUIshell::ResetTerminal ( )
virtual

Reimplemented in G4UItcsh.

Definition at line 107 of file G4VUIshell.cc.

109{
110
111}

◆ SetCurrentDirectory()

void G4VUIshell::SetCurrentDirectory ( const G4String ccd)
inline

Definition at line 114 of file G4VUIshell.hh.

115{
117}

◆ SetLsColor()

void G4VUIshell::SetLsColor ( TermColorIndex  ,
TermColorIndex   
)
inlinevirtual

Reimplemented in G4UItcsh.

Definition at line 119 of file G4VUIshell.hh.

120{
121}

◆ SetNColumn()

void G4VUIshell::SetNColumn ( G4int  ncol)
inline

Definition at line 104 of file G4VUIshell.hh.

105{
106 nColumn= ncol;
107}

◆ SetPrompt()

void G4VUIshell::SetPrompt ( const G4String prompt)
inline

Definition at line 109 of file G4VUIshell.hh.

110{
111 promptSetting= prompt;
112}

◆ ShowCurrentDirectory()

void G4VUIshell::ShowCurrentDirectory ( ) const
inlinevirtual

Definition at line 123 of file G4VUIshell.hh.

124{
126}

Member Data Documentation

◆ commandColor

TermColorIndex G4VUIshell::commandColor
protected

Definition at line 69 of file G4VUIshell.hh.

Referenced by G4UItcsh::SetLsColor().

◆ currentCommandDir

◆ directoryColor

TermColorIndex G4VUIshell::directoryColor
protected

Definition at line 68 of file G4VUIshell.hh.

Referenced by G4UItcsh::SetLsColor().

◆ lsColorFlag

G4bool G4VUIshell::lsColorFlag
protected

Definition at line 67 of file G4VUIshell.hh.

Referenced by G4UItcsh::SetLsColor().

◆ nColumn

G4int G4VUIshell::nColumn
protected

Definition at line 63 of file G4VUIshell.hh.

Referenced by SetNColumn().

◆ promptSetting

G4String G4VUIshell::promptSetting
protected

Definition at line 60 of file G4VUIshell.hh.

Referenced by G4UItcsh::MakePrompt(), MakePrompt(), and SetPrompt().

◆ promptString


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