From a6d3feda8eb9cd252123ffecf878f624f31a2a41 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 13 Jun 2024 18:55:52 +0200 Subject: [PATCH] BKE IDProp: Add utils to get string version of an IDProp type/subtype. --- source/blender/blenkernel/BKE_idprop.hh | 3 ++ .../blender/blenkernel/intern/idprop_utils.cc | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/source/blender/blenkernel/BKE_idprop.hh b/source/blender/blenkernel/BKE_idprop.hh index af3770f5659..a92636f7b7a 100644 --- a/source/blender/blenkernel/BKE_idprop.hh +++ b/source/blender/blenkernel/BKE_idprop.hh @@ -319,6 +319,9 @@ void IDP_repr_fn(const IDProperty *prop, void *user_data); void IDP_print(const IDProperty *prop); +const char *IDP_type_str(eIDPropertyType type, short sub_type); +const char *IDP_type_str(const IDProperty *prop); + void IDP_BlendWrite(BlendWriter *writer, const IDProperty *prop); void IDP_BlendReadData_impl(BlendDataReader *reader, IDProperty **prop, diff --git a/source/blender/blenkernel/intern/idprop_utils.cc b/source/blender/blenkernel/intern/idprop_utils.cc index 8ed265fa1b4..19c894fee7f 100644 --- a/source/blender/blenkernel/intern/idprop_utils.cc +++ b/source/blender/blenkernel/intern/idprop_utils.cc @@ -262,4 +262,53 @@ void IDP_print(const IDProperty *prop) MEM_freeN(repr); } +const char *IDP_type_str(const eIDPropertyType type, const short sub_type) +{ + switch (type) { + case IDP_STRING: + switch (sub_type) { + case IDP_STRING_SUB_UTF8: + return "String"; + case IDP_STRING_SUB_BYTE: + return "Bytes"; + default: + return "String"; + } + case IDP_INT: + return "Int"; + case IDP_FLOAT: + return "Float"; + case IDP_ARRAY: + switch (sub_type) { + case IDP_INT: + return "Array (Int)"; + case IDP_FLOAT: + return "Array (Float)"; + case IDP_DOUBLE: + return "Array (Double)"; + case IDP_BOOLEAN: + return "Array (Boolean)"; + default: + return "Array"; + } + case IDP_GROUP: + return "Group"; + case IDP_ID: + return "ID"; + case IDP_DOUBLE: + return "Double"; + case IDP_IDPARRAY: + return "Array of Properties"; + case IDP_BOOLEAN: + return "Boolean"; + } + BLI_assert_unreachable(); + return "Unknown"; +} + +const char *IDP_type_str(const IDProperty *prop) +{ + return IDP_type_str(eIDPropertyType(prop->type), prop->subtype); +} + /** \} */