Skip to content
Snippets Groups Projects
Commit c0088d86 authored by Whitney Armstrong's avatar Whitney Armstrong Committed by MarkusFrankATcernch
Browse files

Added helper function getAttrOrDefault.

The function getAttrOrDefault(xml::Element e, xml::XmlChar attr_name, T default_value)
will return the attribute converted to to type T but if it is not found it will return
default_value. When building new detectors supplying this is useful for
supplying default attribute values.
parent a6748be1
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,16 @@
/// Namespace for the AIDA detector description toolkit
namespace dd4hep {
/** Helper function to get attribute or return the default.
* If the hasAttr does not return true then the supplied default value is returned.
* This is useful when building a detector and you want to supply a default value.
*/
template <typename T>
T getAttrOrDefault(const dd4hep::xml::Element& e, const dd4hep::xml::XmlChar* attr_name, T default_value)
{
return (e.hasAttr(attr_name)) ? e.attr<T>(attr_name) : default_value;
}
/// Namespace for implementation details of the AIDA detector description toolkit
namespace detail {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment