diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-10-31 23:07:25 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-10-31 23:07:25 +0400 |
commit | c7fbeded4c6cce637f4d64c366d12070d15d2f0c (patch) | |
tree | fe1364dcc4b054865b6e7b38f029e1ed54ae920d /source/blender/blenkernel | |
parent | ae097e72a35f4cff8eaa242b7b17f596c2051907 (diff) |
add IDP_MergeGroup(dst, src, overwrite) function,
like PyDict_Merge()
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_idprop.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/idprop.c | 24 |
2 files changed, 30 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h index 3cf4a2c5cdc..027f06ef84f 100644 --- a/source/blender/blenkernel/BKE_idprop.h +++ b/source/blender/blenkernel/BKE_idprop.h @@ -154,6 +154,12 @@ __attribute__((nonnull)) #endif ; +void IDP_MergeGroup(IDProperty *dest, IDProperty *src, const int do_overwrite) +#ifdef __GNUC__ +__attribute__((nonnull)) +#endif +; + /** * This function has a sanity check to make sure ID properties with the same name don't * get added to the group. diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 8ceaab56f83..88f7d8f6191 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -492,6 +492,30 @@ void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) } } +/* + * If a property is missing in \a dest, add it. + */ +void IDP_MergeGroup(IDProperty *dest, IDProperty *src, const int do_overwrite) +{ + IDProperty *prop; + + if (do_overwrite) { + for (prop = src->data.group.first; prop; prop = prop->next) { + IDProperty *copy = IDP_CopyProperty(prop); + IDP_ReplaceInGroup(dest, copy); + } + } + else { + for (prop = src->data.group.first; prop; prop = prop->next) { + if (IDP_GetPropertyFromGroup(dest, prop->name) == NULL) { + IDProperty *copy = IDP_CopyProperty(prop); + dest->len++; + BLI_addtail(&dest->data.group, copy); + } + } + } +} + /* returns 0 if an id property with the same name exists and it failed, * or 1 if it succeeded in adding to the group.*/ int IDP_AddToGroup(IDProperty *group, IDProperty *prop) |