summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2015-01-05 15:41:37 -0200
committerVitor Sousa <vitorsousasilva@gmail.com>2015-01-05 15:52:27 -0200
commit666b0da912db102c048cd2fd5a964dedfd956b56 (patch)
tree62b8bd69247ed80673564d14ea71a88476702735
parentb713342987703e08b455b1c579084b35c41c6169 (diff)
eolian_cxx: Using eina::optional to handle parameters without @nonull property
-rw-r--r--src/bin/eolian_cxx/eolian_wrappers.hh4
-rw-r--r--src/bindings/eo_cxx/eo_cxx_interop.hh134
-rw-r--r--src/lib/eolian_cxx/eo_types.hh13
-rw-r--r--src/lib/eolian_cxx/grammar/type_generator.hh2
4 files changed, 152 insertions, 1 deletions
diff --git a/src/bin/eolian_cxx/eolian_wrappers.hh b/src/bin/eolian_cxx/eolian_wrappers.hh
index 477173959b..d1b28a6f5f 100644
--- a/src/bin/eolian_cxx/eolian_wrappers.hh
+++ b/src/bin/eolian_cxx/eolian_wrappers.hh
@@ -359,6 +359,10 @@ parameter_type(Eolian_Function_Parameter const& parameter,
359 if (!type.front().binding.empty()) 359 if (!type.front().binding.empty())
360 type.front().binding.insert(0, "const "); 360 type.front().binding.insert(0, "const ");
361 } 361 }
362 if (::eolian_parameter_is_nonull(&parameter))
363 {
364 type.is_nonull = true;
365 }
362 return type; 366 return type;
363} 367}
364 368
diff --git a/src/bindings/eo_cxx/eo_cxx_interop.hh b/src/bindings/eo_cxx/eo_cxx_interop.hh
index ddf4375cd1..ba6a473fc6 100644
--- a/src/bindings/eo_cxx/eo_cxx_interop.hh
+++ b/src/bindings/eo_cxx/eo_cxx_interop.hh
@@ -20,11 +20,27 @@ to_c(std::string const& x)
20} 20}
21 21
22inline const char* 22inline const char*
23to_c(eina::optional<std::string> const& x)
24{
25 if (!x)
26 return nullptr;
27 return x->c_str();
28}
29
30inline const char*
23to_c(efl::eina::stringshare const& x) 31to_c(efl::eina::stringshare const& x)
24{ 32{
25 return x.c_str(); 33 return x.c_str();
26} 34}
27 35
36inline const char*
37to_c(eina::optional<efl::eina::stringshare> const& x)
38{
39 if (!x)
40 return nullptr;
41 return x->c_str();
42}
43
28inline Eina_Bool 44inline Eina_Bool
29to_c(bool x) 45to_c(bool x)
30{ 46{
@@ -51,6 +67,14 @@ Eo* to_c(T const& v, typename std::enable_if<std::is_convertible<T*, ::efl::eo::
51} 67}
52 68
53template <typename T> 69template <typename T>
70Eo* to_c(eina::optional<T> const& v, typename std::enable_if<std::is_convertible<T*, ::efl::eo::concrete*>::value>::type* = 0)
71{
72 if (!v)
73 return nullptr;
74 return v->_eo_ptr();
75}
76
77template <typename T>
54Eo** to_c(T* v, typename std::enable_if<std::is_convertible<T*, ::efl::eo::concrete*>::value>::type* = 0) 78Eo** to_c(T* v, typename std::enable_if<std::is_convertible<T*, ::efl::eo::concrete*>::value>::type* = 0)
55{ 79{
56 static_assert(sizeof(T) == sizeof(Eo*), ""); 80 static_assert(sizeof(T) == sizeof(Eo*), "");
@@ -65,6 +89,15 @@ R to_native(T const& v)
65} 89}
66 90
67template <typename R, typename T> 91template <typename R, typename T>
92R to_native(eina::optional<T> const& v)
93{
94 static_assert(sizeof(T) == sizeof(R), "");
95 if (!v)
96 return nullptr;
97 return v->native_handle();
98}
99
100template <typename R, typename T>
68R to_native(T* v) 101R to_native(T* v)
69{ 102{
70 static_assert(sizeof(T) == sizeof(typename std::remove_pointer<R>::type), ""); 103 static_assert(sizeof(T) == sizeof(typename std::remove_pointer<R>::type), "");
@@ -109,6 +142,24 @@ to_cxx(Eo* x, std::tuple<std::false_type>, tag<T>)
109} 142}
110 143
111template <typename T> 144template <typename T>
145inline eina::optional<T>
146to_cxx(Eo* x, std::tuple<std::true_type>, tag<eina::optional<T> >)
147{
148 if (!x)
149 return nullptr;
150 return T(x);
151}
152
153template <typename T>
154inline eina::optional<T>
155to_cxx(Eo* x, std::tuple<std::false_type>, tag<eina::optional<T> >)
156{
157 if (!x)
158 return nullptr;
159 return T(::eo_ref(x));
160}
161
162template <typename T>
112inline T 163inline T
113to_cxx(Eo** x, std::tuple<std::false_type>, tag<T>) 164to_cxx(Eo** x, std::tuple<std::false_type>, tag<T>)
114{ 165{
@@ -137,6 +188,14 @@ to_cxx(const char* x, std::tuple<std::false_type>, tag<std::string>)
137 return std::string(x); 188 return std::string(x);
138} 189}
139 190
191inline eina::optional<std::string>
192to_cxx(const char* x, std::tuple<std::false_type>, tag<eina::optional<std::string> >)
193{
194 if (!x)
195 return nullptr;
196 return std::string(x);
197}
198
140template <typename T, typename Enable = void> 199template <typename T, typename Enable = void>
141struct traits 200struct traits
142{ 201{
@@ -165,6 +224,15 @@ to_cxx(const Eina_List* x, std::tuple<std::false_type, Args...>, tag< efl::eina:
165} 224}
166 225
167template <typename T, typename ...Args> 226template <typename T, typename ...Args>
227inline eina::optional<efl::eina::range_list<T const> >
228to_cxx(const Eina_List* x, std::tuple<std::false_type, Args...>, tag< eina::optional<efl::eina::range_list<T> > >)
229{
230 if (!x)
231 return nullptr;
232 return efl::eina::range_list<T const> {x};
233}
234
235template <typename T, typename ...Args>
168inline efl::eina::range_list<T> 236inline efl::eina::range_list<T>
169to_cxx(Eina_List* x, std::tuple<std::false_type, Args...>, tag< efl::eina::range_list<T> >) 237to_cxx(Eina_List* x, std::tuple<std::false_type, Args...>, tag< efl::eina::range_list<T> >)
170{ 238{
@@ -172,18 +240,44 @@ to_cxx(Eina_List* x, std::tuple<std::false_type, Args...>, tag< efl::eina::range
172} 240}
173 241
174template <typename T, typename ...Args> 242template <typename T, typename ...Args>
243inline eina::optional<efl::eina::range_list<T> >
244to_cxx(Eina_List* x, std::tuple<std::false_type, Args...>, tag< eina::optional<efl::eina::range_list<T> > >)
245{
246 if (!x)
247 return nullptr;
248 return efl::eina::range_list<T>{x};
249}
250
251template <typename T, typename ...Args>
175inline efl::eina::list<T> 252inline efl::eina::list<T>
176to_cxx(Eina_List* x, std::tuple<std::true_type, Args...>, tag< efl::eina::list<T> >) 253to_cxx(Eina_List* x, std::tuple<std::true_type, Args...>, tag< efl::eina::list<T> >)
177{ 254{
178 return efl::eina::list<T> {x}; 255 return efl::eina::list<T> {x};
179} 256}
180 257
258template <typename T, typename ...Args>
259inline eina::optional<efl::eina::list<T> >
260to_cxx(Eina_List* x, std::tuple<std::true_type, Args...>, tag< eina::optional<efl::eina::list<T> > >)
261{
262 if (!x)
263 return nullptr;
264 return efl::eina::list<T> {x};
265}
266
181inline eina::stringshare 267inline eina::stringshare
182to_cxx(Eina_Stringshare const* x, const std::false_type, tag<eina::stringshare>) 268to_cxx(Eina_Stringshare const* x, const std::false_type, tag<eina::stringshare>)
183{ 269{
184 return ::eina_stringshare_ref(x); 270 return ::eina_stringshare_ref(x);
185} 271}
186 272
273inline eina::optional<eina::stringshare>
274to_cxx(Eina_Stringshare const* x, const std::false_type, tag<eina::optional<eina::stringshare> >)
275{
276 if (!x)
277 return nullptr;
278 return eina::stringshare(::eina_stringshare_ref(x));
279}
280
187template <typename T, typename ...Args> 281template <typename T, typename ...Args>
188inline efl::eina::accessor<T> 282inline efl::eina::accessor<T>
189to_cxx(Eina_Accessor* x, std::tuple<std::false_type, Args...>, tag< efl::eina::accessor<T> >) 283to_cxx(Eina_Accessor* x, std::tuple<std::false_type, Args...>, tag< efl::eina::accessor<T> >)
@@ -192,6 +286,15 @@ to_cxx(Eina_Accessor* x, std::tuple<std::false_type, Args...>, tag< efl::eina::a
192} 286}
193 287
194template <typename T, typename ...Args> 288template <typename T, typename ...Args>
289inline eina::optional<efl::eina::accessor<T> >
290to_cxx(Eina_Accessor* x, std::tuple<std::false_type, Args...>, tag< eina::optional<efl::eina::accessor<T> > >)
291{
292 if (!x)
293 return nullptr;
294 return efl::eina::accessor<T>(x);
295}
296
297template <typename T, typename ...Args>
195inline efl::eina::iterator<T> 298inline efl::eina::iterator<T>
196to_cxx(Eina_Iterator* x, std::tuple<std::false_type, Args...>, tag< efl::eina::iterator<T> >) 299to_cxx(Eina_Iterator* x, std::tuple<std::false_type, Args...>, tag< efl::eina::iterator<T> >)
197{ 300{
@@ -199,6 +302,15 @@ to_cxx(Eina_Iterator* x, std::tuple<std::false_type, Args...>, tag< efl::eina::i
199} 302}
200 303
201template <typename T, typename ...Args> 304template <typename T, typename ...Args>
305inline eina::optional<efl::eina::iterator<T> >
306to_cxx(Eina_Iterator* x, std::tuple<std::false_type, Args...>, tag< eina::optional<efl::eina::iterator<T> > >)
307{
308 if (!x)
309 return nullptr;
310 return efl::eina::iterator<T>(x);
311}
312
313template <typename T, typename ...Args>
202T 314T
203to_cxx(Eo const* x, std::tuple<std::false_type, Args...>, tag< T > 315to_cxx(Eo const* x, std::tuple<std::false_type, Args...>, tag< T >
204 , typename std::enable_if<std::is_base_of<::efl::eo::concrete, T>::value>* = 0) 316 , typename std::enable_if<std::is_base_of<::efl::eo::concrete, T>::value>* = 0)
@@ -208,6 +320,17 @@ to_cxx(Eo const* x, std::tuple<std::false_type, Args...>, tag< T >
208} 320}
209 321
210template <typename T, typename ...Args> 322template <typename T, typename ...Args>
323eina::optional<T>
324to_cxx(Eo const* x, std::tuple<std::false_type, Args...>, tag< eina::optional<T> >
325 , typename std::enable_if<std::is_base_of<::efl::eo::concrete, T>::value>* = 0)
326{
327 // Workaround for erroneous constness
328 if (!x)
329 return nullptr;
330 return T{ ::eo_ref(const_cast<Eo*>(x))};
331}
332
333template <typename T, typename ...Args>
211T 334T
212to_cxx(Eo const* x, std::tuple<std::true_type, Args...>, tag< T > 335to_cxx(Eo const* x, std::tuple<std::true_type, Args...>, tag< T >
213 , typename std::enable_if<std::is_base_of<::efl::eo::concrete, T>::value>* = 0) 336 , typename std::enable_if<std::is_base_of<::efl::eo::concrete, T>::value>* = 0)
@@ -216,6 +339,17 @@ to_cxx(Eo const* x, std::tuple<std::true_type, Args...>, tag< T >
216 return T{const_cast<Eo*>(x)}; 339 return T{const_cast<Eo*>(x)};
217} 340}
218 341
342template <typename T, typename ...Args>
343eina::optional<T>
344to_cxx(Eo const* x, std::tuple<std::true_type, Args...>, tag< eina::optional<T> >
345 , typename std::enable_if<std::is_base_of<::efl::eo::concrete, T>::value>* = 0)
346{
347 // Workaround for erroneous constness
348 if (!x)
349 return nullptr;
350 return T{const_cast<Eo*>(x)};
351}
352
219template <typename T, typename U, typename O> 353template <typename T, typename U, typename O>
220T to_cxx(U object, O o) 354T to_cxx(U object, O o)
221{ 355{
diff --git a/src/lib/eolian_cxx/eo_types.hh b/src/lib/eolian_cxx/eo_types.hh
index 4fa79a4f86..42b034dcef 100644
--- a/src/lib/eolian_cxx/eo_types.hh
+++ b/src/lib/eolian_cxx/eo_types.hh
@@ -80,17 +80,21 @@ struct eolian_type_instance
80{ 80{
81 eolian_type_instance() 81 eolian_type_instance()
82 : is_out(false) 82 : is_out(false)
83 , is_nonull(false)
83 , parts() 84 , parts()
84 {} 85 {}
85 86
86 eolian_type_instance(std::initializer_list<eolian_type> il, 87 eolian_type_instance(std::initializer_list<eolian_type> il,
87 bool is_out_ = false) 88 bool is_out_ = false,
89 bool is_nonull_ = false)
88 : is_out(is_out_) 90 : is_out(is_out_)
91 , is_nonull(is_nonull_)
89 , parts(il) 92 , parts(il)
90 {} 93 {}
91 94
92 explicit eolian_type_instance(std::size_t size) 95 explicit eolian_type_instance(std::size_t size)
93 : is_out(false) 96 : is_out(false)
97 , is_nonull(false)
94 , parts(size) 98 , parts(size)
95 {} 99 {}
96 100
@@ -101,6 +105,7 @@ struct eolian_type_instance
101 eolian_type const& front() const { return parts.front(); } 105 eolian_type const& front() const { return parts.front(); }
102 106
103 bool is_out; 107 bool is_out;
108 bool is_nonull;
104 eolian_type_container parts; 109 eolian_type_container parts;
105}; 110};
106 111
@@ -145,6 +150,12 @@ type_is_class(eolian_type_instance const& type)
145 return type_is_class(type.front()); 150 return type_is_class(type.front());
146} 151}
147 152
153inline bool
154type_is_nonull(eolian_type_instance const& type)
155{
156 return type.is_nonull;
157}
158
148inline eolian_type 159inline eolian_type
149type_to_native(eolian_type const& type) 160type_to_native(eolian_type const& type)
150{ 161{
diff --git a/src/lib/eolian_cxx/grammar/type_generator.hh b/src/lib/eolian_cxx/grammar/type_generator.hh
index 2dc6681f48..5913330b42 100644
--- a/src/lib/eolian_cxx/grammar/type_generator.hh
+++ b/src/lib/eolian_cxx/grammar/type_generator.hh
@@ -93,6 +93,8 @@ operator<<(std::ostream& out, efl::eolian::grammar::reinterpret_type const& x)
93 93
94 if (x._type.is_out && type_is_binding(x._type.front())) 94 if (x._type.is_out && type_is_binding(x._type.front()))
95 res += "*"; 95 res += "*";
96 else if (!x._type.is_nonull && x._type.front().is_class)
97 res = "::efl::eina::optional< " + res + " >";
96 98
97 return out << res; 99 return out << res;
98} 100}