-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEMApplicationInit.hpp
More file actions
71 lines (55 loc) · 1.54 KB
/
EMApplicationInit.hpp
File metadata and controls
71 lines (55 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef EMApplicationInit_hpp
#define EMApplicationInit_hpp
#include <iostream>
#include <vector>
#include <fstream>
#include "EMApplication.hpp"
#include <boost/program_options.hpp>
namespace PO=boost::program_options;
// Documentation
namespace EM {
class EMApplicationInit {
#define MAXCFG 16
public:
EMApplicationInit(EMApplication &app, int argc, char *argv[]);
virtual ~EMApplicationInit();
int operator()();
PO::options_description commandLineOptions;
PO::options_description options;
PO::positional_options_description positionals;
PO::variables_map map;
protected:
EMApplication &emApp;
int argc;
char **argv;
std::vector<EMApplicationInit *> notifyList;
virtual int init() {return 0;};
void notify(){notifyList.push_back(this);} //must be called by subclass::ctor() if subclass::init() defined/needed
};
} // namespcace EM
// The MACRO MAIN standardises the way Applications are initialised
// and passes control to the application main().
#define MAIN \
static EM_APPLICATION_INIT::InitialisedClass app;\
\
int main(int argc, char *argv[]) { \
try { \
EM_APPLICATION_INIT init(app, argc, argv); \
int i; \
if ( (i=init()) ) {return i;} \
} \
catch (EM::EMApplicationException& e) { \
std::cerr << e.what() << std::endl; \
return EXIT_FAILURE; \
} \
\
try { \
return app.main(); \
} \
catch (EM::EMApplicationException& e) { \
std::cerr << e.what() << std::endl; \
return EXIT_FAILURE; \
} \
return EXIT_SUCCESS; \
}
#endif