Scarab  v2.4.3
Project 8 C++ Utility Library
test_app_with_callback.cc
Go to the documentation of this file.
1 /*
2  * test_app_with_callback.cc
3  *
4  * Created on: Jul 24, 2018
5  * Author: N.S. Oblath
6  * Output examples:
7  *
8 > bin/test_app_with_callback
9 2018-07-24 11:40:07 [ PROG] (tid 0x7fff9c9dc380) i/application.cc(92): Final configuration:
10 
11 {
12 }
13 
14 2018-07-24 11:40:07 [ PROG] (tid 0x7fff9c9dc380) i/application.cc(93): Ordered args:
15 
16 [
17 ]
18 
19 2018-07-24 11:40:07 [ PROG] (tid 0x7fff9c9dc380) with_callback.cc(27): My value is: 5
20 
21 
22 > bin/test_app_with_callback value=10
23 
24 2018-07-24 11:40:49 [ PROG] (tid 0x7fff9c9dc380) i/application.cc(92): Final configuration:
25 
26 {
27  value : 10
28 }
29 
30 2018-07-24 11:40:49 [ PROG] (tid 0x7fff9c9dc380) i/application.cc(93): Ordered args:
31 
32 [
33 ]
34 
35 2018-07-24 11:40:49 [ PROG] (tid 0x7fff9c9dc380) with_callback.cc(27): My value is: 10
36  *
37  */
38 
39 
40 #include "application.hh"
41 
42 #include "logger.hh"
43 
44 LOGGER( testlog, "test_app_with_callback" );
45 
46 namespace scarab
47 {
48  struct do_a_thing
49  {
50  do_a_thing() : f_value( 5 ) {}
51 
52  void execute( const main_app& an_app )
53  {
54  // configure to run
55  f_value = an_app.master_config().get_value( "value", f_value );
56 
57  // do a thing!
58  LPROG( testlog, "My value is: " << f_value );
59 
60  return;
61  }
62 
63  int f_value;
64  };
65 }
66 
67 
68 using namespace scarab;
69 
70 int main( int argc, char **argv )
71 {
72  main_app the_main;
73 
74  auto t_dat_callback = [&](){
75  do_a_thing t_dat;
76  t_dat.execute( the_main );
77  };
78 
79  the_main.callback( t_dat_callback );
80 
81  CLI11_PARSE( the_main, argc, argv );
82 
83  return 0;
84 }
85 
86 
void execute(const main_app &an_app)
int main(int argc, char **argv)
#define LPROG(...)
Definition: logger.hh:363
LOGGER(testlog, "test_app_with_callback")
Contains the logger class and macros, based on Kasper&#39;s KLogger class.
Primary application class.
Definition: application.hh:247