-
Notifications
You must be signed in to change notification settings - Fork 24
/
main.cpp
150 lines (137 loc) · 6.36 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
** Copyright 2007-2024, RTE (https://www.rte-france.com)
** See AUTHORS.txt
** SPDX-License-Identifier: MPL-2.0
** This file is part of Antares-Simulator,
** Adequacy and Performance assessment for interconnected energy networks.
**
** Antares_Simulator is free software: you can redistribute it and/or modify
** it under the terms of the Mozilla Public Licence 2.0 as published by
** the Mozilla Foundation, either version 2 of the License, or
** (at your option) any later version.
**
** Antares_Simulator is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** Mozilla Public Licence 2.0 for more details.
**
** You should have received a copy of the Mozilla Public Licence 2.0
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/
#include <yuni/core/system/suspend.h>
#include <antares/antares/fatal-error.h>
#include <antares/args/args_to_utf8.h>
#include <antares/locale/locale.h>
#include <antares/logs/logs.h>
#include <antares/memory/memory.h>
#include "antares/application/application.h"
using namespace Antares;
namespace
{
const char* const MPL_ANNOUNCEMENT
= "Copyright 2007-2023 RTE - Authors: The Antares_Simulator Team \n"
"\n"
"Antares_Simulator is free software : you can redistribute it and / or modify\n"
"it under the terms of the Mozilla Public Licence 2.0 as published by\n"
"the Mozilla Foundation, either version 2 of the License, or\n"
"(at your option) any later version.\n"
"\n"
"There are special exceptions to the terms and conditions of the\n"
"license as they are applied to this software.View the full text of\n"
"the exceptions in file COPYING.txt in the directory of a distribution\n"
"of this software in source form.\n"
"\n"
"Antares_Simulator is distributed in the hope that it will be useful, \n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the\n"
"Mozilla Public Licence 2.0 for more details.\n"
"\n"
"You should have received a copy of the Mozilla Public Licence 2.0\n"
"along with Antares_Simulator.If not, see <https://opensource.org/license/mpl-2-0/>.\n"
"\n";
const char* const ANTARES_LOGO = "\n\n"
" . = - . \n"
" - % % : \n"
" . . - % # : . . \n"
" . - : - + : . . . . . : + = . \n"
" . = : . = - . : = - - = = + * % % - \n"
" . = - . + : . : * % * = - : : + # * . \n"
" - * . . + : : = + + * - . . - + : . \n"
" . * - - # * + = : . . . : + : \n"
" = # : . # % % = . . = = . \n"
" . * * . : # % % : - + . \n"
" : # * . : + = * + . . = - . \n"
" : % + . = = . : + : : + : \n"
" - % * = = . . = = . . - = . \n"
" - % # + : : + = . . = - . . . \n"
" - % % = . : + = : . : + : . - + : \n"
" : % % - . = + = # % = . . . . . : # @ + . \n"
" . # % + . . : * % % # = = = = + + * # - \n"
" + % % - : # % + - = = - : . . . . \n"
" : # % * . . = + . . . . . \n"
" . + % % + . . = + . . . . \n"
" . * % % + . . # % : . . . \n"
" : # % % * - . . + # : . : : . \n"
" : * % % % * - : . . : + : . - = - . \n"
" . = # % % % # * * * # # # + : . \n"
" . : = * # % % % % # + - . \n"
" . . : : : : : . . \n\n";
constexpr int ALLOCATION_FAILURE_EXIT_CODE = 42;
void logAbortion()
{
if (!logs.logfile())
{
logs.fatal() << "Aborting now. (warning: no file log available)";
logs.warning() << "No log file available";
}
else
{
logs.error() << "Aborting now. See logs for more details";
}
}
} // namespace
/*!
** \brief main
*/
int main(int argc, const char** argv)
{
try
{
logs.info(ANTARES_LOGO);
logs.info(MPL_ANNOUNCEMENT);
// Name of the running application for the logger
logs.applicationName("solver");
if (not memory.initializeTemporaryFolder())
{
throw FatalError("Could not initialize temporary folder");
}
// locale
InitializeDefaultLocale();
// Getting real UTF8 arguments
IntoUTF8ArgsTranslator toUTF8ArgsTranslator(argc, argv);
std::tie(argc, argv) = toUTF8ArgsTranslator.convert();
Antares::Solver::Application application;
application.prepare(argc, argv);
application.execute();
application.writeExectutionInfo();
return EXIT_SUCCESS;
}
catch (const std::bad_alloc& exc)
{
logs.fatal() << exc.what();
logAbortion();
return ALLOCATION_FAILURE_EXIT_CODE;
}
catch (const std::exception& exc)
{
logs.fatal() << exc.what();
logAbortion();
return EXIT_FAILURE;
}
catch (...)
{
logs.fatal() << "An unexpected error occurred.";
logAbortion();
return EXIT_FAILURE;
}
}