TizenRefApp-8205 [Gallery] Refactor UCL SharedObject to RefCountAware 27/119927/1
authorIgor Nazarov <i.nazarov@samsung.com>
Mon, 20 Mar 2017 14:23:39 +0000 (16:23 +0200)
committerIgor Nazarov <i.nazarov@samsung.com>
Mon, 20 Mar 2017 14:27:36 +0000 (16:27 +0200)
Change-Id: I22271ec08b5eee6d15b7f38cb3335bb5e5817dce

ucl/inc/ucl/gui/Widget.h
ucl/inc/ucl/misc/RefCountAware.h [new file with mode: 0644]
ucl/inc/ucl/misc/RefCountAware.hpp [new file with mode: 0644]
ucl/inc/ucl/misc/SharedObject.h [deleted file]
ucl/inc/ucl/misc/SharedObject.hpp [deleted file]
ucl/src/gui/Widget.cpp

index 1dd2a38ecd3ff6d0edec50af2f0cdd296db27595..e95c5d857c62c4f7ce5bb091bef9fcfa2e58daa2 100644 (file)
 
 #include "types.h"
 
-#include "ucl/misc/SharedObject.h"
+#include "ucl/misc/RefCountAware.h"
 
 namespace ucl {
 
        UCL_DECLARE_REF_ALIASES(Widget);
 
-       class Widget : public SharedObject {
+       class Widget : public RefCountAware {
        public:
                static constexpr auto EXPAND = EVAS_HINT_EXPAND;
                static constexpr auto FILL = EVAS_HINT_FILL;
diff --git a/ucl/inc/ucl/misc/RefCountAware.h b/ucl/inc/ucl/misc/RefCountAware.h
new file mode 100644 (file)
index 0000000..f037baa
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * 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_MISC_REF_COUNT_AWARE_H__
+#define __UCL_MISC_REF_COUNT_AWARE_H__
+
+#include "ucl/util/types.h"
+#include "ucl/util/memory.h"
+
+namespace ucl {
+
+       UCL_DECLARE_REF_ALIASES(RefCountAware);
+
+       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();
+
+               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;
+
+       protected:
+               RefCountAware(RefCountObjBase *rc);
+               virtual ~RefCountAware() = default;
+
+       protected:
+               RefCountObjBase *const m_rc;
+       };
+
+       // Non-member functions //
+
+       template <class T>
+       SharedRef<T> asShared(T *obj);
+       template <class T>
+       WeakRef<T> asWeak(T *obj);
+
+       template <class T>
+       SharedRef<T> asShared(T &obj);
+       template <class T>
+       WeakRef<T> asWeak(T &obj);
+}
+
+#include "RefCountAware.hpp"
+
+#endif // __UCL_MISC_REF_COUNT_AWARE_H__
diff --git a/ucl/inc/ucl/misc/RefCountAware.hpp b/ucl/inc/ucl/misc/RefCountAware.hpp
new file mode 100644 (file)
index 0000000..b332d8f
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * 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.
+ */
+
+#include "ucl/util/logging.h"
+
+namespace ucl {
+
+       inline RefCountAware::RefCountAware(RefCountObjBase *const rc) :
+               m_rc(rc)
+       {
+       }
+
+       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.asShared<typename std::remove_cv<T>::type>();
+       }
+
+       template <class T>
+       inline WeakRef<T> RefCountAware::asWeak(T &obj)
+       {
+               return obj.asWeak<typename std::remove_cv<T>::type>();
+       }
+
+       inline bool RefCountAware::isShared() const
+       {
+               return !!m_rc;
+       }
+
+       template <class T>
+       inline SharedRef<T> RefCountAware::asShared()
+       {
+               if (!isShared()) {
+                       UCL_ELOG("NOT SHARED: %s", typeid(*this).name());
+                       return {};
+               }
+               return {m_rc, static_cast<T *>(this)};
+       }
+
+       template <class T>
+       inline WeakRef<T> RefCountAware::asWeak()
+       {
+               if (!isShared()) {
+                       UCL_ELOG("NOT SHARED: %s", typeid(*this).name());
+                       return {};
+               }
+               return {m_rc, static_cast<T *>(this)};
+       }
+
+       template <class T>
+       inline SharedRef<const T> RefCountAware::asShared() const
+       {
+               if (!isShared()) {
+                       UCL_ELOG("NOT SHARED: %s", typeid(*this).name());
+                       return {};
+               }
+               return {m_rc, static_cast<const T *>(this)};
+       }
+
+       template <class T>
+       inline WeakRef<const T> RefCountAware::asWeak() const
+       {
+               if (!isShared()) {
+                       UCL_ELOG("NOT SHARED: %s", typeid(*this).name());
+                       return {};
+               }
+               return {m_rc, static_cast<const T *>(this)};
+       }
+
+       inline RefCountAwareSRef RefCountAware::asShared()
+       {
+               return asShared<RefCountAware>();
+       }
+
+       inline RefCountAwareWRef RefCountAware::asWeak()
+       {
+               return asWeak<RefCountAware>();
+       }
+
+       inline RefCountAwareSCRef RefCountAware::asShared() const
+       {
+               return asShared<RefCountAware>();
+       }
+
+       inline RefCountAwareWCRef RefCountAware::asWeak() const
+       {
+               return asWeak<RefCountAware>();
+       }
+
+       // Non-member functions //
+
+       template <class T>
+       inline SharedRef<T> asShared(T *obj)
+       {
+               return RefCountAware::asShared(obj);
+       }
+
+       template <class T>
+       inline WeakRef<T> asWeak(T *obj)
+       {
+               return RefCountAware::asWeak(obj);
+       }
+
+       template <class T>
+       inline SharedRef<T> asShared(T &obj)
+       {
+               return RefCountAware::asShared(obj);
+       }
+
+       template <class T>
+       inline WeakRef<T> asWeak(T &obj)
+       {
+               return RefCountAware::asWeak(obj);
+       }
+}
diff --git a/ucl/inc/ucl/misc/SharedObject.h b/ucl/inc/ucl/misc/SharedObject.h
deleted file mode 100644 (file)
index 80654e4..0000000
+++ /dev/null
@@ -1,78 +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_MISC_SHARED_OBJECT_H__
-#define __UCL_MISC_SHARED_OBJECT_H__
-
-#include "ucl/util/types.h"
-#include "ucl/util/memory.h"
-
-namespace ucl {
-
-       UCL_DECLARE_REF_ALIASES(SharedObject);
-
-       class SharedObject : public NonCopyable {
-       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);
-
-               template <class T>
-               SharedRef<T> asShared();
-               template <class T>
-               WeakRef<T> asWeak();
-
-               template <class T>
-               SharedRef<const T> asShared() const;
-               template <class T>
-               WeakRef<const T> asWeak() const;
-
-               SharedObjectSRef asShared();
-               SharedObjectWRef asWeak();
-
-               SharedObjectSCRef asShared() const;
-               SharedObjectWCRef asWeak() const;
-
-       protected:
-               SharedObject(RefCountObjBase *rc);
-               ~SharedObject() = default;
-
-       protected:
-               RefCountObjBase *const m_rc;
-       };
-
-       // Non-member functions //
-
-       template <class T>
-       SharedRef<T> asShared(T *obj);
-       template <class T>
-       WeakRef<T> asWeak(T *obj);
-
-       template <class T>
-       SharedRef<T> asShared(T &obj);
-       template <class T>
-       WeakRef<T> asWeak(T &obj);
-}
-
-#include "SharedObject.hpp"
-
-#endif // __UCL_MISC_SHARED_OBJECT_H__
diff --git a/ucl/inc/ucl/misc/SharedObject.hpp b/ucl/inc/ucl/misc/SharedObject.hpp
deleted file mode 100644 (file)
index f1fbaed..0000000
+++ /dev/null
@@ -1,129 +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 SharedObject::SharedObject(RefCountObjBase *const rc) :
-               m_rc(rc)
-       {
-       }
-
-       template <class T>
-       inline SharedRef<T> SharedObject::asShared(T *obj)
-       {
-               return (obj ? asShared(*obj) : SharedRef<T>());
-       }
-
-       template <class T>
-       inline WeakRef<T> SharedObject::asWeak(T *obj)
-       {
-               return (obj ? asWeak(*obj) : WeakRef<T>());
-       }
-
-       template <class T>
-       inline SharedRef<T> SharedObject::asShared(T &obj)
-       {
-               return obj.asShared<typename std::remove_cv<T>::type>();
-       }
-
-       template <class T>
-       inline WeakRef<T> SharedObject::asWeak(T &obj)
-       {
-               return obj.asWeak<typename std::remove_cv<T>::type>();
-       }
-
-       template <class T>
-       inline SharedRef<T> SharedObject::asShared()
-       {
-               if (!m_rc) {
-                       return {};
-               }
-               return {m_rc, static_cast<T *>(this)};
-       }
-
-       template <class T>
-       inline WeakRef<T> SharedObject::asWeak()
-       {
-               if (!m_rc) {
-                       return {};
-               }
-               return {m_rc, static_cast<T *>(this)};
-       }
-
-       template <class T>
-       inline SharedRef<const T> SharedObject::asShared() const
-       {
-               if (!m_rc) {
-                       return {};
-               }
-               return {m_rc, static_cast<const T *>(this)};
-       }
-
-       template <class T>
-       inline WeakRef<const T> SharedObject::asWeak() const
-       {
-               if (!m_rc) {
-                       return {};
-               }
-               return {m_rc, static_cast<const T *>(this)};
-       }
-
-       inline SharedObjectSRef SharedObject::asShared()
-       {
-               return asShared<SharedObject>();
-       }
-
-       inline SharedObjectWRef SharedObject::asWeak()
-       {
-               return asWeak<SharedObject>();
-       }
-
-       inline SharedObjectSCRef SharedObject::asShared() const
-       {
-               return asShared<SharedObject>();
-       }
-
-       inline SharedObjectWCRef SharedObject::asWeak() const
-       {
-               return asWeak<SharedObject>();
-       }
-
-       // Non-member functions //
-
-       template <class T>
-       inline SharedRef<T> asShared(T *obj)
-       {
-               return SharedObject::asShared(obj);
-       }
-
-       template <class T>
-       inline WeakRef<T> asWeak(T *obj)
-       {
-               return SharedObject::asWeak(obj);
-       }
-
-       template <class T>
-       inline SharedRef<T> asShared(T &obj)
-       {
-               return SharedObject::asShared(obj);
-       }
-
-       template <class T>
-       inline WeakRef<T> asWeak(T &obj)
-       {
-               return SharedObject::asWeak(obj);
-       }
-}
index 472b1ebe1e934d7848dc4234fb466596e641451c..5012a6a8127225e2fd7ff8f5da87844b46a5dc6d 100644 (file)
@@ -112,7 +112,7 @@ namespace ucl {
 
        Widget::Widget(RefCountObjBase *const rc, Evas_Object *const eo,
                        const bool isOwner) :
-               SharedObject(rc),
+               RefCountAware(rc),
                m_eo(eo),
                m_isOwner(isOwner),
                m_isBoundToEo(false),