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(); \
74 #elif defined(_MSC_VER)
75 // for win32 we need to support four different environments--console mode,
76 // borland compilation, MFC programs and regular windows programs.
78 //! console mode programs can easily write to a command shell.
79 #define HOOPLE_MAIN(obj_name, obj_args) \
80 HOOPLE_STARTUP_CODE; \
81 int main(int argc, char *argv[]) { \
82 SET_ARGC_ARGV(argc, argv); \
84 obj_name to_run_obj obj_args; \
85 return to_run_obj.execute_application(); \
87 #elif defined(_AFXDLL)
88 //! MFC applications generally use a tiny shell which hooks up logging.
89 #define HOOPLE_MAIN(obj_name, obj_args) \
90 HOOPLE_STARTUP_CODE; \
91 SET_ARGC_ARGV(__argc, __argv); \
92 tiny_application<obj_name> theApp;
93 #elif defined(__WIN32__)
94 //! standard win32 applications have no console, so we just log to a file.
95 #define HOOPLE_MAIN(obj_name, obj_args) \
96 HOOPLE_STARTUP_CODE; \
97 int WINAPI WinMain(application_instance instance, \
98 application_instance prev_instance, LPSTR lpCmdLine, \
100 SET_ARGC_ARGV(__argc, __argv); \
101 SET_INSTANCE_HANDLE(instance); \
103 obj_name to_run_obj obj_args; \
104 return to_run_obj.execute_application(); \
111 #else // not __UNIX__ or __WIN32__
112 //! just guessing this might work; otherwise we have no idea.
113 #define HOOPLE_MAIN(obj_name, obj_args) \
114 HOOPLE_STARTUP_CODE; \
115 int main(int argc, char *argv[]) { \
116 SETUP_CONSOLE_LOGGER; \
117 obj_name to_run_obj obj_args; \
118 return to_run_obj.execute_application(); \
124 #endif // outer guard.