From ebf59d4426fcae0d94dabdf6559a8832db224d27 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 7 Oct 2022 00:32:14 +0200 Subject: [PATCH] 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 8b0ab386756007334c961953f10482ea0cb90644 and 97f0fac7d544391d9631127aeaf8fe98fa74baf1 This also fixes the issue referenced in 8c83149c4c5bd596f6bf5f437b1f2bc934a35d4d --- libs/pbd/pbd/property_list.h | 1 + libs/pbd/pbd/property_list_impl.h | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libs/pbd/pbd/property_list.h b/libs/pbd/pbd/property_list.h index 1711b2dd00..330345853f 100644 --- a/libs/pbd/pbd/property_list.h +++ b/libs/pbd/pbd/property_list.h @@ -57,6 +57,7 @@ public: * Defined below, once we have Property */ template bool add (PropertyDescriptor pid, const V& v); + template bool remove (PropertyDescriptor pid); protected: bool _property_owner; diff --git a/libs/pbd/pbd/property_list_impl.h b/libs/pbd/pbd/property_list_impl.h index 194042cf4c..b99f07236b 100644 --- a/libs/pbd/pbd/property_list_impl.h +++ b/libs/pbd/pbd/property_list_impl.h @@ -28,7 +28,13 @@ namespace PBD { template bool PropertyList::add (PropertyDescriptor pid, const V& v) { - return insert (value_type (pid.property_id, new Property (pid, (T)v))).second; + erase (pid.property_id); + return insert (value_type (pid.property_id, new Property (pid, (T)v))).second; +} + +template bool +PropertyList::remove (PropertyDescriptor pid) { + return erase (pid.property_id) > 0; } }