File indexing completed on 2026-09-27 09:14:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef LAGER_FRAMEWORK_LOADED
0021 #define LAGER_FRAMEWORK_LOADED
0022
0023 #include <functional>
0024 #include <string>
0025 #include <vector>
0026
0027 #include <lager/core/configuration.hh>
0028 #include <lager/core/logo.hh>
0029
0030 #include <boost/program_options.hpp>
0031
0032 namespace lager {
0033
0034 class framework_error;
0035 class framework_help;
0036 class framework_file_error;
0037 class framework_parse_error;
0038 }
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 #define MAKE_LAGER_FRAMEWORK(function) \
0052 int main(int argc, char* argv[]) { \
0053 try { \
0054 lager::print_logo(); \
0055 lager::framework lager{argc, argv, (function)}; \
0056 lager.run(); \
0057 return 0; \
0058 } catch (...) { \
0059 return 1; \
0060 } \
0061 }
0062
0063 namespace lager {
0064 class framework {
0065 public:
0066 using lager_function_type =
0067 std::function<int(const configuration& conf, const std::string& output)>;
0068
0069
0070 framework(int argc, char* argv[], lager_function_type lager_function);
0071 ~framework();
0072
0073 int run() const;
0074
0075 private:
0076 boost::program_options::variables_map parse_arguments(int argc,
0077 char* argv[]) const;
0078
0079
0080 ptree get_settings() const;
0081
0082
0083 int root_suppress_signals() const;
0084
0085
0086 template <class T> T get_option(const std::string& key);
0087
0088 int dummy_;
0089
0090 boost::program_options::variables_map args_;
0091 configuration conf_;
0092 std::string output_;
0093 std::ofstream log_file_;
0094 lager_function_type lager_function_;
0095 };
0096 }
0097
0098
0099
0100
0101 namespace lager {
0102 class framework_error : public lager::exception {
0103 public:
0104 framework_error(const std::string& msg,
0105 const std::string& type = "framework_error")
0106 : lager::exception{msg, type} {}
0107 };
0108 class framework_help : public framework_error {
0109 public:
0110 framework_help(const std::string& program,
0111 const boost::program_options::options_description& opts);
0112
0113 private:
0114 std::string
0115 message(const std::string& program,
0116 const boost::program_options::options_description& opts) const;
0117 };
0118 class framework_file_error : public framework_error {
0119 public:
0120 framework_file_error(const std::string& file);
0121 };
0122 class framework_parse_error : public framework_error {
0123 public:
0124 framework_parse_error(const std::string& file);
0125 };
0126 }
0127
0128
0129
0130
0131 namespace lager {
0132
0133 template <class T> T framework::get_option(const std::string& key) {
0134 T val = 0;
0135 auto val_opt = conf_.get_optional<T>(key);
0136 if (args_.count(key)) {
0137 val = args_[key].as<T>();
0138 conf_.set(key, val);
0139 } else if (val_opt) {
0140 val = *val_opt;
0141 } else {
0142 throw framework_error(
0143 "Ensure that '" + key +
0144 "' is set on the command line or in the configuration file");
0145 }
0146 return val;
0147 }
0148 }
0149
0150 #endif