Limbo
3.5.4
Toggle main menu visibility
Loading...
Searching...
No Matches
test
programoptions
test_ProgramOptions.cpp
Go to the documentation of this file.
1
7
8
#include <iostream>
9
#include <string>
10
#include <vector>
11
#include <
limbo/programoptions/ProgramOptions.h
>
12
using
std::cout;
13
using
std::endl;
14
21
int
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
}
limboAssertMsg
#define limboAssertMsg(condition, args...)
custom assertion with message
Definition
AssertMsg.h:24
ProgramOptions.h
Top API for Limbo.ProgramOptions.
limbo::programoptions::ProgramOptions
top API to parse program options
Definition
ProgramOptions.h:458
limbo::programoptions::ProgramOptions::parse
bool parse(int argc, char **argv)
read command line options
limbo::programoptions::ProgramOptions::print
void print() const
print help message
Definition
ProgramOptions.h:500
limbo::programoptions::ProgramOptions::add_option
ProgramOptions & add_option(ValueType const &data)
generic API to add options of various data types
Definition
ProgramOptions.h:537
limbo::programoptions::Value
a generic class for various data values
Definition
ProgramOptions.h:218
limbo::programoptions
namespace for Limbo.ProgramOptions
Definition
ConversionHelpers.h:24
limbo
namespace for Limbo
Definition
GraphUtility.h:23
main
int main()
Definition
test_ChromaticNumber.cpp:78
Generated on
for Limbo by
1.17.0