Visual Servoing Platform
version 3.2.0
parse-argv2.cpp
1
/****************************************************************************
2
*
3
* ViSP, open source Visual Servoing Platform software.
4
* Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5
*
6
* This software is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
* See the file LICENSE.txt at the root directory of this source
11
* distribution for additional information about the GNU GPL.
12
*
13
* For using ViSP with software that can not be combined with the GNU
14
* GPL, please contact Inria about acquiring a ViSP Professional
15
* Edition License.
16
*
17
* See http://visp.inria.fr for more information.
18
*
19
* This software was developed at:
20
* Inria Rennes - Bretagne Atlantique
21
* Campus Universitaire de Beaulieu
22
* 35042 Rennes Cedex
23
* France
24
*
25
* If you have questions regarding the use of this file, please contact
26
* Inria at visp@inria.fr
27
*
28
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30
*
31
* Description:
32
* Example of command line parsing.
33
*
34
* Author:
35
* Fabien Spindler
36
*
37
*****************************************************************************/
38
51
#include <iomanip>
52
#include <sstream>
53
#include <stdio.h>
54
55
#include <visp3/core/vpDebug.h>
56
#include <visp3/io/vpParseArgv.h>
57
58
int
main(
int
argc,
const
char
**argv)
59
{
60
try
{
61
using ::std::cout;
62
using ::std::endl;
63
64
bool
bool_val =
false
;
65
int
int_val = 3;
66
long
long_val = 33333333;
67
float
float_val = 3.14f;
68
double
double_val = 3.1415;
69
char
*string_val = NULL;
70
71
vpParseArgv::vpArgvInfo argTable[] = {
72
{
"-bool"
,
vpParseArgv::ARGV_CONSTANT_BOOL
, 0, (
char
*)&bool_val,
"Bool enabled."
},
73
{
"-integer"
,
vpParseArgv::ARGV_INT
, (
char
*)NULL, (
char
*)&int_val,
"An integer value."
},
74
{
"-long"
,
vpParseArgv::ARGV_LONG
, (
char
*)NULL, (
char
*)&long_val,
"A long value."
},
75
{
"-float"
,
vpParseArgv::ARGV_FLOAT
, (
char
*)NULL, (
char
*)&float_val,
"A float value."
},
76
{
"-double"
,
vpParseArgv::ARGV_DOUBLE
, (
char
*)NULL, (
char
*)&double_val,
"A double value."
},
77
{
"-string"
,
vpParseArgv::ARGV_STRING
, (
char
*)NULL, (
char
*)&string_val,
"A chain value."
},
78
{
"-h"
,
vpParseArgv::ARGV_HELP
, (
char
*)NULL, (
char
*)NULL,
"Print the help."
},
79
{(
char
*)NULL,
vpParseArgv::ARGV_END
, (
char
*)NULL, (
char
*)NULL, (
char
*)NULL}};
80
81
// Read the command line options
82
if
(
vpParseArgv::parse
(&argc, argv, argTable,
vpParseArgv::ARGV_NO_DEFAULTS
)) {
83
return
(-1);
84
}
85
86
cout <<
"Your parameters: "
<< endl;
87
cout <<
" Bool value: "
<< bool_val << endl;
88
cout <<
" Integer value: "
<< int_val << endl;
89
cout <<
" Long value: "
<< long_val << endl;
90
cout <<
" Float value: "
<< float_val << endl;
91
cout <<
" Double value: "
<< double_val << endl;
92
if
(string_val != NULL)
93
cout <<
" String value: "
<< string_val << endl;
94
else
95
cout <<
" String value: \"\""
<< endl << endl;
96
97
cout <<
"Call "
<< argv[0] <<
" -h to see how to change these parameters."
<< endl;
98
99
return
EXIT_SUCCESS;
100
}
catch
(
const
vpException
&e) {
101
std::cout <<
"Catch a ViSP exception: "
<< e.
getStringMessage
() << std::endl;
102
return
EXIT_FAILURE;
103
}
104
}
vpParseArgv::ARGV_HELP
Definition:
vpParseArgv.h:167
vpException::getStringMessage
const std::string & getStringMessage(void) const
Send a reference (constant) related the error message (can be empty).
Definition:
vpException.cpp:91
vpParseArgv::ARGV_CONSTANT_BOOL
Definition:
vpParseArgv.h:157
vpParseArgv::ARGV_STRING
Definition:
vpParseArgv.h:161
vpParseArgv::ARGV_DOUBLE
Definition:
vpParseArgv.h:164
vpParseArgv::ARGV_LONG
Definition:
vpParseArgv.h:160
vpParseArgv::parse
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition:
vpParseArgv.cpp:68
vpParseArgv::ARGV_NO_DEFAULTS
Definition:
vpParseArgv.h:175
vpParseArgv::ARGV_FLOAT
Definition:
vpParseArgv.h:163
vpParseArgv::ARGV_END
Definition:
vpParseArgv.h:168
vpException
error that can be emited by ViSP classes.
Definition:
vpException.h:70
vpParseArgv::ARGV_INT
Definition:
vpParseArgv.h:159
example
parse-argv
parse-argv2.cpp
Generated by
1.8.16