source: trunk/source/interfaces/html/G4UIterminal_8cc-source.html@ 872

Last change on this file since 872 was 571, checked in by garnier, 18 years ago

r581@mac-90108: laurentgarnier | 2007-08-17 17:30:26 +0200
deplacement de frame

  • Property svn:mime-type set to text/html
File size: 20.0 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3<title>G4UIterminal.cc Source File</title>
4<link href="doxygen.css" rel="stylesheet" type="text/css">
5</head><body>
6<!-- Generated by Doxygen 1.3.4 -->
7<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div>
8<h1>G4UIterminal.cc</h1><a href="G4UIterminal_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">//</span>
900002 <span class="comment">// ********************************************************************</span>
1000003 <span class="comment">// * License and Disclaimer *</span>
1100004 <span class="comment">// * *</span>
1200005 <span class="comment">// * The Geant4 software is copyright of the Copyright Holders of *</span>
1300006 <span class="comment">// * the Geant4 Collaboration. It is provided under the terms and *</span>
1400007 <span class="comment">// * conditions of the Geant4 Software License, included in the file *</span>
1500008 <span class="comment">// * LICENSE and available at http://cern.ch/geant4/license . These *</span>
1600009 <span class="comment">// * include a list of copyright holders. *</span>
1700010 <span class="comment">// * *</span>
1800011 <span class="comment">// * Neither the authors of this software system, nor their employing *</span>
1900012 <span class="comment">// * institutes,nor the agencies providing financial support for this *</span>
2000013 <span class="comment">// * work make any representation or warranty, express or implied, *</span>
2100014 <span class="comment">// * regarding this software system or assume any liability for its *</span>
2200015 <span class="comment">// * use. Please see the license in the file LICENSE and URL above *</span>
2300016 <span class="comment">// * for the full disclaimer and the limitation of liability. *</span>
2400017 <span class="comment">// * *</span>
2500018 <span class="comment">// * This code implementation is the result of the scientific and *</span>
2600019 <span class="comment">// * technical work of the GEANT4 collaboration. *</span>
2700020 <span class="comment">// * By using, copying, modifying or distributing the software (or *</span>
2800021 <span class="comment">// * any work based on the software) you agree to acknowledge its *</span>
2900022 <span class="comment">// * use in resulting scientific publications, and indicate your *</span>
3000023 <span class="comment">// * acceptance of all terms of the Geant4 Software license. *</span>
3100024 <span class="comment">// ********************************************************************</span>
3200025 <span class="comment">//</span>
3300026 <span class="comment">//</span>
3400027 <span class="comment">// $Id: G4UIterminal.cc,v 1.21 2006/06/29 19:09:56 gunter Exp $</span>
3500028 <span class="comment">// GEANT4 tag $Name: geant4-08-01-patch-01 $</span>
3600029 <span class="comment">//</span>
3700030
3800031 <span class="preprocessor">#include "G4Types.hh"</span>
3900032 <span class="preprocessor">#include "G4StateManager.hh"</span>
4000033 <span class="preprocessor">#include "G4UIcommandTree.hh"</span>
4100034 <span class="preprocessor">#include "G4UIcommand.hh"</span>
4200035 <span class="preprocessor">#include "G4UIcommandStatus.hh"</span>
4300036 <span class="preprocessor">#include "<a class="code" href="G4UIterminal_8hh.html">G4UIterminal.hh</a>"</span>
4400037 <span class="preprocessor">#include "<a class="code" href="G4UIcsh_8hh.html">G4UIcsh.hh</a>"</span>
4500038 <span class="preprocessor">#include &lt;sstream&gt;</span>
4600039
4700040
48<a name="l00042"></a><a class="code" href="classG4UIterminal.html#a0">00042</a> <a class="code" href="classG4UIterminal.html#a0">G4UIterminal::G4UIterminal</a>(<a class="code" href="classG4VUIshell.html">G4VUIshell</a>* aShell)
4900044 {
5000045 <a class="code" href="classG4UIterminal.html#r0">UI</a>= G4UImanager::GetUIpointer();
5100046 <a class="code" href="classG4UIterminal.html#r0">UI</a>-&gt; SetSession(<span class="keyword">this</span>);
5200047 <a class="code" href="classG4UIterminal.html#r0">UI</a>-&gt; SetCoutDestination(<span class="keyword">this</span>);
5300048
5400049 <a class="code" href="classG4UIterminal.html#r2">iExit</a>= FALSE;
5500050 <a class="code" href="classG4UIterminal.html#r3">iCont</a>= FALSE;
5600051
5700052 <span class="keywordflow">if</span>(aShell) <a class="code" href="classG4UIterminal.html#r1">shell</a>= aShell;
5800053 <span class="keywordflow">else</span> <a class="code" href="classG4UIterminal.html#r1">shell</a>= <span class="keyword">new</span> <a class="code" href="classG4UIcsh.html">G4UIcsh</a>;
5900054 }
6000055
61<a name="l00057"></a><a class="code" href="classG4UIterminal.html#a1">00057</a> <a class="code" href="classG4UIterminal.html#a1">G4UIterminal::~G4UIterminal</a>()
6200058
6300059 {
6400060 <span class="keywordflow">if</span>(<a class="code" href="classG4UIterminal.html#r1">shell</a>) <span class="keyword">delete</span> <a class="code" href="classG4UIterminal.html#r1">shell</a>;
6500061
6600062 <span class="keywordflow">if</span>(G4UImanager::GetUIpointer()) {
6700063 <a class="code" href="classG4UIterminal.html#r0">UI</a>-&gt; SetSession(NULL);
6800064 <a class="code" href="classG4UIterminal.html#r0">UI</a>-&gt; SetCoutDestination(NULL);
6900065 }
7000066 }
7100067
7200068
73<a name="l00070"></a><a class="code" href="classG4UIterminal.html#a2">00070</a> <span class="keywordtype">void</span> <a class="code" href="classG4UIterminal.html#a2">G4UIterminal::SetPrompt</a>(<span class="keyword">const</span> G4String&amp; prompt)
7400071
7500072 {
7600073 <a class="code" href="classG4UIterminal.html#r1">shell</a>-&gt; <a class="code" href="classG4UIterminal.html#a2">SetPrompt</a>(prompt);
7700074 }
7800075
79<a name="l00077"></a><a class="code" href="classG4UIterminal.html#a3">00077</a> G4UIsession* <a class="code" href="classG4UIterminal.html#a3">G4UIterminal::SessionStart</a>()
8000079 {
8100080 <a class="code" href="classG4UIterminal.html#r2">iExit</a>= TRUE;
8200081
8300082 G4String newCommand= <a class="code" href="classG4UIterminal.html#d1">GetCommand</a>();
8400083 <span class="keywordflow">while</span>(<a class="code" href="classG4UIterminal.html#r2">iExit</a>){
8500084 <a class="code" href="classG4UIterminal.html#d0">ExecuteCommand</a>(newCommand);
8600085 newCommand= <a class="code" href="classG4UIterminal.html#d1">GetCommand</a>();
8700086 }
8800087 <span class="keywordflow">return</span> NULL;
8900088 }
9000089
91<a name="l00091"></a><a class="code" href="classG4UIterminal.html#a4">00091</a> <span class="keywordtype">void</span> <a class="code" href="classG4UIterminal.html#a4">G4UIterminal::PauseSessionStart</a>(G4String msg)
9200093 {
9300094 <a class="code" href="classG4UIterminal.html#r3">iCont</a>= TRUE;
9400095
9500096 G4String newCommand= <a class="code" href="classG4UIterminal.html#d1">GetCommand</a>(msg);
9600097 <span class="keywordflow">while</span>(<a class="code" href="classG4UIterminal.html#r3">iCont</a>){
9700098 <a class="code" href="classG4UIterminal.html#d0">ExecuteCommand</a>(newCommand);
9800099 newCommand= <a class="code" href="classG4UIterminal.html#d1">GetCommand</a>(msg);
9900100 }
10000101 }
10100102
102<a name="l00104"></a><a class="code" href="classG4UIterminal.html#d0">00104</a> <span class="keywordtype">void</span> <a class="code" href="classG4UIterminal.html#d0">G4UIterminal::ExecuteCommand</a>(G4String aCommand)
10300106 {
10400107 <span class="keywordflow">if</span>(aCommand.length()&lt;2) <span class="keywordflow">return</span>;
10500108
10600109 G4int returnVal = <a class="code" href="classG4UIterminal.html#r0">UI</a>-&gt; ApplyCommand(aCommand);
10700110
10800111 G4int paramIndex = returnVal % 100;
10900112 <span class="comment">// 0 - 98 : paramIndex-th parameter is invalid</span>
11000113 <span class="comment">// 99 : convination of parameters is invalid</span>
11100114 G4int commandStatus = returnVal - paramIndex;
11200115
11300116 G4UIcommand* cmd = 0;
11400117 <span class="keywordflow">if</span>(commandStatus!=fCommandSucceeded)
11500118 { cmd = <a class="code" href="classG4VBasicShell.html#b4">FindCommand</a>(aCommand); }
11600119
11700120 <span class="keywordflow">switch</span>(commandStatus) {
11800121 <span class="keywordflow">case</span> fCommandSucceeded:
11900122 <span class="keywordflow">break</span>;
12000123 <span class="keywordflow">case</span> fCommandNotFound:
12100124 G4cerr &lt;&lt; <span class="stringliteral">"command &lt;"</span> &lt;&lt; <a class="code" href="classG4UIterminal.html#r0">UI</a>-&gt;SolveAlias(aCommand) &lt;&lt; <span class="stringliteral">"&gt; not found"</span> &lt;&lt; G4endl;
12200125 <span class="keywordflow">if</span>( aCommand.index(<span class="stringliteral">"@@"</span>) != G4String::npos) {
12300126 G4cout &lt;&lt; <span class="stringliteral">"@@G4UIterminal"</span> &lt;&lt; G4endl;
12400127 }
12500128 <span class="keywordflow">break</span>;
12600129 <span class="keywordflow">case</span> fIllegalApplicationState:
12700130 G4cerr &lt;&lt; <span class="stringliteral">"illegal application state -- command refused"</span> &lt;&lt; G4endl;
12800131 <span class="keywordflow">break</span>;
12900132 <span class="keywordflow">case</span> fParameterOutOfRange:
13000133 <span class="comment">// if(paramIndex&lt;99) {</span>
13100134 <span class="comment">// G4cerr &lt;&lt; "Parameter is out of range (index " &lt;&lt; paramIndex &lt;&lt; ")" &lt;&lt; G4endl;</span>
13200135 <span class="comment">// G4cerr &lt;&lt; "Allowed range : " &lt;&lt; cmd-&gt;GetParameter(paramIndex)-&gt;GetParameterRange() &lt;&lt; G4endl;</span>
13300136 <span class="comment">// } else {</span>
13400137 <span class="comment">// G4cerr &lt;&lt; "Parameter is out of range" &lt;&lt; G4endl;</span>
13500138 <span class="comment">// G4cerr &lt;&lt; "Allowed range : " &lt;&lt; cmd-&gt;GetRange() &lt;&lt; G4endl;</span>
13600139 <span class="comment">// }</span>
13700140 <span class="keywordflow">break</span>;
13800141 <span class="keywordflow">case</span> fParameterOutOfCandidates:
13900142 G4cerr &lt;&lt; <span class="stringliteral">"Parameter is out of candidate list (index "</span> &lt;&lt; paramIndex &lt;&lt; <span class="stringliteral">")"</span> &lt;&lt; G4endl;
14000143 G4cerr &lt;&lt; <span class="stringliteral">"Candidates : "</span> &lt;&lt; cmd-&gt;GetParameter(paramIndex)-&gt;GetParameterCandidates() &lt;&lt; G4endl;
14100144 <span class="keywordflow">break</span>;
14200145 <span class="keywordflow">case</span> fParameterUnreadable:
14300146 G4cerr &lt;&lt; <span class="stringliteral">"Parameter is wrong type and/or is not omittable (index "</span> &lt;&lt; paramIndex &lt;&lt; <span class="stringliteral">")"</span> &lt;&lt; G4endl;
14400147 <span class="keywordflow">break</span>;
14500148 <span class="keywordflow">case</span> fAliasNotFound:
14600149 <span class="keywordflow">default</span>:
14700150 G4cerr &lt;&lt; <span class="stringliteral">"command refused ("</span> &lt;&lt; commandStatus &lt;&lt; <span class="stringliteral">")"</span> &lt;&lt; G4endl;
14800151 }
14900152 }
15000153
151<a name="l00155"></a><a class="code" href="classG4UIterminal.html#d1">00155</a> G4String <a class="code" href="classG4UIterminal.html#d1">G4UIterminal::GetCommand</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* msg)
15200157 {
15300158 G4String newCommand;
15400159 G4String nullString;
15500160
15600161 newCommand= <a class="code" href="classG4UIterminal.html#r1">shell</a>-&gt; GetCommandLine(msg);
15700162
15800163 G4String nC= newCommand.strip(G4String::leading);
15900164 <span class="keywordflow">if</span>( nC.length() == 0 ) {
16000165 newCommand= nullString;
16100166
16200167 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( nC(0) == <span class="charliteral">'#'</span> ) {
16300168 G4cout &lt;&lt; nC &lt;&lt; G4endl;
16400169 newCommand= nullString;
16500170
16600171 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(nC==<span class="stringliteral">"ls"</span> || nC(0,3)==<span class="stringliteral">"ls "</span> ) { <span class="comment">// list commands</span>
16700172 <a class="code" href="classG4VBasicShell.html#b13">ListDirectory</a>(nC);
16800173 newCommand= nullString;
16900174
17000175 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(nC==<span class="stringliteral">"lc"</span> || nC(0,3)==<span class="stringliteral">"lc "</span> ) { <span class="comment">// ... by shell</span>
17100176 <a class="code" href="classG4UIterminal.html#r1">shell</a>-&gt; ListCommand(nC.remove(0,2));
17200177 newCommand= nullString;
17300178
17400179 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(nC == <span class="stringliteral">"pwd"</span>) { <span class="comment">// show current directory</span>
17500180 G4cout &lt;&lt; <span class="stringliteral">"Current Command Directory : "</span>
17600181 &lt;&lt; <a class="code" href="classG4VBasicShell.html#b1">GetCurrentWorkingDirectory</a>() &lt;&lt; G4endl;
17700182 newCommand= nullString;
17800183
17900184 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(nC == <span class="stringliteral">"cwd"</span>) { <span class="comment">// ... by shell</span>
18000185 <a class="code" href="classG4UIterminal.html#r1">shell</a>-&gt; ShowCurrentDirectory();
18100186 newCommand= nullString;
18200187
18300188 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(nC == <span class="stringliteral">"cd"</span> || nC(0,3) == <span class="stringliteral">"cd "</span>) { <span class="comment">// "cd"</span>
18400189 <a class="code" href="classG4VBasicShell.html#b12">ChangeDirectoryCommand</a>(nC);
18500190 <a class="code" href="classG4UIterminal.html#r1">shell</a>-&gt; SetCurrentDirectory(<a class="code" href="classG4VBasicShell.html#b1">GetCurrentWorkingDirectory</a>());
18600191 newCommand= nullString;
18700192
18800193 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(nC == <span class="stringliteral">"help"</span> || nC(0,5) == <span class="stringliteral">"help "</span>) { <span class="comment">// "help"</span>
18900194 <a class="code" href="classG4VBasicShell.html#b14">TerminalHelp</a>(nC);
19000195 newCommand= nullString;
19100196
19200197 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(nC(0) == <span class="charliteral">'?'</span>) { <span class="comment">// "show current value of a parameter"</span>
19300198 <a class="code" href="classG4VBasicShell.html#b11">ShowCurrent</a>(nC);
19400199 newCommand= nullString;
19500200
19600201 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(nC == <span class="stringliteral">"hist"</span> || nC == <span class="stringliteral">"history"</span>) { <span class="comment">// "hist/history"</span>
19700202 G4int nh= <a class="code" href="classG4UIterminal.html#r0">UI</a>-&gt; GetNumberOfHistory();
19800203 <span class="keywordflow">for</span> (G4int i=0; i&lt;nh; i++) {
19900204 G4cout &lt;&lt; i &lt;&lt; <span class="stringliteral">": "</span> &lt;&lt; <a class="code" href="classG4UIterminal.html#r0">UI</a>-&gt;GetPreviousCommand(i) &lt;&lt; G4endl;
20000205 }
20100206 newCommand= nullString;
20200207
20300208 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(nC(0) == <span class="charliteral">'!'</span>) { <span class="comment">// "!"</span>
20400209 G4String ss= nC(1, nC.length()-1);
20500210 G4int vl;
20600211 <span class="keyword">const</span> <span class="keywordtype">char</span>* tt= ss;
20700212 std::istringstream is(tt);
20800213 is &gt;&gt; vl;
20900214 G4int nh= <a class="code" href="classG4UIterminal.html#r0">UI</a>-&gt; GetNumberOfHistory();
21000215 <span class="keywordflow">if</span>(vl&gt;=0 &amp;&amp; vl&lt;nh) {
21100216 newCommand= <a class="code" href="classG4UIterminal.html#r0">UI</a>-&gt; GetPreviousCommand(vl);
21200217 G4cout &lt;&lt; newCommand &lt;&lt; G4endl;
21300218 } <span class="keywordflow">else</span> {
21400219 G4cerr &lt;&lt; <span class="stringliteral">"history "</span> &lt;&lt; vl &lt;&lt; <span class="stringliteral">" is not found."</span> &lt;&lt; G4endl;
21500220 newCommand= nullString;
21600221 }
21700222
21800223 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(nC == <span class="stringliteral">"exit"</span>) { <span class="comment">// "exit"</span>
21900224 <span class="keywordflow">if</span>(<a class="code" href="classG4UIterminal.html#r3">iCont</a>) {
22000225 G4cout &lt;&lt; <span class="stringliteral">"You are now processing RUN."</span> &lt;&lt; G4endl;
22100226 G4cout &lt;&lt; <span class="stringliteral">"Please abort it using \"/run/abort\" command first"</span> &lt;&lt; G4endl;
22200227 G4cout &lt;&lt; <span class="stringliteral">" and use \"continue\" command until the application"</span>
22300228 &lt;&lt; G4endl;
22400229 G4cout &lt;&lt; <span class="stringliteral">" becomes to Idle."</span> &lt;&lt; G4endl;
22500230 } <span class="keywordflow">else</span> {
22600231 <a class="code" href="classG4UIterminal.html#r2">iExit</a>= FALSE;
22700232 newCommand= nullString;
22800233 }
22900234
23000235 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( nC == <span class="stringliteral">"cont"</span> || nC == <span class="stringliteral">"continue"</span>){ <span class="comment">// "cont/continu"</span>
23100236 <a class="code" href="classG4UIterminal.html#r3">iCont</a>= FALSE;
23200237 newCommand= nullString;
23300238
23400239 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( nC.empty() ){ <span class="comment">// NULL command</span>
23500240 newCommand= nullString;
23600241
23700242 } <span class="keywordflow">else</span> {
23800243 }
23900244
24000245 <span class="keywordflow">return</span> <a class="code" href="classG4VBasicShell.html#b0">ModifyToFullPathCommand</a>(newCommand);
24100246 }
24200247
24300248
244<a name="l00250"></a><a class="code" href="classG4UIterminal.html#a5">00250</a> G4int <a class="code" href="classG4UIterminal.html#a5">G4UIterminal::ReceiveG4cout</a>(G4String coutString)
24500252 {
24600253 std::cout &lt;&lt; coutString &lt;&lt; std::flush;
24700254 <span class="keywordflow">return</span> 0;
24800255 }
24900256
250<a name="l00258"></a><a class="code" href="classG4UIterminal.html#a6">00258</a> G4int <a class="code" href="classG4UIterminal.html#a6">G4UIterminal::ReceiveG4cerr</a>(G4String cerrString)
25100260 {
25200261 std::cerr &lt;&lt; cerrString &lt;&lt; std::flush;
25300262 <span class="keywordflow">return</span> 0;
25400263 }
25500264
256<a name="l00266"></a><a class="code" href="classG4UIterminal.html#d2">00266</a> G4bool <a class="code" href="classG4UIterminal.html#d2">G4UIterminal::GetHelpChoice</a>(G4int&amp; aInt)
25700268 {
25800269 G4cin &gt;&gt; aInt;
25900270 <span class="keywordflow">if</span>(!G4cin.good()){
26000271 G4cin.clear();
26100272 G4cin.ignore(30,<span class="charliteral">'\n'</span>);
26200273 <span class="keywordflow">return</span> FALSE;
26300274 }
26400275 <span class="keywordflow">return</span> TRUE;
26500276 }
26600277
267<a name="l00279"></a><a class="code" href="classG4UIterminal.html#d3">00279</a> <span class="keywordtype">void</span> <a class="code" href="classG4UIterminal.html#d3">G4UIterminal::ExitHelp</a>()
26800281 {
26900282 <span class="keywordtype">char</span> temp[100];
27000283 G4cin.getline(temp, 100);
27100284 }
27200285
273</pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Jun 22 11:07:02 2007 by
274<a href="http://www.doxygen.org/index.html">
275<img src="doxygen.png" alt="doxygen" align="middle" border=0 >
276</a>1.3.4 </small></address>
277</body>
278</html>
Note: See TracBrowser for help on using the repository browser.