summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-09-28 17:48:04 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-09-28 17:50:14 -0300
commit96d3af10bf199c4a8f563503a663a0890fa1ec84 (patch)
tree499ad99c808fa70952f711863d1937cbc4c9bb76
parenta2ea2cf188ff7d00bac8aba721abd9805576e819 (diff)
eolian-cxx: Add optional parameter to lambda for unnamed proxy instantiation
-rw-r--r--src/bindings/cxx/eo_cxx/eo_cxx_interop.hh34
-rw-r--r--src/lib/eolian_cxx/grammar/class_definition.hpp8
-rw-r--r--src/tests/eolian_cxx/eolian_cxx_test_binding.cc6
3 files changed, 36 insertions, 12 deletions
diff --git a/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh b/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh
index 2f9b6382b3..d77bcf21e0 100644
--- a/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh
+++ b/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh
@@ -830,10 +830,12 @@ T convert_to_return(U& object)
830} 830}
831 831
832/// Miscellaneous 832/// Miscellaneous
833template <typename T, typename Enable = void> 833template <typename T, typename U, typename Enable = void>
834struct is_callable : std::false_type {}; 834struct is_constructor_lambda : std::false_type {};
835template <typename T> 835template <typename T, typename U>
836struct is_callable<T, decltype(std::declval<T>() ())> : std::true_type {}; 836struct is_constructor_lambda<T, U, decltype(std::declval<T>() ())> : std::true_type {};
837template <typename T, typename U>
838struct is_constructor_lambda<T, U, decltype(std::declval<T>() (std::declval<U>()))> : std::true_type {};
837 839
838template <typename P> 840template <typename P>
839inline void do_eo_add(Eo*& object, P const& parent 841inline void do_eo_add(Eo*& object, P const& parent
@@ -843,12 +845,30 @@ inline void do_eo_add(Eo*& object, P const& parent
843 object = ::_efl_add_internal_start(__FILE__, __LINE__, klass, parent._eo_ptr(), EINA_TRUE, EINA_FALSE); 845 object = ::_efl_add_internal_start(__FILE__, __LINE__, klass, parent._eo_ptr(), EINA_TRUE, EINA_FALSE);
844 object = ::_efl_add_end(object, EINA_FALSE, EINA_FALSE); 846 object = ::_efl_add_end(object, EINA_FALSE, EINA_FALSE);
845} 847}
846template <typename P, typename F> 848
847void do_eo_add(Eo*& object, P const& parent, Efl_Class const* klass, F f 849template <typename T>
850struct void_t { typedef void type; };
851
852template <typename F, typename U>
853auto call_lambda(F&& f, U&) -> typename void_t<decltype(f())>::type
854{
855 f();
856}
857
858template <typename F, typename U>
859auto call_lambda(F&& f, U& object) -> typename void_t<decltype(f(object))>::type
860{
861 f(object);
862}
863
864template <typename P, typename F, typename U>
865void do_eo_add(Eo*& object, P const& parent, Efl_Class const* klass
866 , U& proxy
867 , F&& f
848 , typename std::enable_if< eo::is_eolian_object<P>::value>::type* = 0) 868 , typename std::enable_if< eo::is_eolian_object<P>::value>::type* = 0)
849{ 869{
850 object = ::_efl_add_internal_start(__FILE__, __LINE__, klass, parent._eo_ptr(), EINA_TRUE, EINA_FALSE); 870 object = ::_efl_add_internal_start(__FILE__, __LINE__, klass, parent._eo_ptr(), EINA_TRUE, EINA_FALSE);
851 f(); 871 ::efl::eolian::call_lambda(std::forward<F>(f), proxy);
852 object = ::_efl_add_end(object, EINA_FALSE, EINA_FALSE); 872 object = ::_efl_add_end(object, EINA_FALSE, EINA_FALSE);
853} 873}
854 874
diff --git a/src/lib/eolian_cxx/grammar/class_definition.hpp b/src/lib/eolian_cxx/grammar/class_definition.hpp
index 71808a3a48..326ef23578 100644
--- a/src/lib/eolian_cxx/grammar/class_definition.hpp
+++ b/src/lib/eolian_cxx/grammar/class_definition.hpp
@@ -69,13 +69,13 @@ struct class_definition_generator
69 << scope_tab << "{\n" 69 << scope_tab << "{\n"
70 << scope_tab << scope_tab << "::efl::eolian::do_eo_add( ::efl::eo::concrete::_eo_raw, parent, _eo_class());\n" 70 << scope_tab << scope_tab << "::efl::eolian::do_eo_add( ::efl::eo::concrete::_eo_raw, parent, _eo_class());\n"
71 << scope_tab << "}\n" 71 << scope_tab << "}\n"
72 << scope_tab << "template <typename F> " << string << "( ::efl::eo::instantiate_t, F f, typename ::std::enable_if< ::efl::eolian::is_callable<F>::value>::type* = 0)\n" 72 << scope_tab << "template <typename F> " << string << "( ::efl::eo::instantiate_t, F&& f, typename ::std::enable_if< ::efl::eolian::is_constructor_lambda<F, " << string << " >::value>::type* = 0)\n"
73 << scope_tab << "{\n" 73 << scope_tab << "{\n"
74 << scope_tab << scope_tab << "::efl::eolian::do_eo_add( ::efl::eo::concrete::_eo_raw, ::efl::eo::concrete{nullptr}, _eo_class(), f);\n" 74 << scope_tab << scope_tab << "::efl::eolian::do_eo_add( ::efl::eo::concrete::_eo_raw, ::efl::eo::concrete{nullptr}, _eo_class(), *this, std::forward<F>(f));\n"
75 << scope_tab << "}\n" 75 << scope_tab << "}\n"
76 << scope_tab << "template <typename T, typename F> " << string << "( ::efl::eo::instantiate_t, T&& parent, F f, typename ::std::enable_if< ::efl::eolian::is_callable<F>::value && ::efl::eo::is_eolian_object<T>::value>::type* = 0)\n" 76 << scope_tab << "template <typename T, typename F> " << string << "( ::efl::eo::instantiate_t, T&& parent, F&& f, typename ::std::enable_if< ::efl::eolian::is_constructor_lambda<F, " << string << " >::value && ::efl::eo::is_eolian_object<T>::value>::type* = 0)\n"
77 << scope_tab << "{\n" 77 << scope_tab << "{\n"
78 << scope_tab << scope_tab << "::efl::eolian::do_eo_add( ::efl::eo::concrete::_eo_raw, parent, _eo_class(), f);\n" 78 << scope_tab << scope_tab << "::efl::eolian::do_eo_add( ::efl::eo::concrete::_eo_raw, parent, _eo_class(), *this, std::forward<F>(f));\n"
79 << scope_tab << "}\n" 79 << scope_tab << "}\n"
80 // << scope_tab << "explicit " << string << "( ::efl::eo::concrete const& parent)\n" 80 // << scope_tab << "explicit " << string << "( ::efl::eo::concrete const& parent)\n"
81 // << scope_tab << scope_tab << ": ::efl::eo::concrete( ::efl::eo::do_eo_add(parent)) {}\n" 81 // << scope_tab << scope_tab << ": ::efl::eo::concrete( ::efl::eo::do_eo_add(parent)) {}\n"
diff --git a/src/tests/eolian_cxx/eolian_cxx_test_binding.cc b/src/tests/eolian_cxx/eolian_cxx_test_binding.cc
index 90f880e319..ead856268d 100644
--- a/src/tests/eolian_cxx/eolian_cxx_test_binding.cc
+++ b/src/tests/eolian_cxx/eolian_cxx_test_binding.cc
@@ -66,7 +66,11 @@ START_TEST(eolian_cxx_test_type_generation)
66{ 66{
67 efl::eo::eo_init eo_init; 67 efl::eo::eo_init eo_init;
68 68
69 name1::name2::Type_Generation g(efl::eo::instantiate); 69 name1::name2::Type_Generation g1(efl::eo::instantiate);
70 name1::name2::Type_Generation g2(efl::eo::instantiate
71 , [] {});
72 name1::name2::Type_Generation g3(efl::eo::instantiate
73 , [] (name1::name2::Type_Generation) {});
70} 74}
71END_TEST 75END_TEST
72 76