mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-18 11:38:08 +00:00
feat(utils/general): provide a new L_RESOLVE_OVERLOAD macro to get a function pointer of overloaded functions set
This commit is contained in:
parent
798c9502ff
commit
e3219d2ee9
1 changed files with 56 additions and 0 deletions
|
|
@ -38,6 +38,10 @@
|
|||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Export.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#ifndef LINPHONE_PUBLIC
|
||||
#if defined(_MSC_VER)
|
||||
#ifdef LINPHONE_STATIC
|
||||
|
|
@ -66,6 +70,10 @@ LINPHONE_BEGIN_NAMESPACE
|
|||
|
||||
#ifdef __cplusplus
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Debug.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void l_assert (const char *condition, const char *file, int line);
|
||||
|
||||
#ifdef DEBUG
|
||||
|
|
@ -74,6 +82,10 @@ void l_assert (const char *condition, const char *file, int line);
|
|||
#define L_ASSERT(CONDITION) static_cast<void>(false && (CONDITION))
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Optimization.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#define L_LIKELY(EXPRESSION) __builtin_expect(static_cast<bool>(EXPRESSION), true)
|
||||
#define L_UNLIKELY(EXPRESSION) __builtin_expect(static_cast<bool>(EXPRESSION), false)
|
||||
|
|
@ -82,9 +94,17 @@ void l_assert (const char *condition, const char *file, int line);
|
|||
#define L_UNLIKELY(EXPRESSION) EXPRESSION
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Misc.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Define an integer version like: 0xXXYYZZ, XX=MAJOR, YY=MINOR, and ZZ=PATCH.
|
||||
#define L_VERSION(MAJOR, MINOR, PATCH) (((MAJOR) << 16) | ((MINOR) << 8) | (PATCH))
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Data access.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BaseObject;
|
||||
class BaseObjectPrivate;
|
||||
class ClonableObject;
|
||||
|
|
@ -212,6 +232,42 @@ struct AddConstMirror<const T, U> {
|
|||
return std::static_pointer_cast<const CLASS>(Object::getSharedFromThis()); \
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Overload.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace Private {
|
||||
template<typename... Args>
|
||||
struct ResolveMemberFunctionOverload {
|
||||
template<typename Ret, typename Obj>
|
||||
constexpr auto operator() (Ret (Obj::*func)(Args...)) const -> decltype(func) {
|
||||
return func;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
struct ResolveConstMemberFunctionOverload {
|
||||
template<typename Ret, typename Obj>
|
||||
constexpr auto operator() (Ret (Obj::*func)(Args...) const) const -> decltype(func) {
|
||||
return func;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
struct ResolveOverload : ResolveMemberFunctionOverload<Args...>, ResolveConstMemberFunctionOverload<Args...> {
|
||||
using ResolveMemberFunctionOverload<Args...>::operator();
|
||||
using ResolveConstMemberFunctionOverload<Args...>::operator();
|
||||
|
||||
template<typename Ret>
|
||||
constexpr auto operator() (Ret (*func)(Args...)) const -> decltype(func) {
|
||||
return func;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Useful to select a specific overloaded function. (Avoid usage of static_cast.)
|
||||
#define L_RESOLVE_OVERLOAD(ARGS) LinphonePrivate::Private::ResolveOverload<ARGS>
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Wrapper public.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue