increase benchmark duration
[rofl0r-stringswitch.git] / stringswitch.h
blob198980d49f96338d3e2e8341c90f7671fbcba6bd
1 #ifndef STRINGSWITCH_H
2 #define STRINGSWITCH_H
4 #include <string.h>
6 #define stringswitch_enumerator_name(N) strswitch_enumerator_##N
7 #define stringswitch_enumerator_member_name(N, X) strswitch_enumerator_##N##_member_##X
8 #define stringswitch_enumerator_length_name(N) strswitch_enumerator_##N##_length
9 #define stringswitch_enumerator_value_name(N) strswitch_enumerator_##N##_value
10 #define stringswitch_enumerator_eval_func(N) strswitch_enumerator_eval_func_##N
11 #define stringswitch_enumerator_default_member_name(N) stringswitch_enumerator_member_name(N, DEFAULT__________)
13 #define stringswitch_l(N, X, L) int stringswitch_enumerator_value_name(N) = stringswitch_enumerator_eval_func(N)((X), (L)); \
14 switch(stringswitch_enumerator_value_name(N))
16 // for "dynamic" strings, i.e. non-literals
17 #define stringswitch_d(N, X) size_t stringswitch_enumerator_length_name(N) = strlen(X); stringswitch_l(N, X, stringswitch_enumerator_length_name(N))
18 // for static stringliterals
19 #define stringswitch_s(N, X) stringswitch_l(N, X, sizeof(X) - 1)
21 #define stringcase(N, X) case stringswitch_enumerator_member_name(N, X)
22 #define stringcase_default(N) case stringswitch_enumerator_default_member_name(N): default
24 #endif