36 #include "CommandLineArguments.hpp"
81 if ( num_args<valueNumber )
84 ss<<
"Index="<<valueNumber<<
" requested for '"<<rOption<<
"', but only "<<num_args<<
" given.";
88 return (*
p_argv)[index+valueNumber];
109 EXCEPTION(
"Option is a negative number and cannot be converted to unsigned.");
111 return (
unsigned)(i);
118 for (
int i=1; i<*
p_argc; i++)
120 if (rOption==std::string((*
p_argv)[i]))
125 EXCEPTION(
"Command line option '"+rOption+
"' does not exist");
132 int end_idx = start_idx;
133 for (
int i=start_idx+1; i<*
p_argc; i++)
135 std::string argument = std::string((*
p_argv)[i]);
136 if (argument.substr(0,1)==
"-" && argument.substr(1,1).find_first_of(
"0123456789")==std::string::npos)
143 if (end_idx == start_idx)
147 EXCEPTION(
"No value(s) given after command line option '" + rOption +
"'");
156 return end_idx - start_idx;
162 std::string string_arg(val);
168 std::vector<std::string> strings;
170 for(
int i=1; i<=num_args; ++i)
179 std::vector<double> doubles;
181 for(
int i=1; i<=num_args; ++i)
190 std::vector<unsigned> unsigneds;
192 for(
int i=1; i<=num_args; ++i)
201 std::vector<int> ints;
203 for(
int i=1; i<=num_args; ++i)
216 std::transform(string_result.begin(), string_result.end(), string_result.begin(), ::tolower);
218 if (string_result==
"0" || string_result==
"false")
222 else if (string_result==
"1" || string_result==
"true")
228 EXCEPTION(
"The option '" << rOption <<
"' argument '" <<
237 if ( !( rOption.substr(0,1) ==
"-" && rOption.substr(1,1).find_first_of(
"0123456789")==std::string::npos ) )
239 EXCEPTION(
"A command line option must begin with '-' followed by a non-numeric character.");
std::vector< std::string > GetStringsCorrespondingToOption(const std::string &rOption)
std::vector< double > GetDoublesCorrespondingToOption(const std::string &rOption)
#define EXCEPTION(message)
char * GetValueCorrespondingToOption(const std::string &rOption, int valueNumber=1)
std::vector< unsigned > GetUnsignedsCorrespondingToOption(const std::string &rOption)
void TestOptionFormat(const std::string &rOption)
static CommandLineArguments * mpInstance
int GetIndexForArgument(std::string rOption)
bool OptionExists(const std::string &rOption)
std::vector< int > GetIntsCorrespondingToOption(const std::string &rOption)
bool GetBoolCorrespondingToOption(const std::string &rOption)
std::string GetStringCorrespondingToOption(const std::string &rOption, int valueNumber=1)
double GetDoubleCorrespondingToOption(const std::string &rOption, int valueNumber=1)
int GetIntCorrespondingToOption(const std::string &rOption, int valueNumber=1)
#define EXCEPT_IF_NOT(test)
static CommandLineArguments * Instance()
int GetNumberOfArgumentsForOption(const std::string &rOption, bool throwIfNone=false)
unsigned GetUnsignedCorrespondingToOption(const std::string &rOption, int valueNumber=1)