Commit 1e1d0d2f authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Add c-tools macros and methods to convert bctbx_list_t to std::list and the opposite.

parent 665ff35e
......@@ -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<LinphoneChatMessage *> 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) {
......
......@@ -19,6 +19,7 @@
#ifndef _C_TOOLS_H_
#define _C_TOOLS_H_
#include <list>
#include <memory>
#include <string>
......@@ -63,6 +64,22 @@ public:
static_cast<WrappedObject<T> *>(object)->cppPtr = cppPtr;
}
template<typename T>
static inline bctbx_list_t * getCListFromCppList (std::list<T> cppList) {
bctbx_list_t *result = nullptr;
for (auto it = cppList.begin(); it != cppList.end(); it++)
result = bctbx_list_append(result, *it);
return result;
}
template<typename T>
static inline std::list<T> getCppListFromCList (bctbx_list_t *cList) {
std::list<T> result;
for (auto it = cList; it; it = bctbx_list_next(it))
result.push_back(static_cast<T>(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<TYPE *>(LIST)
#define L_GET_CPP_LIST_FROM_C_LIST(LIST, TYPE) \
LINPHONE_NAMESPACE::Wrapper::getCppListFromCList<TYPE *>(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