Refactor cast methods. 42/153442/2 tizen_4.0 submit/tizen_4.0/20171004.071943 tizen_4.0.IoT.p1_release tizen_4.0.IoT.p2_release tizen_4.0.m2_release
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Thu, 28 Sep 2017 10:38:48 +0000 (13:38 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Mon, 2 Oct 2017 09:14:55 +0000 (12:14 +0300)
Change-Id: I97420d0a9f659513516eb607d270dbcaf049e388
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
src/Common/View/inc/View.h
src/Common/View/inc/ViewItem.h
src/Common/View/src/ListView.cpp
src/Common/View/src/MbeRecipientsView.cpp
src/Common/View/src/NaviFrameView.cpp
src/Common/View/src/View.cpp
src/Common/View/src/ViewItem.cpp
src/Viewer/Controller/src/Viewer.cpp

index dbca53c..39804ce 100644 (file)
@@ -235,11 +235,9 @@ namespace Msg {
                        void addSignalCb(const char *emission, const char *source, Edje_Signal_Cb func, void *data);
 
                        template<typename T>
-                       static T staticCast(void *evasObj);
+                       static T *staticCast(const void *evasObj);
                        template<typename T>
-                       static T reinterpretCast(void *evasObj);
-                       template<typename T>
-                       static T dynamicCast(void *evasObj);
+                       static T *dynamicCast(const void *evasObj);
 
                        /**
                         * @brief Gets text placed in specified part.
@@ -313,10 +311,7 @@ namespace Msg {
                        View(View&) = delete;
                        View& operator=(View&) = delete;
                        Evas_Object_Event_Cb getCb(Evas_Callback_Type);
-                       void *getData() const;
-                       static void *getData(Evas_Object *obj);
-                       void setData(const void *data);
-                       static void setData(Evas_Object *obj, const void *data);
+                       static View *getThis(const Evas_Object *obj);
 
                private:
                        static void on_free_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
@@ -487,32 +482,16 @@ namespace Msg {
                return evas_object_data_get(m_pEo, key);
        }
 
-       inline void View::setData(const void *data)
-       {
-               setData(m_pEo, data);
-       }
-
-       inline void *View::getData() const
-       {
-               return getData(m_pEo);
-       }
-
-       template<typename T>
-       inline T View::staticCast(void *evasObj)
-       {
-               return static_cast<T>(getData((Evas_Object*)evasObj));
-       }
-
        template<typename T>
-       inline T View::reinterpretCast(void *evasObj)
+       inline T *View::staticCast(const void *evasObj)
        {
-               return reinterpret_cast<T>(getData((Evas_Object*)evasObj));
+               return static_cast<T*>(getThis((Evas_Object*)evasObj));
        }
 
        template<typename T>
-       inline T View::dynamicCast(void *evasObj)
+       inline T *View::dynamicCast(const void *evasObj)
        {
-               return dynamic_cast<T>(staticCast<View*>(evasObj));
+               return dynamic_cast<T*>(staticCast<View*>(evasObj));
        }
 
        inline void View::addEventCb(Evas_Callback_Type type, Evas_Object_Event_Cb func, const void *data)
index 994248e..779a394 100644 (file)
@@ -71,12 +71,6 @@ namespace Msg {
                        void *getData() const;
 
                        /**
-                        * @brief Sets item-data.
-                        * @param[in] data item-data.
-                        */
-                       void setData(void *data);
-
-                       /**
                         * @brief Gets Elm_Object_Item current view-item is wrapping.
                         * @return wrapped object-item.
                         */
@@ -142,11 +136,9 @@ namespace Msg {
                        static void setText(Elm_Object_Item *it, const TText &text, const char *part = nullptr);
 
                        template<typename T>
-                       static T staticCast(void *elmObjectItem);
-                       template<typename T>
-                       static T reinterpretCast(void *elmObjectItem);
+                       static T *staticCast(const void *elmObjectItem);
                        template<typename T>
-                       static T dynamicCast(void *elmObjectItem);
+                       static T *dynamicCast(const void *elmObjectItem);
 
                protected:
                        virtual ~ViewItem();
@@ -154,6 +146,7 @@ namespace Msg {
                        void setElmObjItem(Elm_Object_Item *item);
 
                private:
+                       static ViewItem *getThis(const Elm_Object_Item *item);
                        static void on_delete_cb(void *data, Evas_Object *obj, void *event_info);
 
                private:
@@ -180,11 +173,6 @@ namespace Msg {
                return elm_object_item_data_get(m_pItem);
        }
 
-       inline void ViewItem::setData(void *data)
-       {
-               elm_object_item_data_set(m_pItem, data);
-       }
-
        inline void ViewItem::disabled(bool val)
        {
                elm_object_item_disabled_set(m_pItem, val);
@@ -231,22 +219,21 @@ namespace Msg {
                return elm_object_item_part_text_get(m_pItem, part);
        }
 
-       template<typename T>
-       inline T ViewItem::staticCast(void *elmObjectItem)
+       inline ViewItem *ViewItem::getThis(const Elm_Object_Item *item)
        {
-               return static_cast<T>(elm_object_item_data_get((Elm_Object_Item*)elmObjectItem));
+               return (ViewItem*)elm_object_item_data_get(item);
        }
 
        template<typename T>
-       inline T ViewItem::reinterpretCast(void *elmObjectItem)
+       inline T *ViewItem::staticCast(const void *elmObjectItem)
        {
-               return reinterpret_cast<T>(elm_object_item_data_get((Elm_Object_Item*)elmObjectItem));
+               return static_cast<T*>(getThis((Elm_Object_Item*)elmObjectItem));
        }
 
        template<typename T>
-       inline T ViewItem::dynamicCast(void *elmObjectItem)
+       inline T *ViewItem::dynamicCast(const void *elmObjectItem)
        {
-               return dynamic_cast<T>(staticCast<ViewItem*>(elmObjectItem));
+               return dynamic_cast<T*>(staticCast<ViewItem*>(elmObjectItem));
        }
 }
 
index df75b73..a828443 100644 (file)
@@ -203,7 +203,7 @@ void ListView::setHomogeneous(bool isHomogeneous)
 ListItem *ListView::getSelectedItem() const
 {
        Elm_Object_Item *elmItem = elm_genlist_selected_item_get(getEo());
-       return ListItem::staticCast<ListItem*>(elmItem);
+       return ListItem::staticCast<ListItem>(elmItem);
 }
 
 unsigned ListView::getItemsCount() const
@@ -213,12 +213,12 @@ unsigned ListView::getItemsCount() const
 
 ListItem *ListView::getNextItem(ListItem &item) const
 {
-       return ListItem::staticCast<ListItem*>(elm_genlist_item_next_get(item));
+       return ListItem::staticCast<ListItem>(elm_genlist_item_next_get(item));
 }
 
 ListItem *ListView::getPrevItem(ListItem &item) const
 {
-       return ListItem::staticCast<ListItem*>(elm_genlist_item_prev_get(item));
+       return ListItem::staticCast<ListItem>(elm_genlist_item_prev_get(item));
 }
 
 void ListView::demoteItem(ListItem &item)
@@ -238,7 +238,7 @@ void ListView::setFilter(void *key)
 
 void ListView::notifyListener(void *data, Evas_Object *obj, void *event_info, ListenerMethod method)
 {
-       ListItem *item = ListItem::staticCast<ListItem*>(event_info);
+       ListItem *item = ListItem::staticCast<ListItem>(event_info);
        MSG_ASSERT(item, "Item is null");
 
        if (item) {
@@ -289,7 +289,7 @@ bool ListView::getMultiSelection() const
 
 void ListView::on_item_selected_cb(void *data, Evas_Object *obj, void *event_info)
 {
-       ListItem *item = ListItem::staticCast<ListItem*>(event_info);
+       ListItem *item = ListItem::staticCast<ListItem>(event_info);
 
        item->setSelected(false);
        if (item->getOwner()->getCheckMode() && item->isCheckable()) {
@@ -302,19 +302,19 @@ void ListView::on_item_selected_cb(void *data, Evas_Object *obj, void *event_inf
 
 void ListView::on_realized_cb(void *data, Evas_Object *obj, void *event_info)
 {
-       ListItem *item = ListItem::staticCast<ListItem*>(event_info);
+       ListItem *item = ListItem::staticCast<ListItem>(event_info);
        item->onRealized(*item);
 }
 
 void ListView::on_unrealized_cb(void *data, Evas_Object *obj, void *event_info)
 {
-       ListItem *item = ListItem::staticCast<ListItem*>(event_info);
+       ListItem *item = ListItem::staticCast<ListItem>(event_info);
        item->onUnrealized(*item);
 }
 
 void ListView::on_longpressed_cb(void *data, Evas_Object *obj, void *event_info)
 {
-       ListItem *item = ListItem::staticCast<ListItem*>(event_info);
+       ListItem *item = ListItem::staticCast<ListItem>(event_info);
        item->setSelected(false);
        if (!item->getOwner()->getCheckMode())
                notifyListener(data, obj, event_info, &IListViewListener::onListItemLongPressed);
index 5e9c791..50d59c2 100644 (file)
@@ -73,7 +73,7 @@ std::vector<MbeRecipientItem*> MbeRecipientsView::getItems() const
 
 MbeRecipientItem *MbeRecipientsView::getSelectedItem() const
 {
-       MbeRecipientItem *pSelected = ViewItem::staticCast<MbeRecipientItem*>(elm_multibuttonentry_selected_item_get(getEo()));
+       auto *pSelected = ViewItem::staticCast<MbeRecipientItem>(elm_multibuttonentry_selected_item_get(getEo()));
        return pSelected ? pSelected : m_pSelectedItem;
 }
 
@@ -94,7 +94,7 @@ void MbeRecipientsView::setListener(IMbeRecipientsListener *pListener)
 
 void MbeRecipientsView::onMbeItemClicked(Evas_Object *obj, void *eventInfo)
 {
-       m_pSelectedItem = ViewItem::staticCast<MbeRecipientItem*>(eventInfo);
+       m_pSelectedItem = ViewItem::staticCast<MbeRecipientItem>(eventInfo);
        if (m_pListener)
                m_pListener->onMbeItemClicked(*m_pSelectedItem);
 }
index bc5b27d..e1b62f2 100644 (file)
@@ -69,7 +69,7 @@ bool NaviFrameView::isLastFrame() const
 
 NaviFrameItem *NaviFrameView::getTopFrame() const
 {
-       return ViewItem::staticCast<NaviFrameItem*>(elm_naviframe_top_item_get(getEo()));
+       return ViewItem::staticCast<NaviFrameItem>(elm_naviframe_top_item_get(getEo()));
 }
 
 int NaviFrameView::getItemsCount() const
@@ -183,7 +183,7 @@ void NaviFrameView::onTransitionFinished(Evas_Object *obj, void *eventInfo)
        MSG_LOG("");
        m_TransitionStatus = false;
 
-       auto *transFinishedItem = ViewItem::staticCast<NaviFrameItem*>(eventInfo);
+       auto *transFinishedItem = ViewItem::staticCast<NaviFrameItem>(eventInfo);
 
        for (NaviFrameItem *item: m_ItemsToDelete) {
                if (item == transFinishedItem)
index c692dd3..84d52a4 100644 (file)
@@ -69,7 +69,7 @@ void View::setEo(Evas_Object *eo)
 
        m_pEo = eo;
        if (eo) {
-               setData(this);
+               evas_object_data_set(eo, thisKey, this);
                setEventCb(EVAS_CALLBACK_FREE);
                setEventCb(EVAS_CALLBACK_DEL);
        }
@@ -139,14 +139,9 @@ Evas_Object *View::addLayout(Evas_Object *parent, const std::string &edjePath, c
        return layout;
 }
 
-void View::setData(Evas_Object *obj, const void *data)
+View *View::getThis(const Evas_Object *obj)
 {
-       evas_object_data_set(obj, thisKey, (void*)data);
-}
-
-void *View::getData(Evas_Object *obj)
-{
-       return evas_object_data_get(obj, thisKey);
+       return static_cast<View*>(evas_object_data_get(obj, thisKey));
 }
 
 std::string Msg::markupToUtf8(const char *str)
index 22b28de..31499ec 100644 (file)
@@ -31,7 +31,7 @@ ViewItem::~ViewItem()
 void ViewItem::setElmObjItem(Elm_Object_Item *item)
 {
        m_pItem = item;
-       setData(this);
+       elm_object_item_data_set(getElmObjItem(), this);
        elm_object_item_del_cb_set(m_pItem, on_delete_cb);
        onAttached(*this);
 }
@@ -43,8 +43,7 @@ void ViewItem::destroy()
 
 void ViewItem::on_delete_cb(void *data, Evas_Object *obj, void *event_info)
 {
-       Elm_Object_Item *it = static_cast<Elm_Object_Item*>(event_info);
-       ViewItem *self = static_cast<ViewItem*>(elm_object_item_data_get(it));
+       auto *self = staticCast<ViewItem>(event_info);
        self->onViewDestroyed();
 }
 
index a545163..913a1b0 100644 (file)
@@ -401,7 +401,7 @@ void Viewer::onSaveAttachmentsItemPressed(PopupListItem &item)
 void Viewer::onRecipItemClicked(Evas_Object *obj, void *eventInfo)
 {
        MSG_LOG("");
-       MbeRecipientItem *item = ViewItem::staticCast<MbeRecipientItem*>(eventInfo);
+       auto *item = ViewItem::staticCast<MbeRecipientItem>(eventInfo);
        recipientClickHandler(item->getAddress());
 }