These are examples of how to create a executable program using the Program class.
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <boost/current_function.hpp>
#include <boost/program_options.hpp>
using boost::program_options::bool_switch;
using boost::program_options::value;
namespace Examples {
logger.info("Test of Message");
logger2.info("Test2 of Message");
logger3.info("Test3 of Message");
}
public:
auto add = config_options.add_options();
bool flag = false;
add("int-option", value<int>()->default_value(int{111}), "An example int option");
add("int-option-with-default-and-default-in-conf", value<int>()->default_value(int{222}), "An example int option");
add("int-option-with-default-no-default-in-conf", value<int>()->default_value(int{444}), "An example int option");
add("int-option-no-default-not-defined-in-conf", value<int>(), "An example int option");
add("int-option-with-no-defaults-anywhere", value<int>(), "An example int option");
add("string-option", value<string>()->default_value(string{}), "An example string option");
add("boolean-option", value<bool>()->default_value(false), "An example boolean option");
add("flag,f", bool_switch(&flag), "An option to set to true");
add("string-option-no-default", value<string>(), "A string option without default value");
add("long-long-option", value<int64_t>()->default_value(int64_t{}), "An example long long option");
add("double-option", value<double>()->default_value(double{}), "An example double option");
add("int-vector-option", value<vector<int>>()->multitoken()->default_value(vector<int>{}, "Empty"),
"An example vector option");
add("threshold,t", value<double>()->default_value(double{0.5}), "An example double option");
return config_options;
}
log.info(
"Entering mainMethod()");
if (args["string-option-no-default"].empty()) {
log.info() <<
"No value are available for string-option-no-default";
}
string string_example{args["string-option"].as<string>()};
log.info() <<
"String option value: " << string_example;
log.info() <<
"The int-option value is " << args[
"int-option"].as<
int>();
log.info() <<
"The threshold value is " << args[
"threshold"].as<
double>();
double input_variable = 3.4756;
int64_t source_id = 12345;
double ra = 45.637;
double method_result = example_class_object.fundamentalTypeMethod(input_variable);
log.info() <<
"Some result: " << method_result;
double first = 1.0;
double division_result{};
try {
log.info(
"# Calling a method throwing an exception ");
double second = 0.0;
division_result = example_class_object.divideNumbers(first, second);
} catch (const Exception& e) {
log.info(
"# In this silly example we continue with a fake fix ");
division_result = example_class_object.divideNumbers(first, 0.000001);
}
log.info() <<
"Second result is: " << division_result;
example_class_object.passingUniquePointer(
std::move(vector_unique_ptr));
vector<double> object_example{vector<double>{1.0, 2.3, 4.5}};
example_class_object.passingObjectInGeneral(object_example);
log.info(
"Exiting mainMethod()");
}
};
}
}
Defines tools to describe the current Elmeents module.
Defines tools to describe the current project.
header to get the module info statically
static ClassExample factoryMethod(const std::int64_t source_id, const double ra)
Example factory method.
Simple example of an Elements program.
OptionsDescription defineSpecificProgramOptions() override
Allows to define the (command line and configuration file) options specific to this program.
ExitCode mainMethod(map< string, VariableValue > &args) override
The "main" method.
static Logging getLogger(const std::string &name="")
Abstract class for all Elements programs.
options_description OptionsDescription
Elements::ExitCode ExitCode
const std::string name() const
#define MAIN_FOR(ELEMENTS_PROGRAM_NAME)
ELEMENTS_API void printProject()
ELEMENTS_API int functionExample(const int j)
void myLocalLogTestFunc()
test function to demonstrate the logger
ELEMENTS_API const ModuleInfo & getThisExecutableInfo()
static std::string name()
static std::string versionString()
static std::string versionString()
static std::string name()