libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
generic_app.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2002 by J.M.McGuiness, coder@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 #include "core/exception.hpp"
20 #include "core/temp_file.hpp"
21 #include "core/cmd_line_processing.hpp"
22 #include "core/generic_app.hpp"
23 
24 #include <ios>
25 #include <iostream>
26 
27 using namespace libjmmcg;
28 
30 
31 struct SomeParams {
32  unsigned long l;
34 };
35 
37 public:
38  inline Processor(SomeParams &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 tchar * const * const argc,unsigned long &i,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,tostream &) {
64  JMMCG_TRACE(_T("Number of items to process: ")+tostring(data_items.size()));
65  return false;
66  }
67 };
68 
70 public:
71  inline TestApp(SomeParams &sp,const logger_ptr_type &l)
73  }
74  inline ~TestApp(void) {
75  }
76 
77  inline exit_codes __fastcall Process(tostream &o) {
78  temp_file<tfstream,ppd::platform_api,ppd::heavyweight_threading> t;
79 // chk_dynamic_cast<temp_file<tfstream>,TestApp & >::test(t);
80 // CHK_DYNAMIC_CAST(temp_file<tfstream>,TestApp &,t);
81 // throw exception(_T("testing testing 1,2,3..."), info::FUNCTION(TestApp::Process, info::function::argument(_T("argv"), 1)), __REV_INFO__);
82  return exit_success;
83  }
84 
85 private:
86  // I don't allow copying or assignment.
87  inline TestApp(const TestApp &) noexcept(true);
88  inline TestApp &operator=(const TestApp &) noexcept(true);
89 };
90 
92  CmdLineParamsData::ParamType(_T("--param1"),_T("Help for param1.")),
93  CmdLineParamsData::ParamType(_T("--param2"),_T("Help for param2."))
94 };
95 const tchar * const CmdLineParamsData::authors[]={
96  _T("J.M.McGuiness.")
97 };
98 const tchar CmdLineParamsData::version[]=_T("0.1");
99 const tchar CmdLineParamsData::copyright[]=_T("2003. This is free software; see the source for copying conditions.");
100 const tchar CmdLineParamsData::warranty[]=_T("There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
101 const tchar CmdLineParamsData::contact_details[]=_T("http://www.hussar.me.uk");
102 const tchar CmdLineParamsData::help_text[]=_T("My test app.");
103 
104 int main(const unsigned int argv, const 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 exit_parameter_error;
112  }
113  logger=cmd_line->Log();
114  }
115  TestApp app(sp,logger);
116  return app.Process(std::cerr);
117  } catch (const exception<ppd::platform_api,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<<crt_exception<ppd::platform_api,ppd::heavyweight_threading>::dump_crt_errno()<<std::endl;
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<<crt_exception<ppd::platform_api,ppd::heavyweight_threading>::dump_crt_errno()<<std::endl;
130  }
132 }