Skip to content

Commit 1c3e5c0

Browse files
nmnobrelindsayad
andcommitted
Add MooseBase::haveParameter(), use it to improve queryParam()
Co-authored-by: Alex Lindsay <alexander.lindsay@inl.gov>
1 parent 76e6f8c commit 1c3e5c0

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

framework/include/base/MooseBase.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ class MooseBase : public ConsoleStreamInterface
157157
/**
158158
* Query a parameter for the object
159159
*
160-
* If the parameter is not valid, nullptr will be returned
161-
*
160+
* If a parameter of the given name and type does not exist or if the
161+
* parameter is not valid, nullptr will be returned
162162
* @param name The name of the parameter
163163
* @return A pointer to the parameter value, if it exists
164164
*/
@@ -192,6 +192,16 @@ class MooseBase : public ConsoleStreamInterface
192192
template <typename T>
193193
T getCheckedPointerParam(const std::string & name, const std::string & error_string = "") const;
194194

195+
/**
196+
* Test if a parameter of the given name and type exists
197+
* @param name The name of the parameter to test
198+
*/
199+
template <typename T>
200+
inline bool haveParameter(const std::string & name) const
201+
{
202+
return _pars.have_parameter<T>(name);
203+
}
204+
195205
/**
196206
* Test if the supplied parameter is valid
197207
* @param name The name of the parameter to test
@@ -412,7 +422,7 @@ template <typename T>
412422
const T *
413423
MooseBase::queryParam(const std::string & name) const
414424
{
415-
return isParamValid(name) ? &getParam<T>(name) : nullptr;
425+
return haveParameter<T>(name) && isParamValid(name) ? &getParam<T>(name) : nullptr;
416426
}
417427

418428
template <typename T>

0 commit comments

Comments
 (0)