From b8be3fa05b44820856cae33de0d812bf749640e9 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Mon, 6 Nov 2017 15:53:28 +0100 Subject: [PATCH] fix(c-wrapper): add private on some functions, owner is by default External --- src/c-wrapper/internal/c-tools.h | 100 ++++++++++++++++--------------- 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/src/c-wrapper/internal/c-tools.h b/src/c-wrapper/internal/c-tools.h index 5c03c244d..ebb68f6ed 100644 --- a/src/c-wrapper/internal/c-tools.h +++ b/src/c-wrapper/internal/c-tools.h @@ -122,8 +122,8 @@ private: // --------------------------------------------------------------------------- enum class WrappedObjectOwner : int { - Internal, - External + External, + Internal }; template @@ -132,7 +132,7 @@ private: std::shared_ptr cppPtr; std::weak_ptr weakCppPtr; - // By default: Internal. + // By default: External. WrappedObjectOwner owner; }; @@ -151,22 +151,39 @@ private: std::terminate(); } -public: // --------------------------------------------------------------------------- - // Belle sip handlers. - // Deal with floating references. + // Get cpp ptr (shared if BaseObject, not shared if ClonableObject) + // from cpp object. // --------------------------------------------------------------------------- - static void onBelleSipFirstRef (belle_sip_object_t *base) { - WrappedBaseObject *wrappedObject = reinterpret_cast *>(base); - if (wrappedObject->owner == WrappedObjectOwner::Internal) - wrappedObject->cppPtr = wrappedObject->weakCppPtr.lock(); + template< + typename CppType, + typename = typename std::enable_if::value, CppType>::type + > + static inline std::shared_ptr getResolvedCppPtr (const CppType *cppObject) { + if (L_UNLIKELY(!cppObject)) + return nullptr; + + try { + typedef typename std::decaygetSharedFromThis())>::type SharedFromThisType; + + return std::static_pointer_cast( + std::const_pointer_cast(cppObject->getSharedFromThis()) + ); + } catch (const std::bad_weak_ptr &e) { + abort(e.what()); + } + + L_ASSERT(false); + return nullptr; } - static void onBelleSipLastRef (belle_sip_object_t *base) { - WrappedBaseObject *wrappedObject = reinterpret_cast *>(base); - if (wrappedObject->owner == WrappedObjectOwner::Internal) - wrappedObject->cppPtr.reset(); + template< + typename CppType, + typename = typename std::enable_if::value, CppType>::type + > + static constexpr const CppType *getResolvedCppPtr (const CppType *cppObject) { + return cppObject; } // --------------------------------------------------------------------------- @@ -192,6 +209,24 @@ public: #endif } +public: + // --------------------------------------------------------------------------- + // Belle sip handlers. + // Deal with floating references. + // --------------------------------------------------------------------------- + + static void onBelleSipFirstRef (belle_sip_object_t *base) { + WrappedBaseObject *wrappedObject = reinterpret_cast *>(base); + if (wrappedObject->owner == WrappedObjectOwner::Internal) + wrappedObject->cppPtr = wrappedObject->weakCppPtr.lock(); + } + + static void onBelleSipLastRef (belle_sip_object_t *base) { + WrappedBaseObject *wrappedObject = reinterpret_cast *>(base); + if (wrappedObject->owner == WrappedObjectOwner::Internal) + wrappedObject->cppPtr.reset(); + } + // --------------------------------------------------------------------------- // Get private data of cpp Object. // --------------------------------------------------------------------------- @@ -356,45 +391,11 @@ public: setCppPtrFromC(cObject, new CppType(*cppObject)); } - // --------------------------------------------------------------------------- - // Get cpp ptr (shared if BaseObject, not shared if ClonableObject) - // from cpp object. - // --------------------------------------------------------------------------- - - template< - typename CppType, - typename = typename std::enable_if::value, CppType>::type - > - static inline std::shared_ptr getResolvedCppPtr (const CppType *cppObject) { - if (L_UNLIKELY(!cppObject)) - return nullptr; - - try { - typedef typename std::decaygetSharedFromThis())>::type SharedFromThisType; - - return std::static_pointer_cast( - std::const_pointer_cast(cppObject->getSharedFromThis()) - ); - } catch (const std::bad_weak_ptr &e) { - abort(e.what()); - } - - L_ASSERT(false); - return nullptr; - } - - template< - typename CppType, - typename = typename std::enable_if::value, CppType>::type - > - static constexpr const CppType *getResolvedCppPtr (const CppType *cppObject) { - return cppObject; - } - // --------------------------------------------------------------------------- // Get c back ptr resolver helpers. // --------------------------------------------------------------------------- +private: template< typename CppType, typename = typename std::enable_if::value, CppType>::type @@ -427,6 +428,7 @@ public: // Get c back ptr helpers. // --------------------------------------------------------------------------- +public: template< typename CppType, typename = typename std::enable_if<