summaryrefslogtreecommitdiff
path: root/src/bindings/mono/eo_mono
diff options
context:
space:
mode:
authorYeongjong Lee <yj34.lee@samsung.com>2019-12-17 11:34:30 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-12-17 11:34:30 -0300
commitf90a97470d54edb20116e55739025e71cdfbbd92 (patch)
tree6b77b487baa2c4a4632fe71252438bab32434d32 /src/bindings/mono/eo_mono
parent7855a97f0d1cb0c1caac0180ae3a6a91e627ad06 (diff)
eina_mono: replace EinaAccessor and EinaIerator with IEnumerable
Summary: Eina.Accessor<T> => System.Collections.IEnumerable<T> Eina.Iterator<T> => System.Collections.IEnumerable<T> Unit test will work with D10879. ref T8486 Test Plan: meson build -Dbindings=mono,cxx -Dmono-beta=true Reviewers: lauromoura Reviewed By: lauromoura Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8486 Differential Revision: https://phab.enlightenment.org/D10878
Diffstat (limited to 'src/bindings/mono/eo_mono')
-rw-r--r--src/bindings/mono/eo_mono/iwrapper.cs86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs
index 497c7d2180..32ed323113 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -759,6 +759,92 @@ public static class Globals
759 Monitor.Exit(Efl.All.InitLock); 759 Monitor.Exit(Efl.All.InitLock);
760 } 760 }
761 761
762 internal static IEnumerable<T> AccessorToIEnumerable<T>(IntPtr accessor)
763 {
764 if (accessor == IntPtr.Zero)
765 throw new ArgumentException("accessor is null", nameof(accessor));
766
767 IntPtr data = IntPtr.Zero;
768 uint position = 0;
769
770 while (Eina.AccessorNativeFunctions.eina_accessor_data_get(accessor, position, out data))
771 {
772 yield return Eina.TraitFunctions.NativeToManaged<T>(data);
773 position += 1;
774 }
775 }
776
777 internal static IntPtr IEnumerableToAccessor<T>(IEnumerable<T> enumerable)
778 {
779 if (enumerable == null)
780 throw new ArgumentException("enumerable is null", nameof(enumerable));
781 IntPtr[] intPtrs = new IntPtr[enumerable.Count()];
782
783 int i = 0;
784 foreach (T data in enumerable)
785 {
786 intPtrs[i] = Eina.TraitFunctions.ManagedToNativeAlloc<T>(data);
787 i++;
788 }
789 IntPtr[] dataArray = intPtrs.ToArray();
790 GCHandle pinnedArray = GCHandle.Alloc(dataArray, GCHandleType.Pinned); //FIXME: Need to free.
791 return Eina.AccessorNativeFunctions.eina_carray_length_accessor_new(pinnedArray.AddrOfPinnedObject(), (uint)(IntPtr.Size), (uint)dataArray.Length);
792 }
793
794 internal static IEnumerable<T> IteratorToIEnumerable<T>(IntPtr iterator)
795 {
796 if (iterator == IntPtr.Zero)
797 throw new ArgumentException("iterator is null", nameof(iterator));
798
799 while (Eina.IteratorNativeFunctions.eina_iterator_next(iterator, out IntPtr data))
800 {
801 yield return Eina.TraitFunctions.NativeToManaged<T>(data);
802 }
803 }
804
805 internal static IntPtr IEnumerableToIterator<T>(IEnumerable<T> enumerable)
806 {
807 if (enumerable == null)
808 throw new ArgumentException("enumerable is null", nameof(enumerable));
809
810 var list = new List<IntPtr>();
811 //IntPtr[] intPtrs = new IntPtr[enumerable.Count()];
812
813 foreach (T data in enumerable)
814 {
815 list.Add(Eina.TraitFunctions.ManagedToNativeAlloc<T>(data));
816 }
817
818 IntPtr[] dataArray = list.ToArray();
819 GCHandle pinnedArray = GCHandle.Alloc(dataArray, GCHandleType.Pinned); //FIXME: Need to free.
820 return Eina.IteratorNativeFunctions.eina_carray_length_iterator_new(pinnedArray.AddrOfPinnedObject(), (uint)(IntPtr.Size), (uint)dataArray.Length);
821 }
822
823 internal static IEnumerable<T> ListToIEnumerable<T>(IntPtr list)
824 {
825 if (list == IntPtr.Zero)
826 throw new ArgumentException("list is null", nameof(list));
827
828 IntPtr l;
829
830 for (l = list; l != IntPtr.Zero; l = Eina.ListNativeFunctions.eina_list_next_custom_export_mono(l))
831 {
832 yield return Eina.TraitFunctions.NativeToManaged<T>(Eina.ListNativeFunctions.eina_list_data_get_custom_export_mono(l));
833 }
834 }
835
836 internal static IntPtr IEnumerableToList<T>(IEnumerable<T> enumerable)
837 {
838 if (enumerable == null)
839 throw new ArgumentException("enumerable is null", nameof(enumerable));
840
841 IntPtr list = IntPtr.Zero;
842 foreach (T data in enumerable)
843 {
844 list = Eina.ListNativeFunctions.eina_list_append(list, Eina.TraitFunctions.ManagedToNativeAlloc(data)); //FIXME: need to free
845 }
846 return list;
847 }
762 848
763 849
764} // Globals 850} // Globals