From e7009b77a235ece2bbcba24c4fc6e2b719a2ab8d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Andre Date: Thu, 2 Nov 2017 18:39:47 +0900 Subject: [PATCH] cxx: Add experimental "easy" way to use wref I hid it behind ifdef for now as I'm very much unsure of what I'm doing. This whole modern C++ thing is still weird to me :) Prerequisite: #define EFL_CXX_WREF_EASY This allows constructs such as: auto wobj = obj._get_wref(); std::cout << wobj->text_get() << std::endl; --- src/bindings/cxx/eo_cxx/eo_wref.hh | 12 ++++++++++++ src/lib/eolian_cxx/grammar/class_definition.hpp | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/src/bindings/cxx/eo_cxx/eo_wref.hh b/src/bindings/cxx/eo_cxx/eo_wref.hh index e0f9c7bf82..124b1da3b7 100644 --- a/src/bindings/cxx/eo_cxx/eo_wref.hh +++ b/src/bindings/cxx/eo_cxx/eo_wref.hh @@ -123,6 +123,18 @@ struct wref return *this; } +#ifdef EFL_CXX_WREF_EASY + T operator->() const { + if (!_eo_wref) return T(nullptr); + return T(detail::ref(_eo_wref)); + } + + T operator*() const { + if (!_eo_wref) return T(nullptr); + return T(detail::ref(_eo_wref)); + } +#endif + private: void _add() { diff --git a/src/lib/eolian_cxx/grammar/class_definition.hpp b/src/lib/eolian_cxx/grammar/class_definition.hpp index 320d806398..54df3301a6 100644 --- a/src/lib/eolian_cxx/grammar/class_definition.hpp +++ b/src/lib/eolian_cxx/grammar/class_definition.hpp @@ -174,6 +174,13 @@ struct class_definition_generator "return ::efl::eo::wref<" << string << ">(*this); }\n" ).generate(sink, std::make_tuple(cls.cxx_name, cls.cxx_name), context)) return false; + if(!as_generator("#ifdef EFL_CXX_WREF_EASY\n").generate(sink, attributes::unused, context)) return false; + if(!as_generator( scope_tab << "const " << string << "* operator->() const { return this; }\n" + ).generate(sink, std::make_tuple(cls.cxx_name, cls.cxx_name), context)) return false; + if(!as_generator( scope_tab << string << "* operator->() { return this; }\n" + ).generate(sink, std::make_tuple(cls.cxx_name, cls.cxx_name), context)) return false; + if(!as_generator("#endif \n").generate(sink, attributes::unused, context)) return false; + if(!as_generator( scope_tab << "::efl::eo::concrete const& _get_concrete() const { return *this; }\n" << scope_tab << "::efl::eo::concrete& _get_concrete() { return *this; }\n" ).generate(sink, attributes::unused, context)) return false;