From: Igor Nazarov Date: Wed, 19 Apr 2017 13:35:39 +0000 (+0300) Subject: TizenRefApp-8409 [Gallery] Improve RefCountAware class functionality X-Git-Tag: submit/tizen/20170531.142232~26 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=50debe4284dbd98fd727a22e0decac753efcf0a4;p=profile%2Fwearable%2Fapps%2Fnative%2Fgallery.git TizenRefApp-8409 [Gallery] Improve RefCountAware class functionality - RefCountAware class functionality rewritten in order to allow more use cases. Change-Id: I08588caf4ebf83d2d330be7e6c0100318934e5a1 --- diff --git a/ucl/inc/ucl/misc/RefCountAware.h b/ucl/inc/ucl/misc/RefCountAware.h index f037baa..7ec13cc 100644 --- a/ucl/inc/ucl/misc/RefCountAware.h +++ b/ucl/inc/ucl/misc/RefCountAware.h @@ -26,33 +26,13 @@ namespace ucl { class RefCountAware : public Polymorphic { public: - template - static SharedRef asShared(T *obj); - template - static WeakRef asWeak(T *obj); - - template - static SharedRef asShared(T &obj); - template - static WeakRef asWeak(T &obj); - bool isShared() const; template - SharedRef asShared(); - template - WeakRef asWeak(); + SharedRef asSharedThis(T *thisAlias) const; template - SharedRef asShared() const; - template - WeakRef asWeak() const; - - RefCountAwareSRef asShared(); - RefCountAwareWRef asWeak(); - - RefCountAwareSCRef asShared() const; - RefCountAwareWCRef asWeak() const; + WeakRef asWeakThis(T *thisAlias) const; protected: RefCountAware(RefCountObjBase *rc); @@ -65,14 +45,42 @@ namespace ucl { // Non-member functions // template - SharedRef asShared(T *obj); + SharedRef asShared(T &obj); template - WeakRef asWeak(T *obj); + SharedRef asShared(T *obj); - template - SharedRef asShared(T &obj); template WeakRef asWeak(T &obj); + template + WeakRef asWeak(T *obj); + + template ::value>::type> + SharedRef asShared(U &obj); + template ::value>::type> + SharedRef asShared(U *obj); + + template ::value>::type> + WeakRef asWeak(U &obj); + template ::value>::type> + WeakRef asWeak(U *obj); + + template ::value>::type> + SharedRef asShared(const U &obj); + template ::value>::type> + SharedRef asShared(const U *obj); + + template ::value>::type> + WeakRef asWeak(const U &obj); + template ::value>::type> + WeakRef asWeak(const U *obj); } #include "RefCountAware.hpp" diff --git a/ucl/inc/ucl/misc/RefCountAware.hpp b/ucl/inc/ucl/misc/RefCountAware.hpp index 7969289..ae51c0d 100644 --- a/ucl/inc/ucl/misc/RefCountAware.hpp +++ b/ucl/inc/ucl/misc/RefCountAware.hpp @@ -23,118 +23,108 @@ namespace ucl { { } - template - inline SharedRef RefCountAware::asShared(T *obj) - { - return (obj ? asShared(*obj) : SharedRef()); - } - - template - inline WeakRef RefCountAware::asWeak(T *obj) - { - return (obj ? asWeak(*obj) : WeakRef()); - } - - template - inline SharedRef RefCountAware::asShared(T &obj) - { - return obj.template asShared::type>(); - } - - template - inline WeakRef RefCountAware::asWeak(T &obj) - { - return obj.template asWeak::type>(); - } - inline bool RefCountAware::isShared() const { return !!m_rc; } template - inline SharedRef RefCountAware::asShared() + inline SharedRef RefCountAware::asSharedThis(T *const thisAlias) const { if (!isShared()) { UCL_ELOG("NOT SHARED: %s", typeid(*this).name()); return {}; } - return {m_rc, static_cast(this)}; + return {m_rc, thisAlias}; } template - inline WeakRef RefCountAware::asWeak() + inline WeakRef RefCountAware::asWeakThis(T *const thisAlias) const { if (!isShared()) { UCL_ELOG("NOT SHARED: %s", typeid(*this).name()); return {}; } - return {m_rc, static_cast(this)}; + return {m_rc, thisAlias}; } + // Non-member functions // + template - inline SharedRef RefCountAware::asShared() const + inline SharedRef asShared(T &obj) { - if (!isShared()) { - UCL_ELOG("NOT SHARED: %s", typeid(*this).name()); - return {}; - } - return {m_rc, static_cast(this)}; + return obj.template asSharedThis(&obj); } template - inline WeakRef RefCountAware::asWeak() const + inline SharedRef asShared(T *obj) { - if (!isShared()) { - UCL_ELOG("NOT SHARED: %s", typeid(*this).name()); - return {}; - } - return {m_rc, static_cast(this)}; + if (!obj) return {}; + return obj->template asSharedThis(obj); } - inline RefCountAwareSRef RefCountAware::asShared() + template + inline WeakRef asWeak(T &obj) { - return asShared(); + return obj.template asWeakThis(&obj); } - inline RefCountAwareWRef RefCountAware::asWeak() + template + inline WeakRef asWeak(T *obj) { - return asWeak(); + if (!obj) return {}; + return obj->template asWeakThis(obj); } - inline RefCountAwareSCRef RefCountAware::asShared() const + template + inline SharedRef asShared(U &obj) { - return asShared(); + return obj.template asSharedThis(&obj); } - inline RefCountAwareWCRef RefCountAware::asWeak() const + template + inline SharedRef asShared(U *obj) { - return asWeak(); + if (!obj) return {}; + return obj->template asSharedThis(obj); } - // Non-member functions // + template + inline WeakRef asWeak(U &obj) + { + return obj.template asWeakThis(&obj); + } - template - inline SharedRef asShared(T *obj) + template + inline WeakRef asWeak(U *obj) { - return RefCountAware::asShared(obj); + if (!obj) return {}; + return obj->template asWeakThis(obj); } - template - inline WeakRef asWeak(T *obj) + template + inline SharedRef asShared(const U &obj) { - return RefCountAware::asWeak(obj); + return obj.template asSharedThis(&obj); } - template - inline SharedRef asShared(T &obj) + template + inline SharedRef asShared(const U *obj) { - return RefCountAware::asShared(obj); + if (!obj) return {}; + return obj->template asSharedThis(obj); } - template - inline WeakRef asWeak(T &obj) + template + inline WeakRef asWeak(const U &obj) + { + return obj.template asWeakThis(&obj); + } + + template + inline WeakRef asWeak(const U *obj) { - return RefCountAware::asWeak(obj); + if (!obj) return {}; + return obj->template asWeakThis(obj); } }