Parameters::Hide split out main implementation

allows putting it in translation unit
This commit is contained in:
Arne Morten Kvarving 2024-09-02 14:19:33 +02:00
parent 7584f588a7
commit 48bcf6ac04
2 changed files with 25 additions and 16 deletions

View File

@ -137,11 +137,31 @@ std::string transformKey(const std::string& s,
return result;
}
} // anonymous namespace
namespace Opm::Parameters {
namespace detail {
void Hide_(const std::string& paramName)
{
if (!MetaData::registrationOpen()) {
throw std::logic_error("Parameter '" + paramName + "' declared as hidden"
" when parameter registration was already closed.");
}
auto paramInfoIt = MetaData::mutableRegistry().find(paramName);
if (paramInfoIt == MetaData::mutableRegistry().end()) {
throw std::logic_error("Tried to declare unknown parameter '"
+ paramName + "' hidden.");
}
auto& paramInfo = paramInfoIt->second;
paramInfo.isHidden = true;
}
}
bool ParamInfo::operator==(const ParamInfo& other) const
{
return other.paramName == paramName

View File

@ -84,6 +84,9 @@ auto getParamName()
}
}
//! \brief Private implementation.
void Hide_(const std::string& paramName);
}
struct ParamInfo
@ -489,7 +492,6 @@ void Register(const char* usageString)
MetaData::mutableRegistry()[paramName] = paramInfo;
}
/*!
* \brief Indicate that a given parameter should not be mentioned in the help message
*
@ -498,20 +500,7 @@ void Register(const char* usageString)
template <class Param>
void Hide()
{
const std::string paramName = detail::getParamName<Param>();
if (!MetaData::registrationOpen()) {
throw std::logic_error("Parameter '" +paramName + "' declared as hidden"
" when parameter registration was already closed.");
}
auto paramInfoIt = MetaData::mutableRegistry().find(paramName);
if (paramInfoIt == MetaData::mutableRegistry().end()) {
throw std::logic_error("Tried to declare unknown parameter '"
+ paramName + "' hidden.");
}
auto& paramInfo = paramInfoIt->second;
paramInfo.isHidden = true;
detail::Hide_(detail::getParamName<Param>());
}
/*!