diff --git a/opm/models/utils/parametersystem.cpp b/opm/models/utils/parametersystem.cpp index 590dd3799..5d6f2276d 100644 --- a/opm/models/utils/parametersystem.cpp +++ b/opm/models/utils/parametersystem.cpp @@ -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, diff --git a/opm/models/utils/parametersystem.hpp b/opm/models/utils/parametersystem.hpp index 9e33a9a99..177a93ed3 100644 --- a/opm/models/utils/parametersystem.hpp +++ b/opm/models/utils/parametersystem.hpp @@ -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 bool IsSet(bool errorIfNotRegistered = true) { - const std::string paramName = detail::getParamName(); - - 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(), errorIfNotRegistered); } /*!