From e12b123cf0daab6858fd29fd56e10f1c6850249d Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 13 Oct 2017 11:08:49 +0200 Subject: [PATCH] feat(General): provide a way to get private data in a a multiple inheritance case. --- include/linphone/utils/general.h | 30 +++++++++++++++++-- src/chat/chat-room/client-group-chat-room.cpp | 4 +-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/include/linphone/utils/general.h b/include/linphone/utils/general.h index 8e9e5d146..1ccee3b72 100644 --- a/include/linphone/utils/general.h +++ b/include/linphone/utils/general.h @@ -20,6 +20,10 @@ #ifndef _GENERAL_H_ #define _GENERAL_H_ +#ifdef __cplusplus + #include +#endif + // ============================================================================= #ifdef __cplusplus @@ -151,8 +155,30 @@ constexpr T *getPublicHelper (Object *object, const ObjectPrivate *) { CLASS (const CLASS &) = delete; \ CLASS &operator= (const CLASS &) = delete; -#define L_D() decltype(std::declval().getPrivate()) const d = getPrivate(); -#define L_Q() decltype(std::declval().getPublic()) const q = getPublic(); +// Get Private data. +#define L_D() decltype(getPrivate()) const d = getPrivate(); + +// Get Public data. +#define L_Q() decltype(getPublic()) const q = getPublic(); + +template +struct AddConstMirror { + typedef U type; +}; + +template +struct AddConstMirror { + typedef typename std::add_const::type type; +}; + +// Get Private data of class in a multiple inheritance case. +#define L_D_T(CLASS, NAME) \ + auto const NAME = static_cast< \ + AddConstMirror< \ + std::remove_reference::type, \ + CLASS ## Private \ + >::type * \ + >(CLASS::mPrivate); #define L_OVERRIDE_SHARED_FROM_THIS(CLASS) \ inline std::shared_ptr getSharedFromThis () { \ diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index 3fdc1bb74..9d0e85137 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -211,6 +211,7 @@ void ClientGroupChatRoom::setParticipantAdminStatus (shared_ptr &pa void ClientGroupChatRoom::setSubject (const string &subject) { L_D(); + L_D_T(RemoteConference, dConference); if (d->state != ChatRoom::State::Created) { lError() << "Cannot change the ClientGroupChatRoom subject in a state other than Created"; @@ -222,8 +223,7 @@ void ClientGroupChatRoom::setSubject (const string &subject) { return; } - shared_ptr session = - static_cast(Conference::mPrivate)->focus->getPrivate()->getSession(); + shared_ptr session = dConference->focus->getPrivate()->getSession(); if (session) session->update(nullptr, subject); else {