Allowed vals can be set in CI

This commit is contained in:
matthias@arch 2023-01-30 16:06:17 +01:00
parent 68d04eb43f
commit c45bd6137c

View File

@ -113,7 +113,7 @@ namespace gz {
* - in SettingsManager::set: depends on throwExceptionWhenNewValueNotAllowed
* @see sm_validity
*/
/* util::unordered_string_map<SettingsManagerAllowedValues<CacheTypes...>> allowedValues; */
util::unordered_string_map<SettingsManagerAllowedValues<CacheTypes...>> 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<std::string>(it->first, it->second)) { */
/* it = settings.erase(it); */
/* } */
/* } */
for (auto it = settings.begin(); it != settings.end(); it++) {
if (!isValueAllowed<std::string>(it->first, it->second)) {
it = settings.erase(it);
}
}
initCache<void, CacheTypes...>();
}
@ -541,18 +541,12 @@ namespace gz {
template<StringConvertible... CacheTypes>
template<util::IsInPack<CacheTypes...> T>
const T& SettingsManager<CacheTypes...>::get(const std::string& key) {
static_assert(util::IsInPack<T, CacheTypes...>, "Type T is not in parameter pack CacheTypes...");
/* if (!isRegisteredType<T>()) { */
/* 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<T>(settings[key])); */
/* settingsCache[typeid(T).name()][key](fromString<T>(settings[key])); */
settingsCache[typeid(T).name()][key] = std::variant<std::monostate, CacheTypes...>(fromString<T>(settings[key]));
}
catch (...) {
@ -581,9 +575,6 @@ namespace gz {
template<StringConvertible... CacheTypes>
template<util::IsInPack<CacheTypes...> T>
const T& SettingsManager<CacheTypes...>::getOr(const std::string& key, const T& fallback) requires std::copy_constructible<T> {
/* if (!isRegisteredType<T>()) { */
/* throw InvalidType("Invalid type: '" + std::string(typeid(T).name()) + "'", "SettingsManager::getOr"); */
/* } */
if (settings.contains(key)) {
return get<T>(key);
}
@ -662,9 +653,6 @@ namespace gz {
template<StringConvertible... CacheTypes>
template<util::IsInPack<CacheTypes...> T>
void SettingsManager<CacheTypes...>::set(const std::string& key, const T& value) {
/* if (!isRegisteredType<T>()) { */
/* 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<StringConvertible... CacheTypes> */
/* template<IntegralInPack<std::string, CacheTypes...> T> */
/* bool SettingsManager<CacheTypes...>::isValueAllowed(const std::string& key, const T& value) const noexcept { */
/* if (!allowedValues.contains(key)) { */
/* return true; */
/* } */
/* const std::vector<T>* av = nullptr; */
/* try { */
/* av = &std::get<std::vector<T>>(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<StringConvertible... CacheTypes>
template<NumberInPack<std::string, CacheTypes...> T>
bool SettingsManager<CacheTypes...>::isValueAllowed(const std::string& key, const T& value) const noexcept {
@ -784,6 +734,7 @@ namespace gz {
} // switch
return false;
}
template<StringConvertible... CacheTypes>
template<NotNumberInPack<std::string, CacheTypes...> T>
bool SettingsManager<CacheTypes...>::isValueAllowed(const std::string& key, const T& value) const noexcept {