Commit 54980b52 authored by Ronan's avatar Ronan

feat(enum-generator): provide two functions getEnumNameAsString and getEnumValueAsString

parent 999c4c17
......@@ -42,14 +42,51 @@ LINPHONE_BEGIN_NAMESPACE
// Enum value declaration.
#define L_DECLARE_ENUM_VALUE(...) L_DECLARE_ENUM_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
#ifdef __cplusplus
// `getEnumValue` helper.
#define L_DECLARE_ENUM_VALUE_STR_CASE(ENUM_NAME, VALUE_NAME, ...) \
case ENUM_NAME::VALUE_NAME: return #ENUM_NAME "::" #VALUE_NAME;
// Helper to get enum name.
#define L_DECLARE_ENUM_NAME(NAME, ...) NAME,
// Get names as string from enum values.
#define L_GET_ENUM_VALUE_NAMES(VALUES) L_GET_HEAP(VALUES(L_DECLARE_ENUM_NAME))
#endif
// -----------------------------------------------------------------------------
// Public API.
// -----------------------------------------------------------------------------
#ifdef __cplusplus
#define L_DECLARE_ENUM(NAME, VALUES) \
enum class NAME { \
VALUES(L_DECLARE_ENUM_VALUE) \
};
}; \
friend constexpr const char *getResolvedEnumNameAsString (NAME) { \
return #NAME; \
} \
friend const char *getResolvedEnumValueAsString (NAME value) { \
switch (value) { \
L_APPLY_WITHOUT_COMMA(L_DECLARE_ENUM_VALUE_STR_CASE, NAME, L_GET_ENUM_VALUE_NAMES(VALUES)) \
} \
return ""; \
}
template<typename T>
inline const char *getEnumNameAsString () {
return getResolvedEnumNameAsString(T());
}
template<typename T>
inline const char *getEnumValueAsString (T value) {
return getResolvedEnumValueAsString(value);
}
#endif
#define L_C_ENUM_PREFIX Linphone
......
......@@ -162,6 +162,76 @@ LINPHONE_BEGIN_NAMESPACE
(MACRONAME, DATA, __VA_ARGS__) \
)
// Map each variadic args without comma separator.
#define L_APPLY_WITHOUT_COMMA_1(MACRONAME, DATA, A1) \
L_CALL_HELPER(MACRONAME, (DATA, A1))
#define L_APPLY_WITHOUT_COMMA_2(MACRONAME, DATA, A1, A2) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_1(MACRONAME, DATA, A2)
#define L_APPLY_WITHOUT_COMMA_3(MACRONAME, DATA, A1, A2, A3) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_2(MACRONAME, DATA, A2, A3)
#define L_APPLY_WITHOUT_COMMA_4(MACRONAME, DATA, A1, A2, A3, A4) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_3(MACRONAME, DATA, A2, A3, A4)
#define L_APPLY_WITHOUT_COMMA_5(MACRONAME, DATA, A1, A2, A3, A4, A5) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_4(MACRONAME, DATA, A2, A3, A4, A5)
#define L_APPLY_WITHOUT_COMMA_6(MACRONAME, DATA, A1, A2, A3, A4, A5, A6) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_5(MACRONAME, DATA, A2, A3, A4, A5, A6)
#define L_APPLY_WITHOUT_COMMA_7(MACRONAME, DATA, A1, A2, A3, A4, A5, A6, A7) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_6(MACRONAME, DATA, A2, A3, A4, A5, A6, A7)
#define L_APPLY_WITHOUT_COMMA_8(MACRONAME, DATA, A1, A2, A3, A4, A5, A6, A7, A8) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_7(MACRONAME, DATA, A2, A3, A4, A5, A6, A7, A8)
#define L_APPLY_WITHOUT_COMMA_9(MACRONAME, DATA, A1, A2, A3, A4, A5, A6, A7, A8, A9) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_8(MACRONAME, DATA, A2, A3, A4, A5, A6, A7, A8, A9)
#define L_APPLY_WITHOUT_COMMA_10(MACRONAME, DATA, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_9(MACRONAME, DATA, A2, A3, A4, A5, A6, A7, A8, A9, A10)
#define L_APPLY_WITHOUT_COMMA_11(MACRONAME, DATA, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_10(MACRONAME, DATA, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11)
#define L_APPLY_WITHOUT_COMMA_12(MACRONAME, DATA, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_11(MACRONAME, DATA, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12)
#define L_APPLY_WITHOUT_COMMA_13(MACRONAME, DATA, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_12(MACRONAME, DATA, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13)
#define L_APPLY_WITHOUT_COMMA_14(MACRONAME, DATA, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_13(MACRONAME, DATA, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14)
#define L_APPLY_WITHOUT_COMMA_15(MACRONAME, DATA, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_14(MACRONAME, DATA, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15)
#define L_APPLY_WITHOUT_COMMA_16(MACRONAME, DATA, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16) \
L_CALL_HELPER(MACRONAME, (DATA, A1)) \
L_APPLY_WITHOUT_COMMA_15(MACRONAME, DATA, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16)
#define L_APPLY_WITHOUT_COMMA(MACRONAME, DATA, ...) \
L_CALL( \
L_CONCAT(L_APPLY_WITHOUT_COMMA_, L_GET_N_ARGS(__VA_ARGS__)), \
(MACRONAME, DATA, __VA_ARGS__) \
)
LINPHONE_END_NAMESPACE
#endif // ifndef _MAGIC_MACROS_H_
......@@ -81,9 +81,8 @@ void ChatMessagePrivate::setState (ChatMessage::State s, bool force) {
)
return;
lInfo() << "Chat message " << this << ": moving from state " <<
linphone_chat_message_state_to_string((LinphoneChatMessageState)state) << " to " <<
linphone_chat_message_state_to_string((LinphoneChatMessageState)s);
lInfo() << "Chat message " << this << ": moving from " << getEnumValueAsString(state) <<
" to " << getEnumValueAsString(s);
state = s;
LinphoneChatMessage *msg = L_GET_C_BACK_PTR(q);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment