config: Add copy_or_remove_attributes()

Unlike copy_attributes(), this erases attributes in the destination that
don't exist in the source.
This commit is contained in:
Iris Morelle 2021-11-12 16:28:34 -03:00 committed by Gunter Labes
parent 0923a67d9b
commit c11d0365f3
No known key found for this signature in database
GPG Key ID: C0C7B971CC910216

View File

@ -524,6 +524,12 @@ public:
}
}
/**
* Copies attributes that exist in the source config.
*
* @param from Source config to copy attributes from.
* @param keys Attribute names.
*/
template<typename... T>
void copy_attributes(const config& from, T... keys)
{
@ -535,6 +541,27 @@ public:
}
}
/**
* Copies or deletes attributes to match the source config.
*
* Attributes that do not exist in the source are fully erased rather than
* set to the unspecified/default attribute value.
*
* @param from Source config to copy attributes from.
* @param keys Attribute names.
*/
template<typename... T>
void copy_or_remove_attributes(const config& from, T... keys)
{
for(const auto& key : {keys...}) {
if(from.has_attribute(key)) {
(*this)[key] = from[key];
} else {
remove_attribute(key);
}
}
}
const_attr_itors attribute_range() const;
attr_itors attribute_range();