55 #include <visp3/core/vpDebug.h> 56 #include <visp3/io/vpParseArgv.h> 58 #define GETOPTARGS "d:f:i:h" 60 void usage(
const char *name,
const char *badparam,
int i_val,
float f_val,
double d_val);
61 bool getOptions(
int argc,
const char **argv,
int &i_val,
float &f_val,
double &d_val);
74 void usage(
const char *name,
const char *badparam,
int i_val,
float f_val,
double d_val)
77 Parsing command line arguments example.\n\ 80 %s [-i <integer>] [-f <float>] [-d <double> [-h]\n\ 95 Print the help.\n\n", i_val, f_val, d_val);
98 fprintf(stderr,
"ERROR: \n");
99 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
115 bool getOptions(
int argc,
const char **argv,
int &i_val,
float &f_val,
double &d_val)
123 d_val = atof(optarg_);
126 f_val = (float)atof(optarg_);
129 i_val = atoi(optarg_);
132 usage(argv[0], NULL, i_val, f_val, d_val);
137 usage(argv[0], optarg_, i_val, f_val, d_val);
143 if ((c == 1) || (c == -1)) {
145 usage(argv[0], NULL, i_val, f_val, d_val);
146 std::cerr <<
"ERROR: " << std::endl;
147 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
154 int main(
int argc,
const char **argv)
162 double d_val = 3.1415;
165 if (getOptions(argc, argv, i_val, f_val, d_val) ==
false) {
169 cout <<
"Your parameters: " << endl;
170 cout <<
" Integer value: " << i_val << endl;
171 cout <<
" Float value: " << f_val << endl;
172 cout <<
" Double value: " << d_val << endl << endl;
173 cout <<
"Call " << argv[0] <<
" -h to see how to change these parameters." << endl;
177 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
error that can be emited by ViSP classes.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)