Blender V5.3
rna_path.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10#include <cstring>
11
12#include <fmt/format.h>
13
14#include "BLI_alloca.hh"
15#include "BLI_dynstr.hh"
16#include "BLI_hash.hh"
17#include "BLI_string.hh"
18#include "BLI_string_ref.hh"
19#include "BLI_utildefines.hh"
20
21#include "BKE_idprop.hh"
22#include "BKE_idtype.hh"
23#include "BKE_lib_id.hh"
24
25#include "DNA_ID.h" /* For ID properties. */
26
27#include "MEM_guardedalloc.h"
28
29#include "RNA_access.hh"
30#include "RNA_define.hh"
31#include "RNA_path.hh"
32#include "RNA_prototypes.hh"
33
35#include "rna_internal.hh"
36
37#include <ranges>
38
39namespace blender {
40
42{
43 if (key.has_value()) {
44 return get_default_hash(path, key.value());
45 }
46 return get_default_hash(path, index.value_or(0));
47};
48
49bool operator==(const RNAPath &left, const RNAPath &right)
50{
51 if (left.path != right.path) {
52 return false;
53 }
54
55 if (left.key.has_value() || right.key.has_value()) {
56 return left.key == right.key;
57 }
58
59 return left.index == right.index;
60}
61
68static char *rna_path_token(const char **path, char *fixedbuf, int fixedlen)
69{
70 int len = 0;
71
72 /* Get data until `.` or `[`. */
73 const char *p = *path;
74 while (*p && !ELEM(*p, '.', '[')) {
75 len++;
76 p++;
77 }
78
79 /* Empty, return. */
80 if (len == 0) [[unlikely]] {
81 return nullptr;
82 }
83
84 /* Try to use fixed buffer if possible. */
85 char *buf = (len + 1 < fixedlen) ? fixedbuf :
86 MEM_new_array_uninitialized<char>(size_t(len) + 1, __func__);
87 memcpy(buf, *path, sizeof(char) * len);
88 buf[len] = '\0';
89
90 if (*p == '.') {
91 p++;
92 }
93 *path = p;
94
95 return buf;
96}
97
108static char *rna_path_token_in_brackets(const char **path,
109 char *fixedbuf,
110 int fixedlen,
111 bool *r_quoted)
112{
113 int len = 0;
114 bool quoted = false;
115
116 BLI_assert(r_quoted != nullptr);
117
118 /* Get data between `[]`, check escaping quotes and back-slashes with #BLI_str_unescape. */
119 if (**path != '[') [[unlikely]] {
120 return nullptr;
121 }
122
123 (*path)++;
124 const char *p = *path;
125
126 /* 2 kinds of look-ups now, quoted or unquoted. */
127 if (*p == '"') {
128 /* Find the matching quote. */
129 (*path)++;
130 p = *path;
131 const char *p_end = BLI_str_escape_find_quote(p);
132 if (p_end == nullptr) {
133 /* No Matching quote. */
134 return nullptr;
135 }
136 /* Exclude the last quote from the length. */
137 len += (p_end - p);
138
139 /* Skip the last quoted char to get the `]`. */
140 p_end += 1;
141 p = p_end;
142 quoted = true;
143 }
144 else {
145 /* Find the matching bracket. */
146 while (*p && (*p != ']')) {
147 len++;
148 p++;
149 }
150 }
151
152 if (*p != ']') [[unlikely]] {
153 return nullptr;
154 }
155
156 /* Support empty strings in quotes, as this is a valid key for an ID-property. */
157 if (!quoted) {
158 /* Empty, return. */
159 if (len == 0) [[unlikely]] {
160 return nullptr;
161 }
162 }
163
164 /* Try to use fixed buffer if possible. */
165 char *buf = (len + 1 < fixedlen) ? fixedbuf :
166 MEM_new_array_uninitialized<char>(size_t(len) + 1, __func__);
167
168 /* Copy string, taking into account escaped `]`. */
169 if (quoted) {
170 BLI_str_unescape(buf, *path, len);
171 /* +1 to step over the last quote. */
172 BLI_assert((*path)[len] == '"');
173 p = (*path) + len + 1;
174 }
175 else {
176 memcpy(buf, *path, sizeof(char) * len);
177 buf[len] = '\0';
178 }
179 /* Set path to start of next token. */
180 if (*p == ']') {
181 p++;
182 }
183 if (*p == '.') {
184 p++;
185 }
186 *path = p;
187
188 *r_quoted = quoted;
189
190 return buf;
191}
192
193template<int64_t N>
194std::optional<ParsedRNAPath<N>> ParsedRNAPath<N>::from_string(const StringRefNull path)
195{
196 if (path.is_empty()) {
197 return std::nullopt;
198 }
199 /* Work directly in optional to avoid having to move it later when it is returned. */
200 std::optional<ParsedRNAPath<N>> parsed;
201 parsed.emplace();
202 const char *current = path.c_str();
203 while (*current) {
204 const char c = *current;
205 if (c == '[') {
206 char buffer[256];
207 bool quoted;
208 char *token = rna_path_token_in_brackets(&current, buffer, sizeof(buffer), &quoted);
209 if (!token) {
210 return std::nullopt;
211 }
212 if (quoted) {
213 parsed->items.append(rna_path::LookupKey(UString(token)));
214 }
215 else {
216 const int64_t index = atoi(token);
217 if (index == 0 && (token[0] != '0' || token[1] != '\0')) {
218 if (buffer != token) {
219 MEM_delete(token);
220 }
221 return std::nullopt;
222 }
223 parsed->items.append(rna_path::LookupIndex(index));
224 }
225 if (buffer != token) {
226 MEM_delete(token);
227 }
228 }
229 else {
230 char buffer[256];
231 char *token = rna_path_token(&current, buffer, sizeof(buffer));
232 if (!token) {
233 return std::nullopt;
234 }
235 parsed->items.append(rna_path::Member(UString(token)));
236 if (buffer != token) {
237 MEM_delete(token);
238 }
239 }
240 }
241 return parsed;
242}
243
244namespace rna_path {
245
246std::string to_string(const Span<Item> items)
247{
248 std::string result;
249 for (const auto &item : items) {
250 if (const Member *member = std::get_if<Member>(&item)) {
251 if (!result.empty()) {
252 result.append(".");
253 }
254 result.append(member->identifier.c_str());
255 }
256 else if (const LookupIndex *lookup_index = std::get_if<LookupIndex>(&item)) {
257 result.append("[");
258 result.append(std::to_string(lookup_index->index));
259 result.append("]");
260 }
261 else if (const LookupKey *lookup_key = std::get_if<LookupKey>(&item)) {
262 result.append("[\"");
263 for (const char c : lookup_key->key.ref()) {
264 if (c == '\\') {
265 result.append("\\\\");
266 }
267 else if (c == '"') {
268 result.append("\\\"");
269 }
270 else {
271 result.append(1, c);
272 }
273 }
274 result.append("\"]");
275 }
276 else {
278 }
279 }
280 return result;
281}
282
283}; // namespace rna_path
284
285template<int64_t N> std::string ParsedRNAPath<N>::to_string() const
286{
287 return rna_path::to_string(this->items);
288}
289
290template class ParsedRNAPath<4>;
291
314static bool rna_path_parse(const PointerRNA *ptr,
315 const ParsedRNAPathRef path,
316 PointerRNA *r_ptr,
317 PropertyRNA **r_prop,
318 int *r_index,
319 PointerRNA *r_item_ptr,
320 Vector<PropertyElemRNA> *r_elements,
321 const bool eval_pointer)
322{
323 BLI_assert(r_item_ptr == nullptr || !eval_pointer);
324 PropertyRNA *prop;
325 PointerRNA curptr, nextptr;
326 int index = -1;
327 const bool do_item_ptr = r_item_ptr != nullptr && !eval_pointer;
328
329 if (do_item_ptr) {
330 nextptr.invalidate();
331 }
332
333 prop = nullptr;
334 curptr = *ptr;
335
336 if (path.is_empty()) {
337 return false;
338 }
339
340 const rna_path::Item *item_iter = path.begin();
341 while (item_iter != path.end()) {
342 if (do_item_ptr) {
343 nextptr.invalidate();
344 }
345
346 if (!curptr) {
347 return false;
348 }
349
350 /* look up property name in current struct */
351 prop = nullptr;
352 if (const auto *member = std::get_if<rna_path::Member>(item_iter)) {
353 prop = RNA_struct_find_property(&curptr, member->identifier);
354 }
355 else if (const auto *lookup_key = std::get_if<rna_path::LookupKey>(item_iter)) {
356 IDProperty *group = RNA_struct_idprops(&curptr, false);
357 if (group) {
358 prop = reinterpret_cast<PropertyRNA *>(
359 IDP_GetPropertyFromGroup(group, lookup_key->key.c_str()));
360 }
361 }
362 else {
363 /* LookupIndex is never a valid property identifier. */
364 return false;
365 }
366
367 if (!prop) {
368 return false;
369 }
370
371 if (r_elements) {
372 /* index will be added later, if needed. */
373 r_elements->append(PropertyElemRNA{
374 .ptr = curptr,
375 .prop = prop,
376 .index = -1,
377 });
378 }
379
380 item_iter++;
381
382 /* now look up the value of this property if it is a pointer or
383 * collection, otherwise return the property rna so that the
384 * caller can read the value of the property itself */
385 switch (RNA_property_type(prop)) {
386 case PROP_POINTER: {
387 /* resolve pointer if further path elements follow
388 * or explicitly requested
389 */
390 if (do_item_ptr || eval_pointer || item_iter != path.end()) {
391 nextptr = RNA_property_pointer_get(&curptr, prop);
392 }
393
394 if (eval_pointer || item_iter != path.end()) {
395 curptr = nextptr;
396 prop = nullptr; /* now we have a PointerRNA, the prop is our parent so forget it */
397 index = -1;
398 }
399 break;
400 }
401 case PROP_COLLECTION: {
402 /* Resolve pointer if further path elements follow. */
403 if (item_iter != path.end()) {
404 if (const auto *lookup_key = std::get_if<rna_path::LookupKey>(item_iter)) {
406 &curptr, prop, lookup_key->key.c_str(), &nextptr))
407 {
408 return false;
409 }
410 item_iter++;
411 }
412 else if (const auto *lookup_index = std::get_if<rna_path::LookupIndex>(item_iter)) {
414 &curptr, prop, int(lookup_index->index), &nextptr))
415 {
416 return false;
417 }
418 item_iter++;
419 }
420 else {
421 /* Member follows collection: resolve to collection's type pointer.
422 * Don't consume the Member; leave it for the next outer iteration. */
423 std::optional<PointerRNA> ptr = RNA_property_collection_type_get(&curptr, prop);
424 if (!ptr) {
425 return false;
426 }
427 nextptr = *ptr;
428 }
429
430 if (eval_pointer || item_iter != path.end()) {
431 curptr = nextptr;
432 prop = nullptr; /* now we have a PointerRNA, the prop is our parent so forget it */
433 index = -1;
434 }
435 }
436 break;
437 }
438 default:
439 if (r_index || r_elements) {
440 if (item_iter == path.end()) {
441 /* A potential array index is not specified. */
442 break;
443 }
444
445 int array_indices[RNA_MAX_ARRAY_DIMENSION] = {0};
446 int dimension_size[RNA_MAX_ARRAY_DIMENSION];
447 const int dim = RNA_property_array_dimension(&curptr, prop, dimension_size);
448 for (const int d : IndexRange(dim)) {
449 if (item_iter == path.end()) {
450 /* Fewer items than dimensions. */
451 return false;
452 }
453
454 if (const auto *lookup_index = std::get_if<rna_path::LookupIndex>(item_iter)) {
455 array_indices[d] = int(lookup_index->index);
456 }
457 else if (const auto *lookup_key = std::get_if<rna_path::LookupKey>(item_iter)) {
458 /* ["x"] quoted-bracket style. */
459 array_indices[d] = RNA_property_array_item_index(prop, lookup_key->key[0]);
460 }
461 else if (dim == 1) {
462 /* .x/.y/.x single letter collection property access. */
463 const auto *member = std::get_if<rna_path::Member>(item_iter);
464 if (!member) {
465 return false;
466 }
467 array_indices[d] = RNA_property_array_item_index(prop, member->identifier[0]);
468 }
469 else {
470 /* Multi-dimensional arrays cannot use a single letter #rna_path::Member. */
471 return false;
472 }
473
474 if (array_indices[d] < 0 || array_indices[d] >= dimension_size[d]) {
475 return false;
476 }
477 item_iter++;
478 }
479
480 /* Besides pointer and collections (handled above), indices are always the path end. */
481 if (item_iter != path.end()) {
482 return false;
483 }
484
485 /* Flatten index over all dimensions. */
486 int dim_total = 1;
487 int flat_index = 0;
488 for (int d = dim - 1; d >= 0; d--) {
489 flat_index += array_indices[d] * dim_total;
490 dim_total *= dimension_size[d];
491 }
492 index = flat_index;
493
494 if (r_elements) {
495 r_elements->last().index = index;
496 }
497 }
498 break;
499 }
500 }
501
502 if (r_ptr) {
503 *r_ptr = curptr;
504 }
505 if (r_prop) {
506 *r_prop = prop;
507 }
508 if (r_index) {
509 *r_index = index;
510 }
511 if (r_item_ptr && do_item_ptr) {
512 *r_item_ptr = nextptr;
513 }
514
515 if (r_elements) {
516 PropertyElemRNA &last = r_elements->last();
517 if ((last.ptr.data != curptr.data || last.prop != prop || last.index != index)) {
518 r_elements->append(PropertyElemRNA{
519 .ptr = curptr,
520 .prop = prop,
521 .index = index,
522 });
523 }
524 }
525
526 return true;
527}
528
530 const char *path,
531 PointerRNA *r_ptr,
532 PropertyRNA **r_prop)
533{
534 if (!path) {
535 return false;
536 }
537 const std::optional<ParsedRNAPath<>> parsed_path = ParsedRNAPath<>::from_string(path);
538 if (!parsed_path) {
539 return false;
540 }
541 if (!rna_path_parse(ptr, *parsed_path, r_ptr, r_prop, nullptr, nullptr, nullptr, true)) {
542 return false;
543 }
544
545 return *r_ptr;
546}
547
549 const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
550{
551 if (!path) {
552 return false;
553 }
554 const std::optional<ParsedRNAPath<>> parsed_path = ParsedRNAPath<>::from_string(path);
555 if (!parsed_path) {
556 return false;
557 }
558 if (!rna_path_parse(ptr, *parsed_path, r_ptr, r_prop, r_index, nullptr, nullptr, true)) {
559 return false;
560 }
561
562 return *r_ptr;
563}
564
566 const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
567{
568 if (!path) {
569 return false;
570 }
571 const std::optional<ParsedRNAPath<>> parsed_path = ParsedRNAPath<>::from_string(path);
572 if (!parsed_path) {
573 return false;
574 }
575 return rna_path_parse(ptr, *parsed_path, r_ptr, r_prop, r_index, nullptr, nullptr, true);
576}
577
579 const char *path,
580 PointerRNA *r_ptr,
581 PropertyRNA **r_prop)
582{
583 if (!path) {
584 return false;
585 }
586 const std::optional<ParsedRNAPath<>> parsed_path = ParsedRNAPath<>::from_string(path);
587 if (!parsed_path) {
588 return false;
589 }
590 if (!rna_path_parse(ptr, *parsed_path, r_ptr, r_prop, nullptr, nullptr, nullptr, false)) {
591 return false;
592 }
593
594 return *r_ptr && *r_prop != nullptr;
595}
596
598 ParsedRNAPathRef path,
599 PointerRNA *r_ptr,
600 PropertyRNA **r_prop)
601{
602 if (!rna_path_parse(ptr, path, r_ptr, r_prop, nullptr, nullptr, nullptr, false)) {
603 return false;
604 }
605
606 return *r_ptr && *r_prop != nullptr;
607}
608
610 const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
611{
612 if (!path) {
613 return false;
614 }
615 const std::optional<ParsedRNAPath<>> parsed_path = ParsedRNAPath<>::from_string(path);
616 if (!parsed_path) {
617 return false;
618 }
619 if (!rna_path_parse(ptr, *parsed_path, r_ptr, r_prop, r_index, nullptr, nullptr, false)) {
620 return false;
621 }
622
623 return *r_ptr && *r_prop != nullptr;
624}
625
627 const char *path,
628 PointerRNA *r_ptr,
629 PropertyRNA **r_prop,
630 PointerRNA *r_item_ptr)
631{
632 if (!path) {
633 return false;
634 }
635 const std::optional<ParsedRNAPath<>> parsed_path = ParsedRNAPath<>::from_string(path);
636 if (!parsed_path) {
637 return false;
638 }
639 if (!rna_path_parse(ptr, *parsed_path, r_ptr, r_prop, nullptr, r_item_ptr, nullptr, false)) {
640 return false;
641 }
642
643 return *r_ptr && *r_prop != nullptr;
644}
645
647 const char *path,
648 PointerRNA *r_ptr,
649 PropertyRNA **r_prop,
650 int *r_index,
651 PointerRNA *r_item_ptr)
652{
653 if (!path) {
654 return false;
655 }
656 const std::optional<ParsedRNAPath<>> parsed_path = ParsedRNAPath<>::from_string(path);
657 if (!parsed_path) {
658 return false;
659 }
660 if (!rna_path_parse(ptr, *parsed_path, r_ptr, r_prop, r_index, r_item_ptr, nullptr, false)) {
661 return false;
662 }
663
664 return *r_ptr && *r_prop != nullptr;
665}
667 const char *path,
668 Vector<PropertyElemRNA> *r_elements)
669{
670 if (!path) {
671 return false;
672 }
673 const std::optional<ParsedRNAPath<>> parsed_path = ParsedRNAPath<>::from_string(path);
674 if (!parsed_path) {
675 return false;
676 }
677 return rna_path_parse(ptr, *parsed_path, nullptr, nullptr, nullptr, nullptr, r_elements, false);
678}
679
680char *RNA_path_append(const char *path,
681 const PointerRNA * /*ptr*/,
682 PropertyRNA *prop,
683 int intkey,
684 const char *strkey)
685{
686 DynStr *dynstr;
687 char *result;
688
689 dynstr = BLI_dynstr_new();
690
691 /* add .identifier */
692 if (path) {
693 BLI_dynstr_append(dynstr, path);
694 if (*path) {
695 BLI_dynstr_append(dynstr, ".");
696 }
697 }
698
700
701 const bool has_key = (intkey > -1) || (strkey != nullptr);
702 if (has_key && (RNA_property_type(prop) == PROP_COLLECTION)) {
703 /* add ["strkey"] or [intkey] */
704 BLI_dynstr_append(dynstr, "[");
705
706 if (strkey) {
707 const int strkey_esc_max_size = (strlen(strkey) * 2) + 1;
708 char *strkey_esc = static_cast<char *>(BLI_array_alloca(strkey_esc, strkey_esc_max_size));
709 BLI_str_escape(strkey_esc, strkey, strkey_esc_max_size);
710 BLI_dynstr_append(dynstr, "\"");
711 BLI_dynstr_append(dynstr, strkey_esc);
712 BLI_dynstr_append(dynstr, "\"");
713 }
714 else {
715 char appendstr[128];
716 SNPRINTF(appendstr, "%d", intkey);
717 BLI_dynstr_append(dynstr, appendstr);
718 }
719
720 BLI_dynstr_append(dynstr, "]");
721 }
722
724 BLI_dynstr_free(dynstr);
725
726 return result;
727}
728
729/* Having both path append & back seems like it could be useful,
730 * this function isn't used at the moment. */
731static UNUSED_FUNCTION_WITH_RETURN_TYPE(char *, RNA_path_back)(const char *path)
732{
733 char fixedbuf[256];
734 const char *previous, *current;
735 char *result;
736 int i;
737
738 if (!path) {
739 return nullptr;
740 }
741
742 previous = nullptr;
743 current = path;
744
745 /* parse token by token until the end, then we back up to the previous
746 * position and strip of the next token to get the path one step back */
747 while (*current) {
748 char *token;
749
750 token = rna_path_token(&current, fixedbuf, sizeof(fixedbuf));
751
752 if (!token) {
753 return nullptr;
754 }
755 if (token != fixedbuf) {
756 MEM_delete(token);
757 }
758
759 /* in case of collection we also need to strip off [] */
760 bool quoted;
761 token = rna_path_token_in_brackets(&current, fixedbuf, sizeof(fixedbuf), &quoted);
762 if (token && token != fixedbuf) {
763 MEM_delete(token);
764 }
765
766 if (!*current) {
767 break;
768 }
769
770 previous = current;
771 }
772
773 if (!previous) {
774 return nullptr;
775 }
776
777 /* copy and strip off last token */
778 i = previous - path;
779 result = BLI_strdup(path);
780
781 if (i > 0 && result[i - 1] == '.') {
782 i--;
783 }
784 result[i] = 0;
785
786 return result;
787}
788
789const char *RNA_path_array_index_token_find(const char *rna_path, const PropertyRNA *array_prop)
790{
791 if (array_prop != nullptr) {
792 if (!ELEM(array_prop->type, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
793 BLI_assert(array_prop->arraydimension == 0);
794 return nullptr;
795 }
796 if (array_prop->arraydimension == 0) {
797 return nullptr;
798 }
799 }
800
801 /* Valid 'array part' of a rna path can only have '[', ']' and digit characters.
802 * It may have more than one of those (e.g. `[12][1]`) in case of multi-dimensional arrays. */
803 if (rna_path[0] == '\0') [[unlikely]] {
804 return nullptr;
805 }
806 size_t rna_path_len = strlen(rna_path) - 1;
807 if (rna_path[rna_path_len] != ']') {
808 return nullptr;
809 }
810
811 const char *last_valid_index_token_start = nullptr;
812 while (rna_path_len--) {
813 switch (rna_path[rna_path_len]) {
814 case '[':
815 if (rna_path_len <= 0 || rna_path[rna_path_len - 1] != ']') {
816 return &rna_path[rna_path_len];
817 }
818 last_valid_index_token_start = &rna_path[rna_path_len];
819 rna_path_len--;
820 break;
821 case '0':
822 case '1':
823 case '2':
824 case '3':
825 case '4':
826 case '5':
827 case '6':
828 case '7':
829 case '8':
830 case '9':
831 break;
832 default:
833 return last_valid_index_token_start;
834 }
835 }
836 return last_valid_index_token_start;
837}
838
839/* generic path search func
840 * if its needed this could also reference the IDProperty direct */
841struct IDP_Chain {
842 IDP_Chain *up; /* parent member, reverse and set to child for path conversion. */
843
844 const char *name;
845 int index;
846};
847
848static char *rna_idp_path_create(IDP_Chain *child_link)
849{
850 DynStr *dynstr = BLI_dynstr_new();
851 char *path;
852 bool is_first = true;
853
854 IDP_Chain *link = child_link;
855
856 /* reverse the list */
857 IDP_Chain *link_prev;
858 link_prev = nullptr;
859 while (link) {
860 IDP_Chain *link_next = link->up;
861 link->up = link_prev;
862 link_prev = link;
863 link = link_next;
864 }
865
866 for (link = link_prev; link; link = link->up) {
867 /* pass */
868 if (link->index >= 0) {
869 BLI_dynstr_appendf(dynstr, is_first ? "%s[%d]" : ".%s[%d]", link->name, link->index);
870 }
871 else {
872 BLI_dynstr_appendf(dynstr, is_first ? "%s" : ".%s", link->name);
873 }
874
875 is_first = false;
876 }
877
878 path = BLI_dynstr_get_cstring(dynstr);
879 BLI_dynstr_free(dynstr);
880
881 if (*path == '\0') {
882 MEM_delete(path);
883 path = nullptr;
884 }
885
886 return path;
887}
888
889static char *rna_idp_path(PointerRNA *ptr,
890 const IDProperty *haystack,
891 const IDProperty *needle,
892 IDP_Chain *parent_link)
893{
894 char *path = nullptr;
895 IDP_Chain link;
896
897 const IDProperty *iter;
898
899 BLI_assert(haystack->type == IDP_GROUP);
900
901 link.up = parent_link;
902 /* Always set both name and index, else a stale value might get used. */
903 link.name = nullptr;
904 link.index = -1;
905
906 for (iter = haystack->data.group.first(); iter; iter = iter->next) {
907 if (needle == iter) { /* found! */
908 link.name = iter->name;
909 link.index = -1;
910 path = rna_idp_path_create(&link);
911 break;
912 }
913
914 /* Early out in case the IDProperty type cannot contain RNA properties. */
915 if (!ELEM(iter->type, IDP_GROUP, IDP_IDPARRAY)) {
916 continue;
917 }
918
919 /* Ensure this is RNA. */
920 /* NOTE: `iter` might be a fully user-defined IDProperty (a.k.a. custom data), which name
921 * collides with an actual fully static RNA property of the same struct (which would then not
922 * be flagged with `PROP_IDPROPERTY`).
923 *
924 * That case must be ignored here, we only want to deal with runtime RNA properties stored in
925 * IDProps.
926 *
927 * See #84091. */
928 PropertyRNA *prop = RNA_struct_find_property(ptr, iter->name);
929 if (prop == nullptr || (prop->flag & PROP_IDPROPERTY) == 0) {
930 continue;
931 }
932
933 if (iter->type == IDP_GROUP) {
934 if (prop->type == PROP_POINTER) {
935 PointerRNA child_ptr = RNA_property_pointer_get(ptr, prop);
936 if (!child_ptr) {
937 /* Pointer ID prop might be a 'leaf' in the IDProp group hierarchy, in which case a null
938 * value is perfectly valid. Just means it won't match the searched needle. */
939 continue;
940 }
941
942 link.name = iter->name;
943 link.index = -1;
944 if ((path = rna_idp_path(&child_ptr, iter, needle, &link))) {
945 break;
946 }
947 }
948 }
949 else if (iter->type == IDP_IDPARRAY) {
950 if (prop->type == PROP_COLLECTION) {
952 if (needle >= array && needle < (iter->len + array)) { /* found! */
953 link.name = iter->name;
954 link.index = int(needle - array);
955 path = rna_idp_path_create(&link);
956 break;
957 }
958 int j;
959 link.name = iter->name;
960 for (j = 0; j < iter->len; j++, array++) {
961 PointerRNA child_ptr;
962 if (RNA_property_collection_lookup_int(ptr, prop, j, &child_ptr)) {
963 if (!child_ptr) {
964 /* Array item ID prop might be a 'leaf' in the IDProp group hierarchy, in which case
965 * a null value is perfectly valid. Just means it won't match the searched needle. */
966 continue;
967 }
968 link.index = j;
969 if ((path = rna_idp_path(&child_ptr, array, needle, &link))) {
970 break;
971 }
972 }
973 }
974 if (path) {
975 break;
976 }
977 }
978 }
979 }
980
981 return path;
982}
983
984std::optional<std::string> RNA_path_from_struct_to_idproperty(PointerRNA *ptr,
985 const IDProperty *needle)
986{
987 const IDProperty *haystack = RNA_struct_system_idprops(ptr, false);
988
989 if (!haystack) { /* can fail when called on bones */
990 return std::nullopt;
991 }
992
993 const char *path = rna_idp_path(ptr, haystack, needle, nullptr);
994 if (!path) {
995 return std::nullopt;
996 }
997
998 std::string string_path(path);
999 MEM_delete(path);
1000
1001 return string_path;
1002}
1003
1004static std::optional<std::string> rna_path_from_ID_to_idpgroup(const PointerRNA *ptr)
1005{
1006 BLI_assert(ptr->owner_id != nullptr);
1007
1008 /* TODO: Support Bones/PoseBones. no pointers stored to the bones from here, only the ID.
1009 * See example in #25746.
1010 * Unless this is added only way to find this is to also search
1011 * all bones and pose bones of an armature or object.
1012 */
1014
1015 return RNA_path_from_struct_to_idproperty(&id_ptr, static_cast<const IDProperty *>(ptr->data));
1016}
1017
1018ID *RNA_find_real_ID_and_path(ID *id, const char **r_path)
1019{
1020 if (r_path) {
1021 *r_path = "";
1022 }
1023
1024 if ((id == nullptr) || (id->flag & ID_FLAG_EMBEDDED_DATA) == 0) {
1025 return id;
1026 }
1027
1028 if (r_path) {
1029 switch (id->id_type()) {
1030 case ID_NT:
1031 *r_path = "node_tree";
1032 break;
1033 case ID_GR:
1034 *r_path = "collection";
1035 break;
1036 default:
1037 BLI_assert_msg(0, "Missing handling of embedded id type.");
1038 }
1039 }
1040
1041 ID *owner_id = BKE_id_owner_get(id);
1042 BLI_assert_msg(owner_id != nullptr, "Missing handling of embedded id type.");
1043 return (owner_id != nullptr) ? owner_id : id;
1044}
1045
1046static std::optional<std::string> rna_prepend_real_ID_path(Main * /*bmain*/,
1047 ID *id,
1048 const StringRef path,
1049 ID **r_real_id)
1050{
1051 if (r_real_id != nullptr) {
1052 *r_real_id = nullptr;
1053 }
1054
1055 const char *prefix;
1056 ID *real_id = RNA_find_real_ID_and_path(id, &prefix);
1057
1058 if (r_real_id != nullptr) {
1059 *r_real_id = real_id;
1060 }
1061
1062 if (!path.is_empty()) {
1063 if (real_id) {
1064 if (prefix[0]) {
1065 return fmt::format("{}{}{}", prefix, path[0] == '[' ? "" : ".", path);
1066 }
1067 return path;
1068 }
1069 }
1070
1071 if (prefix[0] == '\0') {
1072 return std::nullopt;
1073 }
1074
1075 return prefix;
1076}
1077
1078std::optional<std::string> RNA_path_from_ID_to_struct(const PointerRNA *ptr)
1079{
1080 std::optional<std::string> ptrpath;
1081
1082 if (!ptr->has_owner_id() || !*ptr) {
1083 return std::nullopt;
1084 }
1085
1086 if (!RNA_struct_is_ID(ptr->type)) {
1087 if (ptr->type->path) {
1088 /* if type has a path to some ID, use it */
1089 ptrpath = ptr->type->path(const_cast<PointerRNA *>(ptr));
1090 }
1091 else if (ptr->type->nested && RNA_struct_is_ID(ptr->type->nested)) {
1092 PropertyRNA *userprop;
1093
1094 /* find the property in the struct we're nested in that references this struct, and
1095 * use its identifier as the first part of the path used...
1096 */
1097 PointerRNA parentptr = RNA_id_pointer_create(ptr->owner_id);
1098 userprop = rna_struct_find_nested(&parentptr, ptr->type);
1099
1100 if (userprop) {
1101 ptrpath = RNA_property_identifier(userprop);
1102 }
1103 else {
1104 /* can't do anything about this case yet... */
1105 return std::nullopt;
1106 }
1107 }
1108 else if (RNA_struct_is_a(ptr->type, RNA_PropertyGroup)) {
1109 /* special case, easier to deal with here than in ptr->type->path() */
1110 return rna_path_from_ID_to_idpgroup(ptr);
1111 }
1112 else {
1113 return std::nullopt;
1114 }
1115 }
1116
1117 return ptrpath;
1118}
1119
1120std::optional<std::string> RNA_path_from_real_ID_to_struct(Main *bmain,
1121 const PointerRNA *ptr,
1122 ID **r_real)
1123{
1124 const std::optional<std::string> path = RNA_path_from_ID_to_struct(ptr);
1125
1126 /* Null path is valid in that case, when given struct is an ID one. */
1127 return rna_prepend_real_ID_path(bmain, ptr->owner_id, path.value_or(""), r_real);
1128}
1129
1131 const int totdims,
1132 const int index_dim,
1133 int index,
1134 int r_index_multi[RNA_MAX_ARRAY_LENGTH])
1135{
1136 int dimsize_step[RNA_MAX_ARRAY_LENGTH + 1];
1137 int i = totdims - 1;
1138 dimsize_step[i + 1] = 1;
1139 dimsize_step[i] = dimsize[i];
1140 while (--i != -1) {
1141 dimsize_step[i] = dimsize[i] * dimsize_step[i + 1];
1142 }
1143 while (++i != index_dim) {
1144 int index_round = index / dimsize_step[i + 1];
1145 r_index_multi[i] = index_round;
1146 index -= (index_round * dimsize_step[i + 1]);
1147 }
1148 BLI_assert(index == 0);
1149}
1150
1152 PropertyRNA *prop,
1153 int index_dim,
1154 int index,
1155 char *index_str,
1156 int index_str_maxncpy)
1157{
1158 int dimsize[RNA_MAX_ARRAY_LENGTH];
1159 int totdims = RNA_property_array_dimension(ptr, prop, dimsize);
1160 int index_multi[RNA_MAX_ARRAY_LENGTH];
1161
1162 rna_path_array_multi_from_flat_index(dimsize, totdims, index_dim, index, index_multi);
1163
1164 for (int i = 0, offset = 0; (i < index_dim) && (offset < index_str_maxncpy); i++) {
1165 offset += BLI_snprintf_rlen(
1166 &index_str[offset], index_str_maxncpy - offset, "[%d]", index_multi[i]);
1167 }
1168}
1169
1171 PropertyRNA *prop,
1172 int index_dim,
1173 int index,
1174 const StringRef path_prefix)
1175{
1176 const bool is_rna = (prop->magic == RNA_MAGIC);
1177
1178 const char *propname = RNA_property_identifier(prop);
1179
1180 /* support indexing w/ multi-dimensional arrays */
1181 char index_str[RNA_MAX_ARRAY_LENGTH * 12 + 1];
1182 if (index_dim == 0) {
1183 index_str[0] = '\0';
1184 }
1185 else {
1187 ptr, prop, index_dim, index, index_str, sizeof(index_str));
1188 }
1189
1190 if (!path_prefix.is_empty()) {
1191 if (is_rna) {
1192 return fmt::format("{}.{}{}", path_prefix, propname, index_str);
1193 }
1194 char propname_esc[MAX_IDPROP_NAME * 2];
1195 BLI_str_escape(propname_esc, propname, sizeof(propname_esc));
1196 return fmt::format("{}[\"{}\"]{}", path_prefix, propname_esc, index_str);
1197 }
1198
1199 if (is_rna) {
1200 if (index_dim == 0) {
1201 /* Use direct duplication instead of #fmt::format because it's faster. */
1202 return propname;
1203 }
1204 return fmt::format("{}{}", propname, index_str);
1205 }
1206
1207 char propname_esc[MAX_IDPROP_NAME * 2];
1208 BLI_str_escape(propname_esc, propname, sizeof(propname_esc));
1209 return fmt::format("[\"{}\"]{}", propname_esc, index_str);
1210}
1211
1213 PropertyRNA *prop,
1214 int index_dim,
1215 int index)
1216{
1217 return rna_path_from_ptr_to_property_index_ex(ptr, prop, index_dim, index, "");
1218}
1219
1220std::optional<std::string> RNA_path_from_ID_to_property_index(const PointerRNA *ptr,
1221 PropertyRNA *prop,
1222 int index_dim,
1223 int index)
1224{
1225 if (!ptr->has_owner_id() || !*ptr) {
1226 return std::nullopt;
1227 }
1228 /* Path from ID to the struct holding this property. */
1229 std::optional<std::string> ptrpath = RNA_path_from_ID_to_struct(ptr);
1230 /* When there is no path and this is not an ID, there is no path to the ID. */
1231 if (!ptrpath && !RNA_struct_is_ID(ptr->type)) {
1232 return std::nullopt;
1233 }
1234 return rna_path_from_ptr_to_property_index_ex(ptr, prop, index_dim, index, ptrpath.value_or(""));
1235}
1236
1237std::optional<std::string> RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
1238{
1239 return RNA_path_from_ID_to_property_index(ptr, prop, 0, -1);
1240}
1241
1242std::optional<std::string> RNA_path_from_real_ID_to_property_index(Main *bmain,
1243 const PointerRNA *ptr,
1244 PropertyRNA *prop,
1245 int index_dim,
1246 int index,
1247 ID **r_real_id)
1248{
1249 const std::optional<std::string> path = RNA_path_from_ID_to_property_index(
1250 ptr, prop, index_dim, index);
1251 if (!path) {
1252 return std::nullopt;
1253 }
1254
1255 /* Null path is always an error here, in that case do not return the 'fake ID from real ID' part
1256 * of the path either. */
1257 return rna_prepend_real_ID_path(bmain, ptr->owner_id, path->c_str(), r_real_id);
1258}
1259
1260std::optional<std::string> RNA_path_resolve_from_type_to_property(const PointerRNA *ptr,
1261 PropertyRNA *prop,
1262 const StructRNA *type)
1263{
1264 /* Try to recursively find an "type"'d ancestor,
1265 * to handle situations where path from ID is not enough. */
1266 const std::optional<std::string> full_path = RNA_path_from_ID_to_property(ptr, prop);
1267 if (!full_path) {
1268 return std::nullopt;
1269 }
1270
1272
1273 std::optional<std::string> path;
1274 Vector<PropertyElemRNA> path_elems;
1275 if (RNA_path_resolve_elements(&idptr, full_path->c_str(), &path_elems)) {
1276 for (PropertyElemRNA &prop_elem : path_elems | std::views::reverse) {
1277 if (RNA_struct_is_a(prop_elem.ptr.type, type)) {
1278 if (const std::optional<std::string> ref_path = RNA_path_from_ID_to_struct(&prop_elem.ptr))
1279 {
1280 path = StringRef(*full_path).drop_prefix(ref_path->size() + 1);
1281 }
1282 break;
1283 }
1284 }
1285 }
1286
1287 return path;
1288}
1289
1290std::string RNA_path_full_ID_py(ID *id)
1291{
1292 const char *path;
1293 ID *id_real = RNA_find_real_ID_and_path(id, &path);
1294
1295 if (id_real) {
1296 id = id_real;
1297 }
1298 else {
1299 path = "";
1300 }
1301
1302 char lib_filepath_esc[(sizeof(id->lib->filepath) * 2) + 4];
1303 if (ID_IS_LINKED(id)) {
1304 int ofs = 0;
1305 memcpy(lib_filepath_esc, ", \"", 3);
1306 ofs += 3;
1307 ofs += BLI_str_escape(lib_filepath_esc + ofs, id->lib->filepath, sizeof(lib_filepath_esc));
1308 memcpy(lib_filepath_esc + ofs, "\"", 2);
1309 }
1310 else {
1311 lib_filepath_esc[0] = '\0';
1312 }
1313
1314 char id_esc[(sizeof(id->name) - 2) * 2];
1315 BLI_str_escape(id_esc, id->name + 2, sizeof(id_esc));
1316
1317 return fmt::format("bpy.data.{}[\"{}\"{}]{}{}",
1319 id_esc,
1320 lib_filepath_esc,
1321 path[0] ? "." : "",
1322 path);
1323}
1324
1325std::optional<std::string> RNA_path_full_struct_py(const PointerRNA *ptr)
1326{
1327 if (!ptr->owner_id) {
1328 return std::nullopt;
1329 }
1330
1331 /* never fails */
1332 std::string id_path = RNA_path_full_ID_py(ptr->owner_id);
1333
1334 std::optional<std::string> data_path = RNA_path_from_ID_to_struct(ptr);
1335
1336 /* XXX data_path may be null (see #36788),
1337 * do we want to get the 'bpy.data.foo["bar"].(null)' stuff? */
1338 return fmt::format("{}.{}", id_path, data_path.value_or(""));
1339}
1340
1341std::optional<std::string> RNA_path_full_property_py_ex(const PointerRNA *ptr,
1342 PropertyRNA *prop,
1343 int index,
1344 bool use_fallback)
1345{
1346 const char *data_delim;
1347
1348 if (!ptr->owner_id) {
1349 return std::nullopt;
1350 }
1351
1352 /* never fails */
1353 std::string id_path = RNA_path_full_ID_py(ptr->owner_id);
1354
1355 std::optional<std::string> data_path = RNA_path_from_ID_to_property(ptr, prop);
1356 if (data_path) {
1357 data_delim = ((*data_path)[0] == '[') ? "" : ".";
1358 }
1359 else {
1360 if (use_fallback) {
1361 /* Fuzzy fallback. Be explicit in our ignorance. */
1362 data_path = RNA_property_identifier(prop);
1363 data_delim = " ... ";
1364 }
1365 else {
1366 data_delim = ".";
1367 }
1368 }
1369
1370 if ((index == -1) || (RNA_property_array_check(prop) == false)) {
1371 return fmt::format("{}{}{}", id_path, data_delim, data_path.value_or(""));
1372 }
1373 return fmt::format("{}{}{}[{}]", id_path, data_delim, data_path.value_or(""), index);
1374}
1375
1376std::optional<std::string> RNA_path_full_property_py(const PointerRNA *ptr,
1377 PropertyRNA *prop,
1378 int index)
1379{
1380 return RNA_path_full_property_py_ex(ptr, prop, index, false);
1381}
1382
1383std::optional<std::string> RNA_path_struct_property_py(PointerRNA *ptr,
1384 PropertyRNA *prop,
1385 int index)
1386{
1387 if (!ptr->owner_id) {
1388 return std::nullopt;
1389 }
1390
1391 std::optional<std::string> data_path = RNA_path_from_ID_to_property(ptr, prop);
1392
1393 if (!data_path) {
1394 /* This may not be an ID at all, check for simple when pointer owns property.
1395 * TODO: more complex nested case. */
1396 if (!RNA_struct_is_ID(ptr->type)) {
1397 const char *prop_identifier = RNA_property_identifier(prop);
1398 if (RNA_struct_find_property(ptr, prop_identifier) == prop) {
1399 data_path = prop_identifier;
1400 }
1401 }
1402 }
1403
1404 if ((index == -1) || (RNA_property_array_check(prop) == false)) {
1405 return data_path;
1406 }
1407 return fmt::format("{}[{}]", data_path.value_or(""), index);
1408}
1409
1410std::string RNA_path_property_py(const PointerRNA *ptr, PropertyRNA *prop, int index)
1411{
1412 if (RNA_property_array_check(prop) == false) {
1413 index = -1;
1414 }
1415 const int index_dim = (index == -1) ? 0 : 1;
1416 return RNA_path_from_ptr_to_property_index(ptr, prop, index_dim, index);
1417}
1418
1419std::string RNA_path_name_to_infix(const StringRefNull string)
1420{
1421 const std::string old_name_esc = BLI_str_escape(string);
1422 return fmt::format("[\"{}\"]", old_name_esc);
1423}
1424
1425std::string RNA_path_number_to_infix(const int number)
1426{
1427 return fmt::format("[{}]", number);
1428}
1429
1430std::pair<std::string, std::string> RNA_generate_keys_for_path_rename(
1431 const StringRefNull old_infix,
1432 const StringRefNull new_infix,
1433 const int old_subscript,
1434 const int new_subscript,
1435 const bool infix_is_name)
1436
1437{
1438 std::string old_key;
1439 std::string new_key;
1440
1441 if (!old_infix.is_empty() && !new_infix.is_empty()) {
1442 if (infix_is_name) {
1443 old_key = RNA_path_name_to_infix(old_infix);
1444 new_key = RNA_path_name_to_infix(new_infix);
1445 }
1446 else {
1447 old_key = old_infix;
1448 new_key = new_infix;
1449 }
1450 }
1451 else {
1452 old_key = RNA_path_number_to_infix(old_subscript);
1453 new_key = RNA_path_number_to_infix(new_subscript);
1454 }
1455
1456 return {old_key, new_key};
1457}
1458
1459} // namespace blender
#define IDP_property_array_get(prop)
#define BLI_array_alloca(arr, realsize)
Definition BLI_alloca.hh:18
A dynamically sized string ADT.
#define SNPRINTF(dst, format,...)
ID and Library types, which are fundamental for SDNA.
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define MAX_IDPROP_NAME
Definition DNA_ID.h:174
Read Blender memory allocation and freeing.
#define RNA_MAX_ARRAY_LENGTH
Definition RNA_define.hh:26
#define RNA_MAX_ARRAY_DIMENSION
Definition RNA_define.hh:29
#define BLI_assert_unreachable()
#define ELEM(...)
#define BLI_assert_msg(a, msg)
constexpr IndexRange()=default
Vector< rna_path::Item, N > items
Definition RNA_path.hh:144
std::string to_string() const
Definition rna_path.cc:285
static std::optional< ParsedRNAPath > from_string(StringRefNull path)
Definition rna_path.cc:194
constexpr const T * end() const
Definition BLI_span.hh:228
constexpr const T * begin() const
Definition BLI_span.hh:224
constexpr bool is_empty() const
Definition BLI_span.hh:264
constexpr const char * c_str() const
constexpr StringRef()
UString()=default
void append(const T &value)
const T & last(const int64_t n=0) const
constexpr bool is_empty() const
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
bool operator==(const Error &left, const Error &right)
std::variant< Member, LookupIndex, LookupKey > Item
Definition RNA_path.hh:106
std::string to_string(const Span< Item > items)
Definition rna_path.cc:246
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
__int64 int64_t
Definition BKE_text.h:90
PropertyRNA * rna_struct_find_nested(PointerRNA *ptr, StructRNA *srna)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool RNA_path_resolve_property_and_item_pointer_full(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index, PointerRNA *r_item_ptr)
Definition rna_path.cc:646
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bool RNA_path_resolve(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:529
std::optional< std::string > RNA_path_struct_property_py(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition rna_path.cc:1383
PointerRNA RNA_id_pointer_create(ID *id)
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
Definition rna_path.cc:1237
std::optional< std::string > RNA_path_full_struct_py(const PointerRNA *ptr)
Definition rna_path.cc:1325
const char * RNA_property_identifier(const PropertyRNA *prop)
std::string RNA_path_number_to_infix(const int number)
Definition rna_path.cc:1425
static void rna_path_array_multi_string_from_flat_index(const PointerRNA *ptr, PropertyRNA *prop, int index_dim, int index, char *index_str, int index_str_maxncpy)
Definition rna_path.cc:1151
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:818
std::string RNA_path_name_to_infix(const StringRefNull string)
Definition rna_path.cc:1419
std::optional< std::string > RNA_path_from_ID_to_struct(const PointerRNA *ptr)
Definition rna_path.cc:1078
std::pair< std::string, std::string > RNA_generate_keys_for_path_rename(const StringRefNull old_infix, const StringRefNull new_infix, const int old_subscript, const int new_subscript, const bool infix_is_name)
Definition rna_path.cc:1430
std::optional< std::string > RNA_path_from_real_ID_to_property_index(Main *bmain, const PointerRNA *ptr, PropertyRNA *prop, int index_dim, int index, ID **r_real_id)
Definition rna_path.cc:1242
ID * RNA_find_real_ID_and_path(ID *id, const char **r_path)
Definition rna_path.cc:1018
size_t size_t const char * BLI_str_escape_find_quote(const char *str) ATTR_NONNULL(1)
Span< rna_path::Item > ParsedRNAPathRef
Definition RNA_path.hh:113
int RNA_property_array_item_index(PropertyRNA *prop, char name)
static char * rna_path_token_in_brackets(const char **path, char *fixedbuf, int fixedlen, bool *r_quoted)
Definition rna_path.cc:108
size_t BLI_snprintf_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
StructRNA RNA_PropertyGroup
bool RNA_property_array_check(PropertyRNA *prop)
PropertyType RNA_property_type(PropertyRNA *prop)
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition BLI_dynstr.cc:58
static UNUSED_FUNCTION_WITH_RETURN_TYPE(wmGizmoGroup *, idp_gizmogroup_from_region)(ARegion *region)
bool RNA_path_resolve_property_and_item_pointer(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, PointerRNA *r_item_ptr)
Definition rna_path.cc:626
std::optional< std::string > RNA_path_from_real_ID_to_struct(Main *bmain, const PointerRNA *ptr, ID **r_real)
Definition rna_path.cc:1120
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_COLLECTION
Definition RNA_types.hh:216
IDProperty * RNA_struct_system_idprops(PointerRNA *ptr, bool create)
std::string RNA_path_from_ptr_to_property_index(const PointerRNA *ptr, PropertyRNA *prop, int index_dim, int index)
Definition rna_path.cc:1212
IDProperty * RNA_struct_idprops(PointerRNA *ptr, bool create)
std::string RNA_path_full_ID_py(ID *id)
Definition rna_path.cc:1290
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
std::optional< std::string > RNA_path_resolve_from_type_to_property(const PointerRNA *ptr, PropertyRNA *prop, const StructRNA *type)
Definition rna_path.cc:1260
bool RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr)
bool RNA_path_resolve_elements(PointerRNA *ptr, const char *path, Vector< PropertyElemRNA > *r_elements)
Definition rna_path.cc:666
const char * BKE_idtype_idcode_to_name_plural(short idcode)
Definition idtype.cc:268
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
std::string RNA_path_property_py(const PointerRNA *ptr, PropertyRNA *prop, int index)
Definition rna_path.cc:1410
int RNA_property_array_dimension(const PointerRNA *ptr, PropertyRNA *prop, int length[])
bool RNA_struct_is_ID(const StructRNA *type)
static std::optional< std::string > rna_prepend_real_ID_path(Main *, ID *id, const StringRef path, ID **r_real_id)
Definition rna_path.cc:1046
static std::optional< std::string > rna_path_from_ID_to_idpgroup(const PointerRNA *ptr)
Definition rna_path.cc:1004
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
std::optional< std::string > RNA_path_full_property_py(const PointerRNA *ptr, PropertyRNA *prop, int index)
Definition rna_path.cc:1376
static void rna_path_array_multi_from_flat_index(const int dimsize[RNA_MAX_ARRAY_LENGTH], const int totdims, const int index_dim, int index, int r_index_multi[RNA_MAX_ARRAY_LENGTH])
Definition rna_path.cc:1130
std::optional< PointerRNA > RNA_property_collection_type_get(PointerRNA *ptr, PropertyRNA *prop)
static char * rna_path_token(const char **path, char *fixedbuf, int fixedlen)
Definition rna_path.cc:68
std::optional< std::string > RNA_path_from_ID_to_property_index(const PointerRNA *ptr, PropertyRNA *prop, int index_dim, int index)
Definition rna_path.cc:1220
std::optional< std::string > RNA_path_full_property_py_ex(const PointerRNA *ptr, PropertyRNA *prop, int index, bool use_fallback)
Definition rna_path.cc:1341
@ PROP_IDPROPERTY
Definition RNA_types.hh:496
static bool rna_path_parse(const PointerRNA *ptr, const ParsedRNAPathRef path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index, PointerRNA *r_item_ptr, Vector< PropertyElemRNA > *r_elements, const bool eval_pointer)
Definition rna_path.cc:314
char * RNA_path_append(const char *path, const PointerRNA *, PropertyRNA *prop, int intkey, const char *strkey)
Definition rna_path.cc:680
bool RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr)
const char * RNA_path_array_index_token_find(const char *rna_path, const PropertyRNA *array_prop)
Definition rna_path.cc:789
static std::string rna_path_from_ptr_to_property_index_ex(const PointerRNA *ptr, PropertyRNA *prop, int index_dim, int index, const StringRef path_prefix)
Definition rna_path.cc:1170
size_t size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, size_t src_len) ATTR_NONNULL(1
ID * BKE_id_owner_get(ID *id, const bool debug_relationship_assert=true)
Definition lib_id.cc:2770
@ ID_FLAG_EMBEDDED_DATA
Definition DNA_ID.h:775
bool RNA_path_resolve_full_maybe_null(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
Definition rna_path.cc:565
static char * rna_idp_path_create(IDP_Chain *child_link)
Definition rna_path.cc:848
static char * rna_idp_path(PointerRNA *ptr, const IDProperty *haystack, const IDProperty *needle, IDP_Chain *parent_link)
Definition rna_path.cc:889
bool RNA_path_resolve_property_full(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
Definition rna_path.cc:609
DynStr * BLI_dynstr_new() ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition BLI_dynstr.cc:39
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:578
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
std::optional< std::string > RNA_path_from_struct_to_idproperty(PointerRNA *ptr, const IDProperty *needle)
Definition rna_path.cc:984
bool RNA_path_resolve_full(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
Definition rna_path.cc:548
#define RNA_MAGIC
const char * name
Definition rna_path.cc:844
IDP_Chain * up
Definition rna_path.cc:842
ListBaseT< struct IDProperty > group
Definition DNA_ID.h:133
eIDPropertyType type
Definition DNA_ID.h:145
struct IDProperty * next
Definition DNA_ID.h:144
IDPropertyData data
Definition DNA_ID.h:157
StructRNA * type
Definition RNA_types.hh:63
bool has_owner_id() const
Definition RNA_types.hh:186
std::optional< std::string > key
Definition RNA_path.hh:74
std::string path
Definition RNA_path.hh:68
std::optional< int > index
Definition RNA_path.hh:75
int64_t hash() const
Definition rna_path.cc:41