-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
83 lines (68 loc) · 2.28 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* LC_NOTICE_BEGIN
===============================================================================
| Copyright (C) 2021 Luca Ciucci |
|-----------------------------------------------------------------------------|
| Important notices: |
| - This work is distributed under the MIT license, feel free to use this |
| work as you wish. |
| - Read the license file for further info. |
| Written by Luca Ciucci <[email protected]>, 2021 |
===============================================================================
LC_NOTICE_END */
#include <iostream>
#include <iostream>
#include <stdexcept>
#include "main_functions.hpp"
namespace
{
int safe_main(int argc, char** argv);
}
int main(int argc, char** argv)
{
try
{
return safe_main(argc, argv);
}
catch (const std::exception& e)
{
std::cerr << "Uncaught Exception thrown from safe_main(): " << e.what() << std::endl;
}
catch (...)
{
std::cerr << "Uncaught Unknown Exception thrown from safe_main()" << std::endl;
}
return EXIT_FAILURE;
}
// ================================================================
// EXECUTION
// ================================================================
namespace
{
int safe_main(int argc, char** argv)
{
std::cout << "Hello There!" << std::endl;
auto examples = examples_ns::getExamples();
std::cout << "Examples list:" << std::endl;
for (size_t i = 0; i < examples.size(); i++)
std::cout << " - example #" << (i + 1) << ": \"" << examples[i].name << "\"" << std::endl;
std::cout << "Example to run? (0 to exit)" << std::endl;
size_t i = 0;
std::cin >> i;
if (i == 0)
return EXIT_SUCCESS;
i--;
// TODO check out of bound
const auto& ex = examples[i];
std::cout << "running example \"" << ex.name << "\"..." << std::endl;
try
{
auto r = ex.main();
std::cout << "\nThe example finished with exit code " << r << std::endl;
}
catch (const std::exception& e)
{
std::cout << "An exception of type \"" << typeid(e).name() << "\" occurred when running the example : " << e.what() << std::endl;
}
return EXIT_SUCCESS;
}
}