xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
startup.h
Go to the documentation of this file.
1 #pragma once
5 
6 #include "environment.h"
7 #include "static.h"
8 #include "system_exception.h"
9 #include "ustring.h"
11 #include "console.h"
12 #if defined(__CMAKE_TARGET_TYPE__) && __CMAKE_TARGET_TYPE__ == 2 // 2 == GUI_APPLICATION
13 #include "xtd/forms/application.h"
15 #endif
16 
18 #if defined(__CMAKE_TARGET_TYPE__) && __CMAKE_TARGET_TYPE__ == 2 // 2 == GUI_APPLICATION
19 inline void __startup_catch_exception__(const std::exception& e) {xtd::forms::application::open_forms().size() > 0 ? xtd::forms::exception_box::show(xtd::forms::application::open_forms()[0].get(), e, xtd::forms::application::product_name()) : xtd::forms::exception_box::show(e, xtd::forms::application::product_name());}
20 inline void __startup_catch_exception__() {xtd::forms::application::open_forms().size() > 0 ? xtd::forms::exception_box::show(xtd::forms::application::open_forms()[0].get(), xtd::forms::application::product_name()) : xtd::forms::exception_box::show(xtd::forms::application::product_name());}
21 #else
22 inline void __startup_catch_exception__(const std::exception& e) {std::cerr << std::endl << xtd::ustring::format("Unhandled exception: {}", e.what()) << std::endl;}
23 inline void __startup_catch_exception__(const xtd::system_exception& e) { std::cerr << std::endl << xtd::ustring::format("Unhandled exception: {}", e) << std::endl;}
24 inline void __startup_catch_exception__() { std::cerr << std::endl << xtd::ustring::format("Unhandled exception: Unknown exception occurred") << std::endl;}
25 #endif
27 
29 namespace xtd {
49  #define startup_(main_class) \
50  int main(int argc, char* argv[]) {\
51  try {\
52  struct startup final static_ {\
53  static int run(void (*main_function)(), int, char*[]) {main_function(); return xtd::environment::exit_code();}\
54  static int run(int (*main_function)(), int, char*[]) {return main_function();}\
55  static int run(void (*main_function)(int argc, char* argv[]), int argc, char* argv[]) {main_function(argc, argv); return xtd::environment::exit_code();}\
56  static int run(void (*main_function)(xtd::collections::specialized::string_vector), int argc, char* argv[]) {main_function({argv + 1, argv + argc}); return xtd::environment::exit_code();}\
57  static int run(void (*main_function)(const xtd::collections::specialized::string_vector&), int argc, char* argv[]) {main_function({argv + 1, argv + argc}); return xtd::environment::exit_code();}\
58  static int run(int (*main_function)(int argc, char* argv[]), int argc, char* argv[]) {return main_function(argc, argv);}\
59  static int run(int (*main_function)(xtd::collections::specialized::string_vector), int argc, char* argv[]) {return main_function({argv + 1, argv + argc});}\
60  static int run(int (*main_function)(const xtd::collections::specialized::string_vector&), int argc, char* argv[]) {return main_function({argv + 1, argv + argc});}\
61  };\
62  return startup::run(main_class::main, argc, argv);\
63  } catch(const xtd::system_exception& e) {\
64  __startup_catch_exception__(e);\
65  } catch(const std::exception& e) {\
66  __startup_catch_exception__(e);\
67  } catch(...) {\
68  __startup_catch_exception__();\
69  }\
70  }\
71  int __startup_force_to_end_with_semicolon__ = 0
72 }
Contains xtd::forms::application class.
static const form_collection open_forms()
Gets a collection of open forms owned by the application.
static xtd::ustring product_name()
Gets the product name associated with this application.
static dialog_result show()
Displays a exception box. The exception box displays an unknown exception.
Definition: exception_box.h:46
Defines the base class for predefined exceptions in the xtd namespace.
Definition: system_exception.h:24
Contains xtd::console class.
Contains xtd::environment class.
Contains xtd::forms::exception_box dialog.
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:689
@ e
The E key.
@ show
Display the hot-key prefix.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::static_object class.
Contains xtd::collections::specialized::string_vector typedef.
Contains xtd::system_exception exception.
Contains xtd::ustring class.