This source file includes following definitions.
- JMMCG_REVISION_CONSTANT
- ProcessParam
- PostProcessConfigFileItems
- Process
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include "core/exception.hpp"
22 #include "core/temp_file.hpp"
23 #include "core/cmd_line_processing.hpp"
24 #include "core/generic_app.hpp"
25
26 #include <ios>
27 #include <iostream>
28
29 JMMCG_REVISION_CONSTANT("$Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/examples/generic_app.cpp 2185 2017-10-13 10:14:17Z jmmcg $")
30
31 struct SomeParams {
32 unsigned long l;
33 jmmcg::tstring s;
34 };
35
36 class Processor : public jmmcg::ConfigFile<SomeParams,jmmcg::crt_exception<jmmcg::ppd::platform_api,jmmcg::ppd::heavyweight_threading> > {
37 public:
38 inline Processor(SomeParams &p)
39 : jmmcg::ConfigFile<SomeParams,jmmcg::crt_exception<jmmcg::ppd::platform_api,jmmcg::ppd::heavyweight_threading> >(p) {
40 }
41 inline ~Processor(void) {
42 }
43
44 Processor(const Processor &)=delete;
45 void operator=(const Processor &)=delete;
46
47 private:
48 inline bool ProcessParam(const unsigned long recognised_param,const jmmcg::tchar * const * const argc,unsigned long &i,jmmcg::tostream &o) {
49 switch (recognised_param) {
50 case 0:
51 o<<_T("Got arg:")<<params[recognised_param].param<<std::endl;
52 prog_opts.l=2;
53 return true;
54 case 1:
55 o<<_T("Got arg:")<<params[recognised_param].param<<std::endl;
56 prog_opts.s=_T("fdafad");
57 return true;
58 default:;
59 }
60 return false;
61 }
62
63 inline bool PostProcessConfigFileItems(const xmlpp::NodeSet &data_items,jmmcg::tostream &) {
64 JMMCG_TRACE(_T("Number of items to process: ")+jmmcg::tostring(data_items.size()));
65 return false;
66 }
67 };
68
69 class TestApp : public jmmcg::AppBase<SomeParams,Processor::exception_t> {
70 public:
71 inline TestApp(SomeParams &sp,const logger_ptr_type &l)
72 : jmmcg::AppBase<SomeParams,Processor::exception_t>(sp,l) {
73 }
74 inline ~TestApp(void) {
75 }
76
77 inline jmmcg::exit_codes __fastcall Process(jmmcg::tostream &o) {
78 jmmcg::temp_file<jmmcg::tfstream,jmmcg::ppd::platform_api,jmmcg::ppd::heavyweight_threading> t;
79
80
81
82 return jmmcg::exit_success;
83 }
84
85 private:
86
87 inline TestApp(const TestApp &) noexcept(true);
88 inline TestApp &operator=(const TestApp &) noexcept(true);
89 };
90
91 const jmmcg::CmdLineParamsData::ParamType jmmcg::CmdLineParamsData::params[]={
92 jmmcg::CmdLineParamsData::ParamType(_T("--param1"),_T("Help for param1.")),
93 jmmcg::CmdLineParamsData::ParamType(_T("--param2"),_T("Help for param2."))
94 };
95 const jmmcg::tchar * const jmmcg::CmdLineParamsData::authors[]={
96 _T("J.M.McGuiness.")
97 };
98 const jmmcg::tchar jmmcg::CmdLineParamsData::version[]=_T("0.1");
99 const jmmcg::tchar jmmcg::CmdLineParamsData::copyright[]=_T("2003. This is free software; see the source for copying conditions.");
100 const jmmcg::tchar jmmcg::CmdLineParamsData::warranty[]=_T("There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
101 const jmmcg::tchar jmmcg::CmdLineParamsData::contact_details[]=_T("http://www.hussar.me.uk");
102 const jmmcg::tchar jmmcg::CmdLineParamsData::help_text[]=_T("My test app.");
103
104 int main(const unsigned int argv, const jmmcg::tchar * const * const argc) {
105 try {
106 SomeParams sp;
107 TestApp::logger_ptr_type logger;
108 {
109 std::auto_ptr<Processor> cmd_line(new Processor(sp));
110 if (!cmd_line->ProcessParams(argv,argc,std::cout)) {
111 return jmmcg::exit_parameter_error;
112 }
113 logger=cmd_line->Log();
114 }
115 TestApp app(sp,logger);
116 return app.Process(std::cerr);
117 } catch (const jmmcg::exception<jmmcg::ppd::platform_api,jmmcg::ppd::heavyweight_threading> &ex) {
118 std::cerr<<ex;
119 return ex.code();
120 } catch (const std::exception &ex) {
121 std::cerr<<_T("STL (or derived) exception caught, details:\n")<<ex.what()<<std::endl;
122 std::cerr<<_T("Other details, not necessarily related to the STL exception caught.\n");
123 std::cerr<<jmmcg::crt_exception<jmmcg::ppd::platform_api,jmmcg::ppd::heavyweight_threading>::dump_crt_errno()<<std::endl;
124 return jmmcg::exit_stl_exception;
125 } catch (...) {
126 std::cerr<<_T("Unknown exception caught...\n");
127 std::cerr<<_T("Other details, not necessarily related to the exception caught.\n");
128 std::cerr<<jmmcg::crt_exception<jmmcg::ppd::platform_api,jmmcg::ppd::heavyweight_threading>::dump_crt_errno()<<std::endl;
129 return jmmcg::exit_unknown_exception;
130 }
131 return jmmcg::exit_unknown_failure;
132 }