better config check & error message

This commit is contained in:
supermerill 2019-03-29 11:37:44 +01:00
parent fa0ea6e0b5
commit 53bd39d80e

View File

@ -437,10 +437,15 @@ double ConfigBase::get_abs_value(const t_config_option_key &opt_key) const
{
// Get stored option value.
const ConfigOption *raw_opt = this->option(opt_key);
assert(raw_opt != nullptr);
if (raw_opt == nullptr) {
std::stringstream ss; ss << "You can't define an option that need " << opt_key << " without defining it!";
throw std::runtime_error(ss.str());
}
if (raw_opt->type() == coFloat)
return static_cast<const ConfigOptionFloat*>(raw_opt)->value;
if (raw_opt->type() == coFloatOrPercent) {
if(!static_cast<const ConfigOptionFloatOrPercent*>(raw_opt)->percent)
return static_cast<const ConfigOptionFloatOrPercent*>(raw_opt)->value;
// Get option definition.
const ConfigDef *def = this->def();
if (def == nullptr)
@ -453,7 +458,8 @@ double ConfigBase::get_abs_value(const t_config_option_key &opt_key) const
return opt_def->ratio_over.empty() ? 0. :
static_cast<const ConfigOptionFloatOrPercent*>(raw_opt)->get_abs_value(this->get_abs_value(opt_def->ratio_over));
}
throw std::runtime_error("ConfigBase::get_abs_value(): Not a valid option type for get_abs_value()");
std::stringstream ss; ss << "ConfigBase::get_abs_value(): "<< opt_key<<" has not a valid option type for get_abs_value()";
throw std::runtime_error(ss.str());
}
// Return an absolute value of a possibly relative config variable.