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:
parent
b79d99844e
commit
9b23565b0c
1 changed files with 27 additions and 0 deletions
|
@ -525,6 +525,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)
|
||||
{
|
||||
|
@ -536,6 +542,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();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue