diff --git a/BaseLib/ConfigTree-impl.h b/BaseLib/ConfigTree-impl.h index 4256d180a8df156e7ec1fe161550a106091dec49..ed4cc075f75175de0e86feea8fdaa5f153bb89d7 100644 --- a/BaseLib/ConfigTree-impl.h +++ b/BaseLib/ConfigTree-impl.h @@ -187,6 +187,16 @@ getConfigAttribute(std::string const& attr) const error("Did not find XML attribute with name \"" + attr + "\"."); } +template <typename T> +T ConfigTree::getConfigAttribute(std::string const& attr, + T const& default_value) const +{ + if (auto a = getConfigAttributeOptional<T>(attr)) + return *a; + + return default_value; +} + template<typename T> boost::optional<T> ConfigTree:: diff --git a/BaseLib/ConfigTree.h b/BaseLib/ConfigTree.h index 8f30c13bc53d20b35da77dd5c2ac4fdc590f4333..654a9a3c8584b220c4ce9788b8a74f1e31b98b85 100644 --- a/BaseLib/ConfigTree.h +++ b/BaseLib/ConfigTree.h @@ -364,18 +364,32 @@ public: /*! Get XML attribute \c attr of type \c T for the current parameter. * - * \return the requested attribute + * \return the requested attribute's value. * - * \pre \c param must not have been read before from this ConfigTree. + * \pre \c attr must not have been read before from the current parameter. */ template<typename T> T getConfigAttribute(std::string const& attr) const; - /*! Get XML attribute \c attr of type \c T for the current parameter if present. + /*! Get XML attribute \c attr of type \c T for the current parameter or the + * \c default_value. * - * \return the requested attribute + * This method has a similar behaviour as getConfigAttribute(std::string + * const&) except in case of errors the \c default_value is returned. * - * \pre \c param must not have been read before from this ConfigTree. + * \return the requested attribute's value. + * + * \pre \c attr must not have been read before from the current parameter. + */ + template <typename T> + T getConfigAttribute(std::string const& attr, T const& default_value) const; + + /*! Get XML attribute \c attr of type \c T for the current parameter if + * present. + * + * \return the requested attribute's value. + * + * \pre \c attr must not have been read before from the current parameter. */ template<typename T> boost::optional<T> getConfigAttributeOptional(std::string const& attr) const;