Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/idprop.c
| Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | IDProperty *IDP_NewIDPArray(const char *name) | ||||
| IDProperty *prop = MEM_callocN(sizeof(IDProperty), "IDProperty prop array"); | IDProperty *prop = MEM_callocN(sizeof(IDProperty), "IDProperty prop array"); | ||||
| prop->type = IDP_IDPARRAY; | prop->type = IDP_IDPARRAY; | ||||
| prop->len = 0; | prop->len = 0; | ||||
| BLI_strncpy(prop->name, name, MAX_IDPROP_NAME); | BLI_strncpy(prop->name, name, MAX_IDPROP_NAME); | ||||
| return prop; | return prop; | ||||
| } | } | ||||
| IDProperty *IDP_CopyIDPArray(const IDProperty *array) | IDProperty *IDP_CopyIDPArray(const IDProperty *array, const int flag) | ||||
| { | { | ||||
| /* don't use MEM_dupallocN because this may be part of an array */ | /* don't use MEM_dupallocN because this may be part of an array */ | ||||
| IDProperty *narray, *tmp; | IDProperty *narray, *tmp; | ||||
| int i; | int i; | ||||
| BLI_assert(array->type == IDP_IDPARRAY); | BLI_assert(array->type == IDP_IDPARRAY); | ||||
| narray = MEM_mallocN(sizeof(IDProperty), __func__); | narray = MEM_mallocN(sizeof(IDProperty), __func__); | ||||
| *narray = *array; | *narray = *array; | ||||
| narray->data.pointer = MEM_dupallocN(array->data.pointer); | narray->data.pointer = MEM_dupallocN(array->data.pointer); | ||||
| for (i = 0; i < narray->len; i++) { | for (i = 0; i < narray->len; i++) { | ||||
| /* ok, the copy functions always allocate a new structure, | /* ok, the copy functions always allocate a new structure, | ||||
| * which doesn't work here. instead, simply copy the | * which doesn't work here. instead, simply copy the | ||||
| * contents of the new structure into the array cell, | * contents of the new structure into the array cell, | ||||
| * then free it. this makes for more maintainable | * then free it. this makes for more maintainable | ||||
| * code than simply reimplementing the copy functions | * code than simply reimplementing the copy functions | ||||
| * in this loop.*/ | * in this loop.*/ | ||||
| tmp = IDP_CopyProperty(GETPROP(narray, i)); | tmp = IDP_CopyProperty_ex(GETPROP(narray, i), flag); | ||||
| memcpy(GETPROP(narray, i), tmp, sizeof(IDProperty)); | memcpy(GETPROP(narray, i), tmp, sizeof(IDProperty)); | ||||
| MEM_freeN(tmp); | MEM_freeN(tmp); | ||||
| } | } | ||||
| return narray; | return narray; | ||||
| } | } | ||||
| static void IDP_FreeIDPArray(IDProperty *prop, const bool do_id_user) | static void IDP_FreeIDPArray(IDProperty *prop, const bool do_id_user) | ||||
| ▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| if (prop->data.pointer) { | if (prop->data.pointer) { | ||||
| idp_resize_group_array(prop, 0, NULL); | idp_resize_group_array(prop, 0, NULL); | ||||
| MEM_freeN(prop->data.pointer); | MEM_freeN(prop->data.pointer); | ||||
| } | } | ||||
| } | } | ||||
| static IDProperty *idp_generic_copy(const IDProperty *prop) | static IDProperty *idp_generic_copy(const IDProperty *prop, const int UNUSED(flag)) | ||||
| { | { | ||||
| IDProperty *newp = MEM_callocN(sizeof(IDProperty), "IDProperty array dup"); | IDProperty *newp = MEM_callocN(sizeof(IDProperty), __func__); | ||||
| BLI_strncpy(newp->name, prop->name, MAX_IDPROP_NAME); | BLI_strncpy(newp->name, prop->name, MAX_IDPROP_NAME); | ||||
| newp->type = prop->type; | newp->type = prop->type; | ||||
| newp->flag = prop->flag; | newp->flag = prop->flag; | ||||
| newp->data.val = prop->data.val; | newp->data.val = prop->data.val; | ||||
| newp->data.val2 = prop->data.val2; | newp->data.val2 = prop->data.val2; | ||||
| return newp; | return newp; | ||||
| } | } | ||||
| static IDProperty *IDP_CopyArray(const IDProperty *prop) | static IDProperty *IDP_CopyArray(const IDProperty *prop, const int flag) | ||||
| { | { | ||||
| IDProperty *newp = idp_generic_copy(prop); | IDProperty *newp = idp_generic_copy(prop, flag); | ||||
| if (prop->data.pointer) { | if (prop->data.pointer) { | ||||
| newp->data.pointer = MEM_dupallocN(prop->data.pointer); | newp->data.pointer = MEM_dupallocN(prop->data.pointer); | ||||
| if (prop->type == IDP_GROUP) { | if (prop->type == IDP_GROUP) { | ||||
| IDProperty **array = newp->data.pointer; | IDProperty **array = newp->data.pointer; | ||||
| int a; | int a; | ||||
| for (a = 0; a < prop->len; a++) | for (a = 0; a < prop->len; a++) | ||||
| array[a] = IDP_CopyProperty(array[a]); | array[a] = IDP_CopyProperty_ex(array[a], flag); | ||||
| } | } | ||||
| } | } | ||||
| newp->len = prop->len; | newp->len = prop->len; | ||||
| newp->subtype = prop->subtype; | newp->subtype = prop->subtype; | ||||
| newp->totallen = prop->totallen; | newp->totallen = prop->totallen; | ||||
| return newp; | return newp; | ||||
| } | } | ||||
| Show All 36 Lines | IDProperty *IDP_NewString(const char *st, const char *name, int maxlen) | ||||
| } | } | ||||
| prop->type = IDP_STRING; | prop->type = IDP_STRING; | ||||
| BLI_strncpy(prop->name, name, MAX_IDPROP_NAME); | BLI_strncpy(prop->name, name, MAX_IDPROP_NAME); | ||||
| return prop; | return prop; | ||||
| } | } | ||||
| static IDProperty *IDP_CopyString(const IDProperty *prop) | static IDProperty *IDP_CopyString(const IDProperty *prop, const int flag) | ||||
| { | { | ||||
| IDProperty *newp; | IDProperty *newp; | ||||
| BLI_assert(prop->type == IDP_STRING); | BLI_assert(prop->type == IDP_STRING); | ||||
| newp = idp_generic_copy(prop); | newp = idp_generic_copy(prop, flag); | ||||
| if (prop->data.pointer) | if (prop->data.pointer) | ||||
| newp->data.pointer = MEM_dupallocN(prop->data.pointer); | newp->data.pointer = MEM_dupallocN(prop->data.pointer); | ||||
| newp->len = prop->len; | newp->len = prop->len; | ||||
| newp->subtype = prop->subtype; | newp->subtype = prop->subtype; | ||||
| newp->totallen = prop->totallen; | newp->totallen = prop->totallen; | ||||
| return newp; | return newp; | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /* ID Type */ | /* ID Type */ | ||||
| /** \name IDProperty ID API | /** \name IDProperty ID API | ||||
| * \{ */ | * \{ */ | ||||
| static IDProperty *IDP_CopyID(const IDProperty *prop) | static IDProperty *IDP_CopyID(const IDProperty *prop, const int flag) | ||||
| { | { | ||||
| IDProperty *newp; | IDProperty *newp; | ||||
| BLI_assert(prop->type == IDP_ID); | BLI_assert(prop->type == IDP_ID); | ||||
| newp = idp_generic_copy(prop); | newp = idp_generic_copy(prop, flag); | ||||
| newp->data.pointer = prop->data.pointer; | newp->data.pointer = prop->data.pointer; | ||||
| if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) { | |||||
| id_us_plus(IDP_Id(newp)); | id_us_plus(IDP_Id(newp)); | ||||
| } | |||||
| return newp; | return newp; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /* Group Functions */ | /* Group Functions */ | ||||
| /** \name IDProperty Group API | /** \name IDProperty Group API | ||||
| * \{ */ | * \{ */ | ||||
| /** | /** | ||||
| * Checks if a property with the same name as prop exists, and if so replaces it. | * Checks if a property with the same name as prop exists, and if so replaces it. | ||||
| */ | */ | ||||
| static IDProperty *IDP_CopyGroup(const IDProperty *prop) | static IDProperty *IDP_CopyGroup(const IDProperty *prop, const int flag) | ||||
| { | { | ||||
| IDProperty *newp, *link; | IDProperty *newp, *link; | ||||
| BLI_assert(prop->type == IDP_GROUP); | BLI_assert(prop->type == IDP_GROUP); | ||||
| newp = idp_generic_copy(prop); | newp = idp_generic_copy(prop, flag); | ||||
| newp->len = prop->len; | newp->len = prop->len; | ||||
| for (link = prop->data.group.first; link; link = link->next) { | for (link = prop->data.group.first; link; link = link->next) { | ||||
| BLI_addtail(&newp->data.group, IDP_CopyProperty(link)); | BLI_addtail(&newp->data.group, IDP_CopyProperty_ex(link, flag)); | ||||
| } | } | ||||
| return newp; | return newp; | ||||
| } | } | ||||
| /* use for syncing proxies. | /* use for syncing proxies. | ||||
| * When values name and types match, copy the values, else ignore */ | * When values name and types match, copy the values, else ignore */ | ||||
| void IDP_SyncGroupValues(IDProperty *dest, const IDProperty *src) | void IDP_SyncGroupValues(IDProperty *dest, const IDProperty *src) | ||||
| ▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Lines | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /* Main Functions */ | /* Main Functions */ | ||||
| /** \name IDProperty Main API | /** \name IDProperty Main API | ||||
| * \{ */ | * \{ */ | ||||
| IDProperty *IDP_CopyProperty(const IDProperty *prop) | IDProperty *IDP_CopyProperty_ex(const IDProperty *prop, const int flag) | ||||
| { | { | ||||
| switch (prop->type) { | switch (prop->type) { | ||||
| case IDP_GROUP: return IDP_CopyGroup(prop); | case IDP_GROUP: return IDP_CopyGroup(prop, flag); | ||||
| case IDP_STRING: return IDP_CopyString(prop); | case IDP_STRING: return IDP_CopyString(prop, flag); | ||||
| case IDP_ID: return IDP_CopyID(prop); | case IDP_ID: return IDP_CopyID(prop, flag); | ||||
| case IDP_ARRAY: return IDP_CopyArray(prop); | case IDP_ARRAY: return IDP_CopyArray(prop, flag); | ||||
| case IDP_IDPARRAY: return IDP_CopyIDPArray(prop); | case IDP_IDPARRAY: return IDP_CopyIDPArray(prop, flag); | ||||
| default: return idp_generic_copy(prop); | default: return idp_generic_copy(prop, flag); | ||||
| } | |||||
| } | } | ||||
| IDProperty *IDP_CopyProperty(const IDProperty *prop) | |||||
| { | |||||
| return IDP_CopyProperty_ex(prop, 0); | |||||
| } | } | ||||
| /* Updates ID pointers after an object has been copied */ | /* 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! */ | /* TODO Nuke this once its only user has been correctly converted to use generic ID management from BKE_library! */ | ||||
| void IDP_RelinkProperty(struct IDProperty *prop) | void IDP_RelinkProperty(struct IDProperty *prop) | ||||
| { | { | ||||
| if (!prop) | if (!prop) | ||||
| return; | return; | ||||
| ▲ Show 20 Lines • Show All 313 Lines • Show Last 20 Lines | |||||