diff options
author | Igor Nazarov <i.nazarov@samsung.com> | 2017-04-19 16:35:39 +0300 |
---|---|---|
committer | Igor Nazarov <i.nazarov@samsung.com> | 2017-04-19 20:30:15 +0300 |
commit | 50debe4284dbd98fd727a22e0decac753efcf0a4 (patch) | |
tree | e6a84391c23a030cd8fcdcfd75f404ffa39c10f0 | |
parent | 2ce5963e779a74c4c2a37717265951f7971db0db (diff) | |
download | gallery-50debe4284dbd98fd727a22e0decac753efcf0a4.tar.gz gallery-50debe4284dbd98fd727a22e0decac753efcf0a4.tar.bz2 gallery-50debe4284dbd98fd727a22e0decac753efcf0a4.zip |
TizenRefApp-8409 [Gallery] Improve RefCountAware class functionality
- RefCountAware class functionality rewritten in order to allow more use
cases.
Change-Id: I08588caf4ebf83d2d330be7e6c0100318934e5a1
-rw-r--r-- | ucl/inc/ucl/misc/RefCountAware.h | 60 | ||||
-rw-r--r-- | ucl/inc/ucl/misc/RefCountAware.hpp | 112 |
2 files changed, 85 insertions, 87 deletions
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 <class T> - static SharedRef<T> asShared(T *obj); - template <class T> - static WeakRef<T> asWeak(T *obj); - - template <class T> - static SharedRef<T> asShared(T &obj); - template <class T> - static WeakRef<T> asWeak(T &obj); - bool isShared() const; template <class T> - SharedRef<T> asShared(); - template <class T> - WeakRef<T> asWeak(); + SharedRef<T> asSharedThis(T *thisAlias) const; template <class T> - SharedRef<const T> asShared() const; - template <class T> - WeakRef<const T> asWeak() const; - - RefCountAwareSRef asShared(); - RefCountAwareWRef asWeak(); - - RefCountAwareSCRef asShared() const; - RefCountAwareWCRef asWeak() const; + WeakRef<T> asWeakThis(T *thisAlias) const; protected: RefCountAware(RefCountObjBase *rc); @@ -65,14 +45,42 @@ namespace ucl { // Non-member functions // template <class T> - SharedRef<T> asShared(T *obj); + SharedRef<T> asShared(T &obj); template <class T> - WeakRef<T> asWeak(T *obj); + SharedRef<T> asShared(T *obj); template <class T> - SharedRef<T> asShared(T &obj); - template <class T> WeakRef<T> asWeak(T &obj); + template <class T> + WeakRef<T> asWeak(T *obj); + + template <class T, class U, class = typename + std::enable_if<!std::is_same<T, U>::value>::type> + SharedRef<T> asShared(U &obj); + template <class T, class U, class = typename + std::enable_if<!std::is_same<T, U>::value>::type> + SharedRef<T> asShared(U *obj); + + template <class T, class U, class = typename + std::enable_if<!std::is_same<T, U>::value>::type> + WeakRef<T> asWeak(U &obj); + template <class T, class U, class = typename + std::enable_if<!std::is_same<T, U>::value>::type> + WeakRef<T> asWeak(U *obj); + + template <class T, class U, class = typename + std::enable_if<!std::is_same<T, const U>::value>::type> + SharedRef<const T> asShared(const U &obj); + template <class T, class U, class = typename + std::enable_if<!std::is_same<T, const U>::value>::type> + SharedRef<const T> asShared(const U *obj); + + template <class T, class U, class = typename + std::enable_if<!std::is_same<T, const U>::value>::type> + WeakRef<const T> asWeak(const U &obj); + template <class T, class U, class = typename + std::enable_if<!std::is_same<T, const U>::value>::type> + WeakRef<const T> 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 <class T> - inline SharedRef<T> RefCountAware::asShared(T *obj) - { - return (obj ? asShared(*obj) : SharedRef<T>()); - } - - template <class T> - inline WeakRef<T> RefCountAware::asWeak(T *obj) - { - return (obj ? asWeak(*obj) : WeakRef<T>()); - } - - template <class T> - inline SharedRef<T> RefCountAware::asShared(T &obj) - { - return obj.template asShared<typename std::remove_cv<T>::type>(); - } - - template <class T> - inline WeakRef<T> RefCountAware::asWeak(T &obj) - { - return obj.template asWeak<typename std::remove_cv<T>::type>(); - } - inline bool RefCountAware::isShared() const { return !!m_rc; } template <class T> - inline SharedRef<T> RefCountAware::asShared() + inline SharedRef<T> RefCountAware::asSharedThis(T *const thisAlias) const { if (!isShared()) { UCL_ELOG("NOT SHARED: %s", typeid(*this).name()); return {}; } - return {m_rc, static_cast<T *>(this)}; + return {m_rc, thisAlias}; } template <class T> - inline WeakRef<T> RefCountAware::asWeak() + inline WeakRef<T> RefCountAware::asWeakThis(T *const thisAlias) const { if (!isShared()) { UCL_ELOG("NOT SHARED: %s", typeid(*this).name()); return {}; } - return {m_rc, static_cast<T *>(this)}; + return {m_rc, thisAlias}; } + // Non-member functions // + template <class T> - inline SharedRef<const T> RefCountAware::asShared() const + inline SharedRef<T> asShared(T &obj) { - if (!isShared()) { - UCL_ELOG("NOT SHARED: %s", typeid(*this).name()); - return {}; - } - return {m_rc, static_cast<const T *>(this)}; + return obj.template asSharedThis<T>(&obj); } template <class T> - inline WeakRef<const T> RefCountAware::asWeak() const + inline SharedRef<T> asShared(T *obj) { - if (!isShared()) { - UCL_ELOG("NOT SHARED: %s", typeid(*this).name()); - return {}; - } - return {m_rc, static_cast<const T *>(this)}; + if (!obj) return {}; + return obj->template asSharedThis<T>(obj); } - inline RefCountAwareSRef RefCountAware::asShared() + template <class T> + inline WeakRef<T> asWeak(T &obj) { - return asShared<RefCountAware>(); + return obj.template asWeakThis<T>(&obj); } - inline RefCountAwareWRef RefCountAware::asWeak() + template <class T> + inline WeakRef<T> asWeak(T *obj) { - return asWeak<RefCountAware>(); + if (!obj) return {}; + return obj->template asWeakThis<T>(obj); } - inline RefCountAwareSCRef RefCountAware::asShared() const + template <class T, class U, class> + inline SharedRef<T> asShared(U &obj) { - return asShared<RefCountAware>(); + return obj.template asSharedThis<T>(&obj); } - inline RefCountAwareWCRef RefCountAware::asWeak() const + template <class T, class U, class> + inline SharedRef<T> asShared(U *obj) { - return asWeak<RefCountAware>(); + if (!obj) return {}; + return obj->template asSharedThis<T>(obj); } - // Non-member functions // + template <class T, class U, class> + inline WeakRef<T> asWeak(U &obj) + { + return obj.template asWeakThis<T>(&obj); + } - template <class T> - inline SharedRef<T> asShared(T *obj) + template <class T, class U, class> + inline WeakRef<T> asWeak(U *obj) { - return RefCountAware::asShared(obj); + if (!obj) return {}; + return obj->template asWeakThis<T>(obj); } - template <class T> - inline WeakRef<T> asWeak(T *obj) + template <class T, class U, class> + inline SharedRef<const T> asShared(const U &obj) { - return RefCountAware::asWeak(obj); + return obj.template asSharedThis<const T>(&obj); } - template <class T> - inline SharedRef<T> asShared(T &obj) + template <class T, class U, class> + inline SharedRef<const T> asShared(const U *obj) { - return RefCountAware::asShared(obj); + if (!obj) return {}; + return obj->template asSharedThis<const T>(obj); } - template <class T> - inline WeakRef<T> asWeak(T &obj) + template <class T, class U, class> + inline WeakRef<const T> asWeak(const U &obj) + { + return obj.template asWeakThis<const T>(&obj); + } + + template <class T, class U, class> + inline WeakRef<const T> asWeak(const U *obj) { - return RefCountAware::asWeak(obj); + if (!obj) return {}; + return obj->template asWeakThis<const T>(obj); } } |