ViSP  2.6.2
vpParseArgv Class Reference

#include <vpParseArgv.h>

Public Types

enum  vpArgvType {
  ARGV_CONSTANT, ARGV_INT, ARGV_LONG, ARGV_STRING,
  ARGV_REST, ARGV_FLOAT, ARGV_DOUBLE, ARGV_FUNC,
  ARGV_GENFUNC, ARGV_HELP, ARGV_END
}
 
enum  vpArgvFlags {
  ARGV_NO_DEFAULTS = 0x1, ARGV_NO_LEFTOVERS = 0x2, ARGV_NO_ABBREV = 0x4, ARGV_DONT_SKIP_FIRST_ARG = 0x8,
  ARGV_NO_PRINT = 0x10
}
 

Static Public Member Functions

static bool parse (int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
 
static int parse (int argc, const char **argv, const char *validOpts, const char **param)
 

Static Public Attributes

static vpArgvInfo defaultTable [2]
 

Detailed Description

Command line argument parsing.

The code below shows a first way to parse command line arguments using vpParseArgv class. It allows to specify an option name with more than one character.

#include <stdio.h>
#include <visp/vpParseArgv.h>
// Usage : [-int <integer value>] [-float <float value>] [-double <double value>] [-h]
int main(int argc, const char ** argv)
{
// Variables to set by command line parsing
int i_val = 0;
float f_val = 0;
double d_val = 0;
// Parse the command line to set the variables
vpParseArgv::vpArgvInfo argTable[] =
{
{"-int", vpParseArgv::ARGV_INT, (char*) NULL, (char *) &i_val,
"An integer value."},
{"-float", vpParseArgv::ARGV_FLOAT, (char*) NULL, (char *) &f_val,
"A float value."},
{"-double", vpParseArgv::ARGV_DOUBLE, (char*) NULL, (char *) &d_val,
"A double value."},
{"-h", vpParseArgv::ARGV_HELP, (char*) NULL, (char *) NULL,
"Print the help."},
{(char*) NULL, vpParseArgv::ARGV_END, (char*) NULL, (char*) NULL, (char*) NULL}
} ;
// Read the command line options
if(vpParseArgv::parse(&argc, argv, argTable,
return (false);
}
// i_val, f_val, d_val may have new values
}

The code below shows an other way to parse command line arguments using vpParseArgv class. Here command line options are only one character long.

#include <stdio.h>
#include <stdlib.h>
#include <visp/vpParseArgv.h>
// List of allowed command line options
#define GETOPTARGS "d:f:i:h" // double point mean here that the preceding option request an argument
// Usage : [-i <integer value>] [-f <float value>] [-d <double value>] [-h]
int main(int argc, const char ** argv)
{
// Variables to set by command line parsing
int i_val = 0;
float f_val = 0;
double d_val = 0;
// Parse the command line to set the variables
const char *optarg;
int c;
while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg)) > 1) {
switch (c) {
case 'd': d_val = atof(optarg); break;
case 'f': f_val = (float) atof(optarg); break;
case 'i': i_val = atoi(optarg); break;
case 'h': printf("Usage: ...\n"); return true; break;
default:
printf("Usage: ...\n"); return true; break;
}
}
if ((c == 1) || (c == -1)) {
// standalone param or error
printf("Usage: ...\n");
return false;
}
// i_val, f_val, d_val may have new values
}
Examples:
SickLDMRS-Process.cpp.

Definition at line 133 of file vpParseArgv.h.

Member Enumeration Documentation

Flag bits.

Enumerator
ARGV_NO_DEFAULTS 

No default options like -help.

ARGV_NO_LEFTOVERS 

Print an error message if an option is not in the argument list.

ARGV_NO_ABBREV 

No abrevation. Print an error message if an option is abrevated (ie "-i" in place of "-int" which is requested).

ARGV_DONT_SKIP_FIRST_ARG 

Don't skip first argument.

ARGV_NO_PRINT 

No printings.

Definition at line 156 of file vpParseArgv.h.

Legal values for the type field of a vpArgvInfo.

Enumerator
ARGV_CONSTANT 

Stand alone argument.

ARGV_INT 

Argument is associated to an int.

ARGV_LONG 

Argument is associated to a long.

ARGV_STRING 

Argument is associated to a char * string.

ARGV_REST 
ARGV_FLOAT 

Argument is associated to a float.

ARGV_DOUBLE 

Argument is associated to a double.

ARGV_FUNC 
ARGV_GENFUNC 
ARGV_HELP 

Argument is for help displaying.

ARGV_END 

End of the argument list.

Definition at line 139 of file vpParseArgv.h.

Member Function Documentation

bool vpParseArgv::parse ( int *  argcPtr,
const char **  argv,
vpArgvInfo *  argTable,
int  flags 
)
static

Process an argv array according to a table of expectedvcommand-line options.

The return value is a boolean value with true indicating an error. If an error occurs then an error message is printed on stderr. Under normal conditions, both *argcPtr and *argv are modified to return the arguments that couldn't be processed here (they didn't match the option table, or followed an vpParseArgv::ARGV_REST argument).

Parameters
argcPtrPointer to the count of command line arguments.
argvArray of command line argument strings.
argTableArray of command-specific argument descriptions.
flagsThis parameter is to set with vpParseArgv::vpArgvFlags values or combinations of these values using the OR operator (vpParseArgv::ARGV_NO_LEFTOVERS | vpParseArgv::ARGV_NO_DEFAULTS). If the vpParseArgv::ARGV_NO_DEFAULTS bit is set, then don't generate information for default options.
Examples:
AROgre.cpp, AROgreBasic.cpp, BSpline.cpp, calibrate2dGrid.cpp, displayD3D.cpp, displayGDI.cpp, displayGTK.cpp, displayOpenCV.cpp, displaySequence.cpp, displayX.cpp, displayXMulti.cpp, fernClassifier.cpp, grab1394CMU.cpp, grab1394Two.cpp, grabDirectShow.cpp, grabDirectShowMulti.cpp, grabDisk.cpp, grabOpenCV.cpp, grabV4l2.cpp, histogram.cpp, homographyHartleyDLT2DObject.cpp, homographyHLM2DObject.cpp, homographyHLM3DObject.cpp, homographyRansac2DObject.cpp, imageDiskRW.cpp, imageSequenceReader.cpp, keyPointSurf.cpp, mbtTracking.cpp, moveAfma4.cpp, moveBiclops.cpp, Nurbs.cpp, parallelPort.cpp, parse-argv1.cpp, parse-argv2.cpp, photometricVisualServoing.cpp, planarObjectDetector.cpp, poseVirtualVS.cpp, ringLight.cpp, servoAfma4Point2DCamVelocityKalman.cpp, servoBiclopsPoint2DArtVelocity.cpp, servoSimu3D_cdMc_CamVelocity.cpp, servoSimu3D_cdMc_CamVelocityWithoutVpServo.cpp, servoSimu3D_cMcd_CamVelocity.cpp, servoSimu3D_cMcd_CamVelocityWithoutVpServo.cpp, servoSimu4Points.cpp, servoSimuAfma6FourPoints2DCamVelocity.cpp, servoSimuCircle2DCamVelocity.cpp, servoSimuCircle2DCamVelocityDisplay.cpp, servoSimuCylinder.cpp, servoSimuCylinder2DCamVelocityDisplay.cpp, servoSimuCylinder2DCamVelocityDisplaySecondaryTask.cpp, servoSimuFourPoints2DCamVelocity.cpp, servoSimuFourPoints2DCamVelocityDisplay.cpp, servoSimuFourPoints2DPolarCamVelocityDisplay.cpp, servoSimuLine2DCamVelocityDisplay.cpp, servoSimuPoint2DCamVelocity1.cpp, servoSimuPoint2DCamVelocity2.cpp, servoSimuPoint2DCamVelocity3.cpp, servoSimuPoint2DhalfCamVelocity1.cpp, servoSimuPoint2DhalfCamVelocity2.cpp, servoSimuPoint2DhalfCamVelocity3.cpp, servoSimuPoint3DCamVelocity.cpp, servoSimuSphere.cpp, servoSimuSphere2DCamVelocity.cpp, servoSimuSphere2DCamVelocitySecondaryTask.cpp, servoSimuSquareLine2DCamVelocityDisplay.cpp, servoSimuThetaUCamVelocity.cpp, servoSimuViper850FourPoints2DCamVelocity.cpp, SickLDMRS-Process.cpp, simulateCircle2DCamVelocity.cpp, simulateFourPoints2DCartesianCamVelocity.cpp, simulateFourPoints2DPolarCamVelocity.cpp, testClick.cpp, testColvector.cpp, testConversion.cpp, testCreateSubImage.cpp, testDisplacement.cpp, testDisplays.cpp, testFeatureSegment.cpp, testIoPGM.cpp, testIoPPM.cpp, testMatrix.cpp, testMatrixException.cpp, testMouseEvent.cpp, testPose.cpp, testReadImage.cpp, testRobust.cpp, testSurfKeyPoint.cpp, testSvd.cpp, testTime.cpp, testTrackDot.cpp, testTwistMatrix.cpp, testUndistortImage.cpp, testVideoDevice.cpp, testVideoDeviceDual.cpp, testXmlParser.cpp, trackDot.cpp, trackDot2.cpp, trackDot2WithAutoDetection.cpp, trackKltOpencv.cpp, trackMeCircle.cpp, trackMeEllipse.cpp, trackMeLine.cpp, trackMeNurbs.cpp, videoReader.cpp, and wireframeSimulator.cpp.

Definition at line 79 of file vpParseArgv.cpp.

References ARGV_CONSTANT, ARGV_DONT_SKIP_FIRST_ARG, ARGV_DOUBLE, ARGV_END, ARGV_FLOAT, ARGV_FUNC, ARGV_GENFUNC, ARGV_HELP, ARGV_INT, ARGV_LONG, ARGV_NO_ABBREV, ARGV_NO_LEFTOVERS, ARGV_REST, ARGV_STRING, and defaultTable.

int vpParseArgv::parse ( int  argc,
const char **  argv,
const char *  validOpts,
const char **  param 
)
static

Get next command line option and parameter.

Parameters
argcCount of command line arguments.
argvArray of command line argument strings.
validOptsString of valid case-sensitive option characters, a ':' following a given character means that option can take a parameter.
paramPointer to a pointer to a string for output.
Returns
If valid option is found, the character value of that option is returned, and *param points to the parameter if given, or is NULL if no param.
If standalone parameter (with no option) is found, 1 is returned, and param points to the standalone parameter
If option is found, but it is not in the list of valid options, -1 is returned, and *param points to the invalid argument.
When end of argument list is reached, 0 is returned, and *param is NULL.

Definition at line 509 of file vpParseArgv.cpp.

Member Data Documentation

vpParseArgv::vpArgvInfo vpParseArgv::defaultTable
static
Initial value:
= {
{"-help", ARGV_HELP, (char *) NULL, (char *) NULL,
"Print summary of command-line options and abort.\n"},
{NULL, ARGV_END, (char *) NULL, (char *) NULL,
(char *) NULL}
}

Definition at line 182 of file vpParseArgv.h.

Referenced by parse().