#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;
--- /dev/null
+/*
+ * 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__
--- /dev/null
+/*
+ * 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);
+ }
+}
+++ /dev/null
-/*
- * 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__
+++ /dev/null
-/*
- * 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);
- }
-}
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),