summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2017-06-13 14:59:19 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-07-13 18:25:45 -0300
commit23c285d338e871ecef33aee06f863f5ec87eb2d8 (patch)
tree28ccacaebe90aae7819b2f3b05702b0bdfa37444
parentd045753e783a48ca943f89463fbcb1e1279f5943 (diff)
eina_mono: conversion traits to Inlist
-rw-r--r--src/bindings/mono/eina_mono/eina_container_common.cs93
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;
5using eina.Callbacks; 5using eina.Callbacks;
6using static eina.HashNativeFunctions; 6using static eina.HashNativeFunctions;
7using static eina.InarrayNativeFunctions; 7using static eina.InarrayNativeFunctions;
8using static eina.InlistNativeFunctions;
8using static eina.NativeCustomExportFunctions; 9using static eina.NativeCustomExportFunctions;
9using static eina.ContainerCommonData; 10using static eina.ContainerCommonData;
10 11
@@ -66,12 +67,15 @@ public interface IBaseElementTraits<T>
66{ 67{
67 IntPtr ManagedToNativeAlloc(T man); 68 IntPtr ManagedToNativeAlloc(T man);
68 IntPtr ManagedToNativeAllocRef(T man, bool refs = false); 69 IntPtr ManagedToNativeAllocRef(T man, bool refs = false);
70 IntPtr ManagedToNativeAllocInlistNode(T man);
69 IntPtr ManagedToNativeAllocInplace(T man); 71 IntPtr ManagedToNativeAllocInplace(T man);
70 void NativeFree(IntPtr nat); 72 void NativeFree(IntPtr nat);
71 void NativeFreeRef(IntPtr nat, bool unrefs = false); 73 void NativeFreeRef(IntPtr nat, bool unrefs = false);
74 void NativeFreeInlistNode(IntPtr nat);
72 void NativeFreeInplace(IntPtr nat); 75 void NativeFreeInplace(IntPtr nat);
73 void ResidueFreeInplace(IntPtr nat); 76 void ResidueFreeInplace(IntPtr nat);
74 T NativeToManaged(IntPtr nat); 77 T NativeToManaged(IntPtr nat);
78 T NativeToManagedInlistNode(IntPtr nat);
75 T NativeToManagedInplace(IntPtr nat); 79 T NativeToManagedInplace(IntPtr nat);
76 IntPtr EinaCompareCb(); 80 IntPtr EinaCompareCb();
77 IntPtr EinaFreeCb(); 81 IntPtr EinaFreeCb();
@@ -99,6 +103,17 @@ public class StringElementTraits<T> : IBaseElementTraits<T>
99 return ManagedToNativeAlloc(man); 103 return ManagedToNativeAlloc(man);
100 } 104 }
101 105
106 public IntPtr ManagedToNativeAllocInlistNode(T man)
107 {
108 var node = new InlistNode<IntPtr>();
109 node.Val = ManagedToNativeAlloc(man);
110 GCHandle pinnedData = GCHandle.Alloc(node, GCHandleType.Pinned);
111 IntPtr ptr = pinnedData.AddrOfPinnedObject();
112 IntPtr nat = efl_mono_native_alloc_copy(ptr, (uint)(Marshal.SizeOf<InlistNode<IntPtr> >()));
113 pinnedData.Free();
114 return nat;
115 }
116
102 public IntPtr ManagedToNativeAllocInplace(T man) 117 public IntPtr ManagedToNativeAllocInplace(T man)
103 { 118 {
104 return intPtrTraits.ManagedToNativeAlloc(ManagedToNativeAlloc(man)); 119 return intPtrTraits.ManagedToNativeAlloc(ManagedToNativeAlloc(man));
@@ -115,6 +130,15 @@ public class StringElementTraits<T> : IBaseElementTraits<T>
115 NativeFree(nat); 130 NativeFree(nat);
116 } 131 }
117 132
133 public void NativeFreeInlistNode(IntPtr nat)
134 {
135 if (nat == IntPtr.Zero)
136 return;
137 var node = Marshal.PtrToStructure< InlistNode<IntPtr> >(nat);
138 NativeFree(node.Val);
139 efl_mono_native_free(nat);
140 }
141
118 public void NativeFreeInplace(IntPtr nat) 142 public void NativeFreeInplace(IntPtr nat)
119 { 143 {
120 efl_mono_native_free_ref(nat); 144 efl_mono_native_free_ref(nat);
@@ -132,6 +156,17 @@ public class StringElementTraits<T> : IBaseElementTraits<T>
132 return (T)(object)Marshal.PtrToStringAuto(nat); 156 return (T)(object)Marshal.PtrToStringAuto(nat);
133 } 157 }
134 158
159 public T NativeToManagedInlistNode(IntPtr nat)
160 {
161 if (nat == IntPtr.Zero)
162 {
163 eina.Log.Error("Null pointer for Inlist node.");
164 return default(T);
165 }
166 var w = Marshal.PtrToStructure< InlistNode<IntPtr> >(nat);
167 return NativeToManaged(w.Val);
168 }
169
135 public T NativeToManagedInplace(IntPtr nat) 170 public T NativeToManagedInplace(IntPtr nat)
136 { 171 {
137 if (nat == IntPtr.Zero) 172 if (nat == IntPtr.Zero)
@@ -186,6 +221,17 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
186 return intPtrTraits.ManagedToNativeAlloc(h); 221 return intPtrTraits.ManagedToNativeAlloc(h);
187 } 222 }
188 223
224 public IntPtr ManagedToNativeAllocInlistNode(T man)
225 {
226 var node = new InlistNode<IntPtr>();
227 node.Val = ManagedToNativeAlloc(man);
228 GCHandle pinnedData = GCHandle.Alloc(node, GCHandleType.Pinned);
229 IntPtr ptr = pinnedData.AddrOfPinnedObject();
230 IntPtr nat = efl_mono_native_alloc_copy(ptr, (uint)(Marshal.SizeOf<InlistNode<IntPtr> >()));
231 pinnedData.Free();
232 return nat;
233 }
234
189 public IntPtr ManagedToNativeAllocInplace(T man) 235 public IntPtr ManagedToNativeAllocInplace(T man)
190 { 236 {
191 return intPtrTraits.ManagedToNativeAlloc(ManagedToNativeAlloc(man)); 237 return intPtrTraits.ManagedToNativeAlloc(ManagedToNativeAlloc(man));
@@ -204,6 +250,15 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
204 intPtrTraits.NativeFree(nat); 250 intPtrTraits.NativeFree(nat);
205 } 251 }
206 252
253 public void NativeFreeInlistNode(IntPtr nat)
254 {
255 if (nat == IntPtr.Zero)
256 return;
257 var node = Marshal.PtrToStructure< InlistNode<IntPtr> >(nat);
258 NativeFree(node.Val);
259 efl_mono_native_free(nat);
260 }
261
207 public void NativeFreeInplace(IntPtr nat) 262 public void NativeFreeInplace(IntPtr nat)
208 { 263 {
209 NativeFree(intPtrTraits.NativeToManaged(nat)); 264 NativeFree(intPtrTraits.NativeToManaged(nat));
@@ -221,6 +276,17 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
221 return (T) Activator.CreateInstance(concreteType, efl.eo.Globals.efl_ref(nat)); 276 return (T) Activator.CreateInstance(concreteType, efl.eo.Globals.efl_ref(nat));
222 } 277 }
223 278
279 public T NativeToManagedInlistNode(IntPtr nat)
280 {
281 if (nat == IntPtr.Zero)
282 {
283 eina.Log.Error("Null pointer for Inlist node.");
284 return default(T);
285 }
286 var w = Marshal.PtrToStructure< InlistNode<IntPtr> >(nat);
287 return NativeToManaged(w.Val);
288 }
289
224 public T NativeToManagedInplace(IntPtr nat) 290 public T NativeToManagedInplace(IntPtr nat)
225 { 291 {
226 if (nat == IntPtr.Zero) 292 if (nat == IntPtr.Zero)
@@ -262,6 +328,17 @@ public abstract class PrimitiveElementTraits<T>
262 return nat; 328 return nat;
263 } 329 }
264 330
331 public IntPtr ManagedToNativeAllocInlistNode(T man)
332 {
333 var node = new InlistNode<T>();
334 node.Val = man;
335 GCHandle pinnedData = GCHandle.Alloc(node, GCHandleType.Pinned);
336 IntPtr ptr = pinnedData.AddrOfPinnedObject();
337 IntPtr nat = efl_mono_native_alloc_copy(ptr, (uint)(Marshal.SizeOf< InlistNode<T> >()));
338 pinnedData.Free();
339 return nat;
340 }
341
265 public IntPtr ManagedToNativeAllocInplace(T man) 342 public IntPtr ManagedToNativeAllocInplace(T man)
266 { 343 {
267 return ManagedToNativeAlloc(man); 344 return ManagedToNativeAlloc(man);
@@ -272,6 +349,11 @@ public abstract class PrimitiveElementTraits<T>
272 efl_mono_native_free(nat); 349 efl_mono_native_free(nat);
273 } 350 }
274 351
352 public void NativeFreeInlistNode(IntPtr nat)
353 {
354 efl_mono_native_free(nat);
355 }
356
275 public void NativeFreeInplace(IntPtr nat) 357 public void NativeFreeInplace(IntPtr nat)
276 { 358 {
277 // Do nothing 359 // Do nothing
@@ -293,6 +375,17 @@ public abstract class PrimitiveElementTraits<T>
293 return w.Val; 375 return w.Val;
294 } 376 }
295 377
378 public T NativeToManagedInlistNode(IntPtr nat)
379 {
380 if (nat == IntPtr.Zero)
381 {
382 eina.Log.Error("Null pointer for Inlist node.");
383 return default(T);
384 }
385 var w = Marshal.PtrToStructure< InlistNode<T> >(nat);
386 return w.Val;
387 }
388
296 public T NativeToManagedInplace(IntPtr nat) 389 public T NativeToManagedInplace(IntPtr nat)
297 { 390 {
298 return NativeToManaged(nat); 391 return NativeToManaged(nat);