ViSP  3.0.0
parse-argv2.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Example of command line parsing.
32  *
33  * Author:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
53 #include <visp3/core/vpDebug.h>
54 #include <visp3/io/vpParseArgv.h>
55 #include <stdio.h>
56 #include <sstream>
57 #include <iomanip>
58 
59 int
60 main(int argc, const char ** argv)
61 {
62  try {
63  using ::std::cout;
64  using ::std::endl;
65 
66  int i_val = 3;
67  float f_val = 3.14f;
68  double d_val = 3.1415;
69  int flag = 0;
70 
71  vpParseArgv::vpArgvInfo argTable[] =
72  {
73  {"-flag", vpParseArgv::ARGV_CONSTANT, 0, (char *) &flag,
74  "Flag enabled."},
75  {"-integer", vpParseArgv::ARGV_INT, (char*) NULL, (char *) &i_val,
76  "An integer value."},
77  {"-float", vpParseArgv::ARGV_FLOAT, (char*) NULL, (char *) &f_val,
78  "A float value."},
79  {"-double", vpParseArgv::ARGV_DOUBLE, (char*) NULL, (char *) &d_val,
80  "A double value."},
81  {(char*) NULL, vpParseArgv::ARGV_END, (char*) NULL, (char*) NULL, (char*) NULL}
82  } ;
83 
84  // Read the command line options
85  if(vpParseArgv::parse(&argc, argv, argTable, 0)) {
86  return (-1);
87  }
88 
89  cout << "Your parameters: " << endl;
90  cout << " Integer value: " << i_val << endl;
91  cout << " Float value: " << f_val << endl;
92  cout << " Double value: " << d_val << endl << endl;
93  cout << " Flag : " << flag << endl << endl;
94 
95  cout << "Call " << argv[0]
96  << " -h to see how to change these parameters." << endl;
97 
98  return 0;
99  }
100  catch(vpException e) {
101  std::cout << "Catch a ViSP exception: " << e << std::endl;
102  return 1;
103  }
104 }
105 
106 
107 
108 /*
109  * Local variables:
110  * c-basic-offset: 2
111  * End:
112  */
error that can be emited by ViSP classes.
Definition: vpException.h:73
Command line argument parsing.
Definition: vpParseArgv.h:132