Commit 5f232e04 authored by Ronan's avatar Ronan

feat(c-wrapper): clean code

parent 25c138a6
......@@ -19,6 +19,7 @@
#ifndef _UTILS_H_
#define _UTILS_H_
#include <memory>
#include <string>
#include <vector>
......@@ -29,6 +30,26 @@
LINPHONE_BEGIN_NAMESPACE
namespace Utils {
template<typename T>
static constexpr T *getPtr (const std::shared_ptr<T> &object) {
return object.get();
}
template<typename T>
static constexpr T *getPtr (T *object) {
return object;
}
template<typename T>
static constexpr const T *getPtr (const std::shared_ptr<const T> &object) {
return object.get();
}
template<typename T>
static constexpr const T *getPtr (const T *object) {
return object;
}
LINPHONE_PUBLIC bool iequals (const std::string &a, const std::string &b);
LINPHONE_PUBLIC std::vector<std::string> split (const std::string &str, const std::string &delimiter);
......
......@@ -20,7 +20,8 @@
#define _C_TOOLS_H_
#include <list>
#include <memory>
#include "linphone/utils/utils.h"
// TODO: From coreapi. Remove me later.
#include "private.h"
......@@ -74,17 +75,7 @@ public:
typename CppType,
typename = typename std::enable_if<IsCppObject<CppType>::value, CppType>::type
>
static inline decltype (std::declval<CppType>().getPrivate()) getPrivate (CppType *cppObject) {
L_ASSERT(cppObject);
return cppObject->getPrivate();
}
template<
typename CppType,
typename = typename std::enable_if<IsCppObject<CppType>::value, CppType>::type
>
static inline decltype (std::declval<CppType>().getPrivate()) getPrivate (const std::shared_ptr<CppType> &cppObject) {
L_ASSERT(cppObject);
static constexpr inline decltype (std::declval<CppType>().getPrivate()) getPrivate (CppType *cppObject) {
return cppObject->getPrivate();
}
......@@ -162,27 +153,6 @@ public:
(*cppObjectAddr)->setProperty("LinphonePrivate::Wrapper::cBackPtr", cObject);
}
// Macro helpers.
template<typename T>
static inline T *getCppPtr (const std::shared_ptr<T> &cppObject) {
return cppObject.get();
}
template<typename T>
static inline T *getCppPtr (T *cppObject) {
return cppObject;
}
template<typename T>
static inline const T *getCppPtr (const std::shared_ptr<const T> &cppObject) {
return cppObject.get();
}
template<typename T>
static inline const T *getCppPtr (const T *cppObject) {
return cppObject;
}
// ---------------------------------------------------------------------------
// Get c back ptr helpers.
// ---------------------------------------------------------------------------
......@@ -457,13 +427,11 @@ LINPHONE_END_NAMESPACE
// Get the private data of a shared or simple cpp-ptr.
#define L_GET_PRIVATE(CPP_OBJECT) \
LINPHONE_NAMESPACE::Wrapper::getPrivate(CPP_OBJECT)
LINPHONE_NAMESPACE::Wrapper::getPrivate(LINPHONE_NAMESPACE::Utils::getPtr(CPP_OBJECT))
// Get the private data of a shared or simple cpp-ptr of a wrapped C object.
#define L_GET_PRIVATE_FROM_C_OBJECT(C_OBJECT) \
L_GET_PRIVATE(LINPHONE_NAMESPACE::Wrapper::getCppPtr( \
L_GET_CPP_PTR_FROM_C_OBJECT(C_OBJECT) \
))
L_GET_PRIVATE(LINPHONE_NAMESPACE::Utils::getPtr(L_GET_CPP_PTR_FROM_C_OBJECT(C_OBJECT)))
// Get the wrapped C object of a C++ object.
#define L_GET_C_BACK_PTR(C_OBJECT) \
......
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