Limbo 3.5.4
Loading...
Searching...
No Matches
test_ProgramOptions_simple.cpp
Go to the documentation of this file.
1
7
8#include <iostream>
9#include <string>
10#include <vector>
12
19int main(int argc, char** argv)
20{
21 bool help = false;
22 int i = 0;
23 double fp = 0;
24 std::vector<int> vInteger;
25
28 po_type desc ("My options");
29 // add user-defined options
30 desc.add_option(Value<bool>("-help", &help, "print help message").toggle(true).default_value(false).toggle_value(true).help(true)) // specify help option
31 .add_option(Value<int>("-i", &i, "an integer").default_value(100, "1.0.0"))
32 .add_option(Value<double>("-f", &fp, "a floating point").required(true)) // the floating point option is a required option, so user must provide it
33 .add_option(Value<std::vector<int> >("-vi", &vInteger, "vector of integers"))
34 ;
35
36 try
37 {
38 bool flag = desc.parse(argc, argv);
39 if (flag)
40 std::cout << "parsing succeeded\n";
41 }
42 catch (std::exception& e)
43 {
44 std::cout << "parsing failed\n";
45 std::cout << e.what() << "\n";
46 }
47
48 // print help message
49 if (help)
50 {
51 std::cout << desc << "\n";
52 return 1;
53 }
54
55 std::cout << "help = " << ((help)? "true" : "false") << std::endl;
56 std::cout << "i = " << i << std::endl;
57 std::cout << "fp = " << fp << std::endl;
58 std::cout << "vInteger = ";
59 for (std::vector<int>::const_iterator it = vInteger.begin(); it != vInteger.end(); ++it)
60 std::cout << *it << " ";
61 std::cout << std::endl;
62
63 return 0;
64}
Top API for Limbo.ProgramOptions.
top API to parse program options
a generic class for various data values
int main()