diff options
author | mano-wii <germano.costa@ig.com.br> | 2018-10-06 07:15:15 +0300 |
---|---|---|
committer | mano-wii <germano.costa@ig.com.br> | 2018-10-06 07:15:15 +0300 |
commit | 495a7128cb230a26bc72cb735e33be5324bf3baa (patch) | |
tree | 6cee7ac416017617b102c56e8747ef8ee01436e3 /source/blender/python/generic/py_capi_utils.h | |
parent | 0f5533441390d049d2b85e86abdd57b5a874e530 (diff) |
Cleanup: use the naming convention in py_capi_utils
And use inline functions instead of preprocessor directives.
Diffstat (limited to 'source/blender/python/generic/py_capi_utils.h')
-rw-r--r-- | source/blender/python/generic/py_capi_utils.h | 74 |
1 files changed, 69 insertions, 5 deletions
diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h index 8ceb4a76a53..523712d0cb0 100644 --- a/source/blender/python/generic/py_capi_utils.h +++ b/source/blender/python/generic/py_capi_utils.h @@ -132,10 +132,74 @@ Py_LOCAL_INLINE(int64_t) PyC_Long_AsI64(PyObject *value) { return (int64_t)PyLo Py_LOCAL_INLINE(uint64_t) PyC_Long_AsU64(PyObject *value) { return (uint64_t)PyLong_AsUnsignedLongLong(value); } /* utils for format string in `struct` module style syntax */ -#define FORMAT_STR_GET(typestr) ELEM(typestr[0], '!', '<', '=', '>', '@') ? typestr[1] : typestr[0] -#define FORMAT_STR_IS_FLOAT(format) ELEM(format, 'f', 'd', 'e') -#define FORMAT_STR_IS_INT(format) ELEM(format, 'i', 'I', 'l', 'L', 'h', 'H', 'b', 'B', 'q', 'Q', 'n', 'N', 'P') -#define FORMAT_STR_IS_BYTE(format) ELEM(format, 'c', 's', 'p') -#define FORMAT_STR_IS_BOOL(format) ELEM(format, '?') +Py_LOCAL_INLINE(char) PyC_Formatstr_get(char *typestr) +{ + switch (typestr[0]) { + case '!': + case '<': + case '=': + case '>': + case '@': + return typestr[1]; + default: + return typestr[0]; + } +} + +Py_LOCAL_INLINE(bool) PyC_Formatstr_is_float(char format) +{ + switch (format) { + case 'f': + case 'd': + case 'e': + return true; + default: + return false; + } +} + +Py_LOCAL_INLINE(bool) PyC_Formatstr_is_int(char format) +{ + switch (format) { + case 'i': + case 'I': + case 'l': + case 'L': + case 'h': + case 'H': + case 'b': + case 'B': + case 'q': + case 'Q': + case 'n': + case 'N': + case 'P': + return true; + default: + return false; + } +} + +Py_LOCAL_INLINE(bool) PyC_Formatstr_is_byte(char format) +{ + switch (format) { + case 'c': + case 's': + case 'p': + return true; + default: + return false; + } +} + +Py_LOCAL_INLINE(bool) PyC_Formatstr_is_bool(char format) +{ + switch (format) { + case '?': + return true; + default: + return false; + } +} #endif /* __PY_CAPI_UTILS_H__ */ |