From 8afa42b05a260eb4b77327b296e19b24b74b123b Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 18 Sep 2020 15:11:31 +0200 Subject: [PATCH] IDProperties: Add utils to duplicate content of one IDProp into another. --- source/blender/blenkernel/BKE_idprop.h | 1 + source/blender/blenkernel/intern/idprop.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h index e7f9ad207a1..07a82802da8 100644 --- a/source/blender/blenkernel/BKE_idprop.h +++ b/source/blender/blenkernel/BKE_idprop.h @@ -127,6 +127,7 @@ struct IDProperty *IDP_CopyProperty(const struct IDProperty *prop) ATTR_WARN_UNU ATTR_NONNULL(); struct IDProperty *IDP_CopyProperty_ex(const struct IDProperty *prop, const int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +void IDP_CopyPropertyContent(IDProperty *dst, IDProperty *src) ATTR_NONNULL(); bool IDP_EqualsProperties_ex(IDProperty *prop1, IDProperty *prop2, diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 189eef5e175..a3e7d8c794d 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -787,6 +787,19 @@ IDProperty *IDP_CopyProperty(const IDProperty *prop) return IDP_CopyProperty_ex(prop, 0); } +/** + * Copy content from source IDProperty into destination one, freeing destination property's content + * first. + */ +void IDP_CopyPropertyContent(IDProperty *dst, IDProperty *src) +{ + IDProperty *idprop_tmp = IDP_CopyProperty(src); + idprop_tmp->prev = dst->prev; + idprop_tmp->next = dst->next; + SWAP(IDProperty, *dst, *idprop_tmp); + IDP_FreeProperty(idprop_tmp); +} + /* Updates ID pointers after an object has been copied */ /* TODO Nuke this once its only user has been correctly converted * to use generic ID management from BKE_library! */