57 #include <visp/vpDebug.h>
58 #include <visp/vpParseArgv.h>
64 #define GETOPTARGS "d:f:i:h"
66 void usage(
const char *name,
const char *badparam,
int i_val,
float f_val,
double d_val);
67 bool getOptions(
int argc,
const char **argv,
int &i_val,
float &f_val,
double &d_val);
80 void usage(
const char *name,
const char *badparam,
int i_val,
float f_val,
double d_val)
83 Parsing command line arguments example.\n\
86 %s [-i <integer>] [-f <float>] [-d <double> [-h]\n\
101 Print the help.\n\n",
102 i_val, f_val, d_val);
105 fprintf(stderr,
"ERROR: \n" );
106 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
122 bool getOptions(
int argc,
const char **argv,
int &i_val,
float &f_val,
double &d_val)
129 case 'd': d_val = atof(optarg_);
break;
130 case 'f': f_val = (float) atof(optarg_);
break;
131 case 'i': i_val = atoi(optarg_);
break;
132 case 'h': usage(argv[0], NULL, i_val, f_val, d_val);
return false;
break;
135 usage(argv[0], optarg_, i_val, f_val, d_val);
return false;
break;
139 if ((c == 1) || (c == -1)) {
141 usage(argv[0], NULL, i_val, f_val, d_val);
142 std::cerr <<
"ERROR: " << std::endl;
143 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
151 main(
int argc,
const char ** argv)
159 double d_val = 3.1415;
162 if (getOptions(argc, argv, i_val, f_val, d_val) ==
false) {
166 cout <<
"Your parameters: " << endl;
167 cout <<
" Integer value: " << i_val << endl;
168 cout <<
" Float value: " << f_val << endl;
169 cout <<
" Double value: " << d_val << endl << endl;
170 cout <<
"Call " << argv[0]
171 <<
" -h to see how to change these parameters." << endl;
176 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)