Commit ec1c1dbb authored by Ronan's avatar Ronan

feat(c-wrapper): provide better usage on list macros

parent fd1385fd
......@@ -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));
}
// =============================================================================
......
......@@ -207,7 +207,7 @@ public:
}
// ---------------------------------------------------------------------------
// List helpers.
// List conversions.
// ---------------------------------------------------------------------------
template<typename T>
......@@ -226,16 +226,23 @@ public:
return result;
}
template<typename CppType, typename CType>
static inline bctbx_list_t *getCListOfStructPtrFromCppListOfCppObj (const std::list<std::shared_ptr<CppType>> cppList, CType *(*cTypeAllocator)()) {
// ---------------------------------------------------------------------------
// Resolved list conversions.
// ---------------------------------------------------------------------------
template<
typename CppType,
typename = typename std::enable_if<IsCppObject<CppType>::value, CppType>::type
>
static inline bctbx_list_t *getResolvedCListFromCppList (const std::list<std::shared_ptr<CppType>> &cppList) {
bctbx_list_t *result = nullptr;
for (const auto &value : cppList)
result = bctbx_list_append(result, getCBackPtr(value));
return result;
}
template<typename CppType, typename CType>
static inline bctbx_list_t *getCListOfStructPtrFromCppListOfCppObj (const std::list<CppType> cppList, CType *(*cTypeAllocator)()) {
template<typename CppType>
static inline bctbx_list_t *getResolvedCListFromCppList (const std::list<CppType> &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<CType>::type,
typename = typename std::enable_if<std::is_base_of<Object, CppType>::value, CppType>::type
>
static inline std::list<std::shared_ptr<CppType>> getCppListOfCppObjFromCListOfStructPtr (const bctbx_list_t *cList) {
static inline std::list<std::shared_ptr<CppType>> getResolvedCppListFromCList (const bctbx_list_t *cList) {
std::list<std::shared_ptr<CppType>> result;
for (auto it = cList; it; it = bctbx_list_next(it))
result.push_back(getCppPtrFromC(reinterpret_cast<CType *>(bctbx_list_get_data(it))));
......@@ -255,11 +262,11 @@ public:
}
template<
typename CppType,
typename CType,
typename CppType = typename CTypeToCppType<CType>::type,
typename = typename std::enable_if<std::is_base_of<ClonableObject, CppType>::value, CppType>::type
>
static inline std::list<CppType> getCppListOfCppObjFromCListOfStructPtr (const bctbx_list_t *cList) {
static inline std::list<CppType> getResolvedCppListFromCList (const bctbx_list_t *cList) {
std::list<CppType> result;
for (auto it = cList; it; it = bctbx_list_next(it))
result.push_back(*getCppPtrFromC(reinterpret_cast<CType *>(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<TYPE>(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<LINPHONE_NAMESPACE::CPP_TYPE, Linphone ## C_TYPE>(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<LINPHONE_NAMESPACE::CPP_TYPE, Linphone ## C_TYPE>(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<Linphone ## C_TYPE>(C_LIST)
#endif // ifndef _C_TOOLS_H_
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