cxx: Implement proper part support (wrt. refs)
authorJean-Philippe Andre <jp.andre@samsung.com>
Thu, 23 Nov 2017 04:51:10 +0000 (13:51 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Tue, 5 Dec 2017 01:14:03 +0000 (10:14 +0900)
It's VERY hacky, but works as expected: no leak, no extra unref. This is
a lucky case of simply overriding efl_part() implementation in C++,
without having to modify the declaration.

src/Makefile_Cxx.am
src/examples/elementary/bg_cxx_example_02.cc
src/lib/efl/Efl.hh
src/lib/efl/cxx/efl_part_impl.hh [new file with mode: 0644]

index cf99ea3..74ac8f7 100644 (file)
@@ -34,7 +34,7 @@ CLEANFILES += $(elementary_eolian_cxx_hh) $(elementary_eolian_cxx_impl_hh) lib/e
 ### Efl C++
 installed_eflcxxmainheadersdir = $(includedir)/efl-cxx-@VMAJ@/
 nodist_installed_eflcxxmainheaders_DATA = $(efl_eolian_cxx_hh) $(efl_eolian_cxx_impl_hh) lib/efl/Efl.eo.hh
-dist_installed_eflcxxmainheaders_DATA = lib/efl/Efl.hh
+dist_installed_eflcxxmainheaders_DATA = lib/efl/Efl.hh lib/efl/cxx/efl_part_impl.hh
 
 lib/efl/Efl.eo.hh: $(efl_eolian_files) $(_EOLIAN_CXX_DEP)
        $(AM_V_EOLCXX) \
index 8ef33a8..eb71693 100644 (file)
@@ -23,10 +23,6 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
    win.text_set("Bg Image");
    win.autohide_set(true);
 
-   // FIXME: Part API needs some fixing to be nice in C++ :)
-   //efl::eo::downcast<efl::ui::win::Part>(win.part("background"))
-   //      .file_set("performance/background.png", nullptr);
-
    efl::ui::Bg bg(instantiate, win);
    bg.scale_type_set(EFL_UI_IMAGE_SCALE_TYPE_FILL);
    bg.file_set("performance/background.png", nullptr);
index 20dfc1a..a7efc5f 100644 (file)
@@ -3,7 +3,12 @@
 
 #ifdef EFL_BETA_API_SUPPORT
 
+#define EFL_PART_IMPL_HH
+#define EFL_OBJECT_BETA
+#define EFL_OBJECT_PROTECTED
+
 #include <Efl.eo.hh>
+#include "cxx/efl_part_impl.hh"
 
 #endif
 #endif
diff --git a/src/lib/efl/cxx/efl_part_impl.hh b/src/lib/efl/cxx/efl_part_impl.hh
new file mode 100644 (file)
index 0000000..c1c99e7
--- /dev/null
@@ -0,0 +1,26 @@
+//#ifndef EFL_PART_IMPL_HH
+//#define EFL_PART_IMPL_HH
+
+namespace efl {
+inline ::efl::eolian::return_traits< ::efl::Object>::type Part::part( ::efl::eolian::in_traits< ::efl::eina::string_view>::type name) const
+{
+   Eo *handle = ::efl_part(this->_eo_ptr(), name.c_str());
+   ::efl_auto_unref_set(handle, false);
+   return ::efl::Object{handle};
+}
+}
+
+namespace eo_cxx {
+namespace efl { 
+inline ::efl::eolian::return_traits< ::efl::Object>::type Part::part( ::efl::eolian::in_traits< ::efl::eina::string_view>::type name) const
+{
+   Eo *handle = ::efl_part(this->_eo_ptr(), name.c_str());
+   ::efl_auto_unref_set(handle, false);
+   return ::efl::Object{handle};
+}
+inline efl::Part::operator ::efl::Part() const { return *static_cast< ::efl::Part const*>(static_cast<void const*>(this)); }
+inline efl::Part::operator ::efl::Part&() { return *static_cast< ::efl::Part*>(static_cast<void*>(this)); }
+inline efl::Part::operator ::efl::Part const&() const { return *static_cast< ::efl::Part const*>(static_cast<void const*>(this)); }
+} }
+
+//#endif