Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
parse-argv2.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 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 https://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 *
35*****************************************************************************/
36
49#include <iomanip>
50#include <sstream>
51#include <stdio.h>
52
53#include <visp3/core/vpDebug.h>
54#include <visp3/io/vpParseArgv.h>
55
56int main(int argc, const char **argv)
57{
58 try {
59 using ::std::cout;
60 using ::std::endl;
61
62 bool bool_val = false;
63 int int_val = 3;
64 long long_val = 33333333;
65 float float_val = 3.14f;
66 double double_val = 3.1415;
67 char *string_val = NULL;
68
69 vpParseArgv::vpArgvInfo argTable[] = {
70 {"-bool", vpParseArgv::ARGV_CONSTANT_BOOL, 0, (char *)&bool_val, "Bool enabled."},
71 {"-integer", vpParseArgv::ARGV_INT, (char *)NULL, (char *)&int_val, "An integer value."},
72 {"-long", vpParseArgv::ARGV_LONG, (char *)NULL, (char *)&long_val, "A long value."},
73 {"-float", vpParseArgv::ARGV_FLOAT, (char *)NULL, (char *)&float_val, "A float value."},
74 {"-double", vpParseArgv::ARGV_DOUBLE, (char *)NULL, (char *)&double_val, "A double value."},
75 {"-string", vpParseArgv::ARGV_STRING, (char *)NULL, (char *)&string_val, "A chain value."},
76 {"-h", vpParseArgv::ARGV_HELP, (char *)NULL, (char *)NULL, "Print the help."},
77 {(char *)NULL, vpParseArgv::ARGV_END, (char *)NULL, (char *)NULL, (char *)NULL}};
78
79 // Read the command line options
80 if (vpParseArgv::parse(&argc, argv, argTable, vpParseArgv::ARGV_NO_DEFAULTS)) {
81 return EXIT_FAILURE;
82 }
83
84 cout << "Your parameters: " << endl;
85 cout << " Bool value: " << bool_val << endl;
86 cout << " Integer value: " << int_val << endl;
87 cout << " Long value: " << long_val << endl;
88 cout << " Float value: " << float_val << endl;
89 cout << " Double value: " << double_val << endl;
90 if (string_val != NULL)
91 cout << " String value: " << string_val << endl;
92 else
93 cout << " String value: \"\"" << endl << endl;
94
95 cout << "Call " << argv[0] << " -h to see how to change these parameters." << endl;
96
97 return EXIT_SUCCESS;
98 } catch (const vpException &e) {
99 std::cout << "Catch a ViSP exception: " << e.getStringMessage() << std::endl;
100 return EXIT_FAILURE;
101 }
102}
error that can be emitted by ViSP classes.
Definition vpException.h:59
const std::string & getStringMessage() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
@ ARGV_NO_DEFAULTS
No default options like -help.
@ ARGV_DOUBLE
Argument is associated to a double.
@ ARGV_LONG
Argument is associated to a long.
@ ARGV_STRING
Argument is associated to a char * string.
@ ARGV_FLOAT
Argument is associated to a float.
@ ARGV_INT
Argument is associated to an int.
@ ARGV_CONSTANT_BOOL
Stand alone argument associated to a bool var that is set to true.
@ ARGV_END
End of the argument list.
@ ARGV_HELP
Argument is for help displaying.