xtd 0.2.0
Loading...
Searching...
No Matches
startup.hpp
Go to the documentation of this file.
1
4#pragma once
6#include "core_export.hpp"
7#include "delegate.hpp"
8#include "optional.hpp"
9#include "static.hpp"
10#include <exception>
11#define __XTD_CORE_INTERNAL__
13#undef __XTD_CORE_INTERNAL__
14
16namespace xtd {
24 public:
26
46 template <typename main_function_t>
47 static int safe_run(main_function_t main_function) {
48 return internal_safe_run(main_function, std::nullopt, std::nullopt);
49 }
50
71 template <typename main_function_t>
72 static int safe_run(main_function_t main_function, int argc, char* argv[]) {
73 return internal_safe_run(main_function, argc, argv);
74 }
76
78 static int safe_run(xtd::delegate<void()> main_function, int argc, char* argv[]);
79 static int safe_run(xtd::delegate<void()> main_function);
80 static int safe_run(xtd::delegate<void(int, char* [])> main_function, int argc, char* argv[]);
81 static int safe_run(xtd::delegate<void(int, char* [])> main_function);
82 static int safe_run(xtd::delegate<void(const xtd::argument_collection&)> main_function, int argc, char* argv[]);
83 static int safe_run(xtd::delegate<void(const xtd::argument_collection&)> main_function);
84 static int safe_run(xtd::delegate<int()> main_function, int argc, char* argv[]);
85 static int safe_run(xtd::delegate<int()> main_function);
86 static int safe_run(xtd::delegate<int(int, char* [])> main_function, int argc, char* argv[]);
87 static int safe_run(xtd::delegate<int(int, char* [])> main_function);
88 static int safe_run(xtd::delegate<int(const xtd::argument_collection&)> main_function, int argc, char* argv[]);
89 static int safe_run(xtd::delegate<int(const xtd::argument_collection&)> main_function);
90 static int safe_run(void (*main_function)(int, char* []), int argc, char* argv[]);
91 static int safe_run(void (*main_function)(int, char* []));
92 static int safe_run(void (*main_function)(const xtd::argument_collection&), int argc, char* argv[]);
93 static int safe_run(void (*main_function)(const xtd::argument_collection&));
94 static int safe_run(int (*main_function)(int, char* []), int argc, char* argv[]);
95 static int safe_run(int (*main_function)(int, char* []));
96 static int safe_run(int (*main_function)(const xtd::argument_collection&), int argc, char* argv[]);
97 static int safe_run(int (*main_function)(const xtd::argument_collection&));
99
100 private:
101 template <typename main_function_t>
102 static int internal_safe_run(main_function_t main_function, std::optional<int> argc, std::optional<char**> argv) {
103 try {
104 init_safe_run();
105 auto exit_code = argc == std::nullopt && argv == std::nullopt ? run(main_function) : run(main_function, argc.value(), argv.value());
106 end_safe_run();
107 return exit_code;
108 } catch(const std::exception& e) {
109 __show_generic_exception_message__(e);
110 return EXIT_FAILURE;
111 } catch(...) {\
112 __show_generic_exception_message__();
113 return EXIT_FAILURE;
114 }
115 }
116
117 static void init_safe_run();
118
119 static void end_safe_run();
120
121 static int run(xtd::delegate<void()> main_function, int argc, char* argv[]);
122 static int run(xtd::delegate<void()> main_function);
123 static int run(void (*main_function)(), int argc, char* argv[]);
124 static int run(void (*main_function)());
125 static int run(xtd::delegate<void(int, char* [])> main_function, int argc, char* argv[]);
126 static int run(xtd::delegate<void(int, char* [])> main_function);
127 static int run(void (*main_function)(int, char* []), int argc, char* argv[]);
128 static int run(void (*main_function)(int, char* []));
129 static int run(xtd::delegate<void(const xtd::argument_collection&)> main_function, int argc, char* argv[]);
130 static int run(xtd::delegate<void(const xtd::argument_collection&)> main_function);
131 static int run(void (*main_function)(const xtd::argument_collection&), int argc, char* argv[]);
132 static int run(void (*main_function)(const xtd::argument_collection&));
133 static int run(xtd::delegate<void(const std::vector<string>&)> main_function, int argc, char* argv[]);
134 static int run(xtd::delegate<void(const std::vector<string>&)> main_function);
135 static int run(void (*main_function)(const std::vector<string>&), int argc, char* argv[]);
136 static int run(void (*main_function)(const std::vector<string>&));
137 static int run(xtd::delegate<int()> main_function, int argc, char* argv[]);
138 static int run(xtd::delegate<int()> main_function);
139 static int run(int (*main_function)(), int argc, char* argv[]);
140 static int run(int (*main_function)());
141 static int run(xtd::delegate<int(int, char* [])> main_function, int argc, char* argv[]);
142 static int run(xtd::delegate<int(int, char* [])> main_function);
143 static int run(int (*main_function)(int, char* []), int argc, char* argv[]);
144 static int run(int (*main_function)(int, char* []));
145 static int run(xtd::delegate<int(const xtd::argument_collection&)> main_function, int argc, char* argv[]);
146 static int run(xtd::delegate<int(const xtd::argument_collection&)> main_function);
147 static int run(int (*main_function)(const xtd::argument_collection&), int argc, char* argv[]);
148 static int run(int (*main_function)(const xtd::argument_collection&));
149 static int run(xtd::delegate<int(const std::vector<string>&)> main_function, int argc, char* argv[]);
150 static int run(xtd::delegate<int(const std::vector<string>&)> main_function);
151 static int run(int (*main_function)(const std::vector<string>&), int argc, char* argv[]);
152 static int run(int (*main_function)(const std::vector<string>&));
153 };
154}
155
175#define startup_(main_method) \
176 auto main(int argc, char* argv[]) -> int { \
177 return xtd::startup::safe_run(main_method, argc, argv); \
178 } \
179 intptr_t __opaque_sftews__ = 0 // force to end with semicolon
180
188#define startup_class_(main_class) \
189 auto main(int argc, char* argv[]) -> int { \
190 return xtd::startup::safe_run(main_class::main, argc, argv); \
191 } \
192 intptr_t __opaque_sftews__ = 0 // force to end with semicolon
Contains show_generic_exception_message methods.
Contains xtd::argument_collection alias.
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:71
Defines the xtd::startup object that can be used in the main method to safely call the application's ...
Definition startup.hpp:23
static int safe_run(main_function_t main_function, int argc, char *argv[])
Safely call the specified application's main entry point, argc and argv.
Definition startup.hpp:72
static int safe_run(main_function_t main_function)
Safely call the specified application's main entry point.
Definition startup.hpp:47
Contains core_export_ keyword.
Contains xtd::delegate delegate.
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
#define core_export_
Define shared library export.
Definition core_export.hpp:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::optional type.
Contains xtd::static_object class.