summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2017-06-26 17:39:43 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-07-13 18:34:55 -0300
commit7b397ae2861158adb2d65e25dd9115e709538ca0 (patch)
tree28d7dba429341d58a794a4978b5ccce69972d6ff
parent64f88ce0a4f45aa78e29cf3a7f12cbfaef7f60f7 (diff)
eina_mono: get eina.Iterator for the Eina containers (plus IEnumerable implementation for eina.Hash)
-rw-r--r--src/bindings/mono/eina_mono/eina_array.cs9
-rw-r--r--src/bindings/mono/eina_mono/eina_hash.cs60
-rw-r--r--src/bindings/mono/eina_mono/eina_inarray.cs10
-rw-r--r--src/bindings/mono/eina_mono/eina_inlist.cs6
-rw-r--r--src/bindings/mono/eina_mono/eina_list.cs11
5 files changed, 82 insertions, 14 deletions
diff --git a/src/bindings/mono/eina_mono/eina_array.cs b/src/bindings/mono/eina_mono/eina_array.cs
index a6166e04f8..4fff37d09e 100644
--- a/src/bindings/mono/eina_mono/eina_array.cs
+++ b/src/bindings/mono/eina_mono/eina_array.cs
@@ -20,6 +20,9 @@ public static class ArrayNativeFunctions
20 [DllImport("eina")] [return: MarshalAs(UnmanagedType.U1)] public static extern bool 20 [DllImport("eina")] [return: MarshalAs(UnmanagedType.U1)] public static extern bool
21 eina_array_push(IntPtr array, IntPtr data); 21 eina_array_push(IntPtr array, IntPtr data);
22 22
23 [DllImport("eina")] public static extern IntPtr
24 eina_array_iterator_new(IntPtr array);
25
23 [DllImport("eflcustomexportsmono")] public static extern void 26 [DllImport("eflcustomexportsmono")] public static extern void
24 eina_array_free_generic_custom_export_mono(IntPtr array); 27 eina_array_free_generic_custom_export_mono(IntPtr array);
25 [DllImport("eflcustomexportsmono")] public static extern void 28 [DllImport("eflcustomexportsmono")] public static extern void
@@ -270,6 +273,12 @@ public class Array<T> : IEnumerable<T>, IDisposable
270 return true; 273 return true;
271 } 274 }
272 275
276
277 public eina.Iterator<T> GetIterator()
278 {
279 return new eina.Iterator<T>(eina_array_iterator_new(Handle), true, false);
280 }
281
273 public IEnumerator<T> GetEnumerator() 282 public IEnumerator<T> GetEnumerator()
274 { 283 {
275 int len = Length; 284 int len = Length;
diff --git a/src/bindings/mono/eina_mono/eina_hash.cs b/src/bindings/mono/eina_mono/eina_hash.cs
index 6922ea739c..48b0d4e867 100644
--- a/src/bindings/mono/eina_mono/eina_hash.cs
+++ b/src/bindings/mono/eina_mono/eina_hash.cs
@@ -3,12 +3,21 @@ using System.Runtime.InteropServices;
3using System.Collections.Generic; 3using System.Collections.Generic;
4 4
5using static eina.TraitFunctions; 5using static eina.TraitFunctions;
6using static eina.IteratorNativeFunctions;
6using static eina.HashNativeFunctions; 7using static eina.HashNativeFunctions;
7using eina.Callbacks; 8using eina.Callbacks;
8 9
9namespace eina 10namespace eina
10{ 11{
11 12
13[StructLayout(LayoutKind.Sequential)]
14public struct HashTupleNative
15{
16 public IntPtr key;
17 public IntPtr data;
18 public uint key_length;
19}
20
12public static class HashNativeFunctions 21public static class HashNativeFunctions
13{ 22{
14 [DllImport("eina")] public static extern IntPtr 23 [DllImport("eina")] public static extern IntPtr
@@ -92,6 +101,15 @@ public static class HashNativeFunctions
92 [DllImport("eina")] public static extern IntPtr 101 [DllImport("eina")] public static extern IntPtr
93 eina_hash_modify_by_hash(IntPtr hash, IntPtr key, int key_length, int key_hash, IntPtr data); 102 eina_hash_modify_by_hash(IntPtr hash, IntPtr key, int key_length, int key_hash, IntPtr data);
94 103
104 [DllImport("eina")] public static extern IntPtr
105 eina_hash_iterator_key_new(IntPtr hash);
106
107 [DllImport("eina")] public static extern IntPtr
108 eina_hash_iterator_data_new(IntPtr hash);
109
110 [DllImport("eina")] public static extern IntPtr
111 eina_hash_iterator_tuple_new(IntPtr hash);
112
95 [DllImport("eina")] public static extern void 113 [DllImport("eina")] public static extern void
96 eina_hash_foreach(IntPtr hash, IntPtr func, IntPtr fdata); 114 eina_hash_foreach(IntPtr hash, IntPtr func, IntPtr fdata);
97 115
@@ -107,7 +125,7 @@ public static class HashNativeFunctions
107 eina_hash_superfast(string key, int len); 125 eina_hash_superfast(string key, int len);
108} 126}
109 127
110public class Hash<TKey, TValue> : IDisposable 128public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDisposable
111{ 129{
112 public IntPtr Handle {get; set;} = IntPtr.Zero; 130 public IntPtr Handle {get; set;} = IntPtr.Zero;
113 public bool Own {get; set;} 131 public bool Own {get; set;}
@@ -342,19 +360,33 @@ public class Hash<TKey, TValue> : IDisposable
342 return eina_hash_population(Handle); 360 return eina_hash_population(Handle);
343 } 361 }
344 362
345// TODO: implement when iterator is ready 363 public eina.Iterator<TKey> GetKeyIterator()
346// public IEnumerator<KeyValuePair<TKey, TValue> > GetEnumerator() 364 {
347// { 365 return new eina.Iterator<TKey>(eina_hash_iterator_key_new(Handle), true, false);
348// for (IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr)) 366 }
349// { 367
350// yield return NativeToManaged<T>(InternalDataGet(curr)); 368 public eina.Iterator<TValue> GetValueIterator()
351// } 369 {
352// } 370 return new eina.Iterator<TValue>(eina_hash_iterator_data_new(Handle), true, false);
353// 371 }
354// System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 372
355// { 373 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
356// return this.GetEnumerator(); 374 {
357// } 375 IntPtr itr = eina_hash_iterator_tuple_new(Handle);
376 for (IntPtr tuplePtr; !eina_iterator_next(itr, out tuplePtr);)
377 {
378 var tuple = Marshal.PtrToStructure<eina.HashTupleNative>(tuplePtr);
379 var key = NativeToManaged<TKey>(tuple.key);
380 var val = NativeToManaged<TValue>(tuple.data);
381 yield return new KeyValuePair<TKey, TValue>(key, val);
382 }
383 eina_iterator_free(itr);
384 }
385
386 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
387 {
388 return this.GetEnumerator();
389 }
358} 390}
359 391
360} 392}
diff --git a/src/bindings/mono/eina_mono/eina_inarray.cs b/src/bindings/mono/eina_mono/eina_inarray.cs
index ef3acc1d62..966bd9d097 100644
--- a/src/bindings/mono/eina_mono/eina_inarray.cs
+++ b/src/bindings/mono/eina_mono/eina_inarray.cs
@@ -296,6 +296,16 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
296 return true; 296 return true;
297 } 297 }
298 298
299 public eina.Iterator<T> GetIterator()
300 {
301 return new eina.Iterator<T>(eina_inarray_iterator_new(Handle), true, false);
302 }
303
304 public eina.Iterator<T> GetReversedIterator()
305 {
306 return new eina.Iterator<T>(eina_inarray_iterator_reversed_new(Handle), true, false);
307 }
308
299 public IEnumerator<T> GetEnumerator() 309 public IEnumerator<T> GetEnumerator()
300 { 310 {
301 int len = Length; 311 int len = Length;
diff --git a/src/bindings/mono/eina_mono/eina_inlist.cs b/src/bindings/mono/eina_mono/eina_inlist.cs
index b95a5f0dc3..ab5468e903 100644
--- a/src/bindings/mono/eina_mono/eina_inlist.cs
+++ b/src/bindings/mono/eina_mono/eina_inlist.cs
@@ -290,6 +290,12 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
290 Append(v); 290 Append(v);
291 } 291 }
292 292
293
294 public eina.Iterator<T> GetIterator()
295 {
296 return new eina.Iterator<T>(eina_inlist_iterator_new(Handle), true, false);
297 }
298
293 public IEnumerator<T> GetEnumerator() 299 public IEnumerator<T> GetEnumerator()
294 { 300 {
295 for(IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr)) 301 for(IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr))
diff --git a/src/bindings/mono/eina_mono/eina_list.cs b/src/bindings/mono/eina_mono/eina_list.cs
index 7abd8bb99c..afb10dfe47 100644
--- a/src/bindings/mono/eina_mono/eina_list.cs
+++ b/src/bindings/mono/eina_mono/eina_list.cs
@@ -324,6 +324,17 @@ public class List<T> : IEnumerable<T>, IDisposable
324 Append(v); 324 Append(v);
325 } 325 }
326 326
327
328 public eina.Iterator<T> GetIterator()
329 {
330 return new eina.Iterator<T>(eina_list_iterator_new(Handle), true, false);
331 }
332
333 public eina.Iterator<T> GetReversedIterator()
334 {
335 return new eina.Iterator<T>(eina_list_iterator_reversed_new(Handle), true, false);
336 }
337
327 public IEnumerator<T> GetEnumerator() 338 public IEnumerator<T> GetEnumerator()
328 { 339 {
329 for(IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr)) 340 for(IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr))