From c45bd6137c11a1886965d278e52f7b3de723ae1e Mon Sep 17 00:00:00 2001 From: "matthias@arch" Date: Mon, 30 Jan 2023 16:06:17 +0100 Subject: [PATCH] Allowed vals can be set in CI --- src/settings_manager.hpp | 65 +++++----------------------------------- 1 file changed, 8 insertions(+), 57 deletions(-) diff --git a/src/settings_manager.hpp b/src/settings_manager.hpp index bb57637..989da29 100644 --- a/src/settings_manager.hpp +++ b/src/settings_manager.hpp @@ -113,7 +113,7 @@ namespace gz { * - in SettingsManager::set: depends on throwExceptionWhenNewValueNotAllowed * @see sm_validity */ - /* util::unordered_string_map> allowedValues; */ + util::unordered_string_map> allowedValues; /** * @brief Wether to throw an exception when trying to set an invalid value */ @@ -488,7 +488,7 @@ namespace gz { writeFileOnExit = createInfo.writeFileOnExit; throwExceptionWhenNewValueNotAllowed = createInfo.throwExceptionWhenNewValueNotAllowed; - /* allowedValues = std::move(createInfo.allowedValues); */ + allowedValues = std::move(createInfo.allowedValues); settings = std::move(createInfo.initialValues); filepath = createInfo.filepath; @@ -497,11 +497,11 @@ namespace gz { } // erase invalid initalValues - /* for (auto it = settings.begin(); it != settings.end(); it++) { */ - /* if (!isValueAllowed(it->first, it->second)) { */ - /* it = settings.erase(it); */ - /* } */ - /* } */ + for (auto it = settings.begin(); it != settings.end(); it++) { + if (!isValueAllowed(it->first, it->second)) { + it = settings.erase(it); + } + } initCache(); } @@ -541,18 +541,12 @@ namespace gz { template template T> const T& SettingsManager::get(const std::string& key) { - static_assert(util::IsInPack, "Type T is not in parameter pack CacheTypes..."); - /* if (!isRegisteredType()) { */ - /* throw InvalidType("Invalid type: '" + std::string(typeid(T).name()) + "'", "SettingsManager::get"); */ - /* } */ if (!settings.contains(key)) { throw InvalidArgument("Invalid key: '" + key + "'", "SettingsManager::get"); } // if not cached -> cache if (!settingsCache[typeid(T).name()].contains(key)) { try { - /* settingsCache[typeid(T).name()][key].emplace(fromString(settings[key])); */ - /* settingsCache[typeid(T).name()][key](fromString(settings[key])); */ settingsCache[typeid(T).name()][key] = std::variant(fromString(settings[key])); } catch (...) { @@ -581,9 +575,6 @@ namespace gz { template template T> const T& SettingsManager::getOr(const std::string& key, const T& fallback) requires std::copy_constructible { - /* if (!isRegisteredType()) { */ - /* throw InvalidType("Invalid type: '" + std::string(typeid(T).name()) + "'", "SettingsManager::getOr"); */ - /* } */ if (settings.contains(key)) { return get(key); } @@ -662,9 +653,6 @@ namespace gz { template template T> void SettingsManager::set(const std::string& key, const T& value) { - /* if (!isRegisteredType()) { */ - /* throw InvalidType("Invalid type: '" + std::string(typeid(T).name()) + "'", "SettingsManager::set<" + std::string(typeid(T).name()) + ">"); */ - /* } */ // convert to string std::string s; try { @@ -711,44 +699,6 @@ namespace gz { // // ALLOWED VALUES // - /* template */ - /* template T> */ - /* bool SettingsManager::isValueAllowed(const std::string& key, const T& value) const noexcept { */ - /* if (!allowedValues.contains(key)) { */ - /* return true; */ - /* } */ - /* const std::vector* av = nullptr; */ - /* try { */ - /* av = &std::get>(allowedValues.at(key).allowedValues); */ - /* } */ - /* catch (std::bad_variant_access&) { */ - /* return false; */ - /* } */ - - /* switch (allowedValues.at(key).type) { */ - /* case SM_LIST: { */ - /* for (auto it = av->begin(); it != av->end(); it++) { */ - /* if (*it == value) { */ - /* return true; */ - /* } */ - /* } */ - /* } */ - /* break; */ - /* case SM_RANGE: { */ - /* bool valid = true; */ - /* // value >= lowest */ - /* valid &= value >= av->at(0); */ - /* // value < highest */ - /* valid &= value < av->at(1); */ - /* // value == lowest + n * step */ - /* valid &= (value - av->at(0)) % av->at(2) == 0; */ - /* return valid; */ - /* } */ - /* break; */ - /* } // switch */ - /* return false; */ - /* } */ - template template T> bool SettingsManager::isValueAllowed(const std::string& key, const T& value) const noexcept { @@ -784,6 +734,7 @@ namespace gz { } // switch return false; } + template template T> bool SettingsManager::isValueAllowed(const std::string& key, const T& value) const noexcept {