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 +
"'");
155 return end_idx - start_idx;
161 std::string string_arg(val);
167 std::vector<std::string> strings;
169 for (
int i=1; i<=num_args; ++i)
178 std::vector<double> doubles;
180 for (
int i=1; i<=num_args; ++i)
189 std::vector<unsigned> unsigneds;
191 for (
int i=1; i<=num_args; ++i)
200 std::vector<int> ints;
202 for (
int i=1; i<=num_args; ++i)
215 std::transform(string_result.begin(), string_result.end(), string_result.begin(), ::tolower);
217 if (string_result==
"0" || string_result==
"false")
221 else if (string_result==
"1" || string_result==
"true")
227 EXCEPTION(
"The option '" << rOption <<
"' argument '" <<
236 if (!( rOption.substr(0,1) ==
"-" && rOption.substr(1,1).find_first_of(
"0123456789")==std::string::npos))
238 EXCEPTION(
"A command line option must begin with '-' followed by a non-numeric character.");
#define EXCEPTION(message)
#define EXCEPT_IF_NOT(test)
bool OptionExists(const std::string &rOption)
static CommandLineArguments * Instance()
static CommandLineArguments * mpInstance
std::vector< double > GetDoublesCorrespondingToOption(const std::string &rOption)
std::string GetStringCorrespondingToOption(const std::string &rOption, int valueNumber=1)
int GetIndexForArgument(std::string rOption)
std::vector< std::string > GetStringsCorrespondingToOption(const std::string &rOption)
int GetIntCorrespondingToOption(const std::string &rOption, int valueNumber=1)
std::vector< unsigned > GetUnsignedsCorrespondingToOption(const std::string &rOption)
double GetDoubleCorrespondingToOption(const std::string &rOption, int valueNumber=1)
unsigned GetUnsignedCorrespondingToOption(const std::string &rOption, int valueNumber=1)
bool GetBoolCorrespondingToOption(const std::string &rOption)
char * GetValueCorrespondingToOption(const std::string &rOption, int valueNumber=1)
int GetNumberOfArgumentsForOption(const std::string &rOption, bool throwIfNone=false)
std::vector< int > GetIntsCorrespondingToOption(const std::string &rOption)
void TestOptionFormat(const std::string &rOption)