TizenRefApp-8670 [Gallery] Reimplement UCL memory module 14/134114/3
authorIgor Nazarov <i.nazarov@samsung.com>
Wed, 14 Jun 2017 11:17:00 +0000 (14:17 +0300)
committerIgor Nazarov <i.nazarov@samsung.com>
Wed, 14 Jun 2017 18:40:15 +0000 (21:40 +0300)
Change-Id: I152c4353e54b99719b472e6e07a5f91c2936cb14

85 files changed:
inc/gallery/model/Gallery.h
inc/gallery/model/MediaItem.h
inc/gallery/model/SoundManager.h
inc/gallery/presenters/AlertDialog.h
inc/gallery/presenters/AtspiHighlightHelper.h
inc/gallery/presenters/Instance.h
inc/gallery/presenters/MoreOptionsPresenter.h
inc/gallery/presenters/NoContentPage.h
inc/gallery/presenters/Page.h
inc/gallery/presenters/Presenter.h
inc/gallery/presenters/PreviewPage.h
inc/gallery/presenters/ProcessingPresenter.h
inc/gallery/presenters/SelectModePresenter.h
inc/gallery/presenters/ThumbnailPage.h
inc/gallery/presenters/VideoPlayerPage.h
inc/gallery/presenters/ViewerPage.h
inc/gallery/view/ImageGrid.h
inc/gallery/view/ImageViewer.h
inc/gallery/view/PageContent.h
inc/gallery/view/TouchParser.h
src/common.h
src/model/GalleryAlbum.h
src/model/MediaItem.cpp
src/presenters/AlertDialog.cpp
src/presenters/AtspiHighlightHelper.cpp
src/presenters/Instance.cpp
src/presenters/MoreOptionsPresenter.cpp
src/presenters/NoContentPage.cpp
src/presenters/Page.cpp
src/presenters/Presenter.cpp
src/presenters/PreviewPage.cpp
src/presenters/ProcessingPresenter.cpp
src/presenters/SelectModePresenter.cpp
src/presenters/ThumbnailPage.cpp
src/presenters/VideoPlayerPage.cpp
src/presenters/ViewerPage.cpp
src/view/ImageGrid.cpp
src/view/ImageViewer.cpp
src/view/PageContent.cpp
src/view/TouchParser.cpp
ucl/inc/ucl/gui/EdjeWidget.h
ucl/inc/ucl/gui/EdjeWidget.hpp
ucl/inc/ucl/gui/ElmWidget.h
ucl/inc/ucl/gui/Layout.h
ucl/inc/ucl/gui/Naviframe.h
ucl/inc/ucl/gui/StyledWidget.h
ucl/inc/ucl/gui/Widget.h
ucl/inc/ucl/gui/Window.h
ucl/inc/ucl/gui/Window.hpp
ucl/inc/ucl/misc/Event.hpp
ucl/inc/ucl/misc/RefCountAware.h
ucl/inc/ucl/misc/RefCountAware.hpp
ucl/inc/ucl/misc/Timeout.h
ucl/inc/ucl/util/delegation/BaseDelegate.h
ucl/inc/ucl/util/delegation/BaseDelegate.hpp
ucl/inc/ucl/util/delegation/Delegate.h
ucl/inc/ucl/util/delegation/Delegate.hpp
ucl/inc/ucl/util/delegation/Delegate2.h
ucl/inc/ucl/util/delegation/Delegate2.hpp
ucl/inc/ucl/util/delegation/helpers.h
ucl/inc/ucl/util/memory.h
ucl/inc/ucl/util/memory/BaseRef.h
ucl/inc/ucl/util/memory/BaseRef.hpp
ucl/inc/ucl/util/memory/IRefCountObj.h [new file with mode: 0644]
ucl/inc/ucl/util/memory/RefCountObj.h
ucl/inc/ucl/util/memory/RefCountObj.hpp
ucl/inc/ucl/util/memory/RefCountObjBase.h [deleted file]
ucl/inc/ucl/util/memory/RefCountObjBase.hpp [deleted file]
ucl/inc/ucl/util/memory/RefCounterMT.h [new file with mode: 0644]
ucl/inc/ucl/util/memory/RefCounterMT.hpp [new file with mode: 0644]
ucl/inc/ucl/util/memory/RefCounterST.h [new file with mode: 0644]
ucl/inc/ucl/util/memory/RefCounterST.hpp [new file with mode: 0644]
ucl/inc/ucl/util/memory/ReffedObj.h [new file with mode: 0644]
ucl/inc/ucl/util/memory/ReffedObj.hpp [new file with mode: 0644]
ucl/inc/ucl/util/memory/SharedRef.h
ucl/inc/ucl/util/memory/SharedRef.hpp
ucl/inc/ucl/util/memory/WeakRef.h
ucl/inc/ucl/util/memory/WeakRef.hpp
ucl/inc/ucl/util/memory/helpers.h
ucl/inc/ucl/util/smartDelegation/WeakDelegate.h
ucl/inc/ucl/util/smartDelegation/WeakDelegate.hpp
ucl/inc/ucl/util/types/baseTypes.h
ucl/src/gui/ElmWidget.cpp
ucl/src/gui/Naviframe.cpp
ucl/src/gui/Widget.cpp

index 1a711f9d353360afe2b679b518d3b3e7464724d8..e17b1f5798d76477a946133217ee28b285c1a360 100644 (file)
@@ -31,7 +31,7 @@ namespace gallery {
                IMediaAlbumSRef getAlbum();
 
        private:
-               friend class ucl::RefCountObj<Gallery>;
+               friend class ucl::ReffedObj<Gallery>;
                Gallery();
 
                ucl::Result prepare();
index df35b8d76454495234d4496ce19fda95fc2febf8..7b6eea0597454b0d1cbfa2bccc6167c95d9f6ced 100644 (file)
@@ -87,7 +87,7 @@ namespace gallery {
                ucl::Result saveToDevice();
 
        protected:
-               friend class ucl::RefCountObj<MediaItem>;
+               friend class ucl::ReffedObj<MediaItem>;
                MediaItem(int flags, MediaType type);
 
                ucl::Result prepare(media_info_h media);
index df5e36a53399deaf1b3db6fa1ff4f640df7335fe..e5adddb8622a4ff0550f0e752589a5d093d91a7b 100644 (file)
@@ -43,7 +43,7 @@ namespace gallery {
                void delMediaVolumeChangeHandler(const NotiHandler &handler);
 
        private:
-               friend class ucl::RefCountObj<SoundManager>;
+               friend class ucl::ReffedObj<SoundManager>;
                SoundManager();
                ~SoundManager();
 
index 59274a2147f07250434b196f8b11cb7e60e00c38..ce508ff300601a9da0fb257212c8843ef71da549 100644 (file)
@@ -66,8 +66,8 @@ namespace gallery {
                virtual bool isDisposed() const final override;
 
        private:
-               friend class ucl::RefCountObj<AlertDialog>;
-               AlertDialog(ucl::RefCountObjBase &rc,
+               friend class ucl::ReffedObj<AlertDialog>;
+               AlertDialog(ucl::IRefCountObj &rc,
                                const EventHandler &handler);
                virtual ~AlertDialog();
 
index b84471ea991712eb4d07751377f08c859d14172f..ca908e0c07e6bbc41145215a5410d1e95c2c4fb9 100644 (file)
@@ -35,8 +35,8 @@ namespace gallery {
                void registerWidget(ucl::ElmWidget &widget);
 
        private:
-               friend class ucl::RefCountObj<AtspiHighlightHelper>;
-               AtspiHighlightHelper(ucl::RefCountObjBase &rc);
+               friend class ucl::ReffedObj<AtspiHighlightHelper>;
+               AtspiHighlightHelper(ucl::IRefCountObj &rc);
                virtual ~AtspiHighlightHelper();
 
                ucl::Result prepare(ucl::ElmWidget &rootWidget);
index 2fee4585d32df1f8e14f683d6506108858b5752c..bdc4fa66250832458429f17a81e1424305ec1067 100644 (file)
@@ -33,7 +33,7 @@ namespace gallery {
                        public ucl::IInstance,
                        public ucl::IInstanceAppControlExt {
        public:
-               Instance(ucl::RefCountObjBase &rc,
+               Instance(ucl::IRefCountObj &rc,
                                ucl::SysEventProvider &sysEventProvider);
                virtual ~Instance();
 
index c959b3c4c8fa9ff20884fd28da4d302d637a1d13..de89f1ab566d0f24fb0fd5a7d421269cb1280521 100644 (file)
@@ -76,8 +76,8 @@ namespace gallery {
                using MoreOptionsCSRef = ucl::SharedRef<const MoreOptions>;
 
        private:
-               friend class ucl::RefCountObj<MoreOptionsPresenter>;
-               MoreOptionsPresenter(ucl::RefCountObjBase &rc,
+               friend class ucl::ReffedObj<MoreOptionsPresenter>;
+               MoreOptionsPresenter(ucl::IRefCountObj &rc,
                                const MoreOptionsCSRef &options);
                virtual ~MoreOptionsPresenter();
 
index b02900d53803815378956cc7c74411da188e0f72..c61fbf21baf2550959f5b23c289c13b6f330dd21 100644 (file)
@@ -37,8 +37,8 @@ namespace gallery {
                };
 
        private:
-               friend class ucl::RefCountObj<NoContentPage>;
-               NoContentPage(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi,
+               friend class ucl::ReffedObj<NoContentPage>;
+               NoContentPage(ucl::IRefCountObj &rc, const ucl::NaviframeSRef &navi,
                                const ExitRequestHandler &onExitRequest);
                virtual ~NoContentPage();
 
index 4be629e2a6c8c4fe6e21eef93a6ec6a65c5218fe..c1a1b295f2e6bb8bbc438b3c322438c50a5b03a8 100644 (file)
@@ -49,7 +49,7 @@ namespace gallery {
                ucl::NaviItem insertBefore(ARGS &&...args);
 
        protected:
-               Page(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi,
+               Page(ucl::IRefCountObj &rc, const ucl::NaviframeSRef &navi,
                                const ExitRequestHandler &onExitRequest);
                virtual ~Page();
 
index 4ed3530cb6dd4d8a32c1b81da6ee6686a598c7b4..1142452ce2a045e29a2785d3a4cd2801bff19fd2 100644 (file)
@@ -42,7 +42,7 @@ namespace gallery {
                void deactivateBy(void *deactivator);
 
        protected:
-               Presenter(ucl::RefCountObjBase &rc);
+               Presenter(ucl::IRefCountObj &rc);
                virtual ~Presenter();
 
                ucl::Result prepare(ucl::ElmWidget &widget);
index a93691ba6be53a0abc1a1b46dda82861ee7f1743..c499db6ba55568cdcfced3345d13bad5bf4eca74 100644 (file)
@@ -62,8 +62,8 @@ namespace gallery {
                int getCurrentItemIndex() const;
 
        private:
-               friend class ucl::RefCountObj<PreviewPage>;
-               PreviewPage(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi,
+               friend class ucl::ReffedObj<PreviewPage>;
+               PreviewPage(ucl::IRefCountObj &rc, const ucl::NaviframeSRef &navi,
                                const ExitRequestHandler &onExitRequest,
                                const IMediaAlbumSRef &album, bool selectModeStartup);
                virtual ~PreviewPage();
index 59ff50f584e3de782c963892d9de95854100e66f..94e1e80788362cbb282945b3e7100ae47ae2000d 100644 (file)
@@ -53,8 +53,8 @@ namespace gallery {
                void setDismissHandler(const DismissHandler &handler);
 
        private:
-               friend class ucl::RefCountObj<ProcessingPresenter>;
-               ProcessingPresenter(ucl::RefCountObjBase &rc);
+               friend class ucl::ReffedObj<ProcessingPresenter>;
+               ProcessingPresenter(ucl::IRefCountObj &rc);
                virtual ~ProcessingPresenter();
 
                ucl::Result prepare(ucl::ElmWidget &parent,
index 72c014f3629f3337b365b59e791dd6c18e1e75b9..2ba0a56c23d4854b22ffa352b50cf620d4c1c190 100644 (file)
@@ -72,8 +72,8 @@ namespace gallery {
                void update(int selectCount, int totalCount = -1);
 
        private:
-               friend class ucl::RefCountObj<SelectModePresenter>;
-               SelectModePresenter(ucl::RefCountObjBase &rc,
+               friend class ucl::ReffedObj<SelectModePresenter>;
+               SelectModePresenter(ucl::IRefCountObj &rc,
                                PageContent &content, int flags);
                virtual ~SelectModePresenter();
 
index ccfe14eed9819f668b484cba7d1b191be76e4778..914d759148cee171b99a08e9f3a6d7366269f75e 100644 (file)
@@ -49,8 +49,8 @@ namespace gallery {
                };
 
        private:
-               friend class ucl::RefCountObj<ThumbnailPage>;
-               ThumbnailPage(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi,
+               friend class ucl::ReffedObj<ThumbnailPage>;
+               ThumbnailPage(ucl::IRefCountObj &rc, const ucl::NaviframeSRef &navi,
                                const ExitRequestHandler &onExitRequest,
                                const IMediaAlbumSRef &album);
                virtual ~ThumbnailPage();
index 64732fa764ea94d0fd136184f95a1893f4820866..9a61a4e65d618f7411f930e57fd11716a9c47070 100644 (file)
@@ -48,8 +48,8 @@ namespace gallery {
                };
 
        private:
-               friend class ucl::RefCountObj<VideoPlayerPage>;
-               VideoPlayerPage(ucl::RefCountObjBase &rc,
+               friend class ucl::ReffedObj<VideoPlayerPage>;
+               VideoPlayerPage(ucl::IRefCountObj &rc,
                                const ucl::NaviframeSRef &navi,
                                const ExitRequestHandler &onExitRequest,
                                const MediaItemSRef &media);
index 6cb80ad46dbe1ec0d0799e03767cf22a3db441e2..82ecc9242d647fa1e3d7f8e10f07a9cad4a646af 100644 (file)
@@ -60,8 +60,8 @@ namespace gallery {
                const std::string &getMediaId() const;
 
        private:
-               friend class ucl::RefCountObj<ViewerPage>;
-               ViewerPage(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi,
+               friend class ucl::ReffedObj<ViewerPage>;
+               ViewerPage(ucl::IRefCountObj &rc, const ucl::NaviframeSRef &navi,
                                const ExitRequestHandler &onExitRequest,
                                const MediaItemSRef &media, bool exitOnZoomOut);
                virtual ~ViewerPage();
index 31aa0a54a3068f096911d2db6894086eb79a5460..e21a3678dfdb28157b4ffb21ee2fa345e879f280 100644 (file)
@@ -129,8 +129,8 @@ namespace gallery {
                struct LinearInfo;
 
        private:
-               friend class ucl::RefCountObj<ImageGrid>;
-               ImageGrid(ucl::RefCountObjBase *rc, Evas_Object *scroller,
+               friend class ucl::ReffedObj<ImageGrid>;
+               ImageGrid(ucl::IRefCountObj *rc, Evas_Object *scroller,
                                Type type, bool selectModeStartup);
                virtual ~ImageGrid();
 
@@ -243,7 +243,7 @@ namespace gallery {
        private:
                const Info &m_info;
 
-               ucl::StyledWidgetWRef m_scroller;
+               ucl::StyledWidget *m_scroller;
                ucl::ElmWidget m_box;
                ucl::Widget m_rect1;
                ucl::Widget m_rect2;
index 5b6f21585ad47e2a6c8b2e5535b431b5920ea39e..9b6e5d8f3f7134bb8c14e422842d22bd72fdcd57 100644 (file)
@@ -53,8 +53,8 @@ namespace gallery {
                bool isZoomedOut() const;
 
        private:
-               friend class ucl::RefCountObj<ImageViewer>;
-               ImageViewer(ucl::RefCountObjBase &rc, Evas_Object *scroller,
+               friend class ucl::ReffedObj<ImageViewer>;
+               ImageViewer(ucl::IRefCountObj &rc, Evas_Object *scroller,
                                const std::string &highResPath, int loadSize, bool forceLoad);
                virtual ~ImageViewer();
 
@@ -85,7 +85,7 @@ namespace gallery {
                };
 
        private:
-               ucl::StyledWidgetWRef m_scroller;
+               ucl::StyledWidget *m_scroller;
                ucl::Layout m_layout;
                ucl::Widget m_grid;
                ucl::Widget m_lowResImage;
index 9e581b4d84597b9039be1391c99650f1871f439b..194c97b668733b0a3a1e87ab10b27f6776466623 100644 (file)
@@ -63,8 +63,8 @@ namespace gallery {
                ucl::Result setMoreOptionsVisible(bool visible);
 
        private:
-               friend class ucl::RefCountObj<PageContent>;
-               PageContent(ucl::RefCountObjBase &rc,
+               friend class ucl::ReffedObj<PageContent>;
+               PageContent(ucl::IRefCountObj &rc,
                                const ucl::LayoutSRef &layout, int flags);
                virtual ~PageContent();
 
@@ -76,7 +76,7 @@ namespace gallery {
                ucl::Layout *getTopLayout() const;
 
        private:
-               ucl::LayoutWRef m_moreOptions;
+               ucl::Layout *m_mainLayout;
                ucl::LayoutSRef m_selectMode;
                ucl::LayoutSRef m_bottomButton;
        };
index 484fb8438a3313c03a4a53d60767b9c4bd4504c4..be391a39f4e9310a8082aa72d1fff168a6bb91d3 100644 (file)
@@ -30,8 +30,8 @@ namespace gallery {
                using TapHandler = ucl::WeakDelegate<void(int x, int y)>;
 
        private:
-               friend class ucl::RefCountObj<TouchParser>;
-               TouchParser(ucl::RefCountObjBase &rc, ucl::Widget &eventSource);
+               friend class ucl::ReffedObj<TouchParser>;
+               TouchParser(ucl::IRefCountObj &rc, ucl::Widget &eventSource);
                virtual ~TouchParser();
 
        public:
index d6d7bae76df6c22d03759260bd2ed7bb2b702216..43890c017eac4d05515841d482a509b421e31d22 100644 (file)
@@ -46,8 +46,8 @@ namespace gallery {
        using ucl::isNotEmpty;
        using ucl::toEina;
 
-       using ucl::RefCountObj;
-       using ucl::RefCountObjBase;
+       using ucl::ReffedObj;
+       using ucl::IRefCountObj;
        using ucl::SharedRef;
        using ucl::WeakRef;
 
index 57f7e4858120e119a61dc92ef71b1a5a2a8ccc57..715b708a9c5e811a0723f30508a527a40b4ce6c8 100644 (file)
@@ -47,7 +47,7 @@ namespace gallery {
                virtual void defragment() final override;
 
        private:
-               friend class ucl::RefCountObj<GalleryAlbum>;
+               friend class ucl::ReffedObj<GalleryAlbum>;
                GalleryAlbum();
 
                ucl::Result prepare();
index ac8c3ef085a6742b605517eedb08487e30db4c40..a0db727f3415095b47e76784ebabae2fb752ca7a 100644 (file)
@@ -334,7 +334,10 @@ namespace gallery {
                if (!(m_flags & FLAG_REMOVE)) {
                        LOG_RETURN(RES_NOT_SUPPORTED, "Operation not supported!");
                }
-               if (!ecore_file_can_write(m_filePath.c_str())) {
+
+               const bool exists = ecore_file_exists(m_filePath.c_str());
+
+               if (exists && !ecore_file_can_write(m_filePath.c_str())) {
                        LOG_RETURN(RES_FAIL, "File can't be removed!");
                }
 
@@ -350,7 +353,7 @@ namespace gallery {
                        m_isValid = false;
                }
 
-               if (!ecore_file_remove(m_filePath.c_str())) {
+               if (exists && !ecore_file_remove(m_filePath.c_str())) {
                        FLOG("ecore_file_remove() failed! Attempting to rescan....");
                        MutexLock lock(getMediaMutex());
                        const int ret = media_content_scan_file(m_filePath.c_str());
index 57b06d656855cf34ed60bffc868b530511a6ef1f..da1ebe13b18b1b013e6ae252722426c46b8dbff3 100644 (file)
@@ -108,7 +108,7 @@ namespace gallery {
 
        // AlertDialog //
 
-       AlertDialog::AlertDialog(RefCountObjBase &rc,
+       AlertDialog::AlertDialog(IRefCountObj &rc,
                        const EventHandler &handler) :
                Presenter(rc),
                m_handler(handler),
@@ -170,14 +170,16 @@ namespace gallery {
 
        Result AlertDialog::createLayout(const LayoutTheme theme)
        {
-               m_layout = Layout::Builder().
+               const auto layout = Layout::Builder().
                                setTheme(theme).
                                build(*m_popup);
-               if (!m_layout) {
+               if (!layout) {
                        LOG_RETURN(RES_FAIL, "Layout::build() failed!");
                }
 
-               m_popup->setContent(*m_layout);
+               m_popup->setContent(*layout);
+
+               m_layout = layout;
 
                return RES_OK;
        }
@@ -215,15 +217,15 @@ namespace gallery {
 
        void AlertDialog::setTitle(const TString &title)
        {
-               if (m_layout) {
-                       m_layout->setText(title, PART_TITLE);
+               if (const auto layout = m_layout.lock()) {
+                       layout->setText(title, PART_TITLE);
                }
        }
 
        void AlertDialog::setText(const TString &text)
        {
-               if (m_layout) {
-                       m_layout->setText(text);
+               if (const auto layout = m_layout.lock()) {
+                       layout->setText(text);
                }
        }
 
@@ -256,7 +258,6 @@ namespace gallery {
 
        void AlertDialog::handleEvent(const Event event)
        {
-               const auto keepAliver = asShared(*this);
                if (dispatchEvent(event)) {
                        dismiss();
                }
index 08cd14e21173b8232497f41697b5440351783679..ad589c6c54714a6dd330fab498e352de3449cad5 100644 (file)
@@ -40,7 +40,7 @@ namespace gallery {
                return result;
        }
 
-       AtspiHighlightHelper::AtspiHighlightHelper(RefCountObjBase &rc) :
+       AtspiHighlightHelper::AtspiHighlightHelper(IRefCountObj &rc) :
                Presenter(rc)
        {
        }
index fbefd8e56045dfa7b16ae789da9ed31ee5caf84b..2824d4e8d41f8a80af663bc2361aac890058a563 100644 (file)
@@ -45,7 +45,7 @@ namespace gallery {
        using ucl::Theme;
        using ucl::Naviframe;
 
-       Instance::Instance(RefCountObjBase &rc,
+       Instance::Instance(IRefCountObj &rc,
                        SysEventProvider &sysEventProvider) :
                RefCountAware(&rc),
                m_sysEventProvider(sysEventProvider),
@@ -58,8 +58,8 @@ namespace gallery {
        Instance::~Instance()
        {
                stopMediaContentScan();
-               if (m_page) {
-                       m_page->exitNoTransition();
+               if (const auto page = m_page.lock()) {
+                       page->exitNoTransition();
                }
        }
 
@@ -208,14 +208,14 @@ namespace gallery {
        {
                FAIL_RETURN(ensureGalleryModel(), "ensureGalleryModel() failed!");
 
-               if (!m_page) {
-                       if (isEmpty(m_gallery->getAlbum())) {
-                               createNoContentPage();
-                       } else {
-                               createThumbnailPage();
+               if (const auto page = m_page.lock()) {
+                       if (operation == APP_CONTROL_OPERATION_MAIN) {
+                               page->deleteTo();
                        }
-               } else if (operation == APP_CONTROL_OPERATION_MAIN) {
-                       m_page->deleteTo();
+               } else if (isEmpty(m_gallery->getAlbum())) {
+                       createNoContentPage();
+               } else {
+                       createThumbnailPage();
                }
 
                return RES_OK;
@@ -319,13 +319,13 @@ namespace gallery {
        void Instance::onAlbumChanged()
        {
                if (isEmpty(m_gallery->getAlbum())) {
-                       if (dynamic_cast<ThumbnailPage *>(m_page.get())) {
-                               m_page->exitNoTransition();
+                       if (auto page = dynamicRefCast<ThumbnailPage>(m_page).lock()) {
+                               page->exitNoTransition();
                                createNoContentPage();
                        }
                } else {
-                       if (dynamic_cast<NoContentPage *>(m_page.get())) {
-                               m_page->exitNoTransition();
+                       if (auto page = dynamicRefCast<NoContentPage>(m_page).lock()) {
+                               page->exitNoTransition();
                                createThumbnailPage();
                        }
                }
index f0d902f1cb6fe8eb6a49b170e42e41dc15183eea..15492dc7f4e6ebb16387b550e5ecde6cf063d25e 100644 (file)
@@ -99,7 +99,7 @@ namespace gallery {
 
        // MoreOptionsPresenter //
 
-       MoreOptionsPresenter::MoreOptionsPresenter(RefCountObjBase &rc,
+       MoreOptionsPresenter::MoreOptionsPresenter(IRefCountObj &rc,
                        const MoreOptionsCSRef &options) :
                Presenter(rc),
                m_options(options),
@@ -207,11 +207,10 @@ namespace gallery {
        void MoreOptionsPresenter::onOpened(Widget &widget, void *eventInfo)
        {
                stopTimer();
-               const auto keepAliver = asShared(*this);
                sendDeactivateBy(*m_widget, this);
                activateBy(m_widget.get());
-               if (m_listener) {
-                       m_listener->onMoreOptionsOpened(*this);
+               if (const auto listener = m_listener.lock()) {
+                       listener->onMoreOptionsOpened(*this);
                }
                if (!isActive()) {
                        setOpened(false);
@@ -221,20 +220,22 @@ namespace gallery {
        void MoreOptionsPresenter::onClosed(Widget &widget, void *eventInfo)
        {
                stopTimer();
-               const auto keepAliver = asShared(*this);
                deactivateBy(m_widget.get());
                sendActivateBy(*m_widget, this);
-               if (m_listener) {
-                       m_listener->onMoreOptionsClosed(*this);
+               if (const auto listener = m_listener.lock()) {
+                       listener->onMoreOptionsClosed(*this);
                }
        }
 
        void MoreOptionsPresenter::onItemClicked(Widget &widget, void *eventInfo)
        {
-               if (m_listener && isActive() && isOpened()) {
+               if (!isActive() || !isOpened()) {
+                       return;
+               }
+               if (const auto listener = m_listener.lock()) {
                        const auto item = m_map.get(eventInfo);
                        if (item) {
-                               m_listener->onMoreOptionClicked(*this, *item);
+                               listener->onMoreOptionClicked(*this, *item);
                        } else {
                                ELOG("Invalid eventInfo!");
                        }
@@ -243,10 +244,10 @@ namespace gallery {
 
        void MoreOptionsPresenter::onItemSelected(Widget &widget, void *eventInfo)
        {
-               if (m_listener) {
+               if (const auto listener = m_listener.lock()) {
                        const auto item = m_map.get(eventInfo);
                        if (item) {
-                               m_listener->onMoreOptionSelected(*this, *item);
+                               listener->onMoreOptionSelected(*this, *item);
                        } else {
                                ELOG("Invalid eventInfo!");
                        }
index db5c2d6f98806233fea98f36a287000bbda0e0ef..5dc69b3c3d41806e048c58ab142be5dc6ba4e625 100644 (file)
@@ -67,7 +67,7 @@ namespace gallery {
 
        // NoContentPage //
 
-       NoContentPage::NoContentPage(RefCountObjBase &rc,
+       NoContentPage::NoContentPage(IRefCountObj &rc,
                        const NaviframeSRef &navi,
                        const ExitRequestHandler &onExitRequest) :
                Page(rc, navi, onExitRequest)
index 39a69302c77eda5cc5291bfa79d7cdcca6c0d7d7..43ed7686506b901fc271f5847fc75b0d3023db22 100644 (file)
@@ -31,7 +31,7 @@ namespace gallery {
        using ucl::NAVI_TRANSITION_STARTED;
        using ucl::NAVI_TRANSITION_FINISHED;
 
-       Page::Page(RefCountObjBase &rc, const NaviframeSRef &navi,
+       Page::Page(IRefCountObj &rc, const NaviframeSRef &navi,
                        const ExitRequestHandler &onExitRequest) :
                Presenter(rc),
                m_navi(navi),
index 13f2856261b2cf37afb361308af323497c6e9dca..dcbd7d9575b6d3708649a2306a35f620678826f3 100644 (file)
@@ -28,7 +28,7 @@ namespace gallery {
 
        using ucl::Window;
 
-       Presenter::Presenter(RefCountObjBase &rc) :
+       Presenter::Presenter(IRefCountObj &rc) :
                RefCountAware(&rc),
                m_isPrepared(false)
        {
index 05f3f12b55a7f4e3aa026fab96833dccad1bd35e..b91c7fe6cfd9ce715cca0c3c57d81864d9a86071 100644 (file)
@@ -118,7 +118,7 @@ namespace gallery {
 
        class PreviewPage::Item : public RefCountAware {
        public:
-               Item(RefCountObjBase &rc, MediaItemSRef &&media,
+               Item(IRefCountObj &rc, MediaItemSRef &&media,
                                ImageGrid &imageGrid, const int itemIndex) :
                        RefCountAware(&rc),
                        m_media(std::move(media)),
@@ -199,7 +199,7 @@ namespace gallery {
 
        // PreviewPage //
 
-       PreviewPage::PreviewPage(RefCountObjBase &rc,
+       PreviewPage::PreviewPage(IRefCountObj &rc,
                        const NaviframeSRef &navi,
                        const ExitRequestHandler &onExitRequest,
                        const IMediaAlbumSRef &album,
@@ -215,9 +215,13 @@ namespace gallery {
 
        PreviewPage::~PreviewPage()
        {
+               if (m_album) {
+                       m_album->delChangeHandler(WEAK_DELEGATE(
+                                       PreviewPage::onAlbumChanged, asWeak(*this)));
+               }
                closeTempViews();
-               if (m_page) {
-                       m_page->exitNoTransition();
+               if (const auto page = m_page.lock()) {
+                       page->exitNoTransition();
                }
                if (m_imageGrid) {
                        m_imageGrid->setListener(nullptr);
@@ -253,9 +257,8 @@ namespace gallery {
 
        void PreviewPage::checkViewerPage()
        {
-               if (const ViewerPageSRef viewerPage =
-                               dynamicRefCast<ViewerPage>(m_page)) {
-                       const auto mediaId = viewerPage->getMediaId();
+               if (const auto page = dynamicRefCast<ViewerPage>(m_page).lock()) {
+                       const auto mediaId = page->getMediaId();
                        const auto it = std::find_if(m_items.begin(), m_items.end(),
                                [&mediaId](const ItemSRef &item)
                                {
@@ -645,8 +648,8 @@ namespace gallery {
 
        void PreviewPage::closeTempViews()
        {
-               if (m_alert) {
-                       m_alert->dispose();
+               if (const auto alert = m_alert.lock()) {
+                       alert->dispose();
                }
                if (m_more) {
                        m_more->setOpened(false);
index 90e679e357351b6ce6ca72084412d6aec4be1fe6..63bf0cd2bb301985d2a1a9f04f0b76853199d936 100644 (file)
@@ -86,7 +86,7 @@ namespace gallery {
 
        // ProcessingPresenter //
 
-       ProcessingPresenter::ProcessingPresenter(RefCountObjBase &rc) :
+       ProcessingPresenter::ProcessingPresenter(IRefCountObj &rc) :
                Presenter(rc),
                m_iconType(IconType::NONE),
                m_timer(nullptr),
@@ -202,14 +202,16 @@ namespace gallery {
 
        Result ProcessingPresenter::createIcon()
        {
-               m_icon = Layout::Builder().
+               const auto icon = Layout::Builder().
                                setTheme(impl::LAYOUT_POPUP_ICON).
                                build(*m_popup);
-               if (!m_icon) {
+               if (!icon) {
                        LOG_RETURN(RES_FAIL, "Layout::build() failed!");
                }
 
-               m_popup->setContent(*m_icon, impl::PART_TOAST_ICON);
+               m_popup->setContent(*icon, impl::PART_TOAST_ICON);
+
+               m_icon = icon;
 
                return RES_OK;
        }
@@ -283,9 +285,9 @@ namespace gallery {
 
        void ProcessingPresenter::animateIcon()
        {
-               if (m_icon) {
+               if (const auto icon = m_icon.lock()) {
                        if (m_iconType == IconType::CHECK) {
-                               m_icon->emit(impl::SIGNAL_ANIMATE_CHECK);
+                               icon->emit(impl::SIGNAL_ANIMATE_CHECK);
                        }
                }
        }
@@ -321,7 +323,6 @@ namespace gallery {
 
        void ProcessingPresenter::onPopupDismissed(Widget &widget, void *eventInfo)
        {
-               const auto keepAliver = asShared(*this);
                if (m_dismissHandler) {
                        m_dismissHandler();
                }
index d0fec2c2041e298b8e2a08608bfa9f74612e4385..c3e0c9c91fa110fe86b0c80c755d51d02ff83ef5 100644 (file)
@@ -65,7 +65,7 @@ namespace gallery {
 
        // SelectModePresenter //
 
-       SelectModePresenter::SelectModePresenter(RefCountObjBase &rc,
+       SelectModePresenter::SelectModePresenter(IRefCountObj &rc,
                        PageContent &content, const int flags) :
                Presenter(rc),
                m_content(asShared(content)),
@@ -316,8 +316,8 @@ namespace gallery {
 
        void SelectModePresenter::dispatchEvent(const Event event)
        {
-               if (m_listener) {
-                       m_listener->onSelectModeEvent(event);
+               if (const auto listener = m_listener.lock()) {
+                       listener->onSelectModeEvent(event);
                }
        }
 
index 65e51f34006329c73dc3580586b42259e7d5388f..c6defbb446ff79125427be3f4e955b7feaff67df 100644 (file)
@@ -89,7 +89,7 @@ namespace gallery {
 
        class ThumbnailPage::RealizedItem : public RefCountAware {
        public:
-               RealizedItem(RefCountObjBase &rc,
+               RealizedItem(IRefCountObj &rc,
                                ThumbnailPage &parent, const int index) :
                        RefCountAware(&rc),
                        m_parent(parent),
@@ -130,7 +130,7 @@ namespace gallery {
 
        // ThumbnailPage //
 
-       ThumbnailPage::ThumbnailPage(RefCountObjBase &rc,
+       ThumbnailPage::ThumbnailPage(IRefCountObj &rc,
                        const NaviframeSRef &navi,
                        const ExitRequestHandler &onExitRequest,
                        const IMediaAlbumSRef &album) :
@@ -141,11 +141,15 @@ namespace gallery {
 
        ThumbnailPage::~ThumbnailPage()
        {
+               if (m_album) {
+                       m_album->delChangeHandler(WEAK_DELEGATE(
+                                       ThumbnailPage::onAlbumChanged, asWeak(*this)));
+               }
                if (m_more) {
                        m_more->setOpened(false);
                }
-               if (m_page) {
-                       m_page->exitNoTransition();
+               if (const auto page = m_page.lock()) {
+                       page->exitNoTransition();
                }
                if (m_imageGrid) {
                        m_imageGrid->setListener(nullptr);
@@ -348,10 +352,9 @@ namespace gallery {
 
        void ThumbnailPage::onPageExitRequest(Page &page)
        {
-               if (const PreviewPageSRef previewPage =
-                               dynamicRefCast<PreviewPage>(m_page)) {
+               if (const auto page = dynamicRefCast<PreviewPage>(m_page).lock()) {
                        m_imageGrid->scrollToItem(getSafeItemIndex(
-                                       previewPage->getCurrentItemIndex()));
+                                       page->getCurrentItemIndex()));
                }
                m_page.reset();
                popTo();
index 96c384ded2a3ebd953a9834b7293d882dc7f7485..de3dddbd5200334fa223d3d60cce1d4c2e08e19b 100644 (file)
@@ -133,7 +133,7 @@ namespace gallery {
 
        // VideoPlayerPage //
 
-       VideoPlayerPage::VideoPlayerPage(RefCountObjBase &rc,
+       VideoPlayerPage::VideoPlayerPage(IRefCountObj &rc,
                        const NaviframeSRef &navi,
                        const ExitRequestHandler &onExitRequest,
                        const MediaItemSRef &media) :
@@ -153,6 +153,13 @@ namespace gallery {
 
        VideoPlayerPage::~VideoPlayerPage()
        {
+               if (m_soundMgr) {
+                       m_soundMgr->delMediaDeviceStateChangeHandler(WEAK_DELEGATE(
+                                       VideoPlayerPage::onMediaDeviceStateChanged, asWeak(*this)));
+                       m_soundMgr->delMediaVolumeChangeHandler(WEAK_DELEGATE(
+                                       VideoPlayerPage::onMediaVolumeChanged, asWeak(*this)));
+               }
+
                if (isWindowReady()) {
                        setScreenAlwaysOn(false);
                }
index e8a7d85b8339ba213b4f056214887f42820758dc..3dbd236c693154ae41881aeb6e93183ec1c14919 100644 (file)
@@ -114,7 +114,7 @@ namespace gallery {
 
        // ViewerPage //
 
-       ViewerPage::ViewerPage(RefCountObjBase &rc,
+       ViewerPage::ViewerPage(IRefCountObj &rc,
                        const NaviframeSRef &navi,
                        const ExitRequestHandler &onExitRequest,
                        const MediaItemSRef &media,
index ece8828da420ffd0c0af91d0ab887d230ebe14cb..a2725b961578f77a6d9c6b33bda8dad9395b96da 100644 (file)
@@ -249,8 +249,8 @@ namespace gallery {
        private:
                class Item : public RefCountAware {
                public:
-                       friend class RefCountObj<Item>;
-                       Item(RefCountObjBase &rc,
+                       friend class ReffedObj<Item>;
+                       Item(IRefCountObj &rc,
                                        ImageGrid &imageGrid, ElmWidget &parent) :
                                RefCountAware(&rc),
                                m_imageGrid(imageGrid),
@@ -330,8 +330,8 @@ namespace gallery {
                                if (itemIndex < m_imageGrid.m_itemCount) {
                                        m_realizeIndex = itemIndex;
 
-                                       if (m_imageGrid.m_listener) {
-                                               m_imageGrid.m_listener->onItemRealized(itemIndex);
+                                       if (const auto listener = m_imageGrid.m_listener.lock()) {
+                                               listener->onItemRealized(itemIndex);
                                        }
                                }
 
@@ -355,8 +355,8 @@ namespace gallery {
                                const int itemIndex = m_realizeIndex;
                                m_realizeIndex = -1;
 
-                               if (m_imageGrid.m_listener) {
-                                       m_imageGrid.m_listener->onItemUnrealized(itemIndex);
+                               if (const auto listener = m_imageGrid.m_listener.lock()) {
+                                       listener->onItemUnrealized(itemIndex);
                                }
                        }
 
@@ -743,12 +743,12 @@ namespace gallery {
 
        // ImageGrid //
 
-       ImageGrid::ImageGrid(RefCountObjBase *const rc, Evas_Object *const scroller,
+       ImageGrid::ImageGrid(IRefCountObj *const rc, Evas_Object *const scroller,
                        const Type type, const bool selectModeStartup) :
                ElmWidget(rc, scroller, true),
                m_info(getInfo(type)),
 
-               m_scroller(makeShared<StyledWidget>(scroller)),
+               m_scroller(makeShared<StyledWidget>(scroller).get()),
                m_box(elm_box_add(*m_scroller)),
                m_rect1(evas_object_rectangle_add(m_box.getEvas())),
                m_rect2(evas_object_rectangle_add(m_box.getEvas())),
@@ -1009,8 +1009,8 @@ namespace gallery {
                        eext_rotary_object_event_activated_set(m_circleScroller, EINA_TRUE);
                }
 
-               if (m_listener) {
-                       m_listener->onTransitionFinished();
+               if (const auto listener = m_listener.lock()) {
+                       listener->onTransitionFinished();
                }
        }
 
@@ -1283,8 +1283,8 @@ namespace gallery {
        void ImageGrid::handleItemEvent(const int itemIndex,
                        const ItemEvent event, const int x, const int y) const
        {
-               if (m_listener) {
-                       m_listener->onItemEvent(itemIndex, event, x, y);
+               if (const auto listener = m_listener.lock()) {
+                       listener->onItemEvent(itemIndex, event, x, y);
                }
        }
 
@@ -1366,8 +1366,8 @@ namespace gallery {
        Elm_Interface_Atspi_Accessible *ImageGrid::requestAtspi(const int itemIndex)
        {
                if ((itemIndex < 0) || (itemIndex >= m_itemCount)) {
-                       if (m_listener) {
-                               return m_listener->onAccessObjectRequest(
+                       if (const auto listener = m_listener.lock()) {
+                               return listener->onAccessObjectRequest(
                                                (itemIndex >= m_itemCount));
                        }
                        return nullptr;
index 606e376ee922a68b6fef747a1f0e03f91b151a8e..6a530088ccca6c2701d1ce8c761682837ba34cf5 100644 (file)
@@ -74,12 +74,12 @@ namespace gallery {
 
        // ImageViewer //
 
-       ImageViewer::ImageViewer(RefCountObjBase &rc, Evas_Object *const scroller,
+       ImageViewer::ImageViewer(IRefCountObj &rc, Evas_Object *const scroller,
                        const std::string &highResPath, const int loadSize,
                        const bool forceLoad) :
                ElmWidget(&rc, scroller, true),
 
-               m_scroller(makeShared<StyledWidget>(scroller)),
+               m_scroller(makeShared<StyledWidget>(scroller).get()),
                m_layout(elm_layout_add(*m_scroller)),
                m_grid(evas_object_grid_add(m_layout.getEvas())),
                m_lowResImage(evas_object_image_filled_add(m_grid.getEvas())),
index 21d601d050513157b2bbe55e1eb76f8c809dba40..32db59e6d2b7587b61bc861c4159b2ad0ca3b2e4 100644 (file)
@@ -91,10 +91,10 @@ namespace gallery {
 
        // PageContent //
 
-       PageContent::PageContent(RefCountObjBase &rc,
+       PageContent::PageContent(IRefCountObj &rc,
                        const LayoutSRef &layout, const int flags) :
                ElmWidget(&rc, *layout, true),
-               m_moreOptions(layout)
+               m_mainLayout(layout.get())
        {
                prepare(flags);
        }
@@ -105,16 +105,16 @@ namespace gallery {
 
        void PageContent::prepare(const int flags)
        {
-               m_moreOptions->setIsOwner(false);
+               m_mainLayout->setIsOwner(false);
 
-               LayoutSRef parent = m_moreOptions;
+               Layout *parent = m_mainLayout;
 
                if (flags & FLAG_SELECT_BUTTON) {
                        m_selectMode = Layout::Builder().
                                setTheme(impl::LAYOUT_SELECT_MODE).
                                build(*parent);
                        parent->setContent(*m_selectMode);
-                       parent = m_selectMode;
+                       parent = m_selectMode.get();
                }
 
                if (flags & FLAG_BOTTOM_BUTTON) {
@@ -122,7 +122,7 @@ namespace gallery {
                                setTheme(impl::LAYOUT_BOTTOM_BUTTON).
                                build(*parent);
                        parent->setContent(*m_bottomButton);
-                       parent = m_bottomButton;
+                       parent = m_bottomButton.get();
                }
        }
 
@@ -169,10 +169,7 @@ namespace gallery {
 
        Result PageContent::setMoreOptionsVisible(const bool visible)
        {
-               if (!m_moreOptions) {
-                       LOG_RETURN(RES_FAIL, "More options is not supported!");
-               }
-               const auto content = m_moreOptions->getContent(impl::PART_MORE_OPTIONS);
+               const auto content = m_mainLayout->getContent(impl::PART_MORE_OPTIONS);
                if (!content) {
                        LOG_RETURN(RES_FAIL, "More option is not created!");
                }
@@ -190,11 +187,11 @@ namespace gallery {
                case Part::DEFAULT:
                        return impl::callSafe(getTopLayout(), func, PART_CONTENT);
                case Part::OVERLAY:
-                       return impl::callSafe(m_moreOptions.get(), func,
-                                       impl::PART_OVERLAY);
+                       func(*m_mainLayout, impl::PART_OVERLAY);
+                       return RES_OK;
                case Part::MORE_OPTIONS:
-                       return impl::callSafe(m_moreOptions.get(), func,
-                                       impl::PART_MORE_OPTIONS);
+                       func(*m_mainLayout, impl::PART_MORE_OPTIONS);
+                       return RES_OK;
                case Part::SELECT_BUTTON:
                        return impl::callSafe(m_selectMode.get(), func, PART_ICON);
                case Part::BOTTOM_BUTTON:
@@ -211,6 +208,6 @@ namespace gallery {
                if (m_selectMode) {
                        return m_selectMode.get();
                }
-               return m_moreOptions.get();
+               return m_mainLayout;
        }
 }
index d06d2f1fce184c7a85d5f8299ee2312bd45c6d85..8678bdb7bdf3ac1738a43f660ee63fc65abd4405 100644 (file)
@@ -28,7 +28,7 @@ namespace gallery { namespace { namespace impl {
 
 namespace gallery {
 
-       TouchParser::TouchParser(RefCountObjBase &rc, Widget &eventSource) :
+       TouchParser::TouchParser(IRefCountObj &rc, Widget &eventSource) :
                RefCountAware(&rc),
                m_holdTimer(nullptr),
                m_downTime(0),
index 8d20b50ab17e3f54e70f97e84452785d2ee210b3..0ee57f0ba50914b2ebead238248654b373328942 100644 (file)
@@ -43,7 +43,7 @@ namespace ucl {
                                EdjeSignalSrc(""));
 
        protected:
-               EdjeWidget(RefCountObjBase *rc, Evas_Object *eo, bool isOwner = false);
+               EdjeWidget(IRefCountObj *rc, Evas_Object *eo, bool isOwner = false);
        };
 }
 
index 5197f592f690d080f8d695f2f1ddb0ea99294cdd..3f989c75972175ff49f92afc6e566d3fa4381310 100644 (file)
@@ -16,7 +16,7 @@
 
 namespace ucl {
 
-       inline EdjeWidget::EdjeWidget(RefCountObjBase *const rc,
+       inline EdjeWidget::EdjeWidget(IRefCountObj *const rc,
                        Evas_Object *const eo, const bool isOwner) :
                ElmWidget(rc, eo, isOwner)
        {
index 96d5cf26d750b50ef51ad6d93771d354b29a3cff..3856b497852fc41fc2b9d087e534fd589672b86b 100644 (file)
@@ -47,8 +47,8 @@ namespace ucl {
                Window *getWindow() const;
 
        protected:
-               friend class RefCountObj<ElmWidget>;
-               ElmWidget(RefCountObjBase *rc, Evas_Object *eo, bool isOwner = false);
+               friend class ReffedObj<ElmWidget>;
+               ElmWidget(IRefCountObj *rc, Evas_Object *eo, bool isOwner = false);
 
                virtual void setFocusedImpl(bool value) final override;
                virtual bool isFocusedImpl() const final override;
index ec21f450e118b2d1c56e0d52d1b85aece9600fdd..37732ce7ef3991b8a8135ed436dbe337e2f7de40 100644 (file)
@@ -42,7 +42,7 @@ namespace ucl {
                };
 
        public:
-               friend class RefCountObj<Layout>;
+               friend class ReffedObj<Layout>;
                using EdjeWidget::EdjeWidget;
                explicit Layout(Evas_Object *eo, bool isOwner = false);
 
index 0cf36f61531edfab3039c424ea1efb15cca13999..4e4336c792c3cb628d86b98c46ed37c6444559a5 100644 (file)
@@ -85,8 +85,8 @@ namespace ucl {
                std::vector<NaviItem> getItems() const;
 
        private:
-               friend class RefCountObj<Naviframe>;
-               Naviframe(RefCountObjBase &rc, Evas_Object *eo);
+               friend class ReffedObj<Naviframe>;
+               Naviframe(IRefCountObj &rc, Evas_Object *eo);
 
                void onTransitionFinished(Widget &widget, void *eventInfo);
 
index ad995c1f93d439070513b4f273197e183ca6359f..2a0280ca4ef937d1f523afc999d21f3e44516212 100644 (file)
@@ -25,7 +25,7 @@ namespace ucl {
 
        class StyledWidget : public EdjeWidget {
        public:
-               friend class RefCountObj<StyledWidget>;
+               friend class ReffedObj<StyledWidget>;
                using EdjeWidget::EdjeWidget;
                explicit StyledWidget(Evas_Object *eo, bool isOwner = false);
 
index 8dfcd26fef9ee4b62c1173ec8c671033aa4331e9..c317962c033de5d931afbc3759b357d7552f16ea 100644 (file)
@@ -97,8 +97,8 @@ namespace ucl {
                bool isFocused() const;
 
        protected:
-               friend class RefCountObj<Widget>;
-               Widget(RefCountObjBase *rc, Evas_Object *eo, bool isOwner = false);
+               friend class ReffedObj<Widget>;
+               Widget(IRefCountObj *rc, Evas_Object *eo, bool isOwner = false);
 
                virtual void setFocusedImpl(bool value);
                virtual bool isFocusedImpl() const;
@@ -125,7 +125,7 @@ namespace ucl {
 
        protected:
                // This section MUST be protected!
-               // Signal to RefCountObj<T> to call onUniqueChanged()
+               // Signal to RefCountObj<T, C> to call onUniqueChanged()
                enum { ENABLE_ON_UNIQUE_CHANGED_DISPATCH };
                void onUniqueChanged(bool isUnique);
 
index 8e526b4d49c85fddc95bfdbf84dc3350bdc746c2..b611b2569ebc411cdd1e5d43cd02812b628c0c6c 100644 (file)
@@ -80,8 +80,8 @@ namespace ucl {
                void lower();
 
        private:
-               friend class RefCountObj<Window>;
-               Window(RefCountObjBase *rc, Evas_Object *eo,
+               friend class ReffedObj<Window>;
+               Window(IRefCountObj *rc, Evas_Object *eo,
                                bool isOwner, Evas_Object *conform);
 
        private:
index 3d4c959a4c20870c8dcdd8a24ef2ccd749153350..d5b18286a1456a830d10987008ecb67fb8ff9e5b 100644 (file)
@@ -84,7 +84,7 @@ namespace ucl {
 
        // Window //
 
-       inline Window::Window(RefCountObjBase *const rc, Evas_Object *const eo,
+       inline Window::Window(IRefCountObj *const rc, Evas_Object *const eo,
                        const bool isOwner, Evas_Object *const conform) :
                ElmWidget(rc, eo, isOwner),
                m_conform(conform)
index f0caec0837e4700e2abb95c0d01905307dbfd87d..ed4e4025412815452fefe74c1c7d1797ed6ea25c 100644 (file)
@@ -48,10 +48,7 @@ namespace ucl {
        template <class DELEGATE2>
        void Event<DELEGATE>::operator+=(DELEGATE2 &&delegate)
        {
-               if (delegate && std::find(m_delegates.begin(), m_delegates.end(),
-                               delegate) == m_delegates.end()) {
-                       m_delegates.emplace_back(std::forward<DELEGATE2>(delegate));
-               }
+               m_delegates.emplace_back(std::forward<DELEGATE2>(delegate));
        }
 
        template <class DELEGATE>
@@ -73,7 +70,7 @@ namespace ucl {
        template <class DELEGATE>
        bool Event<DELEGATE>::isEmpty() const
        {
-               return (isLocked() ? false : m_delegates.empty());
+               return m_delegates.empty();
        }
 
        template <class DELEGATE>
index 7ec13cce993a4b1fe2417871b130f0976053be70..ed05bfe84e0e49847e3e07c24ae48ba863a466a3 100644 (file)
@@ -35,11 +35,14 @@ namespace ucl {
                WeakRef<T> asWeakThis(T *thisAlias) const;
 
        protected:
-               RefCountAware(RefCountObjBase *rc);
+               RefCountAware(IRefCountObj *rc);
                virtual ~RefCountAware() = default;
 
        protected:
-               RefCountObjBase *const m_rc;
+               enum { IS_REF_COUNT_AWARE };
+
+       protected:
+               IRefCountObj *const m_rc;
        };
 
        // Non-member functions //
index ae51c0d977b3330b05d5f92c2e6857604492fe4f..3906d0eba6e42a5d4922dc80917d7fce477a76bc 100644 (file)
@@ -18,7 +18,7 @@
 
 namespace ucl {
 
-       inline RefCountAware::RefCountAware(RefCountObjBase *const rc) :
+       inline RefCountAware::RefCountAware(IRefCountObj *const rc) :
                m_rc(rc)
        {
        }
index 707c25cebef7b92d9f1f600812bad00ab0781e15..165265c10512894202683e8ed297e8d0abba15a7 100644 (file)
@@ -37,7 +37,7 @@ namespace ucl {
                bool isExpired() const;
 
        private:
-               friend class RefCountObj<Timeout>;
+               friend class ReffedObj<Timeout>;
                Timeout(const TimeoutHandler &handler);
                ~Timeout();
 
index d5c518c530b4549eed623419424e8e8f98ea122a..62b92ffbcbfe4b015926ea57f3704a27e0bba1d2 100644 (file)
@@ -42,8 +42,6 @@ namespace ucl {
                template <class FUNC_SIG>
                BaseDelegate(BaseDelegate2<FUNC_SIG, DATA> &&d) noexcept;
 
-               R operator()(ARGS ...args) const;
-
                void reset() noexcept;
 
                const DATA &getData() const noexcept;
@@ -53,7 +51,7 @@ namespace ucl {
        protected:
                BaseDelegate(const DATA &data, StubA stubA) noexcept;
 
-       private:
+       protected:
                DATA m_data;
                StubA m_stubA;
        };
index 4cb9741ffefd70116bc2f70f015fce77e6ee564a..f25c0a7beac08375b1547c73a4e7b102050ed7a1 100644 (file)
@@ -56,13 +56,6 @@ namespace ucl {
        {
        }
 
-       template <class R, class ...ARGS, class DATA>
-       inline R BaseDelegate<R(ARGS...), DATA>::operator()(ARGS ...args) const
-       {
-               return m_stubA(
-                               static_cast<void *>(m_data), std::forward<ARGS>(args)...);
-       }
-
        template <class R, class ...ARGS, class DATA>
        inline void BaseDelegate<R(ARGS...), DATA>::reset() noexcept
        {
index fd53a0ad4f0ac503946f659a3d732676dfbd01f5..e1e74162e9c1c40f8787eabb74f968cf411ee3d6 100644 (file)
@@ -29,6 +29,8 @@ namespace ucl {
        public:
                using BaseDelegate<R(ARGS...), void *>::BaseDelegate;
 
+               R operator()(ARGS ...args) const;
+
                template <class CLASS, R(CLASS::*METHOD)(ARGS...)>
                static Delegate make(CLASS *data) noexcept;
                template <class CLASS, R(CLASS::*METHOD)(ARGS...) const>
index 5f7be3d49cc8e6d2365b60b7ffdb3f11f27a8c4f..632ec248d799b66014d2337ec081a64ddeed3f72 100644 (file)
 
 namespace ucl {
 
+       template <class R, class ...ARGS>
+       inline R Delegate<R(ARGS...)>::operator()(ARGS ...args) const
+       {
+               return this->m_stubA(this->m_data, std::forward<ARGS>(args)...);
+       }
+
        template <class R, class ...ARGS>
        template <class CLASS, R(CLASS::*METHOD)(ARGS...)>
        inline Delegate<R(ARGS...)>
index c49d31c9fc6b2d293cbe68bd73cd99c128d40d79..56ff3fbeec0623a7e15ebc608d2a770ea26d6129 100644 (file)
@@ -29,6 +29,8 @@ namespace ucl {
        public:
                using BaseDelegate2<R(ARGS...), void *>::BaseDelegate2;
 
+               R operator()(ARGS ...args) const;
+
                template <class CLASS, R(CLASS::*METHOD)(ARGS...)>
                static Delegate2 make(CLASS *data) noexcept;
                template <class CLASS, R(CLASS::*METHOD)(ARGS...) const>
index 4d7786031857a4c5f1c1fea504d1eaa1ac25bb1d..085ba4649583a39420e9bba5b3eff3d2bb9d1a54 100644 (file)
 
 namespace ucl {
 
+       template <class R, class ...ARGS>
+       inline R Delegate2<R(ARGS...)>::operator()(ARGS ...args) const
+       {
+               return this->m_stubA(this->m_data, std::forward<ARGS>(args)...);
+       }
+
        template <class R, class ...ARGS>
        template <class CLASS, R(CLASS::*METHOD)(ARGS...)>
        inline Delegate2<R(ARGS...)>
index 95e0481b11292c8cdbf0730b15b66faf458e25cf..54ebb993d2f902e8a9bfe539a1d01715c402def8 100644 (file)
@@ -64,16 +64,16 @@ namespace ucl {
        inline bool operator==(const BaseDelegate<R(ARGS...), DATA1> &lhs,
                        const BaseDelegate<R(ARGS...), DATA2> &rhs) noexcept
        {
-               return ((lhs.getStubA() == rhs.getStubA()) && (static_cast<void *>(
-                               lhs.getData()) == static_cast<void *>(rhs.getData())));
+               return ((lhs.getStubA() == rhs.getStubA()) && (
+                               lhs.getData() == rhs.getData()));
        }
 
        template <class R, class ...ARGS, class DATA1, class DATA2>
        inline bool operator!=(const BaseDelegate<R(ARGS...), DATA1> &lhs,
                        const BaseDelegate<R(ARGS...), DATA2> &rhs) noexcept
        {
-               return ((lhs.getStubA() != rhs.getStubA()) || (static_cast<void *>(
-                               lhs.getData()) != static_cast<void *>(rhs.getData())));
+               return ((lhs.getStubA() != rhs.getStubA()) || (
+                               lhs.getData() != rhs.getData()));
        }
 
        template <class R, class ...ARGS, class DATA1, class DATA2>
@@ -81,8 +81,8 @@ namespace ucl {
                        const BaseDelegate<R(ARGS...), DATA2> &rhs) noexcept
        {
                return ((lhs.getStubA() < rhs.getStubA()) ||
-                               ((lhs.getStubA() == rhs.getStubA()) && (static_cast<void *>(
-                                       lhs.getData()) < static_cast<void *>(rhs.getData()))));
+                               ((lhs.getStubA() == rhs.getStubA()) && (
+                                       lhs.getData() < rhs.getData())));
        }
 
        template <class R, class ...ARGS, class DATA1, class DATA2>
@@ -90,8 +90,8 @@ namespace ucl {
                        const BaseDelegate<R(ARGS...), DATA2> &rhs) noexcept
        {
                return ((lhs.getStubA() < rhs.getStubA()) ||
-                               ((lhs.getStubA() == rhs.getStubA()) && (static_cast<void *>(
-                                       lhs.getData()) <= static_cast<void *>(rhs.getData()))));
+                               ((lhs.getStubA() == rhs.getStubA()) && (
+                                       lhs.getData() <= rhs.getData())));
        }
 
        template <class R, class ...ARGS, class DATA1, class DATA2>
@@ -99,8 +99,8 @@ namespace ucl {
                        const BaseDelegate<R(ARGS...), DATA2> &rhs) noexcept
        {
                return ((lhs.getStubA() > rhs.getStubA()) ||
-                               ((lhs.getStubA() == rhs.getStubA()) && (static_cast<void *>(
-                                       lhs.getData()) > static_cast<void *>(rhs.getData()))));
+                               ((lhs.getStubA() == rhs.getStubA()) && (
+                                       lhs.getData() > rhs.getData())));
        }
 
        template <class R, class ...ARGS, class DATA1, class DATA2>
@@ -108,8 +108,8 @@ namespace ucl {
                        const BaseDelegate<R(ARGS...), DATA2> &rhs) noexcept
        {
                return ((lhs.getStubA() > rhs.getStubA()) ||
-                               ((lhs.getStubA() == rhs.getStubA()) && (static_cast<void *>(
-                                       lhs.getData()) >= static_cast<void *>(rhs.getData()))));
+                               ((lhs.getStubA() == rhs.getStubA()) && (
+                                       lhs.getData() >= rhs.getData())));
        }
 }
 
index 1fd85237709c7c7dd3966fb32a30c1620f642093..cc3396051af8ef767ed4b1eed6af0b05ec9055cc 100644 (file)
@@ -17,7 +17,6 @@
 #ifndef __UCL_UTIL_MEMORY_H__
 #define __UCL_UTIL_MEMORY_H__
 
-#include "memory/RefCountObjBase.h"
 #include "memory/RefCountObj.h"
 
 #include "memory/BaseRef.h"
index 0aa1b593cc07a61fafcb61a95efd88656b77f7b8..f82a2c918dc7ef9c730b8c789a6e432c0bcaf2d8 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __UCL_UTIL_MEMORY_BASE_REF_H__
 #define __UCL_UTIL_MEMORY_BASE_REF_H__
 
-#include "RefCountObjBase.h"
+#include "IRefCountObj.h"
 
 namespace ucl {
 
@@ -34,23 +34,17 @@ namespace ucl {
                friend class WeakRef;
 
        public:
-               int getUseCount() const;
-
-               T *operator->() const noexcept;
-               typename std::add_lvalue_reference<T>::type operator*() const noexcept;
-
-               template <class U>
-               explicit operator U() const noexcept;
+               int getUseCount() const noexcept;
 
        protected:
                constexpr BaseRef() noexcept;
-               BaseRef(RefCountObjBase *rc, T *ptr) noexcept;
+               BaseRef(IRefCountObj *rc, T *ptr) noexcept;
                BaseRef(BaseRef<T> &&r) noexcept;
                template <class U>
                BaseRef(BaseRef<U> &&r) noexcept;
 
        protected:
-               RefCountObjBase *m_rc;
+               IRefCountObj *m_rc;
                T *m_ptr;
        };
 }
index d587bc141ec661167b722e322797913f44c0533a..adde1c9a8afc2306be405b013d85e3d05c2d6b72 100644 (file)
@@ -25,7 +25,7 @@ namespace ucl {
 
        template <class T>
        inline BaseRef<T>::BaseRef(
-                       RefCountObjBase *const rc, T *const ptr) noexcept :
+                       IRefCountObj *const rc, T *const ptr) noexcept :
                m_rc(rc),
                m_ptr(ptr)
        {
@@ -51,28 +51,8 @@ namespace ucl {
        }
 
        template <class T>
-       inline int BaseRef<T>::getUseCount() const
+       inline int BaseRef<T>::getUseCount() const noexcept
        {
                return (m_rc ? m_rc->getUseCount() : 0);
        }
-
-       template <class T>
-       inline T *BaseRef<T>::operator->() const noexcept
-       {
-               return m_ptr;
-       }
-
-       template <class T>
-       inline typename std::add_lvalue_reference<T>::type
-                       BaseRef<T>::operator*() const noexcept
-       {
-               return *m_ptr;
-       }
-
-       template <class T>
-       template <class U>
-       inline BaseRef<T>::operator U() const noexcept
-       {
-               return static_cast<U>(m_ptr);
-       }
 }
diff --git a/ucl/inc/ucl/util/memory/IRefCountObj.h b/ucl/inc/ucl/util/memory/IRefCountObj.h
new file mode 100644 (file)
index 0000000..567e12c
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __UCL_UTIL_MEMORY_I_REF_COUNT_OBJ_H__
+#define __UCL_UTIL_MEMORY_I_REF_COUNT_OBJ_H__
+
+#include "ucl/util/types/classTypes.h"
+
+namespace ucl {
+
+       class IRefCountObj : public Polymorphic {
+       public:
+               virtual void ref() noexcept = 0;
+               virtual void unref() noexcept = 0;
+               virtual bool refNz() noexcept = 0;
+               virtual void refWeak() noexcept = 0;
+               virtual void unrefWeak() noexcept = 0;
+               virtual unsigned getUseCount() const noexcept = 0;
+       protected:
+               virtual ~IRefCountObj() = default;
+       };
+}
+
+#endif // __UCL_UTIL_MEMORY_I_REF_COUNT_OBJ_H__
index 777f07e9a5b663206cf49b356dd6c91154b1f027..e566179d55cf2539d3f7b7a6490b55a3ead381d1 100644 (file)
 #ifndef __UCL_UTIL_MEMORY_REF_COUNT_OBJ_H__
 #define __UCL_UTIL_MEMORY_REF_COUNT_OBJ_H__
 
-#include "RefCountObjBase.h"
+#include "IRefCountObj.h"
+#include "ReffedObj.h"
 
 namespace ucl {
 
-       template <class T>
-       class RefCountObj : public RefCountObjBase {
+       template <class T, class C>
+       class RefCountObj final : public IRefCountObj {
        public:
                template <class ...ARGS>
                RefCountObj(ARGS &&...args);
 
                T *getObj() noexcept;
 
-       protected:
-               // RefCountObjBase //
-               virtual void dispose() noexcept final override;
-               virtual void onUniqueChanged(bool isUnique) noexcept final override;
+               // IRefCountObj //
+
+               virtual void ref() noexcept final override;
+               virtual void unref() noexcept final override;
+               virtual bool refNz() noexcept final override;
+               virtual void refWeak() noexcept final override;
+               virtual void unrefWeak() noexcept final override;
+               virtual unsigned getUseCount() const noexcept final override;
 
        private:
-               // Consume-all SFINAE functions
-               template <class T2, class ...ARGS>
-               void createObj(const P<0> &, ARGS &&...args);
+               template <class T2, class = char[1]>
+               struct IsRefCountAware : std::false_type {};
+               template <class T2>
+               struct IsRefCountAware<T2, char[T2::IS_REF_COUNT_AWARE * 0 + 1]> :
+                               std::true_type {};
+
+               template <class T2, class = char[1]>
+               struct IsOnUniqueAware : std::false_type {};
                template <class T2>
-               void dispatchOnUniqueChanged(
-                               const P<0> &, const bool isUnique) noexcept;
+               struct IsOnUniqueAware<T2,
+                               char[T2::ENABLE_ON_UNIQUE_CHANGED_DISPATCH * 0 + 1]> :
+                               std::true_type {};
 
-               // Specialized SFINAE functions
+       private:
+               virtual ~RefCountObj() = default;
+
+               template <class T2, class ...ARGS, class =
+                               typename std::enable_if<!IsRefCountAware<T2>::value>::type>
+               void createObj(const P<0> &, ARGS &&...args)
+               {
+                       m_obj.create(std::forward<ARGS>(args)...);
+               }
 
-               template <class T2, class ...ARGS>
+               template <class T2, class ...ARGS, class =
+                               typename std::enable_if<IsRefCountAware<T2>::value>::type>
                auto createObj(const P<1> &, ARGS &&...args) -> decltype(
-                               (void)(new T2(this, std::forward<ARGS>(args)...)))
+                               ReffedObj<T>::template check<T2>(
+                                               (IRefCountObj *)0, std::forward<ARGS>(args)...))
                {
-                       new (getObj()) T(this, std::forward<ARGS>(args)...);
+                       m_obj.create(static_cast<IRefCountObj *>(this),
+                                       std::forward<ARGS>(args)...);
                }
 
-               template <class T2, class ...ARGS>
+               template <class T2, class ...ARGS, class =
+                               typename std::enable_if<IsRefCountAware<T2>::value>::type>
                auto createObj(const P<2> &, ARGS &&...args) -> decltype(
-                               (void)(new T2(*this, std::forward<ARGS>(args)...)))
+                               ReffedObj<T>::template check<T2>(
+                                               *(IRefCountObj *)0, std::forward<ARGS>(args)...))
+               {
+                       m_obj.create(*static_cast<IRefCountObj *>(this),
+                                       std::forward<ARGS>(args)...);
+               }
+
+               void dispatchOnUniqueChanged(const bool isUnique)
+               {
+                       dispatchOnUniqueChanged<T>(P<1>(), isUnique);
+               }
+
+               template <class T2>
+               void dispatchOnUniqueChanged(...)
                {
-                       new (getObj()) T(*this, std::forward<ARGS>(args)...);
                }
 
-               template <class T2,
-                               class = char(*)[T2::ENABLE_ON_UNIQUE_CHANGED_DISPATCH * 0 + 1]>
-               void dispatchOnUniqueChanged(
-                               const P<1> &, const bool isUnique) noexcept
+               template <class T2, class =
+                               typename std::enable_if<IsOnUniqueAware<T2>::value>::type>
+               void dispatchOnUniqueChanged(const P<1> &, const bool isUnique)
                {
-                       getObj()->onUniqueChanged(isUnique);
+                       m_obj.template dispatchOnUniqueChanged<T>(isUnique);
                }
 
        private:
-               // Proper-aligned storage for T
-               typename std::aligned_storage<sizeof(T), alignof(T)>::type m_obj;
+               ReffedObj<T> m_obj;
+               C m_useCounter;
+               C m_weakCounter;
        };
 }
 
index 3807bd33ce9c0effc9010da8d3864466048d80b3..8fce0e3967dbcebdf3572055760466588c3052d5 100644 (file)
 
 namespace ucl {
 
-       template <class T>
+       template <class T, class C>
        template <class ...ARGS>
-       inline RefCountObj<T>::RefCountObj(ARGS &&...args)
+       inline RefCountObj<T, C>::RefCountObj(ARGS &&...args) :
+               m_useCounter(1),
+               m_weakCounter(1)
        {
                createObj<T>(P<2>(), std::forward<ARGS>(args)...);
        }
 
-       template <class T>
-       inline T *RefCountObj<T>::getObj() noexcept
+       template <class T, class C>
+       inline T *RefCountObj<T, C>::getObj() noexcept
        {
-               return static_cast<T *>(static_cast<void *>(&m_obj));
+               return m_obj.get();
        }
 
-       template <class T>
-       inline void RefCountObj<T>::dispose() noexcept
+       template <class T, class C>
+       inline void RefCountObj<T, C>::ref() noexcept
        {
-               if (!isDisposed()) {
-                       RefCountObjBase::dispose();
-                       getObj()->~T();
+               if (m_useCounter.ref() == 2) {
+                       dispatchOnUniqueChanged(false);
                }
        }
 
-       template <class T>
-       inline void RefCountObj<T>::onUniqueChanged(const bool isUnique) noexcept
+       template <class T, class C>
+       inline void RefCountObj<T, C>::unref() noexcept
        {
-               dispatchOnUniqueChanged<T>(P<1>(), isUnique);
+               const auto newCount = m_useCounter.unref();
+               if (newCount == 0) {
+                       m_obj.destroy();
+                       unrefWeak();
+               } else if (newCount == 1) {
+                       dispatchOnUniqueChanged(true);
+               }
+       }
+
+       template <class T, class C>
+       inline bool RefCountObj<T, C>::refNz() noexcept
+       {
+               const auto newCount = m_useCounter.refNz();
+               if (newCount == 0) {
+                       return false;
+               }
+               if (newCount == 2) {
+                       dispatchOnUniqueChanged(false);
+               }
+               return true;
        }
 
-       template <class T>
-       template <class T2, class ...ARGS>
-       inline void RefCountObj<T>::createObj(const P<0> &, ARGS &&...args)
+       template <class T, class C>
+       inline void RefCountObj<T, C>::refWeak() noexcept
        {
-               new (getObj()) T(std::forward<ARGS>(args)...);
+               m_weakCounter.ref();
+       }
+
+       template <class T, class C>
+       inline void RefCountObj<T, C>::unrefWeak() noexcept
+       {
+               if (m_weakCounter.unref() == 0) {
+                       delete this;
+               }
        }
 
-       template <class T>
-       template <class T2>
-       inline void RefCountObj<T>::dispatchOnUniqueChanged(
-                       const P<0> &, const bool isUnique) noexcept
+       template <class T, class C>
+       inline unsigned RefCountObj<T, C>::getUseCount() const noexcept
        {
+               return m_useCounter.get();
        }
 }
diff --git a/ucl/inc/ucl/util/memory/RefCountObjBase.h b/ucl/inc/ucl/util/memory/RefCountObjBase.h
deleted file mode 100644 (file)
index 4e6edf0..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2017 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __UCL_UTIL_MEMORY_REF_COUNT_OBJ_BASE_H__
-#define __UCL_UTIL_MEMORY_REF_COUNT_OBJ_BASE_H__
-
-#include "ucl/util/types/classTypes.h"
-
-namespace ucl {
-
-       class RefCountObjBase : public Polymorphic {
-       public:
-               void ref() noexcept;
-               void unref() noexcept;
-
-               void refWeak() noexcept;
-               void unrefWeak() noexcept;
-
-               int getUseCount() const noexcept;
-               bool isDisposed() const noexcept;
-
-       protected:
-               RefCountObjBase();
-               virtual ~RefCountObjBase() = default;
-
-               virtual void dispose() noexcept;
-               virtual void onUniqueChanged(bool isUnique) noexcept = 0;
-
-       private:
-               int m_useRefs;
-               int m_weakRefs;
-               bool m_isDisposed;
-       };
-}
-
-#include "RefCountObjBase.hpp"
-
-#endif // __UCL_UTIL_MEMORY_REF_COUNT_OBJ_BASE_H__
diff --git a/ucl/inc/ucl/util/memory/RefCountObjBase.hpp b/ucl/inc/ucl/util/memory/RefCountObjBase.hpp
deleted file mode 100644 (file)
index c4b5d42..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2017 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-namespace ucl {
-
-       inline RefCountObjBase::RefCountObjBase() :
-               m_useRefs(0),
-               m_weakRefs(1),
-               m_isDisposed(false)
-       {
-       }
-
-       inline void RefCountObjBase::ref() noexcept
-       {
-               ++m_useRefs;
-               if (m_useRefs == 2) {
-                       onUniqueChanged(false);
-               }
-       }
-
-       inline void RefCountObjBase::unref() noexcept
-       {
-               --m_useRefs;
-               if (m_useRefs <= 1) {
-                       if (m_useRefs == 1) {
-                               onUniqueChanged(true);
-                       } else {
-                               dispose();
-                               unrefWeak();
-                       }
-               }
-       }
-
-       inline void RefCountObjBase::refWeak() noexcept
-       {
-               ++m_weakRefs;
-       }
-
-       inline void RefCountObjBase::unrefWeak() noexcept
-       {
-               --m_weakRefs;
-               if (m_weakRefs == 0) {
-                       delete this;
-               }
-       }
-
-       inline int RefCountObjBase::getUseCount() const noexcept
-       {
-               return m_useRefs;
-       }
-
-       inline bool RefCountObjBase::isDisposed() const noexcept
-       {
-               return m_isDisposed;
-       }
-
-       inline void RefCountObjBase::dispose() noexcept
-       {
-               m_isDisposed = true;
-       }
-}
diff --git a/ucl/inc/ucl/util/memory/RefCounterMT.h b/ucl/inc/ucl/util/memory/RefCounterMT.h
new file mode 100644 (file)
index 0000000..1d2fb95
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __UCL_UTIL_MEMORY_REF_COUNTER_MT_H__
+#define __UCL_UTIL_MEMORY_REF_COUNTER_MT_H__
+
+#include "ucl/util/types/baseTypes.h"
+
+namespace ucl {
+
+       class RefCounterMT final {
+       public:
+               explicit RefCounterMT(const UInt count = 0) noexcept;
+
+               UInt ref() noexcept;
+               UInt unref() noexcept;
+               UInt refNz() noexcept;
+
+               UInt get() const noexcept;
+
+       private:
+               std::atomic<UInt> m_counter;
+       };
+}
+
+#include "RefCounterMT.hpp"
+
+#endif // __UCL_UTIL_MEMORY_REF_COUNTER_MT_H__
diff --git a/ucl/inc/ucl/util/memory/RefCounterMT.hpp b/ucl/inc/ucl/util/memory/RefCounterMT.hpp
new file mode 100644 (file)
index 0000000..1ff459b
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace ucl {
+
+       inline RefCounterMT::RefCounterMT(const UInt count) noexcept :
+               m_counter(count)
+       {
+       }
+
+       inline UInt RefCounterMT::ref() noexcept
+       {
+               return (m_counter.fetch_add(1, std::memory_order_acq_rel) + 1);
+       }
+
+       inline UInt RefCounterMT::unref() noexcept
+       {
+               return (m_counter.fetch_sub(1, std::memory_order_acq_rel) - 1);
+       }
+
+       inline UInt RefCounterMT::refNz() noexcept
+       {
+               auto curCount = m_counter.load(std::memory_order_relaxed);
+               for (;;) {
+                       if (curCount == 0) {
+                               return 0;
+                       }
+                       const auto newCount = (curCount + 1);
+                       if (m_counter.compare_exchange_weak(curCount, newCount,
+                                       std::memory_order_acq_rel, std::memory_order_relaxed)) {
+                               return newCount;
+                       }
+               }
+       }
+
+       inline UInt RefCounterMT::get() const noexcept
+       {
+               return m_counter.load(std::memory_order_relaxed);
+       }
+}
diff --git a/ucl/inc/ucl/util/memory/RefCounterST.h b/ucl/inc/ucl/util/memory/RefCounterST.h
new file mode 100644 (file)
index 0000000..30e5e35
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __UCL_UTIL_MEMORY_REF_COUNTER_ST_H__
+#define __UCL_UTIL_MEMORY_REF_COUNTER_ST_H__
+
+#include "ucl/util/types/baseTypes.h"
+
+namespace ucl {
+
+       class RefCounterST final {
+       public:
+               explicit RefCounterST(const UInt count = 0) noexcept;
+
+               UInt ref() noexcept;
+               UInt unref() noexcept;
+               UInt refNz() noexcept;
+
+               UInt get() const noexcept;
+
+       private:
+               UInt m_counter;
+       };
+}
+
+#include "RefCounterST.hpp"
+
+#endif // __UCL_UTIL_MEMORY_REF_COUNTER_ST_H__
diff --git a/ucl/inc/ucl/util/memory/RefCounterST.hpp b/ucl/inc/ucl/util/memory/RefCounterST.hpp
new file mode 100644 (file)
index 0000000..45781c7
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace ucl {
+
+       inline RefCounterST::RefCounterST(const UInt count) noexcept :
+               m_counter(count)
+       {
+       }
+
+       inline UInt RefCounterST::ref() noexcept
+       {
+               return (++m_counter);
+       }
+
+       inline UInt RefCounterST::unref() noexcept
+       {
+               return (--m_counter);
+       }
+
+       inline UInt RefCounterST::refNz() noexcept
+       {
+               if (m_counter == 0) {
+                       return 0;
+               }
+               return ref();
+       }
+
+       inline UInt RefCounterST::get() const noexcept
+       {
+               return m_counter;
+       }
+}
diff --git a/ucl/inc/ucl/util/memory/ReffedObj.h b/ucl/inc/ucl/util/memory/ReffedObj.h
new file mode 100644 (file)
index 0000000..ed84b66
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __UCL_UTIL_MEMORY_REFFED_OBJ_H__
+#define __UCL_UTIL_MEMORY_REFFED_OBJ_H__
+
+#include "RefCounterST.h"
+#include "RefCounterMT.h"
+
+namespace ucl {
+
+       template <class T, class C>
+       class RefCountObj;
+
+       template <class T>
+       class ReffedObj final {
+       private:
+               friend class RefCountObj<T, RefCounterST>;
+               friend class RefCountObj<T, RefCounterMT>;
+
+               template <class ...ARGS>
+               void create(ARGS &&...args);
+               void destroy() noexcept;
+
+               T *get() noexcept;
+
+               template <class T2>
+               void dispatchOnUniqueChanged(bool isUnique);
+
+       private:
+               template <class T2, class ...ARGS>
+               static constexpr auto check(ARGS &&...args) -> decltype(
+                               (void)(new T2(std::forward<ARGS>(args)...)))
+               {
+                       return;
+               }
+
+       private:
+               typename std::aligned_storage<sizeof(T), alignof(T)>::type m_obj;
+       };
+}
+
+#include "ReffedObj.hpp"
+
+#endif // __UCL_UTIL_MEMORY_REFFED_OBJ_H__
diff --git a/ucl/inc/ucl/util/memory/ReffedObj.hpp b/ucl/inc/ucl/util/memory/ReffedObj.hpp
new file mode 100644 (file)
index 0000000..5e9f473
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace ucl {
+
+       template <class T>
+       template <class ...ARGS>
+       inline void ReffedObj<T>::create(ARGS &&...args)
+       {
+               new (get()) T(std::forward<ARGS>(args)...);
+       }
+
+       template <class T>
+       inline void ReffedObj<T>::destroy() noexcept
+       {
+               get()->~T();
+       }
+
+       template <class T>
+       inline T *ReffedObj<T>::get() noexcept
+       {
+               return static_cast<T *>(static_cast<void *>(&m_obj));
+       }
+
+       template <class T>
+       template <class T2>
+       inline void ReffedObj<T>::dispatchOnUniqueChanged(const bool isUnique)
+       {
+               get()->onUniqueChanged(isUnique);
+       }
+}
index 4bd7ca0bc3db70f9b1240b7975085c3e02533510..396d176b67dd0b8dc4fa8b43d24bd8d74d6dee8a 100644 (file)
@@ -22,7 +22,7 @@
 namespace ucl {
 
        template <class T>
-       class SharedRef : public BaseRef<T> {
+       class SharedRef final : public BaseRef<T> {
        public:
                template <class U>
                friend void swap(SharedRef<U> &x, SharedRef<U> &y) noexcept;
@@ -36,11 +36,12 @@ namespace ucl {
                constexpr SharedRef() noexcept;
                constexpr SharedRef(std::nullptr_t) noexcept;
 
-               SharedRef(RefCountObjBase *rc, T *ptr) noexcept;
+               SharedRef(IRefCountObj *rc, T *ptr) noexcept;
+               SharedRef(IRefCountObj *rc, T *ptr, bool noRef) noexcept;
 
                SharedRef(const SharedRef<T> &r) noexcept;
                template <class U>
-               SharedRef(const BaseRef<U> &r) noexcept;
+               SharedRef(const SharedRef<U> &r) noexcept;
 
                SharedRef(SharedRef<T> &&r) noexcept;
                template <class U>
@@ -55,6 +56,9 @@ namespace ucl {
                T *get() const noexcept;
                operator bool() const noexcept;
 
+               T *operator->() const noexcept;
+               typename std::add_lvalue_reference<T>::type operator*() const noexcept;
+
                template <class U, class = typename std::enable_if<
                        std::is_convertible<T *, U *>::value && (
                                std::is_same<typename std::remove_cv<U>::type, void>::value ||
@@ -70,6 +74,8 @@ namespace ucl {
 
        template <class T, class ...ARGS>
        SharedRef<T> makeShared(ARGS &&...args);
+       template <class T, class ...ARGS>
+       SharedRef<T> makeSharedMT(ARGS &&...args);
 
        template <class T, class U>
        const SharedRef<T> &constRefCast(const SharedRef<U> &r) noexcept;
index 5b5ad55c64c9b055322f3838857288ec488f3f76..f085b9c19818ed880799542b041bae7a4784ba86 100644 (file)
@@ -14,8 +14,6 @@
  * limitations under the License.
  */
 
-#include "RefCountObj.h"
-
 namespace ucl {
 
        template <class T>
@@ -30,12 +28,19 @@ namespace ucl {
 
        template <class T>
        inline SharedRef<T>::SharedRef(
-                       RefCountObjBase *const rc, T *const ptr) noexcept :
+                       IRefCountObj *const rc, T *const ptr) noexcept :
                BaseRef<T>(rc, ptr)
        {
                this->m_rc->ref();
        }
 
+       template <class T>
+       inline SharedRef<T>::SharedRef(
+                       IRefCountObj *const rc, T *const ptr, bool noRef) noexcept :
+               BaseRef<T>(rc, ptr)
+       {
+       }
+
        template <class T>
        inline SharedRef<T>::SharedRef(const SharedRef<T> &r) noexcept :
                BaseRef<T>(r.m_rc, r.m_ptr)
@@ -47,7 +52,7 @@ namespace ucl {
 
        template <class T>
        template <class U>
-       inline SharedRef<T>::SharedRef(const BaseRef<U> &r) noexcept :
+       inline SharedRef<T>::SharedRef(const SharedRef<U> &r) noexcept :
                BaseRef<T>(r.m_rc, r.m_ptr)
        {
                if (this->m_rc) {
@@ -101,13 +106,35 @@ namespace ucl {
                return !!this->m_ptr;
        }
 
+       template <class T>
+       inline T *SharedRef<T>::operator->() const noexcept
+       {
+               return this->m_ptr;
+       }
+
+       template <class T>
+       inline typename std::add_lvalue_reference<T>::type
+                       SharedRef<T>::operator*() const noexcept
+       {
+               return *this->m_ptr;
+       }
+
        // Non-member functions //
 
        template <class T, class ...ARGS>
        SharedRef<T> makeShared(ARGS &&...args)
        {
-               const auto rc = new RefCountObj<T>(std::forward<ARGS>(args)...);
-               return {rc, rc->getObj()};
+               const auto rc = new RefCountObj<T, RefCounterST>(
+                               std::forward<ARGS>(args)...);
+               return {rc, rc->getObj(), true};
+       }
+
+       template <class T, class ...ARGS>
+       SharedRef<T> makeSharedMT(ARGS &&...args)
+       {
+               const auto rc = new RefCountObj<T, RefCounterMT>(
+                               std::forward<ARGS>(args)...);
+               return {rc, rc->getObj(), true};
        }
 
        template <class T>
index 78450a51f2ab78cebe7a0ffe764046b019ce362e..4cccbe6e8aa2564f7f6a311139f7fa860b781e0a 100644 (file)
@@ -22,7 +22,7 @@
 namespace ucl {
 
        template <class T>
-       class WeakRef : public BaseRef<T> {
+       class WeakRef final : public BaseRef<T> {
        public:
                template <class U>
                friend void swap(WeakRef<U> &x, WeakRef<U> &y) noexcept;
@@ -36,7 +36,7 @@ namespace ucl {
                constexpr WeakRef() noexcept;
                constexpr WeakRef(std::nullptr_t) noexcept;
 
-               WeakRef(RefCountObjBase *rc, T *ptr) noexcept;
+               WeakRef(IRefCountObj *rc, T *ptr) noexcept;
 
                WeakRef(const WeakRef<T> &r) noexcept;
                template <class U>
@@ -52,7 +52,9 @@ namespace ucl {
 
                void reset() noexcept;
 
-               T *get() const noexcept;
+               SharedRef<T> lock() const noexcept;
+
+               T *getUnsafePtr() const noexcept;
                operator bool() const noexcept;
 
                template <class U, class = typename std::enable_if<
index b1681ed662ffbb93b6a3b4504e1755816e7db60a..6634f3c0ccde622d957d32e9a846f6080bcf0f03 100644 (file)
@@ -28,7 +28,7 @@ namespace ucl {
 
        template <class T>
        inline WeakRef<T>::WeakRef(
-                       RefCountObjBase *const rc, T *const ptr) noexcept :
+                       IRefCountObj *const rc, T *const ptr) noexcept :
                BaseRef<T>(rc, ptr)
        {
                this->m_rc->refWeak();
@@ -88,7 +88,16 @@ namespace ucl {
        }
 
        template <class T>
-       inline T *WeakRef<T>::get() const noexcept
+       inline SharedRef<T> WeakRef<T>::lock() const noexcept
+       {
+               if (this->m_rc && this->m_rc->refNz()) {
+                       return {this->m_rc, this->m_ptr, true};
+               }
+               return {};
+       }
+
+       template <class T>
+       inline T *WeakRef<T>::getUnsafePtr() const noexcept
        {
                return (operator bool() ? this->m_ptr : nullptr);
        }
@@ -96,7 +105,7 @@ namespace ucl {
        template <class T>
        inline WeakRef<T>::operator bool() const noexcept
        {
-               return (this->m_ptr && !this->m_rc->isDisposed());
+               return (this->m_rc && (this->m_rc->getUseCount() > 0));
        }
 
        // Non-member functions //
@@ -117,13 +126,13 @@ namespace ucl {
        template <class T, class U>
        inline WeakRef<T> staticRefCast(const WeakRef<U> &r) noexcept
        {
-               return {r.m_rc, static_cast<T *>(r.get())};
+               return {r.m_rc, static_cast<T *>(r.getUnsafePtr())};
        }
 
        template <class T, class U>
        inline WeakRef<T> dynamicRefCast(const WeakRef<U> &r) noexcept
        {
-               const auto ptr = dynamic_cast<T *>(r.get());
+               const auto ptr = dynamic_cast<T *>(r.getUnsafePtr());
                if (!ptr) {
                        return {};
                }
index 4e6c0e0ee7a6ebc77299d7860199e839ecce6754..bef907b2b9172b184a96fc875f5fa6b9cb2d9eb7 100644 (file)
@@ -37,52 +37,74 @@ namespace ucl {
 
        // Relation operators //
 
+       namespace himpl {
+
+               template <class T, class = typename std::enable_if<
+                       !std::is_base_of<BaseRef<typename T::Type>, T>::value>::type>
+               inline const T &getCmpPtr(const T &ptr) noexcept
+               {
+                       return ptr;
+               }
+
+               template <class T>
+               inline T *getCmpPtr(const SharedRef<T> &r) noexcept
+               {
+                       return r.get();
+               }
+
+               template <class T>
+               inline T *getCmpPtr(const WeakRef<T> &r) noexcept
+               {
+                       return r.getUnsafePtr();
+               }
+       }
+
        template <class T, class U, class = typename std::enable_if<
-               std::is_base_of<BaseRef<typename T::Type>, T>::value &&
+               std::is_base_of<BaseRef<typename T::Type>, T>::value ||
                std::is_base_of<BaseRef<typename U::Type>, U>::value>::type>
        inline bool operator==(const T &lhs, const U &rhs) noexcept
        {
-               return (lhs.get() == rhs.get());
+               return (himpl::getCmpPtr(lhs) == himpl::getCmpPtr(rhs));
        }
 
        template <class T, class U, class = typename std::enable_if<
-               std::is_base_of<BaseRef<typename T::Type>, T>::value &&
+               std::is_base_of<BaseRef<typename T::Type>, T>::value ||
                std::is_base_of<BaseRef<typename U::Type>, U>::value>::type>
        inline bool operator!=(const T &lhs, const U &rhs) noexcept
        {
-               return (lhs.get() != rhs.get());
+               return (himpl::getCmpPtr(lhs) != himpl::getCmpPtr(rhs));
        }
 
        template <class T, class U, class = typename std::enable_if<
-               std::is_base_of<BaseRef<typename T::Type>, T>::value &&
+               std::is_base_of<BaseRef<typename T::Type>, T>::value ||
                std::is_base_of<BaseRef<typename U::Type>, U>::value>::type>
        inline bool operator<(const T &lhs, const U &rhs) noexcept
        {
-               return (lhs.get() < rhs.get());
+               return (himpl::getCmpPtr(lhs) < himpl::getCmpPtr(rhs));
        }
 
        template <class T, class U, class = typename std::enable_if<
-               std::is_base_of<BaseRef<typename T::Type>, T>::value &&
+               std::is_base_of<BaseRef<typename T::Type>, T>::value ||
                std::is_base_of<BaseRef<typename U::Type>, U>::value>::type>
        inline bool operator<=(const T &lhs, const U &rhs) noexcept
        {
-               return (lhs.get() <= rhs.get());
+               return (himpl::getCmpPtr(lhs) <= himpl::getCmpPtr(rhs));
        }
 
        template <class T, class U, class = typename std::enable_if<
-               std::is_base_of<BaseRef<typename T::Type>, T>::value &&
+               std::is_base_of<BaseRef<typename T::Type>, T>::value ||
                std::is_base_of<BaseRef<typename U::Type>, U>::value>::type>
        inline bool operator>(const T &lhs, const U &rhs) noexcept
        {
-               return (lhs.get() > rhs.get());
+               return (himpl::getCmpPtr(lhs) > himpl::getCmpPtr(rhs));
        }
 
        template <class T, class U, class = typename std::enable_if<
-               std::is_base_of<BaseRef<typename T::Type>, T>::value &&
+               std::is_base_of<BaseRef<typename T::Type>, T>::value ||
                std::is_base_of<BaseRef<typename U::Type>, U>::value>::type>
        inline bool operator>=(const T &lhs, const U &rhs) noexcept
        {
-               return (lhs.get() >= rhs.get());
+               return (himpl::getCmpPtr(lhs) >= himpl::getCmpPtr(rhs));
        }
 
        template <class T, class = typename std::enable_if<
index 0d29f0fba7096249a869a53867292f2db66740ea..97e1ae828259cee440db5a65f6ceec6f96966aea 100644 (file)
@@ -31,6 +31,8 @@ namespace ucl {
        public:
                using BaseDelegate<R(ARGS...), WeakRef<void>>::BaseDelegate;
 
+               R operator()(ARGS ...args) const;
+
                template <class CLASS, R(CLASS::*METHOD)(ARGS...)>
                static WeakDelegate make(const WeakRef<CLASS> &data) noexcept;
 
index e4b4b5d6f4b304302edf37732e12942c7be5dc58..fa7b3f8ff3a02739dc8a1480ec13c8777ef51935 100644 (file)
 
 namespace ucl {
 
+       template <class R, class ...ARGS>
+       inline R WeakDelegate<R(ARGS...)>::operator()(ARGS ...args) const
+       {
+               const auto tmp = this->m_data.lock();
+               if (tmp) {
+                       return this->m_stubA(tmp.get(), std::forward<ARGS>(args)...);
+               }
+               return R();
+       }
+
        template <class R, class ...ARGS>
        template <class CLASS, R(CLASS::*METHOD)(ARGS...)>
        inline WeakDelegate<R(ARGS...)> WeakDelegate<R(ARGS...)>::make(
index 5b280de6819a865081366583f89909566184d5f9..c5062db0cccb412cfe5f109d3dd0be0f8a6fbf44 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <string>
 #include <memory>
+#include <atomic>
 #include <functional>
 #include <type_traits>
 #include <utility>
index 73856be8d07b6e0e53926a92b8360856d64ac5d7..7c39f813db65f58685e6300b5edf95e376a7f146 100644 (file)
@@ -21,7 +21,7 @@
 
 namespace ucl {
 
-       ElmWidget::ElmWidget(RefCountObjBase *rc, Evas_Object *eo, bool isOwner) :
+       ElmWidget::ElmWidget(IRefCountObj *rc, Evas_Object *eo, bool isOwner) :
                Widget(rc, eo, isOwner),
                m_isAtspiGestureCbSet(false)
        {
index 881390c859983ab1d9bef404f94bcc06c9bfafa8..69d80a5419bebdbee2adafe4cb33e934a3c3035a 100644 (file)
@@ -47,7 +47,7 @@ namespace ucl {
 
        // Naviframe //
 
-       Naviframe::Naviframe(RefCountObjBase &rc, Evas_Object *eo) :
+       Naviframe::Naviframe(IRefCountObj &rc, Evas_Object *eo) :
                StyledWidget(&rc, eo, true),
                m_isInTransition(false)
        {
index 0d546f4d6f05360fa21bf30bf77b546e6e72ed00..d2c0dd65a3e9eeb4ade1d7a2294dc018fb49ebf0 100644 (file)
@@ -110,7 +110,7 @@ namespace ucl {
 
        // Widget //
 
-       Widget::Widget(RefCountObjBase *const rc, Evas_Object *const eo,
+       Widget::Widget(IRefCountObj *const rc, Evas_Object *const eo,
                        const bool isOwner) :
                RefCountAware(rc),
                m_eo(eo),
@@ -175,11 +175,9 @@ namespace ucl {
 
        void Widget::updateRefs()
        {
-               const auto rc = m_rc;
-
                updateEoRef();
 
-               if (rc && !rc->isDisposed()) {
+               if (m_rc) {
                        updateSelfRef();
                }
        }