Parameters::SetDefault split out parts of implementation

allows putting it in translation unit
This commit is contained in:
Arne Morten Kvarving 2024-09-02 14:19:33 +02:00
parent 741e97da61
commit 65158cd3fb
2 changed files with 17 additions and 7 deletions

View File

@ -207,6 +207,16 @@ void Register_(const std::string& paramName,
MetaData::mutableRegistry()[paramName] = paramInfo;
}
void SetDefault_(const std::string& paramName,
const std::string& paramValue)
{
if (MetaData::registry().find(paramName) == MetaData::registry().end()) {
throw std::runtime_error("Accessing parameter " + paramName +
" without prior registration is not allowed.");
}
MetaData::mutableRegistry()[paramName].defaultValue = paramValue;
}
}
bool ParamInfo::operator==(const ParamInfo& other) const

View File

@ -96,6 +96,10 @@ void Register_(const std::string& paramName,
const std::string& defaultValue,
const char* usageString);
//! \brief Private implementation.
void SetDefault_(const std::string& paramName,
const std::string& paramValue);
}
struct ParamInfo
@ -143,7 +147,7 @@ auto Get(bool errorIfNotRegistered = true);
* \endcode
*/
template <class Param>
auto SetDefault(decltype(Param::value) new_value);
void SetDefault(decltype(Param::value) new_value);
class ParamRegFinalizerBase_
{
@ -372,16 +376,12 @@ auto Get(bool errorIfNotRegistered)
}
template <class Param>
auto SetDefault(decltype(Param::value) new_value)
void SetDefault(decltype(Param::value) new_value)
{
const std::string paramName = detail::getParamName<Param>();
if (MetaData::registry().find(paramName) == MetaData::registry().end()) {
throw std::runtime_error("Accessing parameter " + paramName +
" without prior registration is not allowed.");
}
std::ostringstream oss;
oss << new_value;
MetaData::mutableRegistry()[paramName].defaultValue = oss.str();
detail::SetDefault_(paramName, oss.str());
}
/*!