application_base.h

Go to the documentation of this file.
00001 #ifndef APPLICATION_BASE_CLASS
00002 #define APPLICATION_BASE_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : application_base                                                  *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2000-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00019 
00025 #include "opsysdll.h"
00026 
00027 #include <basis/object_base.h>
00028 #include <data_struct/static_memory_gremlin.h>
00029 
00030 // an allowed hierarchy violation.
00031 #include <loggers/file_logger.h>
00032 
00033 class OPSYSTEM_CLASS_STYLE application_base
00034 : public virtual object_base
00035 {
00036 public:
00037   virtual ~application_base();
00038   virtual int execute() = 0;
00040 
00044 };
00045 
00047 
00048 #if 0
00049 
00051 
00058 class example_app_base : public application_base
00059 {
00060 public:
00061   example_app_base() : application_base(static_class_name()) {}
00063 
00064   IMPLEMENT_CLASS_NAME("example_app_base");
00066 
00067   int execute() { /* do stuff and return final exit value. */ }
00068 };
00069 
00071 
00072 int __example__main(int argc, char *argv[])
00073 {
00074   example_app_base root_program;
00075   return root_program.execute();
00076 }
00077 
00079 
00080 int WINAPI __example__WinMain(application_instance instance,
00081      application_instance prev_instance, LPSTR lpCmdLine, int nCmdShow)
00082 {
00083   example_app_base root_program;
00084   return root_program.execute();
00085 }
00086 
00088 
00094 class mfc_example_app_base : public tiny_shell
00095 {
00096 public:
00097   mfc_example_app_base();
00098   int execute() {} 
00099 };
00100 
00102 
00112 HOOPLE_MAIN(example_app_base, (P, D, Q))
00113 
00114 
00115 HOOPLE_MAIN(example_app_base, )
00116 
00117 #endif // example guard.
00118 
00120 
00122 
00126 #ifdef __UNIX__
00127   #define SET_ARGC_ARGV(argc, argv) { \
00128     __argc = argc; \
00129     __argv = argv; \
00130   }
00131 #else
00132   #define SET_ARGC_ARGV(argc, argv) {}
00133     // nothing.
00134 #endif
00135 
00136 // The following versions of main programs are provided for different operating
00137 // systems and compilation environments.  These support the requirements of the
00138 // HOOPLE startup code and program-wide features, assuming an object derived
00139 // from application_base is available.
00140 // The object derived from application_base must be provided in "obj_name".
00141 // The "obj_args" are any arguments that need to be passed to the object's
00142 // constructor; this list can be empty.
00143 // Note that the default logger used for unix and console mode win32 programs
00144 // is the console logger; that can be changed in the startup code for the
00145 // "obj_name".
00146 
00147 #ifdef __WXWIDGETS__
00149 //where'd this go? IMPLEMENT_APP(obj_name); 
00150 
00151   #define HOOPLE_MAIN(obj_name, obj_args) \
00152     HOOPLE_STARTUP_CODE; \
00153     int main(int argc, char *argv[]) { \
00154       SET_ARGC_ARGV(argc, argv); \
00155       SET_DEFAULT_COMBO_LOGGER; \
00156       obj_name root_object obj_args; \
00157       return root_object.execute(); \
00158     }
00159 //in progress
00160 #elif defined(__UNIX__)
00162   #define HOOPLE_MAIN(obj_name, obj_args) \
00163     HOOPLE_STARTUP_CODE; \
00164     int main(int argc, char *argv[]) { \
00165       SET_ARGC_ARGV(argc, argv); \
00166       SET_DEFAULT_COMBO_LOGGER; \
00167       obj_name root_object obj_args; \
00168       return root_object.execute(); \
00169     }
00170 #elif defined(__WIN32__)
00171   // for win32 we need to support four different environments--console mode,
00172   // borland compilation, MFC programs and regular windows programs.
00173   #ifdef _CONSOLE
00175     #define HOOPLE_MAIN(obj_name, obj_args) \
00176       HOOPLE_STARTUP_CODE; \
00177       int main(int argc, char *argv[]) { \
00178         SET_DEFAULT_COMBO_LOGGER; \
00179         obj_name root_object obj_args; \
00180         return root_object.execute(); \
00181       }
00182   #elif defined(_AFXDLL)
00184     #define HOOPLE_MAIN(obj_name, obj_args)  \
00185       HOOPLE_STARTUP_CODE; \
00186       tiny_application<obj_name> theApp;
00187   #elif defined(__WIN32__)
00189     #define HOOPLE_MAIN(obj_name, obj_args)  \
00190       HOOPLE_STARTUP_CODE; \
00191       int WINAPI WinMain(application_instance instance, \
00192           application_instance prev_instance, LPSTR lpCmdLine, \
00193           int nCmdShow) { \
00194         SET_INSTANCE_HANDLE(instance); \
00195         SET_DEFAULT_FILE_LOGGER; \
00196         obj_name root_object obj_args; \
00197         return root_object.execute(); \
00198       }
00199   #endif
00200 #else  // not __UNIX__ or __WIN32__
00202   #define HOOPLE_MAIN(obj_name, obj_args)  \
00203     HOOPLE_STARTUP_CODE; \
00204     int main(int argc, char *argv[]) { \
00205       SET_DEFAULT_CONSOLE_LOGGER; \
00206       obj_name root_object obj_args; \
00207       return root_object.execute(); \
00208     }
00209 #endif
00210 
00211 #endif // outer guard.
00212 

Generated on Fri Sep 5 04:28:47 2008 for HOOPLE Libraries by  doxygen 1.5.1