root/examples/generic_app.cpp

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. JMMCG_REVISION_CONSTANT
  2. ProcessParam
  3. PostProcessConfigFileItems
  4. Process
  5. main

   1 /******************************************************************************
   2 ** $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 $
   3 ** 
   4 ** Copyright (C) 2002 by J.M.McGuiness, coder@hussar.me.uk
   5 **
   6 ** This library is free software; you can redistribute it and/or
   7 ** modify it under the terms of the GNU Lesser General Public
   8 ** License as published by the Free Software Foundation; either
   9 ** version 2.1 of the License, or (at your option) any later version.
  10 **
  11 ** This library is distributed in the hope that it will be useful,
  12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14 ** Lesser General Public License for more details.
  15 **
  16 ** You should have received a copy of the GNU Lesser General Public
  17 ** License along with this library; if not, write to the Free Software
  18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  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 //              jmmcg::chk_dynamic_cast<jmmcg::temp_file<jmmcg::tfstream>,TestApp & >::test(t);
  80 //              CHK_DYNAMIC_CAST(jmmcg::temp_file<jmmcg::tfstream>,TestApp &,t);
  81 //              throw jmmcg::exception(_T("testing testing 1,2,3..."), jmmcg::info::FUNCTION(TestApp::Process, jmmcg::info::function::argument(_T("argv"), 1)), __REV_INFO__);
  82                 return jmmcg::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 
  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 }

/* [<][>][^][v][top][bottom][index][help] */