forked from degauden/Elements
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSimpleProgram.h
More file actions
94 lines (79 loc) · 3.24 KB
/
Copy pathSimpleProgram.h
File metadata and controls
94 lines (79 loc) · 3.24 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
/**
* @file SimpleProgram.h
*
* @date Aug 27, 2014
* @author Hubert Degaudenzi
*
*
* @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_SIMPLE_PROGRAM_H_
#define ELEMENTSKERNEL_ELEMENTSKERNEL_SIMPLE_PROGRAM_H_
#include "ElementsKernel/Exit.h" // for ExitCode
#include "ElementsKernel/Export.h" // for ELEMENTS_API
#include "ElementsKernel/Logging.h" // for Logging
#include "ElementsKernel/Path.h" // for Item
namespace Elements {
/**
* @class SimpleProgram
* @brief Provides a framework for creating structured programs with customizable logic.
*
* SimpleProgram is a base class for defining programs that adhere to a specific execution
* structure. It manages program setup, execution, and offers a way to define program-specific
* functionality by overriding virtual methods.
*/
class ELEMENTS_API SimpleProgram {
public:
ExitCode run(int argc, char** argv) noexcept;
const Path::Item& getProgramPath() const;
const Path::Item& getProgramName() const;
protected:
SimpleProgram() = default;
virtual ~SimpleProgram();
virtual ExitCode main() = 0;
virtual void defineOptions() = 0;
private:
void setup(int argc, char** argv);
private:
Path::Item m_program_name;
Path::Item m_program_path;
};
/** @example ElementsExamples/src/program/AnotherSimpleProgram.cpp
* This is an example of how to use the SimpleProgram class.
*/
} // namespace Elements
/**
* @def MAIN(ELEMENTS_PROGRAM)
* Macro which must be used to create a main in classes
* that derived from Elements::SimpleProgram, i.e., these derived classes
* must end with the following line:
* @code
* MAIN(ELEMENTS_PROGRAM)
* @endcode.
* @param ELEMENTS_PROGRAM name of the main program class, derived from
* the class Elements::SimpleProgram class.
*/
#define MAIN(ELEMENTS_PROGRAM) \
ELEMENTS_API int main(int argc, char* argv[]) { \
auto program = ELEMENTS_PROGRAM(); \
Elements::ExitCode exit_code = program.run(argc, argv); \
return static_cast<Elements::ExitCodeType>(exit_code); \
}
#endif // ELEMENTSKERNEL_ELEMENTSKERNEL_SIMPLE_PROGRAM_H_
/**@}*/