1 #ifndef HOOPLE_MAIN_GROUP
2 #define HOOPLE_MAIN_GROUP
4 /*****************************************************************************\
6 * Name : HOOPLE_MAIN group
7 * Author : Chris Koeritz
9 *******************************************************************************
10 * Copyright (c) 2000-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 //! @file "hoople_main.h" Provides macros that implement the 'main' program of an application.
20 #include "application_shell.h"
21 #include "command_line.h"
22 #include "windoze_helper.h"
24 #include <basis/contracts.h>
25 #include <loggers/critical_events.h>
26 #include <loggers/combo_logger.h>
27 #include <structures/static_memory_gremlin.h>
28 #include <loggers/program_wide_logger.h>
30 namespace application {
32 // The following versions of main programs are provided for different operating
33 // systems and compilation environments. These support the requirements of the
34 // HOOPLE startup code and program-wide features, assuming an object derived
35 // from base_application is available.
36 // The object derived from base_application must be provided in "obj_name".
37 // The "obj_args" are any arguments that need to be passed to the object's
38 // constructor; this list can be empty.
39 // Note that the default logger used for unix and console mode win32 programs
40 // is the console logger; that can be changed in the startup code for the
43 #define HOOPLE_STARTUP_CODE \
44 DEFINE_INSTANCE_HANDLE;
47 //! main program for applications using WxWidgets library.
48 #define HOOPLE_MAIN(obj_name, obj_args) \
49 HOOPLE_STARTUP_CODE; \
50 int main(int argc, char *argv[]) { \
51 SET_ARGC_ARGV(argc, argv); \
53 obj_name to_run_obj obj_args; \
54 return to_run_obj.execute_application(); \
59 #elif defined(__UNIX__) || defined(__GNU_WINDOWS__)
60 //! options that should work for most unix and linux apps.
61 #define HOOPLE_MAIN(obj_name, obj_args) \
62 HOOPLE_STARTUP_CODE; \
63 int main(int argc, char *argv[]) { \
64 SET_ARGC_ARGV(argc, argv); \
66 obj_name to_run_obj obj_args; \
67 return to_run_obj.execute_application(); \
72 #elif defined(_MSC_VER)
73 // for win32 we need to support four different environments--console mode,
74 // borland compilation, MFC programs and regular windows programs.
76 //! console mode programs can easily write to a command shell.
77 #define HOOPLE_MAIN(obj_name, obj_args) \
78 HOOPLE_STARTUP_CODE; \
79 int main(int argc, char *argv[]) { \
80 SET_ARGC_ARGV(argc, argv); \
82 obj_name to_run_obj obj_args; \
83 return to_run_obj.execute_application(); \
85 #elif defined(_AFXDLL)
86 //! MFC applications generally use a tiny shell which hooks up logging.
87 #define HOOPLE_MAIN(obj_name, obj_args) \
88 HOOPLE_STARTUP_CODE; \
89 SET_ARGC_ARGV(__argc, __argv); \
90 tiny_application<obj_name> theApp;
91 #elif defined(__WIN32__)
92 //! standard win32 applications have no console, so we just log to a file.
93 #define HOOPLE_MAIN(obj_name, obj_args) \
94 HOOPLE_STARTUP_CODE; \
95 int WINAPI WinMain(application_instance instance, \
96 application_instance prev_instance, LPSTR lpCmdLine, \
98 SET_ARGC_ARGV(__argc, __argv); \
99 SET_INSTANCE_HANDLE(instance); \
101 obj_name to_run_obj obj_args; \
102 return to_run_obj.execute_application(); \
108 #else // not __UNIX__ or __WIN32__
109 //! just guessing this might work; otherwise we have no idea.
110 #define HOOPLE_MAIN(obj_name, obj_args) \
111 HOOPLE_STARTUP_CODE; \
112 int main(int argc, char *argv[]) { \
113 SETUP_CONSOLE_LOGGER; \
114 obj_name to_run_obj obj_args; \
115 return to_run_obj.execute_application(); \
121 #endif // outer guard.