From 1e1d0d2f7fb6f7e62138fd56a1a4546e50da3d6c Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Tue, 12 Sep 2017 11:55:35 +0200 Subject: [PATCH] Add c-tools macros and methods to convert bctbx_list_t to std::list and the opposite. --- coreapi/chat.c | 6 +----- src/c-wrapper/c-tools.h | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/coreapi/chat.c b/coreapi/chat.c index 807c1701b..b51c7284a 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -682,11 +682,7 @@ void linphone_chat_room_set_call(LinphoneChatRoom *cr, LinphoneCall *call) { } bctbx_list_t * linphone_chat_room_get_transient_messages(const LinphoneChatRoom *cr) { - std::list l = L_GET_PRIVATE(cr->cr)->getTransientMessages(); - bctbx_list_t *result = nullptr; - for (auto it = l.begin(); it != l.end(); it++) - result = bctbx_list_append(result, *it); - return result; + return L_GET_C_LIST_FROM_CPP_LIST(L_GET_PRIVATE(cr->cr)->getTransientMessages(), LinphoneChatMessage); } const char *linphone_chat_message_state_to_string(const LinphoneChatMessageState state) { diff --git a/src/c-wrapper/c-tools.h b/src/c-wrapper/c-tools.h index 8f4b6d738..e97368bcf 100644 --- a/src/c-wrapper/c-tools.h +++ b/src/c-wrapper/c-tools.h @@ -19,6 +19,7 @@ #ifndef _C_TOOLS_H_ #define _C_TOOLS_H_ +#include #include #include @@ -63,6 +64,22 @@ public: static_cast *>(object)->cppPtr = cppPtr; } + template + static inline bctbx_list_t * getCListFromCppList (std::list cppList) { + bctbx_list_t *result = nullptr; + for (auto it = cppList.begin(); it != cppList.end(); it++) + result = bctbx_list_append(result, *it); + return result; + } + + template + static inline std::list getCppListFromCList (bctbx_list_t *cList) { + std::list result; + for (auto it = cList; it; it = bctbx_list_next(it)) + result.push_back(static_cast(bctbx_list_get_data(it))); + return result; + } + private: Wrapper (); @@ -121,4 +138,9 @@ LINPHONE_END_NAMESPACE #define L_GET_PRIVATE_FROM_C_STRUCT(OBJECT, TYPE) \ L_GET_PRIVATE(L_GET_CPP_PTR_FROM_C_STRUCT(OBJECT, TYPE).get()) +#define L_GET_C_LIST_FROM_CPP_LIST(LIST, TYPE) \ + LINPHONE_NAMESPACE::Wrapper::getCListFromCppList(LIST) +#define L_GET_CPP_LIST_FROM_C_LIST(LIST, TYPE) \ + LINPHONE_NAMESPACE::Wrapper::getCppListFromCList(LIST) + #endif // ifndef _C_TOOLS_H_