diff options
Diffstat (limited to 'source/blender/makesrna/intern/rna_access.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index dda1c2ff56a..246446313d4 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -748,8 +748,7 @@ bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna) PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier) { - if (identifier[0] == '[' && identifier[1] == '"') { /* " (dummy comment to avoid confusing some - * function lists in text editors) */ + if (identifier[0] == '[' && identifier[1] == '"') { /* id prop lookup, not so common */ PropertyRNA *r_prop = NULL; PointerRNA r_ptr; /* only support single level props */ @@ -833,19 +832,33 @@ const struct ListBase *RNA_struct_type_properties(StructRNA *srna) return &srna->cont.properties; } -PropertyRNA *RNA_struct_type_find_property(StructRNA *srna, const char *identifier) +PropertyRNA *RNA_struct_type_find_property_no_base(StructRNA *srna, const char *identifier) { return BLI_findstring_ptr(&srna->cont.properties, identifier, offsetof(PropertyRNA, identifier)); } +/** + * \note #RNA_struct_find_property is a higher level alternative to this function + * which takes a #PointerRNA instead of a #StructRNA. + */ +PropertyRNA *RNA_struct_type_find_property(StructRNA *srna, const char *identifier) +{ + for (; srna; srna = srna->base) { + PropertyRNA *prop = RNA_struct_type_find_property_no_base(srna, identifier); + if (prop != NULL) { + return prop; + } + } + return NULL; +} + FunctionRNA *RNA_struct_find_function(StructRNA *srna, const char *identifier) { #if 1 FunctionRNA *func; - StructRNA *type; - for (type = srna; type; type = type->base) { + for (; srna; srna = srna->base) { func = (FunctionRNA *)BLI_findstring_ptr( - &type->functions, identifier, offsetof(FunctionRNA, identifier)); + &srna->functions, identifier, offsetof(FunctionRNA, identifier)); if (func) { return func; } @@ -2847,7 +2860,7 @@ void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value) BLI_assert(RNA_property_type(prop) == PROP_FLOAT); BLI_assert(RNA_property_array_check(prop) == false); /* useful to check on bad values but set function should clamp */ - /* BLI_assert(RNA_property_float_clamp(ptr, prop, &value) == 0); */ + // BLI_assert(RNA_property_float_clamp(ptr, prop, &value) == 0); if ((idprop = rna_idproperty_check(&prop, ptr))) { RNA_property_float_clamp(ptr, prop, &value); @@ -3241,7 +3254,7 @@ char *RNA_property_string_get_alloc( buf = fixedbuf; } else { - buf = MEM_mallocN(sizeof(char) * (length + 1), "RNA_string_get_alloc"); + buf = MEM_mallocN(sizeof(char) * (length + 1), __func__); } #ifndef NDEBUG @@ -3376,10 +3389,8 @@ void RNA_property_string_get_default(PropertyRNA *prop, char *value, const int m strcpy(value, sprop->defaultvalue); } -char *RNA_property_string_get_default_alloc(PointerRNA *ptr, - PropertyRNA *prop, - char *fixedbuf, - int fixedlen) +char *RNA_property_string_get_default_alloc( + PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len) { char *buf; int length; @@ -3392,11 +3403,15 @@ char *RNA_property_string_get_default_alloc(PointerRNA *ptr, buf = fixedbuf; } else { - buf = MEM_callocN(sizeof(char) * (length + 1), "RNA_string_get_alloc"); + buf = MEM_callocN(sizeof(char) * (length + 1), __func__); } RNA_property_string_get_default(prop, buf, length + 1); + if (r_len) { + *r_len = length; + } + return buf; } @@ -6423,15 +6438,18 @@ void RNA_string_get(PointerRNA *ptr, const char *name, char *value) } } -char *RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen) +char *RNA_string_get_alloc( + PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len) { PropertyRNA *prop = RNA_struct_find_property(ptr, name); if (prop) { - /* TODO: pass length. */ - return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen, NULL); + return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen, r_len); } printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name); + if (r_len != NULL) { + *r_len = 0; + } return NULL; } @@ -8002,7 +8020,7 @@ bool RNA_property_reset(PointerRNA *ptr, PropertyRNA *prop, int index) } case PROP_STRING: { - char *value = RNA_property_string_get_default_alloc(ptr, prop, NULL, 0); + char *value = RNA_property_string_get_default_alloc(ptr, prop, NULL, 0, NULL); RNA_property_string_set(ptr, prop, value); MEM_freeN(value); return true; |