diff options
author | Vitor Sousa <vitorsousasilva@gmail.com> | 2017-06-13 14:59:19 -0300 |
---|---|---|
committer | Vitor Sousa <vitorsousasilva@gmail.com> | 2017-06-20 14:33:12 -0300 |
commit | f4c2aa0da1206e00ed6713070e97ea282a756c51 (patch) | |
tree | a5fbbdfaeeee4852b673d382d074c84b48b2f6dc | |
parent | aae735d675524f1755af31ab41350d35f78ab3ee (diff) | |
download | efl-f4c2aa0da1206e00ed6713070e97ea282a756c51.tar.gz |
eina_mono: conversion traits to Inlist
-rw-r--r-- | src/bindings/mono/eina_mono/eina_container_common.cs | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/bindings/mono/eina_mono/eina_container_common.cs b/src/bindings/mono/eina_mono/eina_container_common.cs index 17b59cbea1..f9b51b5340 100644 --- a/src/bindings/mono/eina_mono/eina_container_common.cs +++ b/src/bindings/mono/eina_mono/eina_container_common.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using eina.Callbacks; using static eina.HashNativeFunctions; using static eina.InarrayNativeFunctions; +using static eina.InlistNativeFunctions; using static eina.NativeCustomExportFunctions; using static eina.ContainerCommonData; @@ -66,12 +67,15 @@ public interface IBaseElementTraits<T> { IntPtr ManagedToNativeAlloc(T man); IntPtr ManagedToNativeAllocRef(T man, bool refs = false); + IntPtr ManagedToNativeAllocInlistNode(T man); IntPtr ManagedToNativeAllocInplace(T man); void NativeFree(IntPtr nat); void NativeFreeRef(IntPtr nat, bool unrefs = false); + void NativeFreeInlistNode(IntPtr nat); void NativeFreeInplace(IntPtr nat); void ResidueFreeInplace(IntPtr nat); T NativeToManaged(IntPtr nat); + T NativeToManagedInlistNode(IntPtr nat); T NativeToManagedInplace(IntPtr nat); IntPtr EinaCompareCb(); IntPtr EinaFreeCb(); @@ -99,6 +103,17 @@ public class StringElementTraits<T> : IBaseElementTraits<T> return ManagedToNativeAlloc(man); } + public IntPtr ManagedToNativeAllocInlistNode(T man) + { + var node = new InlistNode<IntPtr>(); + node.Val = ManagedToNativeAlloc(man); + GCHandle pinnedData = GCHandle.Alloc(node, GCHandleType.Pinned); + IntPtr ptr = pinnedData.AddrOfPinnedObject(); + IntPtr nat = efl_mono_native_alloc_copy(ptr, (uint)(Marshal.SizeOf<InlistNode<IntPtr> >())); + pinnedData.Free(); + return nat; + } + public IntPtr ManagedToNativeAllocInplace(T man) { return intPtrTraits.ManagedToNativeAlloc(ManagedToNativeAlloc(man)); @@ -115,6 +130,15 @@ public class StringElementTraits<T> : IBaseElementTraits<T> NativeFree(nat); } + public void NativeFreeInlistNode(IntPtr nat) + { + if (nat == IntPtr.Zero) + return; + var node = Marshal.PtrToStructure< InlistNode<IntPtr> >(nat); + NativeFree(node.Val); + efl_mono_native_free(nat); + } + public void NativeFreeInplace(IntPtr nat) { efl_mono_native_free_ref(nat); @@ -132,6 +156,17 @@ public class StringElementTraits<T> : IBaseElementTraits<T> return (T)(object)Marshal.PtrToStringAuto(nat); } + public T NativeToManagedInlistNode(IntPtr nat) + { + if (nat == IntPtr.Zero) + { + eina.Log.Error("Null pointer for Inlist node."); + return default(T); + } + var w = Marshal.PtrToStructure< InlistNode<IntPtr> >(nat); + return NativeToManaged(w.Val); + } + public T NativeToManagedInplace(IntPtr nat) { if (nat == IntPtr.Zero) @@ -186,6 +221,17 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T> return intPtrTraits.ManagedToNativeAlloc(h); } + public IntPtr ManagedToNativeAllocInlistNode(T man) + { + var node = new InlistNode<IntPtr>(); + node.Val = ManagedToNativeAlloc(man); + GCHandle pinnedData = GCHandle.Alloc(node, GCHandleType.Pinned); + IntPtr ptr = pinnedData.AddrOfPinnedObject(); + IntPtr nat = efl_mono_native_alloc_copy(ptr, (uint)(Marshal.SizeOf<InlistNode<IntPtr> >())); + pinnedData.Free(); + return nat; + } + public IntPtr ManagedToNativeAllocInplace(T man) { return intPtrTraits.ManagedToNativeAlloc(ManagedToNativeAlloc(man)); @@ -204,6 +250,15 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T> intPtrTraits.NativeFree(nat); } + public void NativeFreeInlistNode(IntPtr nat) + { + if (nat == IntPtr.Zero) + return; + var node = Marshal.PtrToStructure< InlistNode<IntPtr> >(nat); + NativeFree(node.Val); + efl_mono_native_free(nat); + } + public void NativeFreeInplace(IntPtr nat) { NativeFree(intPtrTraits.NativeToManaged(nat)); @@ -221,6 +276,17 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T> return (T) Activator.CreateInstance(concreteType, efl.eo.Globals.efl_ref(nat)); } + public T NativeToManagedInlistNode(IntPtr nat) + { + if (nat == IntPtr.Zero) + { + eina.Log.Error("Null pointer for Inlist node."); + return default(T); + } + var w = Marshal.PtrToStructure< InlistNode<IntPtr> >(nat); + return NativeToManaged(w.Val); + } + public T NativeToManagedInplace(IntPtr nat) { if (nat == IntPtr.Zero) @@ -262,6 +328,17 @@ public abstract class PrimitiveElementTraits<T> return nat; } + public IntPtr ManagedToNativeAllocInlistNode(T man) + { + var node = new InlistNode<T>(); + node.Val = man; + GCHandle pinnedData = GCHandle.Alloc(node, GCHandleType.Pinned); + IntPtr ptr = pinnedData.AddrOfPinnedObject(); + IntPtr nat = efl_mono_native_alloc_copy(ptr, (uint)(Marshal.SizeOf< InlistNode<T> >())); + pinnedData.Free(); + return nat; + } + public IntPtr ManagedToNativeAllocInplace(T man) { return ManagedToNativeAlloc(man); @@ -272,6 +349,11 @@ public abstract class PrimitiveElementTraits<T> efl_mono_native_free(nat); } + public void NativeFreeInlistNode(IntPtr nat) + { + efl_mono_native_free(nat); + } + public void NativeFreeInplace(IntPtr nat) { // Do nothing @@ -293,6 +375,17 @@ public abstract class PrimitiveElementTraits<T> return w.Val; } + public T NativeToManagedInlistNode(IntPtr nat) + { + if (nat == IntPtr.Zero) + { + eina.Log.Error("Null pointer for Inlist node."); + return default(T); + } + var w = Marshal.PtrToStructure< InlistNode<T> >(nat); + return w.Val; + } + public T NativeToManagedInplace(IntPtr nat) { return NativeToManaged(nat); |