[Bf-blender-cvs] [89c168c] tmp-id-users: Move pyrna_set_to_enum_bitmap to bpy_rna.c
Campbell Barton
noreply at git.blender.org
Wed Jan 6 19:46:20 CET 2016
Commit: 89c168cb2d1d2aaf863a4853803421d27b414a6a
Author: Campbell Barton
Date: Thu Jan 7 05:39:08 2016 +1100
Branches: tmp-id-users
https://developer.blender.org/rB89c168cb2d1d2aaf863a4853803421d27b414a6a
Move pyrna_set_to_enum_bitmap to bpy_rna.c
===================================================================
M source/blender/python/intern/bpy_rna.c
M source/blender/python/intern/bpy_rna.h
M source/blender/python/intern/bpy_rna_id_collection.c
===================================================================
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 45a5735..d338b49 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -37,6 +37,7 @@
#include "RNA_types.h"
+#include "BLI_bitmap.h"
#include "BLI_dynstr.h"
#include "BLI_string.h"
#include "BLI_listbase.h"
@@ -1176,6 +1177,69 @@ static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *pr
return 0;
}
+/**
+ * Takes a set of strings and map it to and array of booleans.
+ *
+ * Useful when the values aren't flags.
+ *
+ * \param type_convert_sign: Maps signed to unsuigned range,
+ * needed when we want to use the full range of a signed short/char.
+ */
+BLI_bitmap *pyrna_set_to_enum_bitmap(
+ EnumPropertyItem *items, PyObject *value,
+ int type_size, bool type_convert_sign,
+ int bitmap_size,
+ const char *error_prefix)
+{
+ /* set looping */
+ Py_ssize_t pos = 0;
+ Py_ssize_t hash = 0;
+ PyObject *key;
+
+ BLI_bitmap *bitmap = BLI_BITMAP_NEW(bitmap_size, __func__);
+
+ while (_PySet_NextEntry(value, &pos, &key, &hash)) {
+ const char *param = _PyUnicode_AsString(key);
+ if (param == NULL) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s expected a string, not %.200s",
+ error_prefix, Py_TYPE(key)->tp_name);
+ goto error;
+ }
+
+ int ret;
+ if (pyrna_enum_value_from_id(items, param, &ret, error_prefix) == -1) {
+ goto error;
+ }
+
+ int index = ret;
+
+ if (type_convert_sign) {
+ if (type_size == 2) {
+ union { signed short as_signed; unsigned short as_unsigned; } ret_convert;
+ ret_convert.as_signed = (signed short)ret;
+ index = (int)ret_convert.as_unsigned;
+ }
+ else if (type_size == 1) {
+ union { signed char as_signed; unsigned char as_unsigned; } ret_convert;
+ ret_convert.as_signed = (signed char)ret;
+ index = (int)ret_convert.as_unsigned;
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+ BLI_assert(index < bitmap_size);
+ BLI_BITMAP_ENABLE(bitmap, index);
+ }
+
+ return bitmap;
+
+error:
+ MEM_freeN(bitmap);
+ return NULL;
+}
+
/* 'value' _must_ be a set type, error check before calling */
int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix)
{
diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h
index f546c29..c5d4a34 100644
--- a/source/blender/python/intern/bpy_rna.h
+++ b/source/blender/python/intern/bpy_rna.h
@@ -184,6 +184,11 @@ bool pyrna_id_FromPyObject(PyObject *obj, struct ID **id);
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const char *error_prefix);
PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
+unsigned int *pyrna_set_to_enum_bitmap(
+ struct EnumPropertyItem *items, PyObject *value,
+ int type_size, bool type_convert_sign,
+ int bitmap_size,
+ const char *error_prefix);
PyObject *pyrna_enum_bitfield_to_py(struct EnumPropertyItem *items, int value);
int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix);
diff --git a/source/blender/python/intern/bpy_rna_id_collection.c b/source/blender/python/intern/bpy_rna_id_collection.c
index 0970e67..5edd05e 100644
--- a/source/blender/python/intern/bpy_rna_id_collection.c
+++ b/source/blender/python/intern/bpy_rna_id_collection.c
@@ -125,69 +125,6 @@ static bool foreach_libblock_id_user_map_callback(void *user_data, ID **id_p, in
return true;
}
-/**
- * Takes a set of strings and map it to and array of booleans.
- *
- * Useful when the values aren't flags.
- *
- * \param type_convert_sign: Maps signed to unsuigned range,
- * needed when we want to use the full range of a signed short/char.
- */
-static BLI_bitmap *pyrna_set_to_enum_bitmap(
- EnumPropertyItem *items, PyObject *value,
- int type_size, bool type_convert_sign,
- int bitmap_size,
- const char *error_prefix)
-{
- /* set looping */
- Py_ssize_t pos = 0;
- Py_ssize_t hash = 0;
- PyObject *key;
-
- BLI_bitmap *bitmap = BLI_BITMAP_NEW(bitmap_size, __func__);
-
- while (_PySet_NextEntry(value, &pos, &key, &hash)) {
- const char *param = _PyUnicode_AsString(key);
- if (param == NULL) {
- PyErr_Format(PyExc_TypeError,
- "%.200s expected a string, not %.200s",
- error_prefix, Py_TYPE(key)->tp_name);
- goto error;
- }
-
- int ret;
- if (pyrna_enum_value_from_id(items, param, &ret, error_prefix) == -1) {
- goto error;
- }
-
- int index = ret;
-
- if (type_convert_sign) {
- if (type_size == 2) {
- union { signed short as_signed; unsigned short as_unsigned; } ret_convert;
- ret_convert.as_signed = (signed short)ret;
- index = (int)ret_convert.as_unsigned;
- }
- else if (type_size == 1) {
- union { signed char as_signed; unsigned char as_unsigned; } ret_convert;
- ret_convert.as_signed = (signed char)ret;
- index = (int)ret_convert.as_unsigned;
- }
- else {
- BLI_assert(0);
- }
- }
- BLI_assert(index < bitmap_size);
- BLI_BITMAP_ENABLE(bitmap, index);
- }
-
- return bitmap;
-
-error:
- MEM_freeN(bitmap);
- return NULL;
-}
-
PyDoc_STRVAR(bpy_user_map_doc,
".. method:: user_map([subset=(id1, id2, ...)], key_types={..}, value_types={..})\n"
More information about the Bf-blender-cvs
mailing list