jpeg pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=258a214e0f88915fce7651d4de595a2863716e40

commit 258a214e0f88915fce7651d4de595a2863716e40
Author: Jean-Philippe Andre <jp.an...@samsung.com>
Date:   Fri Nov 10 19:04:23 2017 +0900

    cxx: Add event_cb_add functions to events
    
    This enables a syntax like:
    
      button.clicked_event_cb_add([]() { std::cout << "Hello" << std::endl; });
    
    I could not manage to pass the std::placeholders inside the template,
    depending on whether the lambda has arguments or not. Not sure if
    that's even possible.
---
 src/lib/eolian_cxx/grammar/class_definition.hpp | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/lib/eolian_cxx/grammar/class_definition.hpp 
b/src/lib/eolian_cxx/grammar/class_definition.hpp
index 13349d4007..295662f94d 100644
--- a/src/lib/eolian_cxx/grammar/class_definition.hpp
+++ b/src/lib/eolian_cxx/grammar/class_definition.hpp
@@ -156,6 +156,24 @@ struct class_definition_generator
                 << scope_tab << "} const " << string_replace(',', '_') << 
"_event;\n"
              ))).generate(sink, std::vector<attributes::event_def>{e}, 
context))
             return false;
+          if (!as_generator(
+                 scope_tab << "template <typename F>\n"
+                 << scope_tab << "typename 
std::enable_if<std::is_bind_expression<F>::value, 
::efl::eolian::signal_connection>::type\n"
+                 << scope_tab << string_replace(',', '_') << "_event_cb_add(F 
function)\n"
+                 << scope_tab << "{\n"
+                 << scope_tab << scope_tab << "return 
::efl::eolian::event_add(" << string_replace(',', '_') << "_event, *this, 
function);\n"
+                 << scope_tab << "}\n")
+              .generate(sink, std::make_tuple(e.name, e.name), context))
+            return false;
+          if (!as_generator(
+                 scope_tab << "template <typename F>\n"
+                 << scope_tab << "typename 
std::enable_if<!std::is_bind_expression<F>::value, 
::efl::eolian::signal_connection>::type\n"
+                 << scope_tab << string_replace(',', '_') << "_event_cb_add(F 
function)\n"
+                 << scope_tab << "{\n"
+                 << scope_tab << scope_tab << "return 
::efl::eolian::event_add(" << string_replace(',', '_') << "_event, *this, 
std::bind(function));\n"
+                 << scope_tab << "}\n")
+              .generate(sink, std::make_tuple(e.name, e.name), context))
+            return false;
           if (e.beta && !as_generator("#endif\n").generate(sink, 
attributes::unused, context))
             return false;
           if (e.protect && !as_generator("#endif\n").generate(sink, 
attributes::unused, context))

-- 


Reply via email to