diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index e19ec6f9d..debae113a 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -213,7 +213,7 @@ LinphoneParticipant *linphone_chat_room_add_participant (LinphoneChatRoom *cr, c } void linphone_chat_room_add_participants (LinphoneChatRoom *cr, const bctbx_list_t *addresses) { - L_GET_CPP_PTR_FROM_C_OBJECT(cr)->addParticipants(L_GET_CPP_LIST_OF_CPP_OBJ_FROM_C_LIST_OF_STRUCT_PTR(addresses, Address, Address), nullptr, false); + L_GET_CPP_PTR_FROM_C_OBJECT(cr)->addParticipants(L_GET_RESOLVED_CPP_LIST_FROM_C_LIST(addresses, Address), nullptr, false); } bool_t linphone_chat_room_can_handle_participants (const LinphoneChatRoom *cr) { @@ -230,7 +230,7 @@ int linphone_chat_room_get_nb_participants (const LinphoneChatRoom *cr) { } bctbx_list_t *linphone_chat_room_get_participants (const LinphoneChatRoom *cr) { - return L_GET_C_LIST_OF_STRUCT_PTR_FROM_CPP_LIST_OF_CPP_OBJ(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getParticipants(), Participant, Participant); + return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getParticipants()); } void linphone_chat_room_remove_participant (LinphoneChatRoom *cr, LinphoneParticipant *participant) { @@ -238,7 +238,7 @@ void linphone_chat_room_remove_participant (LinphoneChatRoom *cr, LinphonePartic } void linphone_chat_room_remove_participants (LinphoneChatRoom *cr, const bctbx_list_t *participants) { - L_GET_CPP_PTR_FROM_C_OBJECT(cr)->removeParticipants(L_GET_CPP_LIST_OF_CPP_OBJ_FROM_C_LIST_OF_STRUCT_PTR(participants, Participant, Participant)); + L_GET_CPP_PTR_FROM_C_OBJECT(cr)->removeParticipants(L_GET_RESOLVED_CPP_LIST_FROM_C_LIST(participants, Participant)); } // ============================================================================= diff --git a/src/c-wrapper/internal/c-tools.h b/src/c-wrapper/internal/c-tools.h index 8e4da1d84..5bb3ffd59 100644 --- a/src/c-wrapper/internal/c-tools.h +++ b/src/c-wrapper/internal/c-tools.h @@ -207,7 +207,7 @@ public: } // --------------------------------------------------------------------------- - // List helpers. + // List conversions. // --------------------------------------------------------------------------- template @@ -226,16 +226,23 @@ public: return result; } - template - static inline bctbx_list_t *getCListOfStructPtrFromCppListOfCppObj (const std::list> cppList, CType *(*cTypeAllocator)()) { + // --------------------------------------------------------------------------- + // Resolved list conversions. + // --------------------------------------------------------------------------- + + template< + typename CppType, + typename = typename std::enable_if::value, CppType>::type + > + static inline bctbx_list_t *getResolvedCListFromCppList (const std::list> &cppList) { bctbx_list_t *result = nullptr; for (const auto &value : cppList) result = bctbx_list_append(result, getCBackPtr(value)); return result; } - template - static inline bctbx_list_t *getCListOfStructPtrFromCppListOfCppObj (const std::list cppList, CType *(*cTypeAllocator)()) { + template + static inline bctbx_list_t *getResolvedCListFromCppList (const std::list &cppList) { bctbx_list_t *result = nullptr; for (const auto &value : cppList) result = bctbx_list_append(result, getCBackPtr(value)); @@ -243,11 +250,11 @@ public: } template< - typename CppType, typename CType, + typename CppType = typename CTypeToCppType::type, typename = typename std::enable_if::value, CppType>::type > - static inline std::list> getCppListOfCppObjFromCListOfStructPtr (const bctbx_list_t *cList) { + static inline std::list> getResolvedCppListFromCList (const bctbx_list_t *cList) { std::list> result; for (auto it = cList; it; it = bctbx_list_next(it)) result.push_back(getCppPtrFromC(reinterpret_cast(bctbx_list_get_data(it)))); @@ -255,11 +262,11 @@ public: } template< - typename CppType, typename CType, + typename CppType = typename CTypeToCppType::type, typename = typename std::enable_if::value, CppType>::type > - static inline std::list getCppListOfCppObjFromCListOfStructPtr (const bctbx_list_t *cList) { + static inline std::list getResolvedCppListFromCList (const bctbx_list_t *cList) { std::list result; for (auto it = cList; it; it = bctbx_list_next(it)) result.push_back(*getCppPtrFromC(reinterpret_cast(bctbx_list_get_data(it)))); @@ -458,9 +465,10 @@ LINPHONE_END_NAMESPACE #define L_GET_CPP_LIST_FROM_C_LIST(C_LIST, TYPE) \ LINPHONE_NAMESPACE::Wrapper::getCppListFromCList(C_LIST) -#define L_GET_C_LIST_OF_STRUCT_PTR_FROM_CPP_LIST_OF_CPP_OBJ(LIST, CPP_TYPE, C_TYPE) \ - LINPHONE_NAMESPACE::Wrapper::getCListOfStructPtrFromCppListOfCppObj(LIST, _linphone_ ## C_TYPE ## _init) -#define L_GET_CPP_LIST_OF_CPP_OBJ_FROM_C_LIST_OF_STRUCT_PTR(LIST, CPP_TYPE, C_TYPE) \ - LINPHONE_NAMESPACE::Wrapper::getCppListOfCppObjFromCListOfStructPtr(LIST) +// Transforms cpp list and c list and convert cpp object to c object. +#define L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(CPP_LIST) \ + LINPHONE_NAMESPACE::Wrapper::getResolvedCListFromCppList(CPP_LIST) +#define L_GET_RESOLVED_CPP_LIST_FROM_C_LIST(C_LIST, C_TYPE) \ + LINPHONE_NAMESPACE::Wrapper::getResolvedCppListFromCList(C_LIST) #endif // ifndef _C_TOOLS_H_