Insert_or_assign properties, allow to override properties

This allows to copy a property list and then selectively
replace various properties. e.g.

```
PropertyList plist (region->properties ());
plist.add (Properties::length, len);
plist.remove (Properties::start);
```

See also 8b0ab38675
and 97f0fac7d5
This also fixes the issue referenced in
8c83149c4c
This commit is contained in:
Robin Gareus 2022-10-07 00:32:14 +02:00
parent ddec1a9a98
commit ebf59d4426
2 changed files with 8 additions and 1 deletions

View file

@ -57,6 +57,7 @@ public:
* Defined below, once we have Property<T>
*/
template<typename T, typename V> bool add (PropertyDescriptor<T> pid, const V& v);
template<typename T> bool remove (PropertyDescriptor<T> pid);
protected:
bool _property_owner;

View file

@ -28,7 +28,13 @@ namespace PBD {
template<typename T, typename V> bool
PropertyList::add (PropertyDescriptor<T> pid, const V& v) {
return insert (value_type (pid.property_id, new Property<T> (pid, (T)v))).second;
erase (pid.property_id);
return insert (value_type (pid.property_id, new Property<T> (pid, (T)v))).second;
}
template<typename T> bool
PropertyList::remove (PropertyDescriptor<T> pid) {
return erase (pid.property_id) > 0;
}
}