Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/examples/extended/medical/dna/chem1/src/CommandLineParser.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/medical/dna/chem1/src/CommandLineParser.cc (Version 11.3.0) and /examples/extended/medical/dna/chem1/src/CommandLineParser.cc (Version 10.1.p2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // This example is provided by the Geant4-DNA      26 // This example is provided by the Geant4-DNA collaboration
 27 // Any report or published results obtained us     27 // Any report or published results obtained using the Geant4-DNA software
 28 // shall cite the following Geant4-DNA collabo     28 // shall cite the following Geant4-DNA collaboration publication:
 29 // Med. Phys. 37 (2010) 4692-4708                  29 // Med. Phys. 37 (2010) 4692-4708
 30 // J. Comput. Phys. 274 (2014) 841-882             30 // J. Comput. Phys. 274 (2014) 841-882
 31 // The Geant4-DNA web site is available at htt     31 // The Geant4-DNA web site is available at http://geant4-dna.org
 32 //                                                 32 //
 33 // Author: Mathieu Karamitros                      33 // Author: Mathieu Karamitros
 34 //                                                 34 //
                                                   >>  35 // $Id$
 35 //                                                 36 //
 36 /// \file CommandLineParser.cc                 <<  37 /// \file CommandLineParser
 37 /// \brief Implementation of the CommandLinePa     38 /// \brief Implementation of the CommandLineParser class
 38                                                    39 
 39 #include "CommandLineParser.hh"                << 
 40                                                << 
 41 #include <iomanip>                                 40 #include <iomanip>
                                                   >>  41 #include "CommandLineParser.hh"
 42                                                    42 
 43 using namespace std;                               43 using namespace std;
 44 using namespace G4DNAPARSER;                       44 using namespace G4DNAPARSER;
 45                                                    45 
 46 CommandLineParser* CommandLineParser::fpInstan     46 CommandLineParser* CommandLineParser::fpInstance(0);
 47 G4String Command::fNoOption = "NoOption";          47 G4String Command::fNoOption = "NoOption";
 48                                                    48 
                                                   >>  49 
 49 //....oooOO0OOooo........oooOO0OOooo........oo     50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 50                                                    51 
 51 inline bool MATCH(const char* a, const char* b <<  52 inline bool MATCH(const char *a, const char *b)
 52 {                                                  53 {
 53   return strcmp(a, b) == 0;                        54   return strcmp(a, b) == 0;
 54 }                                                  55 }
 55                                                    56 
 56 //....oooOO0OOooo........oooOO0OOooo........oo     57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 57                                                    58 
 58 CommandLineParser::CommandLineParser()             59 CommandLineParser::CommandLineParser()
 59 {                                                  60 {
 60   // G4cout << "############ NEW PARSE #######     61   // G4cout << "############ NEW PARSE ##########" << G4endl;
 61   fpInstance = this;                               62   fpInstance = this;
 62   fOptionsWereSetup = false;                       63   fOptionsWereSetup = false;
 63   fMaxMarkerLength = 0;                            64   fMaxMarkerLength = 0;
 64   fMaxOptionNameLength = 0;                        65   fMaxOptionNameLength = 0;
 65   AddCommand("--help", Command::WithoutOption,     66   AddCommand("--help", Command::WithoutOption, "Print this help");
 66   AddCommand("-h", Command::WithoutOption, "Pr     67   AddCommand("-h", Command::WithoutOption, "Print this help");
 67   AddCommand("&", Command::WithoutOption);         68   AddCommand("&", Command::WithoutOption);
 68                                                    69 
 69   fVerbose = 0;                                    70   fVerbose = 0;
 70 }                                                  71 }
 71                                                    72 
 72 //....oooOO0OOooo........oooOO0OOooo........oo     73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 73                                                    74 
 74 CommandLineParser* CommandLineParser::GetParse     75 CommandLineParser* CommandLineParser::GetParser()
 75 {                                                  76 {
 76   if (!fpInstance) new CommandLineParser;          77   if (!fpInstance) new CommandLineParser;
 77   return fpInstance;                               78   return fpInstance;
 78 }                                                  79 }
 79                                                    80 
 80 //....oooOO0OOooo........oooOO0OOooo........oo     81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 81                                                    82 
 82 CommandLineParser::~CommandLineParser()            83 CommandLineParser::~CommandLineParser()
 83 {                                                  84 {
 84   std::map<G4String, Command*>::iterator it =      85   std::map<G4String, Command*>::iterator it = fCommandMap.begin();
 85   for (; it != fCommandMap.end(); it++) {      <<  86   for (; it != fCommandMap.end(); it++)
                                                   >>  87   {
 86     if (it->second) delete it->second;             88     if (it->second) delete it->second;
 87   }                                                89   }
 88 }                                                  90 }
 89                                                    91 
 90 //....oooOO0OOooo........oooOO0OOooo........oo     92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 91                                                    93 
 92 void CommandLineParser::DeleteInstance()           94 void CommandLineParser::DeleteInstance()
 93 {                                                  95 {
 94   if (fpInstance) {                            <<  96   if (fpInstance)
                                                   >>  97   {
 95     delete fpInstance;                             98     delete fpInstance;
 96     fpInstance = 0;                                99     fpInstance = 0;
 97   }                                               100   }
 98 }                                                 101 }
 99                                                   102 
100 //....oooOO0OOooo........oooOO0OOooo........oo    103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
101                                                   104 
102 Command::Command(Command::Type commandType, co << 105 Command::Command(Command::Type commandType,
                                                   >> 106                  const G4String& description)
103 {                                                 107 {
104   fType = commandType;                            108   fType = commandType;
105   fDescription = description;                     109   fDescription = description;
106   fActive = false;                                110   fActive = false;
107 }                                                 111 }
108                                                   112 
109 CommandWithOption::CommandWithOption(Command:: << 113 CommandWithOption::CommandWithOption(Command::Type commandType,
110                                      const G4S << 114                  const G4String& description,
111   : Command(commandType, description)          << 115                  const G4String& defaultOption,
                                                   >> 116                  const G4String& optionName) : 
                                                   >> 117 Command(commandType, description)
112 {                                                 118 {
113   fDefaultOption = defaultOption;                 119   fDefaultOption = defaultOption;
114   fOptionName = optionName;                       120   fOptionName = optionName;
115   fOption = "";                                   121   fOption = "";
116 }                                                 122 }
117                                                   123 
                                                   >> 124 
118 //....oooOO0OOooo........oooOO0OOooo........oo    125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
119                                                   126 
120 int CommandLineParser::Parse(int& argc, char** << 127 int CommandLineParser::Parse(int& argc, char **argv)
121 {                                                 128 {
122   //    G4cout << "Parse " << G4endl;             129   //    G4cout << "Parse " << G4endl;
123   static char null[1] = {""};                  << 130   static char null[1] = { "" };
124   int firstArgc = argc;                           131   int firstArgc = argc;
125                                                   132 
126   for (int i = 1; i < firstArgc; i++) {        << 133   for (int i = 1; i < firstArgc; i++)
                                                   >> 134   {
127     Command* command = FindCommand(argv[i]);      135     Command* command = FindCommand(argv[i]);
128     if (command == 0) continue;                   136     if (command == 0) continue;
129                                                   137 
130     if (fVerbose) G4cout << "Command : " << ar    138     if (fVerbose) G4cout << "Command : " << argv[i] << G4endl;
131                                                   139 
132     fOptionsWereSetup = true;                     140     fOptionsWereSetup = true;
133     command->fActive = true;                      141     command->fActive = true;
134                                                   142 
135     G4String marker(argv[i]);                     143     G4String marker(argv[i]);
136                                                   144 
137     if (strcmp(argv[i], "-h") != 0 && strcmp(a << 145     if (strcmp(argv[i], "-h") != 0 && strcmp(argv[i], "--help") != 0)
                                                   >> 146     {
138       argv[i] = null;                             147       argv[i] = null;
139     }                                             148     }
140                                                   149 
141     if (command->fType == Command::WithOption) << 150     if (command->fType == Command::WithOption)
                                                   >> 151     {
142       if (fVerbose) G4cout << "WithOption" <<     152       if (fVerbose) G4cout << "WithOption" << G4endl;
143                                                   153 
144       if (i + 1 > firstArgc || argv[i + 1] ==  << 154       if(i+1 > firstArgc || argv[i+1]==0 || argv[i+1][0]=='-')
145         G4cerr << "An command line option is m << 155       {
                                                   >> 156         G4cerr << "An command line option is missing for "
                                                   >> 157                << marker << G4endl;
146         abort();                                  158         abort();
147       }                                           159       }
148                                                   160 
149       command->SetOption((const char*)strdup(a << 161       command->SetOption( (const char*) strdup(argv[i+1]) );
150       argv[i + 1] = null;                      << 162       argv[i+1] = null;
151       i++;                                        163       i++;
152     }                                             164     }
153     else if (command->fType == Command::Option << 165     else if(command->fType == Command::OptionNotCompulsory)
154       if (fVerbose) G4cout << "OptionNotCompul << 166     {
155                                                << 167       if(fVerbose)
156       if (i + 1 < firstArgc) {                 << 168       G4cout <<"OptionNotCompulsory"<<G4endl;
157         G4String buffer = (const char*)strdup( << 
158                                                   169 
159         if (buffer.empty() == false) {         << 170       if(i+1 < firstArgc)
160           if (buffer.at(0) != '-' && buffer.at << 171       {
161               && buffer.at(0) != '|')          << 172         G4String buffer = (const char*) strdup(argv[i+1]);
                                                   >> 173 
                                                   >> 174         if(buffer.empty() == false)
                                                   >> 175         {
                                                   >> 176           if(buffer.at(0) != '-'
                                                   >> 177              && buffer.at(0) != '&'
                                                   >> 178              && buffer.at(0) != '>'
                                                   >> 179              && buffer.at(0) != '|')
162           {                                       180           {
163             if (fVerbose) {                    << 181             if(fVerbose)
                                                   >> 182             {
164               G4cout << "facultative option is    183               G4cout << "facultative option is : " << buffer << G4endl;
165             }                                     184             }
166                                                   185 
167             command->SetOption((const char*)st << 186             command->SetOption( (const char*) strdup(argv[i+1]) );
168             argv[i + 1] = null;                << 187             argv[i+1] = null;
169             i++;                                  188             i++;
170             continue;                             189             continue;
171           }                                       190           }
172         }                                         191         }
173       }                                           192       }
174                                                   193 
175       if (fVerbose) G4cout << "Option not set" << 194       if(fVerbose)
                                                   >> 195       G4cout << "Option not set" << G4endl;
176                                                   196 
177       command->SetOption("");                     197       command->SetOption("");
178     }                                             198     }
179   }                                               199   }
180   CorrectRemainingOptions(argc, argv);            200   CorrectRemainingOptions(argc, argv);
181                                                   201 
182   Command* commandLine(0);                        202   Command* commandLine(0);
183   if ((commandLine = GetCommandIfActive("--hel << 203   if ((commandLine = GetCommandIfActive("--help")) || (commandLine =
                                                   >> 204       GetCommandIfActive("-h")))
                                                   >> 205   {
184     G4cout << "Usage : " << argv[0] << " [OPTI    206     G4cout << "Usage : " << argv[0] << " [OPTIONS]" << G4endl;
185     PrintHelp();                                  207     PrintHelp();
186     return 1;                                     208     return 1;
187   }                                               209   }
188                                                   210 
189   return 0;                                       211   return 0;
190 }                                                 212 }
191                                                   213 
192 //....oooOO0OOooo........oooOO0OOooo........oo    214 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
193                                                   215 
194 void CommandLineParser::PrintHelp()               216 void CommandLineParser::PrintHelp()
195 {                                                 217 {
196   std::map<G4String, Command*>::iterator it;      218   std::map<G4String, Command*>::iterator it;
197                                                   219 
198   int maxFieldLength = fMaxMarkerLength + fMax    220   int maxFieldLength = fMaxMarkerLength + fMaxOptionNameLength + 4;
199                                                   221 
200   G4cout << "Options: " << G4endl;                222   G4cout << "Options: " << G4endl;
201                                                   223 
202   for (it = fCommandMap.begin(); it != fComman << 224   for (it = fCommandMap.begin(); it != fCommandMap.end(); it++)
                                                   >> 225   {
203     Command* command = it->second;                226     Command* command = it->second;
204     if (command) {                             << 227     if (command)
                                                   >> 228     {
205       G4cout << setw(maxFieldLength) << left;     229       G4cout << setw(maxFieldLength) << left;
206                                                   230 
207       G4String toPrint = it->first;               231       G4String toPrint = it->first;
208                                                   232 
209       if (toPrint == "&") {                    << 233       if (toPrint == "&")
                                                   >> 234       {
210         continue;                                 235         continue;
211       }                                           236       }
212       else if (toPrint == "-h")                << 237       else if (toPrint == "-h") continue;
213         continue;                              << 238       else if (toPrint == "--help")
214       else if (toPrint == "--help") {          << 239       {
215         toPrint += ", -h";                        240         toPrint += ", -h";
216       }                                           241       }
217                                                   242 
218       if (command->GetDefaultOption() != "") { << 243       if (command->GetDefaultOption() != "")
                                                   >> 244       {
219         toPrint += " \"" + command->GetDefault    245         toPrint += " \"" + command->GetDefaultOption() + "\"";
220       }                                           246       }
221                                                   247 
222       G4cout << toPrint;                          248       G4cout << toPrint;
223                                                   249 
224       G4cout << command->GetDescription() << G    250       G4cout << command->GetDescription() << G4endl;
225     }                                             251     }
226   }                                               252   }
227 }                                                 253 }
228                                                   254 
229 //....oooOO0OOooo........oooOO0OOooo........oo    255 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
230                                                   256 
231 void CommandLineParser::CorrectRemainingOption << 257 void CommandLineParser::CorrectRemainingOptions(int& argc, char **argv)
232 {                                                 258 {
233   // remove handled arguments from argument ar    259   // remove handled arguments from argument array
234   int j = 0;                                      260   int j = 0;
235   for (int i = 0; i < argc; i++) {             << 261   for (int i = 0; i < argc; i++)
236     if (strcmp(argv[i], "")) {                 << 262   {
                                                   >> 263     if (strcmp(argv[i], ""))
                                                   >> 264     {
237       argv[j] = argv[i];                          265       argv[j] = argv[i];
238       j++;                                        266       j++;
239     }                                             267     }
240   }                                               268   }
241   argc = j;                                       269   argc = j;
242 }                                                 270 }
243                                                   271 
244 //....oooOO0OOooo........oooOO0OOooo........oo    272 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
245                                                   273 
246 void CommandLineParser::AddCommand(const G4Str << 274 void CommandLineParser::AddCommand(const G4String& marker,
247                                    const G4Str << 275                                    Command::Type type,
                                                   >> 276                                    const G4String& description,
                                                   >> 277                                    const G4String& defaultOption,
248                                    const G4Str    278                                    const G4String& optionName)
249 {                                                 279 {
250   // G4cout << "Add command : "<< marker << G4    280   // G4cout << "Add command : "<< marker << G4endl;
251                                                << 281   
252   Command* command = 0;                           282   Command* command = 0;
253   switch (type) {                              << 283   switch(type)
254     case Command::WithoutOption:               << 284   {
255       command = new Command(type, description) << 285  case Command::WithoutOption:
256       break;                                   << 286         command = new Command(type, description);
257                                                << 287         break;
258     default:                                   << 288         
259       command = new CommandWithOption(type, de << 289         default:
260       if ((int)defaultOption.length() > fMaxOp << 290         command = new CommandWithOption(type, 
261         fMaxOptionNameLength = defaultOption.l << 291                                         description, 
262       break;                                   << 292                                         defaultOption, 
                                                   >> 293                                         optionName);
                                                   >> 294         if ((int) defaultOption.length() > fMaxOptionNameLength)
                                                   >> 295           fMaxOptionNameLength = defaultOption.length();
                                                   >> 296         break;
263   }                                               297   }
264                                                   298 
265   if ((int)marker.length() > fMaxMarkerLength) << 299   if ((int) marker.length() > fMaxMarkerLength) fMaxMarkerLength =
                                                   >> 300       marker.length();
266   fCommandMap.insert(make_pair(marker, command    301   fCommandMap.insert(make_pair(marker, command));
267 }                                                 302 }
268                                                   303 
269 /*                                                304 /*
270 // Add one command but multiple markers           305 // Add one command but multiple markers
271 void Parser::AddCommand(vector<G4String> marke    306 void Parser::AddCommand(vector<G4String> markers,
272                         CommandType type,         307                         CommandType type,
273                         const G4String& descri    308                         const G4String& description,
274                         const G4String& option    309                         const G4String& optionName)
275 {                                                 310 {
276   // G4cout << "Add command : "<< marker << G4    311   // G4cout << "Add command : "<< marker << G4endl;
277   Command* command = new Command(type, descrip    312   Command* command = new Command(type, description, optionName);
278                                                   313 
279   for (size_t i = 0; i < markers.size; i++)       314   for (size_t i = 0; i < markers.size; i++)
280   {                                               315   {
281     G4String marker = markers[i];                 316     G4String marker = markers[i];
282     if ((int) marker.length() > fMaxMarkerLeng    317     if ((int) marker.length() > fMaxMarkerLength)
283     {                                             318     {
284       fMaxMarkerLength = marker.length();         319       fMaxMarkerLength = marker.length();
285     }                                             320     }
286     if ((int) optionName.length() > fMaxOption    321     if ((int) optionName.length() > fMaxOptionNameLength)
287     {                                             322     {
288       fMaxOptionNameLength = optionName.length    323       fMaxOptionNameLength = optionName.length();
289     }                                             324     }
290     fCommandMap.insert(make_pair(marker, comma    325     fCommandMap.insert(make_pair(marker, command));
291   }                                               326   }
292 }                                                 327 }
293 */                                                328 */
294                                                   329 
295 //....oooOO0OOooo........oooOO0OOooo........oo    330 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
296                                                   331 
297 Command* CommandLineParser::FindCommand(const     332 Command* CommandLineParser::FindCommand(const G4String& marker)
298 {                                                 333 {
299   std::map<G4String, Command*>::iterator it =     334   std::map<G4String, Command*>::iterator it = fCommandMap.find(marker);
300   if (it == fCommandMap.end()) {               << 335   if (it == fCommandMap.end())
                                                   >> 336   {
301     // G4cerr << "command not found" << G4endl    337     // G4cerr << "command not found" << G4endl;
302     return 0;                                     338     return 0;
303   }                                               339   }
304   return it->second;                              340   return it->second;
305 }                                                 341 }
306                                                   342 
307 //....oooOO0OOooo........oooOO0OOooo........oo    343 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
308                                                   344 
309 Command* CommandLineParser::GetCommandIfActive << 345 Command* CommandLineParser::GetCommandIfActive(const G4String &marker)
310 {                                                 346 {
311   Command* command = FindCommand(marker);         347   Command* command = FindCommand(marker);
312   if (command) {                               << 348   if (command)
                                                   >> 349   {
313     // G4cout << "Command found : "<< marker <    350     // G4cout << "Command found : "<< marker << G4endl;
314                                                   351 
315     if (command->fActive) {                    << 352     if (command->fActive)
                                                   >> 353     {
316       // G4cout << "Command Active" << G4endl;    354       // G4cout << "Command Active" << G4endl;
317       return command;                             355       return command;
318     }                                             356     }
319     // else                                       357     // else
320     //  G4cout <<"Command not active" << G4end    358     //  G4cout <<"Command not active" << G4endl;
321   }                                               359   }
322   else {                                       << 360   else
                                                   >> 361   {
323     G4ExceptionDescription description;           362     G4ExceptionDescription description;
324     description << "You try to retrieve a comm << 363     description << "You try to retrieve a command that was not registered : "
325     G4Exception("CommandLineParser::GetCommand << 364            << marker << G4endl;
326                 description, "");              << 365     G4Exception("CommandLineParser::GetCommandIfActive",
                                                   >> 366                 "COMMAND LINE NOT DEFINED", FatalException, description, "");
327     // If you are using this class outside of     367     // If you are using this class outside of Geant4, use exit(-1) instead
328     // exit(-1);                               << 368     //exit(-1);
329   }                                               369   }
330   return 0;                                       370   return 0;
331 }                                                 371 }
332                                                   372 
333 //....oooOO0OOooo........oooOO0OOooo........oo    373 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
334                                                   374 
335 bool CommandLineParser::CheckIfNotHandledOptio    375 bool CommandLineParser::CheckIfNotHandledOptionsExists(int& argc, char** argv)
336 {                                                 376 {
337   if (argc > 0) {                              << 377   if (argc > 0)
                                                   >> 378   {
338     G4bool kill = false;                          379     G4bool kill = false;
339     for (G4int i = 1; i < argc; i++) {         << 380     for (G4int i = 1; i < argc; i++)
340       if (strcmp(argv[i], "")) {               << 381     {
                                                   >> 382       if (strcmp(argv[i], ""))
                                                   >> 383       {
341         kill = true;                              384         kill = true;
342         G4cerr << "Unknown argument : " << arg    385         G4cerr << "Unknown argument : " << argv[i] << "\n";
343       }                                           386       }
344     }                                             387     }
345     if (kill) {                                << 388     if (kill)
346       G4cerr << "The option " << argv[0] << "  << 389     {
                                                   >> 390       G4cerr << "The option " << argv[0]
                                                   >> 391              << " is not handled this programme." << G4endl;
347       G4cout << "Usage : " << argv[0] << " [OP    392       G4cout << "Usage : " << argv[0] << " [OPTIONS]" << G4endl;
348       PrintHelp();                                393       PrintHelp();
349       return true;  // KILL APPLICATION        << 394       return true; // KILL APPLICATION
350     }                                             395     }
351   }                                               396   }
352   return false;                                   397   return false;
353 }                                                 398 }
354                                                   399