[Bf-blender-cvs] [54af7cbf4b1] master: BLI_string: Add STR_ELEM macro

Campbell Barton noreply at git.blender.org
Wed Apr 10 09:37:03 CEST 2019


Commit: 54af7cbf4b16fd6585baba227b604768c86745a2
Author: Campbell Barton
Date:   Wed Apr 10 09:24:40 2019 +0200
Branches: master
https://developer.blender.org/rB54af7cbf4b16fd6585baba227b604768c86745a2

BLI_string: Add STR_ELEM macro

A string comparison version of the ELEM macro,
add to avoid verbose & repetitive strcmp/STREQ usage.

===================================================================

M	source/blender/blenlib/BLI_string.h

===================================================================

diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h
index 831626b164b..09844d75c93 100644
--- a/source/blender/blenlib/BLI_string.h
+++ b/source/blender/blenlib/BLI_string.h
@@ -32,6 +32,7 @@ extern "C" {
 #endif
 
 #include "BLI_compiler_attrs.h"
+#include "BLI_utildefines_variadic.h"
 
 char *BLI_strdupn(const char *str, const size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 
@@ -117,6 +118,53 @@ int BLI_string_find_split_words(
     len += BLI_snprintf_rlen(dst + len, ARRAY_SIZE(dst) - len, format, __VA_ARGS__)
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name Equal to Any Element (STR_ELEM) Macro
+ *
+ * Follows #ELEM macro convention.
+ * \{ */
+
+/* STR_ELEM#(v, ...): is the first arg equal any others? */
+/* Internal helpers. */
+#define _VA_STR_ELEM2(v, a) \
+       (strcmp(v, a) == 0)
+#define _VA_STR_ELEM3(v, a, b) \
+       (_VA_STR_ELEM2(v, a) || ((v) == (b)))
+#define _VA_STR_ELEM4(v, a, b, c) \
+       (_VA_STR_ELEM3(v, a, b) || ((v) == (c)))
+#define _VA_STR_ELEM5(v, a, b, c, d) \
+       (_VA_STR_ELEM4(v, a, b, c) || ((v) == (d)))
+#define _VA_STR_ELEM6(v, a, b, c, d, e) \
+       (_VA_STR_ELEM5(v, a, b, c, d) || ((v) == (e)))
+#define _VA_STR_ELEM7(v, a, b, c, d, e, f) \
+       (_VA_STR_ELEM6(v, a, b, c, d, e) || ((v) == (f)))
+#define _VA_STR_ELEM8(v, a, b, c, d, e, f, g) \
+       (_VA_STR_ELEM7(v, a, b, c, d, e, f) || ((v) == (g)))
+#define _VA_STR_ELEM9(v, a, b, c, d, e, f, g, h) \
+       (_VA_STR_ELEM8(v, a, b, c, d, e, f, g) || ((v) == (h)))
+#define _VA_STR_ELEM10(v, a, b, c, d, e, f, g, h, i) \
+       (_VA_STR_ELEM9(v, a, b, c, d, e, f, g, h) || ((v) == (i)))
+#define _VA_STR_ELEM11(v, a, b, c, d, e, f, g, h, i, j) \
+       (_VA_STR_ELEM10(v, a, b, c, d, e, f, g, h, i) || ((v) == (j)))
+#define _VA_STR_ELEM12(v, a, b, c, d, e, f, g, h, i, j, k) \
+       (_VA_STR_ELEM11(v, a, b, c, d, e, f, g, h, i, j) || ((v) == (k)))
+#define _VA_STR_ELEM13(v, a, b, c, d, e, f, g, h, i, j, k, l) \
+       (_VA_STR_ELEM12(v, a, b, c, d, e, f, g, h, i, j, k) || ((v) == (l)))
+#define _VA_STR_ELEM14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) \
+       (_VA_STR_ELEM13(v, a, b, c, d, e, f, g, h, i, j, k, l) || ((v) == (m)))
+#define _VA_STR_ELEM15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
+       (_VA_STR_ELEM14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) || ((v) == (n)))
+#define _VA_STR_ELEM16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
+       (_VA_STR_ELEM15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) || ((v) == (o)))
+#define _VA_STR_ELEM17(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
+       (_VA_STR_ELEM16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) || ((v) == (p)))
+
+/* reusable STR_ELEM macro */
+#define STR_ELEM(...) VA_NARGS_CALL_OVERLOAD(_VA_STR_ELEM, __VA_ARGS__)
+
+/** \} */
+
+
 #ifdef __cplusplus
 }
 #endif



More information about the Bf-blender-cvs mailing list