summaryrefslogtreecommitdiff
path: root/src/bindings/cxx/eo_cxx/eo_event.hh
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-06 02:54:36 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-06 02:54:36 -0300
commit2a3d7860dbc11458425e162cd69ee399e9025251 (patch)
tree84c5b21b644c4cf8806a8eee07b4ed81922c92b4 /src/bindings/cxx/eo_cxx/eo_event.hh
parent4d1b3191d94fcc70472552b1bb554984a9cb0288 (diff)
eolian-cxx: Rewrite to accomodate new features of the C++ binding
Diffstat (limited to 'src/bindings/cxx/eo_cxx/eo_event.hh')
-rw-r--r--src/bindings/cxx/eo_cxx/eo_event.hh71
1 files changed, 60 insertions, 11 deletions
diff --git a/src/bindings/cxx/eo_cxx/eo_event.hh b/src/bindings/cxx/eo_cxx/eo_event.hh
index 320bfc9cba..2120121cd8 100644
--- a/src/bindings/cxx/eo_cxx/eo_event.hh
+++ b/src/bindings/cxx/eo_cxx/eo_event.hh
@@ -8,11 +8,13 @@
8 8
9#include <Eo.h> 9#include <Eo.h>
10#include <Ecore.h> 10#include <Ecore.h>
11#include "eo_concrete.hh"
12#include "eo_cxx_interop.hh"
11 13
12#include <functional> 14#include <functional>
13#include <memory> 15#include <memory>
14 16
15namespace efl { namespace eo { 17namespace efl { namespace eolian {
16 18
17typedef ::Eo_Callback_Priority callback_priority; 19typedef ::Eo_Callback_Priority callback_priority;
18namespace callback_priorities 20namespace callback_priorities
@@ -121,30 +123,77 @@ signal_connection make_signal_connection(std::unique_ptr<F>& data, Eo* eo, ::Eo_
121 123
122namespace _detail { 124namespace _detail {
123 125
124template <typename T, typename F> 126template <typename T, typename P, typename F>
125Eina_Bool really_call_event(T& wrapper, F& f, Eo_Event_Description const& desc, void *info 127Eina_Bool really_call_event(T& wrapper, F& f, void *, std::true_type, std::true_type)
126 , std::true_type)
127{ 128{
128 f(wrapper, desc, info); 129 f(wrapper);
129 return true; 130 return true;
130} 131}
131template <typename T, typename F> 132template <typename T, typename P, typename F>
132Eina_Bool really_call_event(T& wrapper, F& f, Eo_Event_Description const& desc, void *info 133Eina_Bool really_call_event(T& wrapper, F& f, void *info, std::true_type, std::false_type)
133 , std::false_type) 134{
135 f(wrapper, convert_to_event<P>(info));
136 return true;
137}
138template <typename T, typename P, typename F>
139Eina_Bool really_call_event(T& wrapper, F& f, void *, std::false_type, std::true_type)
134{ 140{
135 return f(wrapper, desc, info); 141 return f(wrapper);
142}
143template <typename T, typename P, typename F>
144Eina_Bool really_call_event(T& wrapper, F& f, void *info, std::false_type, std::false_type)
145{
146 return f(wrapper, convert_to_event<P>(info));
136} 147}
137 148
149template <typename T, typename P, typename F, typename Enable = void>
150struct is_void;
151template <typename T, typename P, typename F>
152struct is_void<T, P, F, typename std::enable_if
153 <std::is_void<decltype(std::declval<F>()(std::declval<T>(), std::declval<P>()))>::value>::type>
154 : std::true_type {};
155template <typename T, typename P, typename F>
156struct is_void<T, P, F, typename std::enable_if
157 <!std::is_void<decltype(std::declval<F>()(std::declval<T>(), std::declval<P>()))>::value>::type>
158 : std::false_type {};
159template <typename T, typename F>
160struct is_void<T, void, F, typename std::enable_if
161 <std::is_void<decltype(std::declval<F>()(std::declval<T>()))>::value>::type>
162 : std::true_type {};
138template <typename T, typename F> 163template <typename T, typename F>
164struct is_void<T, void, F, typename std::enable_if
165 <!std::is_void<decltype(std::declval<F>()(std::declval<T>()))>::value>::type>
166 : std::false_type {};
167
168template <typename T, typename P, typename F>
139Eina_Bool 169Eina_Bool
140event_callback(void *data, ::Eo_Event const* event) 170event_callback(void *data, ::Eo_Event const* event)
141{ 171{
142 T wrapper(::eo_ref(event->object)); 172 T wrapper(::eo_ref(event->object));
143 F *f = static_cast<F*>(data); 173 F *f = static_cast<F*>(data);
144 return _detail::really_call_event(wrapper, *f, *event->desc, event->info 174 return _detail::really_call_event<T, P>
145 , std::is_void<decltype((*f)(wrapper, *event->desc, event->info))>()); 175 (wrapper, *f, event->info, is_void<T, P, F>(), std::is_void<P>{});
176}
146} 177}
147 178
179template <typename Event, typename Object, typename F>
180signal_connection event_add(Event event, Object object, F&& function)
181{
182 static_assert((eo::is_eolian_object<Object>::value), "Type is not an object");
183
184 typedef typename std::remove_reference<F>::type function_type;
185 std::unique_ptr<function_type> f(new function_type(std::forward<F>(function)));
186
187 ::eo_event_callback_priority_add
188 (object._eo_ptr(), event.description(), 0
189 , static_cast<Eo_Event_Cb>
190 (&_detail::event_callback<Object, typename Event::parameter_type, function_type>)
191 , f.get());
192 return make_signal_connection
193 (f, object._eo_ptr()
194 , static_cast<Eo_Event_Cb>
195 (&_detail::event_callback<Object, typename Event::parameter_type, function_type>)
196 , event.description());
148} 197}
149 198
150} } 199} }