summaryrefslogtreecommitdiff
path: root/src/bindings/mono/eina_mono/eina_list.cs
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-09-30 23:08:44 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2019-09-30 23:09:29 -0300
commit74e79b5ae27efa7ed8f4baa1a9c1ae91cd52d178 (patch)
treecc949d7c345a8407c2d7a3c8ded7dc0a3473d12d /src/bindings/mono/eina_mono/eina_list.cs
parent16e21c331472f7e16fe264afb190027e83fe2661 (diff)
csharp: Allow improved cbs in eina comparators
Summary: Instead of receiving a callback that compares two intptrs (which is still used internally), expose a more C#-friendly delegate which is wrapped into the native one. Test Plan: run test suite Reviewers: felipealmeida, segfaultxavi, brunobelo Reviewed By: felipealmeida Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D10253
Diffstat (limited to 'src/bindings/mono/eina_mono/eina_list.cs')
-rw-r--r--src/bindings/mono/eina_mono/eina_list.cs23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/bindings/mono/eina_mono/eina_list.cs b/src/bindings/mono/eina_mono/eina_list.cs
index 9fe5e90..c65801c 100644
--- a/src/bindings/mono/eina_mono/eina_list.cs
+++ b/src/bindings/mono/eina_mono/eina_list.cs
@@ -110,6 +110,10 @@ public class List<T> : IEnumerable<T>, IDisposable
110 public bool Own {get;set;} 110 public bool Own {get;set;}
111 public bool OwnContent {get;set;} 111 public bool OwnContent {get;set;}
112 112
113 /// <summary>Delegate for comparing two elements of this list.</summary>
114 /// <returns>-1, 0 or 1 for respectively smaller, equal or larger.</returns>
115 public delegate int Compare(T a, T b);
116
113 public int Length 117 public int Length
114 { 118 {
115 get { return Count(); } 119 get { return Count(); }
@@ -256,10 +260,10 @@ public class List<T> : IEnumerable<T>, IDisposable
256 Handle = eina_list_sorted_insert(Handle, EinaCompareCb<T>(), ele); 260 Handle = eina_list_sorted_insert(Handle, EinaCompareCb<T>(), ele);
257 } 261 }
258 262
259 public void SortedInsert(Eina_Compare_Cb compareCb, T val) 263 public void SortedInsert(Compare compareCb, T val)
260 { 264 {
261 IntPtr ele = ManagedToNativeAlloc(val); 265 IntPtr ele = ManagedToNativeAlloc(val);
262 Handle = eina_list_sorted_insert(Handle, Marshal.GetFunctionPointerForDelegate(compareCb), ele); 266 Handle = eina_list_sorted_insert(Handle, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)), ele);
263 } 267 }
264 268
265 public void Sort(int limit = 0) 269 public void Sort(int limit = 0)
@@ -267,14 +271,21 @@ public class List<T> : IEnumerable<T>, IDisposable
267 Handle = eina_list_sort(Handle, (uint)limit, EinaCompareCb<T>()); 271 Handle = eina_list_sort(Handle, (uint)limit, EinaCompareCb<T>());
268 } 272 }
269 273
270 public void Sort(Eina_Compare_Cb compareCb) 274 public void Sort(Compare compareCb)
275 {
276 Handle = eina_list_sort(Handle, 0, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)));
277 }
278
279 public void Sort(int limit, Compare compareCb)
271 { 280 {
272 Handle = eina_list_sort(Handle, 0, Marshal.GetFunctionPointerForDelegate(compareCb)); 281 Handle = eina_list_sort(Handle, (uint)limit, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)));
273 } 282 }
274 283
275 public void Sort(int limit, Eina_Compare_Cb compareCb) 284 private Eina.Callbacks.EinaCompareCb GetNativeCompareCb(Compare managedCb)
276 { 285 {
277 Handle = eina_list_sort(Handle, (uint)limit, Marshal.GetFunctionPointerForDelegate(compareCb)); 286 return (IntPtr a, IntPtr b) => {
287 return managedCb(NativeToManaged<T>(a), NativeToManaged<T>(b));
288 };
278 } 289 }
279 290
280 public T Nth(int n) 291 public T Nth(int n)