mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-15 17:25:32 +00:00
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
0923a67d9b
commit
c11d0365f3
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user