57 #include <visp/vpDebug.h>
58 #include <visp/vpParseArgv.h>
64 #define GETOPTARGS "d:f:i:h"
77 void usage(
const char *name,
const char *badparam,
int i_val,
float f_val,
double d_val)
80 Parsing command line arguments example.\n\
83 %s [-i <integer>] [-f <float>] [-d <double> [-h]\n\
102 fprintf(stderr,
"ERROR: \n" );
103 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
119 bool getOptions(
int argc,
const char **argv,
int &i_val,
float &f_val,
double &d_val)
126 case 'd': d_val = atof(optarg);
break;
127 case 'f': f_val = (float) atof(optarg);
break;
128 case 'i': i_val = atoi(optarg);
break;
129 case 'h': usage(argv[0], NULL, i_val, f_val, d_val);
return false;
break;
132 usage(argv[0], optarg, i_val, f_val, d_val);
return false;
break;
136 if ((c == 1) || (c == -1)) {
138 usage(argv[0], NULL, i_val, f_val, d_val);
139 std::cerr <<
"ERROR: " << std::endl;
140 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
148 main(
int argc,
const char ** argv)
155 double d_val = 3.1415;
158 if (getOptions(argc, argv, i_val, f_val, d_val) ==
false) {
162 cout <<
"Your parameters: " << endl;
163 cout <<
" Integer value: " << i_val << endl;
164 cout <<
" Float value: " << f_val << endl;
165 cout <<
" Double value: " << d_val << endl << endl;
166 cout <<
"Call " << argv[0]
167 <<
" -h to see how to change these parameters." << endl;
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)