summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-11-10 19:04:23 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-12-05 10:09:58 +0900
commit258a214e0f88915fce7651d4de595a2863716e40 (patch)
tree09c6e9383968b63ef922d001d118797ffc3ba513
parentdb8227a34ad616db95d319430d270c6372485e86 (diff)
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.
-rw-r--r--src/lib/eolian_cxx/grammar/class_definition.hpp18
1 files changed, 18 insertions, 0 deletions
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
156 << scope_tab << "} const " << string_replace(',', '_') << "_event;\n" 156 << scope_tab << "} const " << string_replace(',', '_') << "_event;\n"
157 ))).generate(sink, std::vector<attributes::event_def>{e}, context)) 157 ))).generate(sink, std::vector<attributes::event_def>{e}, context))
158 return false; 158 return false;
159 if (!as_generator(
160 scope_tab << "template <typename F>\n"
161 << scope_tab << "typename std::enable_if<std::is_bind_expression<F>::value, ::efl::eolian::signal_connection>::type\n"
162 << scope_tab << string_replace(',', '_') << "_event_cb_add(F function)\n"
163 << scope_tab << "{\n"
164 << scope_tab << scope_tab << "return ::efl::eolian::event_add(" << string_replace(',', '_') << "_event, *this, function);\n"
165 << scope_tab << "}\n")
166 .generate(sink, std::make_tuple(e.name, e.name), context))
167 return false;
168 if (!as_generator(
169 scope_tab << "template <typename F>\n"
170 << scope_tab << "typename std::enable_if<!std::is_bind_expression<F>::value, ::efl::eolian::signal_connection>::type\n"
171 << scope_tab << string_replace(',', '_') << "_event_cb_add(F function)\n"
172 << scope_tab << "{\n"
173 << scope_tab << scope_tab << "return ::efl::eolian::event_add(" << string_replace(',', '_') << "_event, *this, std::bind(function));\n"
174 << scope_tab << "}\n")
175 .generate(sink, std::make_tuple(e.name, e.name), context))
176 return false;
159 if (e.beta && !as_generator("#endif\n").generate(sink, attributes::unused, context)) 177 if (e.beta && !as_generator("#endif\n").generate(sink, attributes::unused, context))
160 return false; 178 return false;
161 if (e.protect && !as_generator("#endif\n").generate(sink, attributes::unused, context)) 179 if (e.protect && !as_generator("#endif\n").generate(sink, attributes::unused, context))