Limbo 3.5.4
Loading...
Searching...
No Matches
test_ProgramOptions.cpp
Go to the documentation of this file.
1
7
8#include <iostream>
9#include <string>
10#include <vector>
12using std::cout;
13using std::endl;
14
21int main(int argc, char** argv)
22{
23 using namespace limbo;
24 using namespace limbo::programoptions;
25
26 bool help = false;
27 int i = 0;
28 double fp = 0;
29 std::string str;
30 std::vector<int> vInteger;
31 std::vector<std::string> vString;
32
33 ProgramOptions po ("My options");
34 po.add_option(Value<bool>("-help", &help, "print help message").toggle(true).default_value(false).toggle_value(true).help(true))
35 .add_option(Value<int>("-i", &i, "an integer").default_value(100, "1.0.0"))
36 .add_option(Value<double>("-f", &fp, "a floating point").required(true))
37 .add_option(Value<std::string>("-s", &str, "a string").required(true))
38 .add_option(Value<std::vector<int> >("-vi", &vInteger, "vector of integers"))
39 .add_option(Value<std::vector<std::string> >("-vs", &vString, "vector of string"))
40 ;
41
42 po.print();
43 try
44 {
45 bool flag = po.parse(argc, argv);
46 if (flag)
47 cout << "parsing succeeded\n";
48 }
49 catch (std::exception& e)
50 {
51 cout << "parsing failed\n";
52 cout << e.what() << "\n";
53 }
54
55 cout << "help = " << ((help)? "true" : "false") << endl;
56 cout << "i = " << i << endl;
57 cout << "fp = " << fp << endl;
58 cout << "str = " << str << endl;
59 cout << "vInteger = ";
60 for (std::vector<int>::const_iterator it = vInteger.begin(); it != vInteger.end(); ++it)
61 cout << *it << " ";
62 cout << endl;
63 cout << "vString = ";
64 for (std::vector<std::string>::const_iterator it = vString.begin(); it != vString.end(); ++it)
65 cout << *it << " ";
66 cout << endl;
67
68 limboAssertMsg(help == false, "help turned to true");
69
70 return 0;
71}
#define limboAssertMsg(condition, args...)
custom assertion with message
Definition AssertMsg.h:24
Top API for Limbo.ProgramOptions.
top API to parse program options
bool parse(int argc, char **argv)
read command line options
void print() const
print help message
ProgramOptions & add_option(ValueType const &data)
generic API to add options of various data types
a generic class for various data values
namespace for Limbo.ProgramOptions
namespace for Limbo
int main()