From 1f606e40e1dfc6a7b9237dc7f632d5e64666a951 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 13 Jun 2022 13:52:21 +0200 Subject: [PATCH] App: implement '*' operator for weak pointer classes --- src/App/DocumentObserver.cpp | 14 ++++++++++++-- src/App/DocumentObserver.h | 25 +++++++++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/App/DocumentObserver.cpp b/src/App/DocumentObserver.cpp index 4e8fa83035..dfc4eeac59 100644 --- a/src/App/DocumentObserver.cpp +++ b/src/App/DocumentObserver.cpp @@ -593,7 +593,12 @@ bool DocumentWeakPtrT::expired() const noexcept return (d->_document == nullptr); } -App::Document* DocumentWeakPtrT::operator->() noexcept +App::Document* DocumentWeakPtrT::operator*() const noexcept +{ + return d->_document; +} + +App::Document* DocumentWeakPtrT::operator->() const noexcept { return d->_document; } @@ -686,7 +691,12 @@ DocumentObjectWeakPtrT& DocumentObjectWeakPtrT::operator= (App::DocumentObject* return *this; } -App::DocumentObject* DocumentObjectWeakPtrT::operator->() noexcept +App::DocumentObject* DocumentObjectWeakPtrT::operator*() const noexcept +{ + return d->get(); +} + +App::DocumentObject* DocumentObjectWeakPtrT::operator->() const noexcept { return d->get(); } diff --git a/src/App/DocumentObserver.h b/src/App/DocumentObserver.h index 6630a497d3..2ac41a868f 100644 --- a/src/App/DocumentObserver.h +++ b/src/App/DocumentObserver.h @@ -294,11 +294,16 @@ public: * \return true if the managed object has already been deleted, false otherwise. */ bool expired() const noexcept; + /*! + * \brief operator * + * \return pointer to the document + */ + App::Document* operator*() const noexcept; /*! * \brief operator -> * \return pointer to the document */ - App::Document* operator->() noexcept; + App::Document* operator->() const noexcept; private: // disable @@ -334,10 +339,15 @@ public: */ DocumentObjectWeakPtrT& operator= (App::DocumentObject* p); /*! - * \brief operator -> - * \return pointer to the document + * \brief operator * + * \return pointer to the document object */ - App::DocumentObject* operator->() noexcept; + App::DocumentObject* operator*() const noexcept; + /*! + * \brief operator -> + * \return pointer to the document object + */ + App::DocumentObject* operator->() const noexcept; /*! * \brief operator == * \return true if both objects are equal, false otherwise @@ -400,6 +410,13 @@ public: ptr = p; return *this; } + /*! + * \brief operator -> + * \return pointer to the document object + */ + T* operator*() const { + return ptr.get(); + } /*! * \brief operator -> * \return pointer to the document object