#pragma once #include #include #include #include #include #include #include #include namespace trygvis { namespace apps { template using o = std::experimental::optional; namespace po = boost::program_options; using namespace log4cplus; using json = nlohmann::json; class missing_key : public std::runtime_error { public: missing_key(const json::string_t key) : runtime_error("Missing key: " + key), key(key) {} const json::string_t key; }; template T get(json j, std::string key) { auto ref = j[key]; if (ref.is_null()) { throw missing_key(key); } return ref; } class app_execution { public: app_execution(po::options_description desc, po::variables_map vm, Logger logger) : desc(desc), vm(vm), logger(logger) {} const po::options_description desc; const po::variables_map vm; const log4cplus::Logger logger; void usage(); }; class app { public: app(std::string app_name) : app_name(app_name) {} app(const app &) = delete; app(app &&) = default; virtual ~app() = default; app &operator=(const app &) = delete; virtual void add_options(po::options_description_easy_init &options) {} virtual void add_extra_options(po::options_description &options) {} virtual int main(app_execution &execution) = 0; const std::string app_name; }; std::string get_hostname(); int real_main(app *app, int argc, const char *argv[]); template class noop_delete { public: void operator()(T *) const {} }; static inline void noop_deleter(void *) {} } }