forked from degauden/Elements
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgramManager.h
More file actions
299 lines (254 loc) · 7.96 KB
/
Copy pathProgramManager.h
File metadata and controls
299 lines (254 loc) · 7.96 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/**
* @file ProgramManager.h
*
* Created on: Jan 7, 2015
* Author: Pierre Dubath
*
* @copyright 2012-2020 Euclid Science Ground Segment
*
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option)
* any later version.
*
* This library 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 GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @addtogroup ElementsKernel ElementsKernel
* @{
*/
#ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_PROGRAMMANAGER_H_
#define ELEMENTSKERNEL_ELEMENTSKERNEL_PROGRAMMANAGER_H_
#include <memory> // for allocator, unique_ptr
#include <string> // for string, basic_string
#include <vector> // for vector
#include <log4cpp/Priority.hh> // for Priority, Priority::DEBUG
#include "ElementsKernel/Environment.h" // for Environment
#include "ElementsKernel/Export.h" // for ELEMENTS_API
#include "ElementsKernel/Path.h" // for Item
#include "ElementsKernel/Program.h" // IWYU pragma: keep
namespace Elements {
enum class ExitCode : int;
}
namespace boost::program_options {
template <class charT>
class basic_parsed_options;
}
namespace Elements {
/**
* @class ProgramManager
* @ingroup ElementsKernel
* @brief
* Class for managing all Elements programs
* @details
* This base class offers solutions for the common needs of
* all Elements programs, such as those dealing with program
* options and logging.
*/
class ELEMENTS_API ProgramManager {
public:
/**
* @brief Constructor
*/
explicit ProgramManager(std::unique_ptr<Program> program_ptr, const std::string& parent_project_version = "",
const std::string& parent_project_name = "",
const std::string& parent_project_vcs_version = "",
const std::string& parent_module_version = "", const std::string& parent_module_name = "",
const std::vector<std::string>& search_dirs = {},
const log4cpp::Priority::Value& elements_loglevel = log4cpp::Priority::DEBUG,
bool no_config_file = false, bool no_default_conf = false);
/**
* @brief Destructor
*/
virtual ~ProgramManager();
/**
* @brief This is the public entry point,
* i.e., the only method called from the main
*
* @param argc
* Command line argument number
* @param argv
* Command line arguments
*/
ExitCode run(int argc, char* argv[]);
/**
* @brief This function returns the version of the program
* computed at compile time. This is the same as the project
* version that contains the program
*/
std::string getVersion() const;
/**
* @brief This is the set_terminate handler
* that is used in the #MAIN_FOR macro.
*/
static void onTerminate() noexcept;
private:
/**
* @brief Getter
*
* @return
* The program path
*/
const Path::Item& getProgramPath() const;
/**
* @brief Getter
*
* @return
* The program name
*/
const Path::Item& getProgramName() const;
/**
* @brief
* Get a default configuration file name and path, to be used if not
* provided as a command line option
*
* @return
* A complete name/path to the default configuration file
*/
static Path::Item getDefaultConfigFile(const Path::Item& program_name, const std::string& module_name = "");
/**
* @brief
* Strip the path from argv[0] to set the program name
* @param arg0
* The first element of the command line, i.e., argv[0]
* @return
* A BOOST path with the program name
*/
static Path::Item setProgramName(char* arg0);
/**
* @brief
* Strip the name from argv[0] to set the program path
* @param arg0
* The first element of the command line, i.e., argv[0]
* @return
* A BOOST path with the program path
*/
static Path::Item setProgramPath(char* arg0);
/**
* @brief
* Program setup taking care of command line options and logging
* initialization
*/
void setup(int argc, char* argv[]);
void tearDown(const ExitCode&) const;
/**
* @brief Get the program options from the command line
* into thevariables_map
*
* @return
* A BOOST variable_map
*/
Program::VariablesMap getProgramOptions(int argc, char* argv[]);
/**
* @brief Log Header
*/
void logHeader(const std::string& program_name) const;
/**
* @brief Log Footer
*/
void logFooter(const std::string& program_name) const;
/**
* @brief Log all program options
*
*/
void logAllOptions() const;
/**
* @brief Log the program environment
*/
void logTheEnvironment() const;
/**
* @brief Bootstrap the Environment
* from the executable location and the
* install path computed at install time.
*/
void bootstrapEnvironment(char* arg0);
/**
* @brief check the explicit command line arguments.
* For the moment, it only checks if the configuration
* file being passed does exist. It exits with ExitCode::CONFIG
* if the file cannot be found.
*/
template <class charT>
void checkCommandLineOptions(const boost::program_options::basic_parsed_options<charT>& cmd_line_options);
private:
/**
* This is the BOOST program options variable_map used to store all
* program options. It is similar to a std::map but the element can be
* of different types. See the pseudoMain() in ElementsExamples/src/program/Program.cpp
* to see how to retrieve options from this map.
*/
Program::VariablesMap m_variables_map{};
/**
* Name of the executable (from argv[0])
*/
Path::Item m_program_name;
/**
* Path of the executable (from argv[0])
*/
Path::Item m_program_path;
/**
* Pointer to a program interface, which provides two methods
* defineSpecificProgramOption()
* mainMethod()
*
*/
std::unique_ptr<Program> m_program_ptr;
/**
* Internal version of the project
*/
std::string m_parent_project_version;
/**
* Name of the parent project. To avoid ambiguities and because a module
* can be moved from one project to another, the full version of the
* program will look like
*
* m_parent_project_version [m_parent_project_name]
*/
std::string m_parent_project_name;
/**
* Internal version of the program. By convention, it is the same
* as the VCS version of the parent project
*/
std::string m_parent_project_vcs_version;
/**
* Version of the parent Elements module
*/
std::string m_parent_module_version;
/**
* Name of the parent project.
*/
std::string m_parent_module_name;
/**
* List of directories needed to update the runtime search
* environment (PATH, LD_LIBRARY_PATH, ELEMENTS_CONF_PATH,
* and ELEMENTS_AUX_PATH). This list contains the install
* locations of all the dependent projects.
*/
std::vector<std::string> m_search_dirs;
/**
* Local environment of the executable
*/
Environment m_env;
/**
* default info level for the Elements internal logging messages
*/
log4cpp::Priority::Value m_elements_loglevel;
/**
* prevent the --config-file option to be added
*/
bool m_no_config_file;
/**
* prevent the location of default configuration files
*/
bool m_no_default_conf;
};
} // namespace Elements
#define ELEMENTSKERNEL_ELEMENTSKERNEL_PROGRAM_MANAGER_IMPL_
#include "ElementsKernel/_impl/ProgramManager.tpp" // IWYU pragma: export
#undef ELEMENTSKERNEL_ELEMENTSKERNEL_PROGRAM_MANAGER_IMPL_
#endif // ELEMENTSKERNEL_ELEMENTSKERNEL_PROGRAMMANAGER_H_
/**@}*/