8 #ifndef _COMMAND_LINE_PARSER_H
9 #define _COMMAND_LINE_PARSER_H
32 int print(stringstream &s)
const{
33 s <<
"[CommandLine] ";
51 s <<
"no description";
77 "Global debug level",
true);
83 inline int parse(
int argc,
char **argv)
const{
85 for(
int i = 0; i < argc; i++){
87 if((
string(argv[i]) ==
"-h")||(
string(argv[i]) ==
"--help")){
91 for(
int j = 0; j < (int)
arguments_.size(); j++){
94 if((
string(argv[i]) ==
"-" +
arguments_[j].key_)
102 stringstream s(argv[i + 1]);
106 stringstream s(argv[i + 1]);
112 if(
string(argv[i]) ==
"-" +
arguments_[j].key_){
120 for(
int i = 0; i < (int)
arguments_.size(); i++){
125 msg <<
"[CommandLine] Missing mandatory argument:" << endl;
127 dMsg(cerr, msg.str(), 1);
134 msg <<
"[CommandLine] Missing mandatory argument:" << endl;
136 dMsg(cerr, msg.str(), 1);
141 if(*(
arguments_[i].doubleValue_) == -DBL_MAX){
143 msg <<
"[CommandLine] Missing mandatory argument:" << endl;
145 dMsg(cerr, msg.str(), 1);
157 o <<
"[CommandLine] Options and arguments:" << endl;
158 for(
int i = 0; i < (int)
arguments_.size(); i++){
190 if(*(
arguments_[i].doubleValue_) == -DBL_MAX){
207 msg <<
"[CommandLine]" << endl;
208 msg <<
"[CommandLine] Usage:" << endl;
209 msg <<
"[CommandLine] " << binPath << endl;
210 msg <<
"[CommandLine] Argument(s):" << endl;
211 for(
int i = 0; i < (int)
arguments_.size(); i++){
216 msg <<
"[CommandLine] Option(s):" << endl;
217 for(
int i = 0; i < (int)
arguments_.size(); i++){
223 dMsg(cerr, msg.str(), 1);
230 const string &description =
""){
244 const string &description =
"",
245 const bool &optional =
false){
260 const string &description =
"",
261 const bool &optional =
false){
276 const string &description =
"",
277 const bool &optional =
false){
294 vector<CommandLineArgument>
string description_
Definition: CommandLineParser.h:72
int printUsage(const string &binPath) const
Definition: CommandLineParser.h:204
double * doubleValue_
Definition: CommandLineParser.h:68
vector< CommandLineArgument > arguments_
Definition: CommandLineParser.h:289
const int msg(const char *msg, const int &debugLevel=infoMsg) const
Definition: Debug.cpp:67
int parse(int argc, char **argv) const
Definition: CommandLineParser.h:83
~CommandLineParser()
Definition: CommandLineParser.h:80
int setIntArgument(const string &key, int *value, const string &description="", const bool &optional=false)
Definition: CommandLineParser.h:259
virtual const int dMsg(ostream &stream, string msg, const int &debugLevel=infoMsg) const
Definition: Debug.cpp:52
Definition: CommandLineParser.h:20
int printArgs(ostream &o) const
Definition: CommandLineParser.h:155
string key_
Definition: CommandLineParser.h:71
int print(stringstream &s) const
Definition: CommandLineParser.h:32
int setDoubleArgument(const string &key, double *value, const string &description="", const bool &optional=false)
Definition: CommandLineParser.h:243
int setOption(const string &key, bool *value, const string &description="")
Definition: CommandLineParser.h:229
CommandLineArgument()
Definition: CommandLineParser.h:25
Minimalist debugging class.
Definition: Debug.h:39
CommandLineParser()
Definition: CommandLineParser.h:75
bool isAnOption_
Definition: CommandLineParser.h:63
Basic command line parsing.
Definition: CommandLineParser.h:15
bool isOptional_
Definition: CommandLineParser.h:63
Definition: CommandLineParser.h:13
bool * boolValue_
Definition: CommandLineParser.h:66
int setStringArgument(const string &key, string *value, const string &description="", const bool &optional=false)
Definition: CommandLineParser.h:275
int globalDebugLevel_
Definition: Debug.cpp:5
string * stringValue_
Definition: CommandLineParser.h:69
int * intValue_
Definition: CommandLineParser.h:67