Scarab
v2.4.4
Project 8 C++ Utility Library
library
test
test_app_with_options.cc
Go to the documentation of this file.
1
/*
2
* test_app_with_options.cc
3
*
4
* Created on: Oct 28, 2018
5
* Author: N.S. Oblath
6
*
7
* Output examples:
8
*
9
> bin/test_app_with_options -f 5 -s "hello" -t "world"
10
2018-10-29 11:15:20 [ PROG] (tid 0x7fffb0945380) i/application.cc(97): Final configuration:
11
12
{
13
third-value : world
14
}
15
16
2018-10-29 11:15:20 [ PROG] (tid 0x7fffb0945380) i/application.cc(98): Ordered args:
17
18
[
19
]
20
21
2018-10-29 11:15:20 [ PROG] (tid 0x7fffb0945380) _with_options.cc(69): First value: 5
22
2018-10-29 11:15:20 [ PROG] (tid 0x7fffb0945380) _with_options.cc(70): Second value: hello
23
2018-10-29 11:15:20 [ PROG] (tid 0x7fffb0945380) _with_options.cc(71): Third value: world
24
*
25
*/
26
27
#include "
application.hh
"
28
29
#include "
logger.hh
"
30
31
using namespace
scarab
;
32
33
LOGGER
( testlog,
"test_app_with_options"
);
34
35
class
test_app
:
public
main_app
36
{
37
public
:
38
test_app
() :
39
main_app
(),
40
f_first_value(),
41
f_second_value()
42
{
43
// Add an option that sets the value directly
44
add_option(
"-f,--first-value"
, f_first_value,
"Set the first value"
);
45
46
// Add an option that sets the value via callback
47
add_option(
"-s,--second-value"
, [
this
](std::vector< std::string > args) { f_second_value = args[0];
return
true
; },
"Set the second value"
);
48
49
// Add an option that sets the value into the configuration via callback
50
add_option(
"-t,--third-value"
, [
this
](std::vector< std::string > args) { f_master_config.add(
"third-value"
, args[0] );
return
true
; },
"Set the third value"
);
51
}
52
virtual
~test_app
() {}
53
54
void
set_first_value
(
int
a_value ) { f_first_value = a_value; }
55
int
get_first_value
() {
return
f_first_value; }
56
57
const
std::string&
second_value
()
const
{
return
f_second_value; }
58
std::string&
second_value
() {
return
f_second_value; }
59
60
private
:
61
int
f_first_value
;
62
std::string
f_second_value
;
63
};
64
65
int
main
(
int
argc,
char
**argv )
66
{
67
test_app
the_main;
68
69
CLI11_PARSE( the_main, argc, argv );
70
71
LPROG
( testlog,
"First value: "
<< the_main.
get_first_value
() );
72
LPROG
( testlog,
"Second value: "
<< the_main.
second_value
() );
73
LPROG
( testlog,
"Third value: "
<< the_main.master_config()[
"third-value"
]() );
74
75
return
0;
76
}
test_app::f_second_value
std::string f_second_value
Definition:
test_app_with_options.cc:62
test_app::second_value
const std::string & second_value() const
Definition:
test_app_with_options.cc:57
test_app::second_value
std::string & second_value()
Definition:
test_app_with_options.cc:58
scarab::LOGGER
LOGGER(mtlog, "authentication")
LPROG
#define LPROG(...)
Definition:
logger.hh:363
scarab
Definition:
authentication.cc:18
main
int main(int argc, char **argv)
Definition:
test_app_with_options.cc:65
logger.hh
Contains the logger class and macros, based on Kasper's KLogger class.
test_app
Definition:
test_app_with_options.cc:35
test_app::~test_app
virtual ~test_app()
Definition:
test_app_with_options.cc:52
test_app::set_first_value
void set_first_value(int a_value)
Definition:
test_app_with_options.cc:54
application.hh
test_app::get_first_value
int get_first_value()
Definition:
test_app_with_options.cc:55
scarab::main_app
Primary application class.
Definition:
application.hh:247
test_app::test_app
test_app()
Definition:
test_app_with_options.cc:38
test_app::f_first_value
int f_first_value
Definition:
test_app_with_options.cc:61
Generated by
1.8.13