From 44421abbe89be2c6a6290182571fff82dfec9651 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 15 Mar 2018 16:26:38 +0100 Subject: Moved Configuration class into library --- src/configuration.h | 76 ----------------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 src/configuration.h (limited to 'src/configuration.h') diff --git a/src/configuration.h b/src/configuration.h deleted file mode 100644 index 5038a4d..0000000 --- a/src/configuration.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of smolbote. It's copyrighted by the contributors recorded - * in the version control history of the file, available from its original - * location: https://neueland.iserlohn-fortress.net/smolbote.hg - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef CONFIGURATION_H -#define CONFIGURATION_H - -#include -#include -#include -#include -#include -#include - -class Configuration -{ -public: - explicit Configuration(); - ~Configuration(); - - bool read(const QString &path); - bool parse(int argc, const char **argv); - - template - std::optional value(const char *path) const - { - // if setting doesn't exist, we crash - // in debug builds, check if setting exists -#ifdef QT_DEBUG - if(vm.count(path) == 0) { - qWarning("value(%s) does not exist, probably crashing now", path); - } -#endif - - if constexpr(std::is_same_v) { - std::string r; - try { - r = vm[path].as(); - } catch (boost::bad_any_cast &) { - // try int - try { - r = std::to_string(vm[path].as()); - } catch (boost::bad_any_cast &) { - - // try bool, and crash if not that either - r = vm[path].as() ? "true" : "false"; - } - - } - - // check if it's a path - if(r.front() == '~') { - r.replace(0, 1, m_homePath); - } - - return std::optional(r); - } else - return std::optional(vm[path].as()); - } - - const std::vector> & options() { - return desc.options(); - } - -private: - boost::program_options::options_description desc; - boost::program_options::variables_map vm; - - std::string m_homePath; -}; - -#endif // CONFIGURATION_H -- cgit v1.2.1