From 9ea4905b450b6c4f7eb275e8e58f255288ee84e3 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 5 Jun 2018 17:17:52 +0200 Subject: Add QString cast to Configuration::value --- lib/configuration/configuration.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'lib/configuration') diff --git a/lib/configuration/configuration.h b/lib/configuration/configuration.h index 1d0fb54..1df6bb5 100644 --- a/lib/configuration/configuration.h +++ b/lib/configuration/configuration.h @@ -43,32 +43,33 @@ public: if(vm.count(path) == 0) { #ifdef QT_DEBUG - qWarning("value(%s) does not exist, probably crashing now", path); + qWarning("value(%s) does not exist", path); #endif return std::nullopt; } - 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"; - } + if constexpr(std::is_same_v) { + return std::optional(vm[path].as()); + + } else if constexpr(std::is_same_v) { + + if (vm[path].value().type() == typeid(int)) { + return std::optional(std::to_string(vm[path].as())); + } + + if (vm[path].value().type() == typeid(bool)) { + return std::optional(vm[path].as() ? "true" : "false"); } + std::string r = vm[path].as(); + // 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()); } -- cgit v1.2.1