36#include "CommandLineArguments.hpp"
43#include "PetscException.hpp"
85 if (num_args < valueNumber)
88 ss<<
"Index="<<valueNumber<<
" requested for '"<<rOption<<
"', but only "<<num_args<<
" given.";
92 return (*
p_argv)[index+valueNumber];
113 EXCEPTION(
"Option is a negative number and cannot be converted to unsigned.");
115 return (
unsigned)(i);
122 for (
int i=1; i<*
p_argc; i++)
124 if (rOption==std::string((*
p_argv)[i]))
130 EXCEPTION(
"Command line option '"+rOption+
"' does not exist");
143 PETSCEXCEPT(PetscOptionsHasName(
nullptr,
nullptr, rOption.c_str(), &found));
150 std::vector<std::string> unused;
151 for (
int i=1; i<*
p_argc; i++)
153 std::string argument = std::string((*
p_argv)[i]);
154 bool is_option = (argument.substr(0,1)==
"-" && argument.substr(1,1).find_first_of(
"0123456789")==std::string::npos);
157 || std::find(unused.begin(), unused.end(), argument) != unused.end())
162 PetscBool used_by_petsc = PETSC_FALSE;
166 std::string petsc_name = argument.substr(1);
167 PETSCEXCEPT(PetscOptionsUsed(
nullptr, petsc_name.c_str(), &used_by_petsc));
171 unused.push_back(argument);
181 int end_idx = start_idx;
182 for (
int i=start_idx+1; i<*
p_argc; i++)
184 std::string argument = std::string((*
p_argv)[i]);
185 if (argument.substr(0,1)==
"-" && argument.substr(1,1).find_first_of(
"0123456789")==std::string::npos)
192 if (end_idx == start_idx)
196 EXCEPTION(
"No value(s) given after command line option '" + rOption +
"'");
204 return end_idx - start_idx;
210 std::string string_arg(val);
216 std::vector<std::string> strings;
218 for (
int i=1; i<=num_args; ++i)
227 std::vector<double> doubles;
229 for (
int i=1; i<=num_args; ++i)
238 std::vector<unsigned> unsigneds;
240 for (
int i=1; i<=num_args; ++i)
249 std::vector<int> ints;
251 for (
int i=1; i<=num_args; ++i)
264 std::transform(string_result.begin(), string_result.end(), string_result.begin(), ::tolower);
266 if (string_result==
"0" || string_result==
"false")
270 else if (string_result==
"1" || string_result==
"true")
276 EXCEPTION(
"The option '" << rOption <<
"' argument '" <<
285 if (!( rOption.substr(0,1) ==
"-" && rOption.substr(1,1).find_first_of(
"0123456789")==std::string::npos))
287 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)
std::set< std::string > mUsedOptions
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)
void MarkOptionUsed(const std::string &rOption)
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)
std::vector< std::string > GetUnusedOptions()