diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-08-13 10:30:04 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-08-13 10:30:04 +0400 |
commit | bf52b68dcd1864fd35309f9aae19f146da5b774e (patch) | |
tree | aea9cce847b38dce0f76e61991d490c71e51502c /source/blender/blenkernel/intern/idprop.c | |
parent | e50ef6da2dba248ef9fcf14a10d67ef003649e5a (diff) |
minor changes to rna/python.
- raise an exception when python calls is_property_set(name) or is_property_hidden(name) and the property does not exist.
- added BLI_findstring_ptr(), which finds a named item in a listbase where that name is a pointer to a string.
- replaced inline for loops with calls to BLI_findstring_ptr() and IDP_GetPropertyFromGroup().
Diffstat (limited to 'source/blender/blenkernel/intern/idprop.c')
-rw-r--r-- | source/blender/blenkernel/intern/idprop.c | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 2ccb33b088a..a0df73d6c42 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -27,6 +27,7 @@ #include <stdio.h> #include <stdlib.h> +#include <stddef.h> #include <string.h> #include "BKE_idprop.h" @@ -491,47 +492,41 @@ void IDP_ReplaceGroupInGroup(IDProperty *dest, IDProperty *src) void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) { IDProperty *loop; - for (loop=group->data.group.first; loop; loop=loop->next) { - if (BSTR_EQ(loop->name, prop->name)) { - BLI_insertlink(&group->data.group, loop, prop); - - BLI_remlink(&group->data.group, loop); - IDP_FreeProperty(loop); - MEM_freeN(loop); - return; - } + if((loop= IDP_GetPropertyFromGroup(group, prop->name))) { + BLI_insertlink(&group->data.group, loop, prop); + + BLI_remlink(&group->data.group, loop); + IDP_FreeProperty(loop); + MEM_freeN(loop); + } + else { + group->len++; + BLI_addtail(&group->data.group, prop); } - - group->len++; - BLI_addtail(&group->data.group, prop); } /*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) { - IDProperty *loop; - for (loop=group->data.group.first; loop; loop=loop->next) { - if (BSTR_EQ(loop->name, prop->name)) return 0; + if(IDP_GetPropertyFromGroup(group, prop->name) == NULL) { + group->len++; + BLI_addtail(&group->data.group, prop); + return 1; } - group->len++; - BLI_addtail(&group->data.group, prop); - - return 1; + return 0; } int IDP_InsertToGroup(IDProperty *group, IDProperty *previous, IDProperty *pnew) { - IDProperty *loop; - for (loop=group->data.group.first; loop; loop=loop->next) { - if (BSTR_EQ(loop->name, pnew->name)) return 0; + if(IDP_GetPropertyFromGroup(group, pnew->name) == NULL) { + group->len++; + BLI_insertlink(&group->data.group, previous, pnew); + return 1; } - - group->len++; - BLI_insertlink(&group->data.group, previous, pnew); - return 1; + return 0; } void IDP_RemFromGroup(IDProperty *group, IDProperty *prop) @@ -542,11 +537,7 @@ void IDP_RemFromGroup(IDProperty *group, IDProperty *prop) IDProperty *IDP_GetPropertyFromGroup(IDProperty *prop, const char *name) { - IDProperty *loop; - for (loop=prop->data.group.first; loop; loop=loop->next) { - if (strcmp(loop->name, name)==0) return loop; - } - return NULL; + return (IDProperty *)BLI_findstring(&prop->data.group, name, offsetof(IDProperty, name)); } typedef struct IDPIter { |