Parameters::IsSet 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 98b33d582f
commit 741e97da61
2 changed files with 22 additions and 15 deletions

View File

@ -160,6 +160,24 @@ void Hide_(const std::string& paramName)
paramInfo.isHidden = true;
}
bool IsSet_(const std::string& paramName, bool errorIfNotRegistered)
{
if (errorIfNotRegistered) {
if (MetaData::registrationOpen()) {
throw std::runtime_error("Parameters can only checked after _all_ of them have "
"been registered.");
}
if (MetaData::registry().find(paramName) == MetaData::registry().end())
throw std::runtime_error("Accessing parameter " + std::string(paramName) +
" without prior registration is not allowed.");
}
// check whether the parameter is in the parameter tree
return MetaData::tree().hasKey(paramName);
}
void Register_(const std::string& paramName,
const std::string& paramTypeName,
const std::string& defaultValue,

View File

@ -87,6 +87,9 @@ auto getParamName()
//! \brief Private implementation.
void Hide_(const std::string& paramName);
//! \brief Private implementation.
bool IsSet_(const std::string& paramName, bool errorIfNotRegistered);
//! \brief Private implementation.
void Register_(const std::string& paramName,
const std::string& paramTypeName,
@ -428,21 +431,7 @@ void reset();
template <class Param>
bool IsSet(bool errorIfNotRegistered = true)
{
const std::string paramName = detail::getParamName<Param>();
if (errorIfNotRegistered) {
if (MetaData::registrationOpen()) {
throw std::runtime_error("Parameters can only checked after _all_ of them have "
"been registered.");
}
if (MetaData::registry().find(paramName) == MetaData::registry().end())
throw std::runtime_error("Accessing parameter " + std::string(paramName) +
" without prior registration is not allowed.");
}
// check whether the parameter is in the parameter tree
return MetaData::tree().hasKey(paramName);
return detail::IsSet_(detail::getParamName<Param>(), errorIfNotRegistered);
}
/*!