Add utility function to reset ID property value to a given one

This is similar to idproperty_reset() defined in layer.c, but it does not
re-alloc property itself.

We should replace idproperty_reset() with IDP_Reset() now.
This commit is contained in:
Sergey Sharybin
2018-01-24 15:00:01 +01:00
parent 90768c9b68
commit 56a336196d
2 changed files with 21 additions and 0 deletions

View File

@@ -32,6 +32,10 @@
#include "BLI_compiler_attrs.h"
#ifdef __cplusplus
extern "C" {
#endif
struct IDProperty;
struct ID;
@@ -119,6 +123,8 @@ void IDP_ClearProperty(IDProperty *prop);
void IDP_RelinkProperty(struct IDProperty *prop);
void IDP_Reset(IDProperty *prop, const IDProperty *reference);
#define IDP_Int(prop) ((prop)->data.val)
#define IDP_Array(prop) ((prop)->data.pointer)
/* C11 const correctness for casts */
@@ -151,4 +157,8 @@ void IDP_RelinkProperty(struct IDProperty *prop);
void IDP_spit(IDProperty *prop);
#endif
#ifdef __cplusplus
}
#endif
#endif /* __BKE_IDPROP_H__ */

View File

@@ -1094,4 +1094,15 @@ void IDP_ClearProperty(IDProperty *prop)
prop->len = prop->totallen = 0;
}
void IDP_Reset(IDProperty *prop, const IDProperty *reference)
{
if (prop == NULL) {
return;
}
IDP_ClearProperty(prop);
if (reference != NULL) {
IDP_MergeGroup(prop, reference, true);
}
}
/** \} */