41 #include "CommandLineParser.hh"
44 using namespace G4DNAPARSER;
47 G4String Command::fNoOption =
"NoOption";
51 inline bool MATCH(
const char *
a,
const char *b)
53 return strcmp(a, b) == 0;
58 CommandLineParser::CommandLineParser()
62 fOptionsWereSetup =
false;
64 fMaxOptionNameLength = 0;
65 AddCommand(
"--help", Command::WithoutOption,
"Print this help");
66 AddCommand(
"-h", Command::WithoutOption,
"Print this help");
67 AddCommand(
"&", Command::WithoutOption);
82 CommandLineParser::~CommandLineParser()
84 std::map<G4String, Command*>::iterator it = fCommandMap.begin();
85 for (; it != fCommandMap.end(); it++)
87 if (it->second)
delete it->second;
93 void CommandLineParser::DeleteInstance()
108 fDescription = description;
112 CommandWithOption::CommandWithOption(
Command::Type commandType,
116 Command(commandType, description)
118 fDefaultOption = defaultOption;
119 fOptionName = optionName;
128 static char null[1] = {
"" };
129 int firstArgc = argc;
131 for (
int i = 1; i < firstArgc; i++)
134 if (command == 0)
continue;
143 if (strcmp(argv[i],
"-h") != 0 && strcmp(argv[i],
"--help") != 0)
152 if(i+1 > firstArgc || argv[i+1]==0 || argv[i+1][0]==
'-')
154 G4cerr <<
"An command line option is missing for "
159 command->
SetOption( (
const char*) strdup(argv[i+1]) );
172 if(buffer.empty() ==
false)
174 if(buffer.at(0) !=
'-'
175 && buffer.at(0) !=
'&'
176 && buffer.at(0) !=
'>'
177 && buffer.at(0) !=
'|')
181 G4cout <<
"facultative option is : " << buffer <<
G4endl;
184 command->
SetOption( (
const char*) strdup(argv[i+1]) );
204 G4cout <<
"Usage : " << argv[0] <<
" [OPTIONS]" <<
G4endl;
216 std::map<G4String, Command*>::iterator it;
235 else if (toPrint ==
"-h")
continue;
236 else if (toPrint ==
"--help")
259 for (
int i = 0; i < argc; i++)
261 if (strcmp(argv[i],
""))
284 command =
new Command(type, description);
293 fMaxOptionNameLength = defaultOption.length();
332 std::map<G4String, Command*>::iterator it =
fCommandMap.find(marker);
361 description <<
"You try to retrieve a command that was not registered : "
363 G4Exception(
"CommandLineParser::GetCommandIfActive",
378 for (
G4int i = 1; i < argc; i++)
380 if (strcmp(argv[i],
""))
383 G4cerr <<
"Unknown argument : " << argv[i] <<
"\n";
388 G4cerr <<
"The option " << argv[0]
389 <<
" is not handled this programme." <<
G4endl;
390 G4cout <<
"Usage : " << argv[0] <<
" [OPTIONS]" <<
G4endl;
void Parse(int &argc, char **argv)
Command * FindCommand(const G4String &marker)
std::ostringstream G4ExceptionDescription
std::vector< ExP01TrackerHit * > a
const G4String & GetDescription()
G4int fMaxOptionNameLength
virtual const G4String & GetDefaultOption()
virtual void SetOption(const G4String &)
G4GLOB_DLL std::ostream G4cerr
void CorrectRemainingOptions(int &argc, char **argv)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Command * GetCommandIfActive(const G4String &marker)
G4GLOB_DLL std::ostream G4cout
bool CheckIfNotHandledOptionsExists(int &argc, char **argv)
void AddCommand(const G4String &marker, Command::Type, const G4String &description="", const G4String &defaultOption="", const G4String &optionName="")
std::map< G4String, Command * > fCommandMap