aboutsummaryrefslogtreecommitdiff
path: root/lib/configuration/configuration.h
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-06-05 17:17:52 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-06-05 17:17:52 +0200
commit9ea4905b450b6c4f7eb275e8e58f255288ee84e3 (patch)
tree8445d7ad31743ca317e88dc69531fdb6549fd632 /lib/configuration/configuration.h
parentClazy fixes (diff)
downloadsmolbote-9ea4905b450b6c4f7eb275e8e58f255288ee84e3.tar.xz
Add QString cast to Configuration::value
Diffstat (limited to 'lib/configuration/configuration.h')
-rw-r--r--lib/configuration/configuration.h29
1 files changed, 15 insertions, 14 deletions
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<T, std::string>) {
- std::string r;
- try {
- r = vm[path].as<std::string>();
- } catch(boost::bad_any_cast &) {
- // try int
- try {
- r = std::to_string(vm[path].as<int>());
- } catch(boost::bad_any_cast &) {
-
- // try bool, and crash if not that either
- r = vm[path].as<bool>() ? "true" : "false";
- }
+ if constexpr(std::is_same_v<T, QString>) {
+ return std::optional<QString>(vm[path].as<const char*>());
+
+ } else if constexpr(std::is_same_v<T, std::string>) {
+
+ if (vm[path].value().type() == typeid(int)) {
+ return std::optional<std::string>(std::to_string(vm[path].as<int>()));
+ }
+
+ if (vm[path].value().type() == typeid(bool)) {
+ return std::optional<std::string>(vm[path].as<bool>() ? "true" : "false");
}
+ std::string r = vm[path].as<std::string>();
+
// check if it's a path
if(r.front() == '~') {
r.replace(0, 1, m_homePath);
}
return std::optional<std::string>(r);
+
} else
return std::optional<T>(vm[path].as<T>());
}