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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-04-10 10:24:40 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-10 10:25:53 +0300
commit54af7cbf4b16fd6585baba227b604768c86745a2 (patch)
treea322391bbbcf32aea97f46feb49f0e8eb3095a6c /source
parent55c152164f825d9d0fa15dcdd3806818e48c7075 (diff)
BLI_string: Add STR_ELEM macro
A string comparison version of the ELEM macro, add to avoid verbose & repetitive strcmp/STREQ usage.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenlib/BLI_string.h48
1 files changed, 48 insertions, 0 deletions
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