Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2019-02-08 16:34:13 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2019-02-08 20:53:09 +0300
commita8f28329ad43569ff4242682353c504b08201c08 (patch)
tree7dbd30c131599dc632160d5d54d577cfadf949a2 /source/blender/blenkernel/intern/idcode.c
parent02581a7ef819bfd388420114280ab4a83f155eaf (diff)
BKE_idcode: Add utils to convert from 'lbarray' index to ID type.
This can be useful to be able to match some random array data with ListBase array of IDs generated by `set_listbasepointers()`.
Diffstat (limited to 'source/blender/blenkernel/intern/idcode.c')
-rw-r--r--source/blender/blenkernel/intern/idcode.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c
index 8e6df9f6158..d057eae88a4 100644
--- a/source/blender/blenkernel/intern/idcode.c
+++ b/source/blender/blenkernel/intern/idcode.c
@@ -310,6 +310,58 @@ int BKE_idcode_to_index(const short idcode)
}
/**
+ * Get an idcode from an index (e.g. INDEX_ID_OB -> ID_OB).
+ */
+short BKE_idcode_from_index(const int index)
+{
+#define CASE_IDCODE(_id) case INDEX_ID_##_id: return ID_##_id
+
+ switch (index) {
+ CASE_IDCODE(AC);
+ CASE_IDCODE(AR);
+ CASE_IDCODE(BR);
+ CASE_IDCODE(CA);
+ CASE_IDCODE(CF);
+ CASE_IDCODE(CU);
+ CASE_IDCODE(GD);
+ CASE_IDCODE(GR);
+ CASE_IDCODE(IM);
+ CASE_IDCODE(KE);
+ CASE_IDCODE(IP);
+ CASE_IDCODE(LA);
+ CASE_IDCODE(LI);
+ CASE_IDCODE(LS);
+ CASE_IDCODE(LT);
+ CASE_IDCODE(MA);
+ CASE_IDCODE(MB);
+ CASE_IDCODE(MC);
+ CASE_IDCODE(ME);
+ CASE_IDCODE(MSK);
+ CASE_IDCODE(NT);
+ CASE_IDCODE(OB);
+ CASE_IDCODE(PA);
+ CASE_IDCODE(PAL);
+ CASE_IDCODE(PC);
+ CASE_IDCODE(LP);
+ CASE_IDCODE(SCE);
+ CASE_IDCODE(SCR);
+ CASE_IDCODE(SPK);
+ CASE_IDCODE(SO);
+ CASE_IDCODE(TE);
+ CASE_IDCODE(TXT);
+ CASE_IDCODE(VF);
+ CASE_IDCODE(WM);
+ CASE_IDCODE(WO);
+ CASE_IDCODE(WS);
+ }
+
+ BLI_assert(0);
+ return -1;
+
+#undef CASE_IDCODE
+}
+
+/**
* Convert an idcode into a name (plural).
*
* \param idcode: The code to convert.