27 #include <boost/current_function.hpp> 39 using boost::program_options::options_description;
40 using boost::program_options::value;
41 using boost::program_options::variable_value;
42 using boost::program_options::bool_switch;
57 logger.info(
"Test of Message");
60 logger2.info(
"Test2 of Message");
63 logger3.info(
"Test3 of Message");
91 options_description config_options {
"Example program options" };
96 config_options.add_options()
97 (
"int-option", value<int>()->default_value(
int {111}),
98 "An example int option")
99 (
"int-option-with-default-and-default-in-conf", value<int>()->default_value(
int {222}),
100 "An example int option")
101 (
"int-option-with-default-no-default-in-conf", value<int>()->default_value(
int {444}),
102 "An example int option")
103 (
"int-option-no-default-not-defined-in-conf", value<int>(),
104 "An example int option")
105 (
"int-option-with-no-defaults-anywhere", value<int>(),
106 "An example int option")
107 (
"string-option", value<string>()->default_value(
string { }),
108 "An example string option")
109 (
"boolean-option", value<bool>()->default_value(
false),
110 "An example boolean option")
111 (
"flag,f", bool_switch(&flag),
112 "An option to set to true")
113 (
"string-option-no-default", value<string>(),
114 "A string option without default value")
115 (
"long-long-option", value<int64_t>()->default_value(int64_t { }),
116 "An example long long option")
117 (
"double-option", value<double>()->default_value(
double { }),
118 "An example double option")
119 (
"int-vector-option",
120 value<vector<int>>()->multitoken()->default_value(
vector<int> { },
"Empty"),
121 "An example vector option")
122 (
"threshold,t", value<double>()->default_value(
double {0.5}),
123 "An example double option");
125 return config_options;
142 log.info(
"Entering mainMethod()");
157 if (args[
"string-option-no-default"].empty()) {
158 log.info() <<
"No value are available for string-option-no-default";
170 string string_example { args[
"string-option"].as<
string>() };
171 log.info() <<
"String option value: " << string_example;
173 log.info() <<
"The int-option value is " << args[
"int-option"].as<
int>();
174 log.info() <<
"The threshold value is " << args[
"threshold"].as<
double>();
178 double input_variable = 3.4756;
179 int64_t source_id = 12345;
192 log.info() <<
"Some result: " << method_result;
195 double division_result{};
198 log.info(
"# Calling a method throwing an exception ");
205 log.info() <<
e.what();
207 log.info(
"# In this silly example we continue with a fake fix ");
209 division_result = example_class_object.
divideNumbers(first, 0.000001);
211 log.info() <<
"Second result is: " << division_result;
237 log.info(
"Exiting mainMethod()");
ExitCode
Strongly typed exit numbers.
void passingObjectInGeneral(const std::vector< double > &input_object) const
Example method taking an object in input.
double divideNumbers(const double first, const double second) const
Divide two double variables.
constexpr double e
The base of the natural logarithm .
ELEMENTS_API const ModuleInfo & getThisExecutableInfo()
void myLocalLogTestFunc()
test function to demonstrate the logger
ELEMENTS_API int functionExample(const int j)
ExitCode mainMethod(map< string, variable_value > &args) override
The "main" method.
Abstract class for all Elements programs.
void passingUniquePointer(std::unique_ptr< std::vector< double >> vector_unique_ptr) const
Example method with a unique pointer argument.
header to get the module info statically
#define MAIN_FOR(ELEMENTS_PROGRAM_NAME)
options_description defineSpecificProgramOptions() override
Allows to define the (command line and configuration file) options specific to this program...
const std::string name() const
Elements base exception class.
double fundamentalTypeMethod(const double input_variable) const
Simple method example.
Simple example of an Elements program.
static Logging getLogger(const std::string &name="")
static ClassExample factoryMethod(const std::int64_t source_id, const double ra)
Example factory method.