Scarab  v2.4.8
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 #include "application.hh"
40 
41 #include "logger.hh"
42 
43 LOGGER( testlog, "test_app_with_callback" );
44 
45 namespace scarab
46 {
47  struct do_a_thing
48  {
49  do_a_thing() : f_value( 5 ) {}
50 
51  void execute( const main_app& an_app )
52  {
53  // configure to run
54  f_value = an_app.master_config().get_value( "value", f_value );
55 
56  // do a thing!
57  LPROG( testlog, "My value is: " << f_value );
58 
59  return;
60  }
61 
62  int f_value;
63  };
64 }
65 
66 
67 using namespace scarab;
68 
69 int main( int argc, char **argv )
70 {
71  main_app the_main;
72 
73  auto t_dat_callback = [&](){
74  do_a_thing t_dat;
75  t_dat.execute( the_main );
76  };
77 
78  the_main.callback( t_dat_callback );
79 
80  CLI11_PARSE( the_main, argc, argv );
81 
82  return 0;
83 }
84 
85 
void execute(const main_app &an_app)
int main(int argc, char **argv)
#define LPROG(...)
Definition: logger.hh:368
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:252