cxx: Add _get_wref() convenience to all classes

This allows constructs like:

  auto w_obj = obj._get_wref();
  auto cb = std::bind([w_obj]() {
    auto o = w_obj.lock();
    if (!o) return;
    o->call();
  });
  event_add(..., obj, cb);

Note: I don't like how those wref work. Close to c++ wref but far from
EFL wref.
This commit is contained in:
Jean-Philippe Andre 2017-11-02 18:14:59 +09:00
parent 88e10da36b
commit 73ec85aeff
1 changed files with 4 additions and 0 deletions

View File

@ -170,6 +170,10 @@ struct class_definition_generator
// /// @endcond
if(!as_generator(scope_tab << "/// @endcond\n").generate(sink, attributes::unused, context)) return false;
if(!as_generator( scope_tab << "::efl::eo::wref<" << string << "> _get_wref() const { "
"return ::efl::eo::wref<" << string << ">(*this); }\n"
).generate(sink, std::make_tuple(cls.cxx_name, cls.cxx_name), 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;