12#include <fmt/format.h>
32#include "RNA_prototypes.hh"
43 if (
key.has_value()) {
55 if (left.
key.has_value() || right.
key.has_value()) {
56 return left.
key == right.
key;
73 const char *p = *path;
74 while (*p && !
ELEM(*p,
'.',
'[')) {
80 if (
len == 0) [[unlikely]] {
85 char *buf = (
len + 1 < fixedlen) ? fixedbuf :
87 memcpy(buf, *path,
sizeof(
char) *
len);
119 if (**path !=
'[') [[unlikely]] {
124 const char *p = *path;
132 if (p_end ==
nullptr) {
146 while (*p && (*p !=
']')) {
152 if (*p !=
']') [[unlikely]] {
159 if (
len == 0) [[unlikely]] {
165 char *buf = (
len + 1 < fixedlen) ? fixedbuf :
173 p = (*path) +
len + 1;
176 memcpy(buf, *path,
sizeof(
char) *
len);
200 std::optional<ParsedRNAPath<N>> parsed;
202 const char *current = path.
c_str();
204 const char c = *current;
217 if (
index == 0 && (token[0] !=
'0' || token[1] !=
'\0')) {
218 if (buffer != token) {
225 if (buffer != token) {
236 if (buffer != token) {
249 for (
const auto &item : items) {
250 if (
const Member *member = std::get_if<Member>(&item)) {
254 result.append(member->identifier.c_str());
256 else if (
const LookupIndex *lookup_index = std::get_if<LookupIndex>(&item)) {
258 result.append(std::to_string(lookup_index->index));
261 else if (
const LookupKey *lookup_key = std::get_if<LookupKey>(&item)) {
263 for (
const char c : lookup_key->key.ref()) {
321 const bool eval_pointer)
323 BLI_assert(r_item_ptr ==
nullptr || !eval_pointer);
327 const bool do_item_ptr = r_item_ptr !=
nullptr && !eval_pointer;
341 while (item_iter != path.
end()) {
352 if (
const auto *member = std::get_if<rna_path::Member>(item_iter)) {
355 else if (
const auto *lookup_key = std::get_if<rna_path::LookupKey>(item_iter)) {
390 if (do_item_ptr || eval_pointer || item_iter != path.
end()) {
394 if (eval_pointer || item_iter != path.
end()) {
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))
412 else if (
const auto *lookup_index = std::get_if<rna_path::LookupIndex>(item_iter)) {
414 &curptr, prop,
int(lookup_index->index), &nextptr))
430 if (eval_pointer || item_iter != path.
end()) {
439 if (r_index || r_elements) {
440 if (item_iter == path.
end()) {
449 if (item_iter == path.
end()) {
454 if (
const auto *lookup_index = std::get_if<rna_path::LookupIndex>(item_iter)) {
455 array_indices[d] = int(lookup_index->index);
457 else if (
const auto *lookup_key = std::get_if<rna_path::LookupKey>(item_iter)) {
463 const auto *member = std::get_if<rna_path::Member>(item_iter);
474 if (array_indices[d] < 0 || array_indices[d] >= dimension_size[d]) {
481 if (item_iter != path.
end()) {
488 for (
int d = dim - 1; d >= 0; d--) {
489 flat_index += array_indices[d] * dim_total;
490 dim_total *= dimension_size[d];
511 if (r_item_ptr && do_item_ptr) {
512 *r_item_ptr = nextptr;
541 if (!
rna_path_parse(ptr, *parsed_path, r_ptr, r_prop,
nullptr,
nullptr,
nullptr,
true)) {
558 if (!
rna_path_parse(ptr, *parsed_path, r_ptr, r_prop, r_index,
nullptr,
nullptr,
true)) {
575 return rna_path_parse(ptr, *parsed_path, r_ptr, r_prop, r_index,
nullptr,
nullptr,
true);
590 if (!
rna_path_parse(ptr, *parsed_path, r_ptr, r_prop,
nullptr,
nullptr,
nullptr,
false)) {
594 return *r_ptr && *r_prop !=
nullptr;
602 if (!
rna_path_parse(ptr, path, r_ptr, r_prop,
nullptr,
nullptr,
nullptr,
false)) {
606 return *r_ptr && *r_prop !=
nullptr;
619 if (!
rna_path_parse(ptr, *parsed_path, r_ptr, r_prop, r_index,
nullptr,
nullptr,
false)) {
623 return *r_ptr && *r_prop !=
nullptr;
639 if (!
rna_path_parse(ptr, *parsed_path, r_ptr, r_prop,
nullptr, r_item_ptr,
nullptr,
false)) {
643 return *r_ptr && *r_prop !=
nullptr;
660 if (!
rna_path_parse(ptr, *parsed_path, r_ptr, r_prop, r_index, r_item_ptr,
nullptr,
false)) {
664 return *r_ptr && *r_prop !=
nullptr;
677 return rna_path_parse(ptr, *parsed_path,
nullptr,
nullptr,
nullptr,
nullptr, r_elements,
false);
701 const bool has_key = (intkey > -1) || (strkey !=
nullptr);
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));
734 const char *previous, *current;
755 if (token != fixedbuf) {
762 if (token && token != fixedbuf) {
781 if (i > 0 &&
result[i - 1] ==
'.') {
791 if (array_prop !=
nullptr) {
803 if (
rna_path[0] ==
'\0') [[unlikely]] {
806 size_t rna_path_len = strlen(
rna_path) - 1;
807 if (
rna_path[rna_path_len] !=
']') {
811 const char *last_valid_index_token_start =
nullptr;
812 while (rna_path_len--) {
815 if (rna_path_len <= 0 ||
rna_path[rna_path_len - 1] !=
']') {
818 last_valid_index_token_start = &
rna_path[rna_path_len];
833 return last_valid_index_token_start;
836 return last_valid_index_token_start;
852 bool is_first =
true;
861 link->
up = link_prev;
866 for (link = link_prev; link; link = link->
up) {
868 if (link->
index >= 0) {
894 char *path =
nullptr;
901 link.
up = parent_link;
906 for (iter = haystack->
data.
group.first(); iter; iter = iter->
next) {
907 if (needle == iter) {
944 if ((path =
rna_idp_path(&child_ptr, iter, needle, &link))) {
960 for (j = 0; j < iter->
len; j++,
array++) {
993 const char *path =
rna_idp_path(ptr, haystack, needle,
nullptr);
998 std::string string_path(path);
1029 switch (
id->id_type()) {
1031 *r_path =
"node_tree";
1034 *r_path =
"collection";
1042 BLI_assert_msg(owner_id !=
nullptr,
"Missing handling of embedded id type.");
1043 return (owner_id !=
nullptr) ? owner_id :
id;
1051 if (r_real_id !=
nullptr) {
1052 *r_real_id =
nullptr;
1058 if (r_real_id !=
nullptr) {
1059 *r_real_id = real_id;
1065 return fmt::format(
"{}{}{}", prefix, path[0] ==
'[' ?
"" :
".", path);
1071 if (prefix[0] ==
'\0') {
1072 return std::nullopt;
1080 std::optional<std::string> ptrpath;
1083 return std::nullopt;
1105 return std::nullopt;
1113 return std::nullopt;
1132 const int index_dim,
1137 int i = totdims - 1;
1138 dimsize_step[i + 1] = 1;
1139 dimsize_step[i] = dimsize[i];
1141 dimsize_step[i] = dimsize[i] * dimsize_step[i + 1];
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]);
1156 int index_str_maxncpy)
1164 for (
int i = 0, offset = 0; (i < index_dim) && (offset < index_str_maxncpy); i++) {
1166 &index_str[offset], index_str_maxncpy - offset,
"[%d]", index_multi[i]);
1182 if (index_dim == 0) {
1183 index_str[0] =
'\0';
1187 ptr, prop, index_dim,
index, index_str,
sizeof(index_str));
1192 return fmt::format(
"{}.{}{}", path_prefix, propname, index_str);
1196 return fmt::format(
"{}[\"{}\"]{}", path_prefix, propname_esc, index_str);
1200 if (index_dim == 0) {
1204 return fmt::format(
"{}{}", propname, index_str);
1209 return fmt::format(
"[\"{}\"]{}", propname_esc, index_str);
1226 return std::nullopt;
1232 return std::nullopt;
1250 ptr, prop, index_dim,
index);
1252 return std::nullopt;
1268 return std::nullopt;
1273 std::optional<std::string> path;
1280 path =
StringRef(*full_path).drop_prefix(ref_path->size() + 1);
1302 char lib_filepath_esc[(
sizeof(
id->lib->filepath) * 2) + 4];
1305 memcpy(lib_filepath_esc,
", \"", 3);
1307 ofs +=
BLI_str_escape(lib_filepath_esc + ofs,
id->lib->filepath,
sizeof(lib_filepath_esc));
1308 memcpy(lib_filepath_esc + ofs,
"\"", 2);
1311 lib_filepath_esc[0] =
'\0';
1314 char id_esc[(
sizeof(
id->name) - 2) * 2];
1317 return fmt::format(
"bpy.data.{}[\"{}\"{}]{}{}",
1328 return std::nullopt;
1338 return fmt::format(
"{}.{}", id_path, data_path.value_or(
""));
1346 const char *data_delim;
1349 return std::nullopt;
1357 data_delim = ((*data_path)[0] ==
'[') ?
"" :
".";
1363 data_delim =
" ... ";
1371 return fmt::format(
"{}{}{}", id_path, data_delim, data_path.value_or(
""));
1373 return fmt::format(
"{}{}{}[{}]", id_path, data_delim, data_path.value_or(
""),
index);
1388 return std::nullopt;
1399 data_path = prop_identifier;
1407 return fmt::format(
"{}[{}]", data_path.value_or(
""),
index);
1415 const int index_dim = (
index == -1) ? 0 : 1;
1422 return fmt::format(
"[\"{}\"]", old_name_esc);
1427 return fmt::format(
"[{}]", number);
1433 const int old_subscript,
1434 const int new_subscript,
1435 const bool infix_is_name)
1438 std::string old_key;
1439 std::string new_key;
1442 if (infix_is_name) {
1447 old_key = old_infix;
1448 new_key = new_infix;
1456 return {old_key, new_key};
#define IDP_property_array_get(prop)
#define BLI_array_alloca(arr, realsize)
A dynamically sized string ADT.
#define SNPRINTF(dst, format,...)
ID and Library types, which are fundamental for SDNA.
#define ID_IS_LINKED(_id)
Read Blender memory allocation and freeing.
#define RNA_MAX_ARRAY_LENGTH
#define RNA_MAX_ARRAY_DIMENSION
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
constexpr IndexRange()=default
Vector< rna_path::Item, N > items
std::string to_string() const
static std::optional< ParsedRNAPath > from_string(StringRefNull path)
constexpr const T * end() const
constexpr const T * begin() const
constexpr bool is_empty() const
constexpr const char * c_str() const
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)
bool operator==(const Error &left, const Error &right)
std::variant< Member, LookupIndex, LookupKey > Item
std::string to_string(const Span< Item > items)
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
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)
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)
std::optional< std::string > RNA_path_struct_property_py(PointerRNA *ptr, PropertyRNA *prop, int index)
PointerRNA RNA_id_pointer_create(ID *id)
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
std::optional< std::string > RNA_path_full_struct_py(const PointerRNA *ptr)
const char * RNA_property_identifier(const PropertyRNA *prop)
std::string RNA_path_number_to_infix(const int number)
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)
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
std::string RNA_path_name_to_infix(const StringRefNull string)
std::optional< std::string > RNA_path_from_ID_to_struct(const PointerRNA *ptr)
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)
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)
ID * RNA_find_real_ID_and_path(ID *id, const char **r_path)
size_t size_t const char * BLI_str_escape_find_quote(const char *str) ATTR_NONNULL(1)
Span< rna_path::Item > ParsedRNAPathRef
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)
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()
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)
std::optional< std::string > RNA_path_from_real_ID_to_struct(Main *bmain, const PointerRNA *ptr, ID **r_real)
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)
IDProperty * RNA_struct_idprops(PointerRNA *ptr, bool create)
std::string RNA_path_full_ID_py(ID *id)
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)
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)
const char * BKE_idtype_idcode_to_name_plural(short idcode)
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)
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)
static std::optional< std::string > rna_path_from_ID_to_idpgroup(const PointerRNA *ptr)
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)
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])
std::optional< PointerRNA > RNA_property_collection_type_get(PointerRNA *ptr, PropertyRNA *prop)
static char * rna_path_token(const char **path, char *fixedbuf, int fixedlen)
std::optional< std::string > RNA_path_from_ID_to_property_index(const PointerRNA *ptr, PropertyRNA *prop, int index_dim, int index)
std::optional< std::string > RNA_path_full_property_py_ex(const PointerRNA *ptr, PropertyRNA *prop, int index, bool use_fallback)
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)
char * RNA_path_append(const char *path, const PointerRNA *, PropertyRNA *prop, int intkey, const char *strkey)
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)
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)
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)
bool RNA_path_resolve_full_maybe_null(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
static char * rna_idp_path_create(IDP_Chain *child_link)
static char * rna_idp_path(PointerRNA *ptr, const IDProperty *haystack, const IDProperty *needle, IDP_Chain *parent_link)
bool RNA_path_resolve_property_full(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
DynStr * BLI_dynstr_new() ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
std::optional< std::string > RNA_path_from_struct_to_idproperty(PointerRNA *ptr, const IDProperty *needle)
bool RNA_path_resolve_full(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
ListBaseT< struct IDProperty > group
bool has_owner_id() const
unsigned int arraydimension
std::optional< std::string > key
std::optional< int > index