From 98b33d582fef1e116b80893348c880c585bb54ac Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Mon, 2 Sep 2024 14:19:33 +0200 Subject: [PATCH] Parameters::Register split out parts of implementation allows putting it in translation unit --- opm/models/utils/parametersystem.cpp | 29 ++++++++++++++++++++++++++++ opm/models/utils/parametersystem.hpp | 29 +++++++--------------------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/opm/models/utils/parametersystem.cpp b/opm/models/utils/parametersystem.cpp index ab32421b0..590dd3799 100644 --- a/opm/models/utils/parametersystem.cpp +++ b/opm/models/utils/parametersystem.cpp @@ -160,6 +160,35 @@ void Hide_(const std::string& paramName) paramInfo.isHidden = true; } +void Register_(const std::string& paramName, + const std::string& paramTypeName, + const std::string& defaultValue, + const char* usageString) +{ + if (!MetaData::registrationOpen()) { + throw std::logic_error("Parameter registration was already closed before " + "the parameter '" + paramName + "' was registered."); + } + + ParamInfo paramInfo; + paramInfo.paramName = paramName; + paramInfo.paramTypeName = paramTypeName; + paramInfo.usageString = usageString; + paramInfo.defaultValue = defaultValue; + paramInfo.isHidden = false; + if (MetaData::registry().find(paramName) != MetaData::registry().end()) { + // allow to register a parameter twice, but only if the + // parameter name, type and usage string are exactly the same. + if (MetaData::registry().at(paramName) == paramInfo) { + return; + } + throw std::logic_error("Parameter " + paramName + +" registered twice with non-matching characteristics."); + } + + MetaData::mutableRegistry()[paramName] = paramInfo; +} + } bool ParamInfo::operator==(const ParamInfo& other) const diff --git a/opm/models/utils/parametersystem.hpp b/opm/models/utils/parametersystem.hpp index 3e1a3d2a5..9e33a9a99 100644 --- a/opm/models/utils/parametersystem.hpp +++ b/opm/models/utils/parametersystem.hpp @@ -87,6 +87,12 @@ auto getParamName() //! \brief Private implementation. void Hide_(const std::string& paramName); +//! \brief Private implementation. +void Register_(const std::string& paramName, + const std::string& paramTypeName, + const std::string& defaultValue, + const char* usageString); + } struct ParamInfo @@ -459,11 +465,6 @@ template void Register(const char* usageString) { const std::string paramName = detail::getParamName(); - if (!MetaData::registrationOpen()) { - throw std::logic_error("Parameter registration was already closed before " - "the parameter '" + paramName + "' was registered."); - } - const auto defaultValue = Param::value; using ParamType = std::conditional_t, std::string, @@ -471,25 +472,9 @@ void Register(const char* usageString) MetaData::registrationFinalizers().push_back( std::make_unique>()); - ParamInfo paramInfo; - paramInfo.paramName = paramName; - paramInfo.paramTypeName = Dune::className(); - paramInfo.usageString = usageString; std::ostringstream oss; oss << defaultValue; - paramInfo.defaultValue = oss.str(); - paramInfo.isHidden = false; - if (MetaData::registry().find(paramName) != MetaData::registry().end()) { - // allow to register a parameter twice, but only if the - // parameter name, type and usage string are exactly the same. - if (MetaData::registry().at(paramName) == paramInfo) { - return; - } - throw std::logic_error("Parameter " + paramName - +" registered twice with non-matching characteristics."); - } - - MetaData::mutableRegistry()[paramName] = paramInfo; + detail::Register_(paramName, Dune::className(), oss.str(), usageString); } /*!