diff options
Diffstat (limited to 'source/blender/makesrna/intern/rna_access.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 99 |
1 files changed, 91 insertions, 8 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index a299302f04f..bfa1e7cef93 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -76,6 +76,9 @@ void RNA_init(void) StructRNA *srna; PropertyRNA *prop; + BLENDER_RNA.structs_map = BLI_ghash_str_new_ex(__func__, 2048); + BLENDER_RNA.structs_len = 0; + for (srna = BLENDER_RNA.structs.first; srna; srna = srna->cont.next) { if (!srna->cont.prophash) { srna->cont.prophash = BLI_ghash_str_new("RNA_init gh"); @@ -86,6 +89,9 @@ void RNA_init(void) } } } + BLI_assert(srna->flag & STRUCT_PUBLIC_NAMESPACE); + BLI_ghash_insert(BLENDER_RNA.structs_map, (void *)srna->identifier, srna); + BLENDER_RNA.structs_len += 1; } } @@ -513,13 +519,7 @@ static const char *rna_ensure_property_name(const PropertyRNA *prop) StructRNA *RNA_struct_find(const char *identifier) { - StructRNA *type; - if (identifier) { - for (type = BLENDER_RNA.structs.first; type; type = type->cont.next) - if (STREQ(type->identifier, identifier)) - return type; - } - return NULL; + return BLI_ghash_lookup(BLENDER_RNA.structs_map, identifier); } const char *RNA_struct_identifier(const StructRNA *type) @@ -815,6 +815,89 @@ char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, i return NULL; } +/** + * Use when registering structs with the #STRUCT_PUBLIC_NAMESPACE flag. + */ +bool RNA_struct_available_or_report(ReportList *reports, const char *identifier) +{ + const StructRNA *srna_exists = RNA_struct_find(identifier); + if (UNLIKELY(srna_exists != NULL)) { + /* Use comprehensive string construction since this is such a rare occurrence + * and information here may cut down time troubleshooting. */ + DynStr *dynstr = BLI_dynstr_new(); + BLI_dynstr_appendf(dynstr, "Type identifier '%s' is already in use: '", identifier); + BLI_dynstr_append(dynstr, srna_exists->identifier); + int i = 0; + if (srna_exists->base) { + for (const StructRNA *base = srna_exists->base; base; base = base->base) { + BLI_dynstr_append(dynstr, "("); + BLI_dynstr_append(dynstr, base->identifier); + i += 1; + } + while (i--) { + BLI_dynstr_append(dynstr, ")"); + } + } + BLI_dynstr_append(dynstr, "'."); + char *result = BLI_dynstr_get_cstring(dynstr); + BLI_dynstr_free(dynstr); + BKE_report(reports, RPT_ERROR, result); + MEM_freeN(result); + return false; + } + else { + return true; + } +} + +bool RNA_struct_bl_idname_ok_or_report(ReportList *reports, const char *identifier, const char *sep) +{ + const int len_sep = strlen(sep); + const int len_id = strlen(identifier); + const char *p = strstr(identifier, sep); + /* TODO: make error, for now warning until add-ons update. */ +#if 1 + const int report_level = RPT_WARNING; + const bool failure = true; +#else + const int report_level = RPT_ERROR; + const bool failure = false; +#endif + if (p == NULL || p == identifier || p + len_sep >= identifier + len_id) { + BKE_reportf(reports, report_level, "'%s' doesn't contain '%s' with prefix & suffix", identifier, sep); + return failure; + } + + const char *c, *start, *end, *last; + start = identifier; + end = p; + last = end - 1; + for (c = start; c != end; c++) { + if (((*c >= 'A' && *c <= 'Z') || + ((c != start) && (*c >= '0' && *c <= '9')) || + ((c != start) && (c != last) && (*c == '_'))) == 0) + { + BKE_reportf(reports, report_level, "'%s' doesn't have upper case alpha-numeric prefix", identifier); + return failure; + } + } + + start = p + len_sep; + end = identifier + len_id; + last = end - 1; + for (c = start; c != end; c++) { + if (((*c >= 'A' && *c <= 'Z') || + (*c >= 'a' && *c <= 'z') || + (*c >= '0' && *c <= '9') || + ((c != start) && (c != last) && (*c == '_'))) == 0) + { + BKE_reportf(reports, report_level, "'%s' doesn't have an alpha-numeric suffix", identifier); + return failure; + } + } + return true; +} + /* Property Information */ const char *RNA_property_identifier(PropertyRNA *prop) @@ -6446,7 +6529,7 @@ static int rna_function_parameter_parse(PointerRNA *ptr, PropertyRNA *prop, Prop tid, fid, pid, RNA_struct_identifier(ptype), RNA_struct_identifier(srna)); return -1; } - + *((void **)dest) = *((void **)src); break; |