[EflSharp] Update Circle and efl cs files (#819)
[platform/core/csapi/tizenfx.git] / internals / src / EflSharp / EflSharp / efl / eina_container_common.cs
1 #pragma warning disable 1591
2
3 using System;
4 using System.Linq;
5 using System.Runtime.InteropServices;
6 using System.Collections.Generic;
7 using System.Reflection;
8
9 using Eina.Callbacks;
10 using static Eina.HashNativeFunctions;
11 using static Eina.InarrayNativeFunctions;
12 using static Eina.InlistNativeFunctions;
13 using static Eina.NativeCustomExportFunctions;
14
15 namespace Eina
16 {
17
18 public enum ElementType
19 {
20     NumericType,
21     StringType,
22     ObjectType
23 };
24
25 [StructLayout(LayoutKind.Sequential)]
26 public struct InlistMem
27 {
28     public IntPtr next {get;set;}
29     public IntPtr prev {get;set;}
30     public IntPtr last {get;set;}
31 }
32
33 [StructLayout(LayoutKind.Sequential)]
34 public struct InlistNode<T>
35 {
36     public InlistMem __in_list {get;set;}
37     public T Val {get;set;}
38 }
39
40 public interface IBaseElementTraits<T>
41 {
42     IntPtr ManagedToNativeAlloc(T man);
43     IntPtr ManagedToNativeAllocInlistNode(T man);
44     void ManagedToNativeCopyTo(T man, IntPtr mem);
45     void NativeFree(IntPtr nat);
46     void NativeFreeInlistNodeElement(IntPtr nat);
47     void NativeFreeInlistNode(IntPtr nat, bool freeElement);
48     void NativeFreeInplace(IntPtr nat);
49     void ResidueFreeInplace(IntPtr nat);
50     T NativeToManaged(IntPtr nat);
51     T NativeToManagedInlistNode(IntPtr nat);
52     T NativeToManagedInplace(IntPtr nat);
53     IntPtr EinaCompareCb();
54     IntPtr EinaFreeCb();
55     IntPtr EinaHashNew();
56     IntPtr EinaInarrayNew(uint step);
57     IntPtr EinaHashIteratorKeyNew(IntPtr hash);
58 }
59
60 public class StringElementTraits : IBaseElementTraits<string>
61 {
62     public StringElementTraits()
63     {
64     }
65
66     public IntPtr ManagedToNativeAlloc(string man)
67     {
68         IntPtr newstring = MemoryNative.StrDup(man);
69         return newstring;
70     }
71
72     public IntPtr ManagedToNativeAllocInlistNode(string man)
73     {
74         var node = new InlistNode<IntPtr>();
75         node.Val = ManagedToNativeAlloc(man);
76         GCHandle pinnedData = GCHandle.Alloc(node, GCHandleType.Pinned);
77         IntPtr ptr = pinnedData.AddrOfPinnedObject();
78         IntPtr nat = MemoryNative.AllocCopy(ptr, Marshal.SizeOf<InlistMem>() + Marshal.SizeOf<IntPtr>());
79         pinnedData.Free();
80         return nat;
81     }
82
83     public void ManagedToNativeCopyTo(string man, IntPtr mem)
84     {
85         IntPtr stringptr = ManagedToNativeAlloc(man);
86         Marshal.WriteIntPtr(mem, stringptr);
87     }
88
89     public void NativeFree(IntPtr nat)
90     {
91         if (nat != IntPtr.Zero)
92         {
93             MemoryNative.Free(nat);
94         }
95     }
96
97     public void NativeFreeInlistNodeElement(IntPtr nat)
98     {
99         if (nat == IntPtr.Zero)
100         {
101             return;
102         }
103
104         var val = Marshal.PtrToStructure<IntPtr>
105             (nat + Marshal.SizeOf<InlistMem>());
106         NativeFree(val);
107     }
108
109     public void NativeFreeInlistNode(IntPtr nat, bool freeElement)
110     {
111         if (nat == IntPtr.Zero)
112         {
113             return;
114         }
115
116         if (freeElement)
117         {
118             NativeFreeInlistNodeElement(nat);
119         }
120
121         MemoryNative.Free(nat);
122     }
123
124     public void NativeFreeInplace(IntPtr nat)
125     {
126         MemoryNative.FreeRef(nat);
127     }
128
129     public void ResidueFreeInplace(IntPtr nat)
130     {
131     }
132
133     public string NativeToManaged(IntPtr nat)
134     {
135         if (nat == IntPtr.Zero)
136         {
137             return default(string);
138         }
139
140         return StringConversion.NativeUtf8ToManagedString(nat);
141     }
142
143     public string NativeToManagedInlistNode(IntPtr nat)
144     {
145         if (nat == IntPtr.Zero)
146         {
147             Eina.Log.Error("Null pointer for Inlist node.");
148             return default(string);
149         }
150
151         IntPtr ptr_location = nat + Marshal.SizeOf<InlistMem>();
152         return NativeToManaged(Marshal.ReadIntPtr(ptr_location));
153     }
154
155     // Strings inplaced are always a pointer, because they are variable-sized
156     public string NativeToManagedInplace(IntPtr nat)
157     {
158         if (nat == IntPtr.Zero)
159         {
160             return default(string);
161         }
162
163         nat = Marshal.ReadIntPtr(nat);
164         if (nat == IntPtr.Zero)
165         {
166             return default(string);
167         }
168
169         return NativeToManaged(nat);
170     }
171
172     public IntPtr EinaCompareCb()
173     {
174         return MemoryNative.StrCompareFuncPtrGet();
175     }
176
177     public IntPtr EinaFreeCb()
178     {
179         return MemoryNative.FreeFuncPtrGet();
180     }
181
182     public IntPtr EinaHashNew()
183     {
184         return eina_hash_string_superfast_new(IntPtr.Zero);
185     }
186
187     public IntPtr EinaInarrayNew(uint step)
188     {
189         return eina_inarray_new((uint)Marshal.SizeOf<IntPtr>(), step);
190     }
191
192     public IntPtr EinaHashIteratorKeyNew(IntPtr hash)
193     {
194         return eina_hash_iterator_key_new(hash);
195     }
196 }
197
198 public class EflObjectElementTraits<T> : IBaseElementTraits<T>
199 {
200     public IntPtr ManagedToNativeAlloc(T man)
201     {
202         IntPtr h = ((Efl.Eo.IWrapper)man).NativeHandle;
203         if (h == IntPtr.Zero)
204         {
205             return h;
206         }
207
208         return Efl.Eo.Globals.efl_ref(h);
209     }
210
211     public IntPtr ManagedToNativeAllocInlistNode(T man)
212     {
213         var node = new InlistNode<IntPtr>();
214         node.Val = ManagedToNativeAlloc(man);
215         GCHandle pinnedData = GCHandle.Alloc(node, GCHandleType.Pinned);
216         IntPtr ptr = pinnedData.AddrOfPinnedObject();
217         IntPtr nat = MemoryNative.AllocCopy(ptr, Marshal.SizeOf<InlistMem>() + Marshal.SizeOf<IntPtr>());
218         pinnedData.Free();
219         return nat;
220     }
221
222     public void ManagedToNativeCopyTo(T man, IntPtr mem)
223     {
224         IntPtr v = ManagedToNativeAlloc(man);
225         Marshal.WriteIntPtr(mem, v);
226     }
227
228     public void NativeFree(IntPtr nat)
229     {
230         if (nat != IntPtr.Zero)
231         {
232             Efl.Eo.Globals.efl_mono_thread_safe_efl_unref(nat);
233         }
234     }
235
236     public void NativeFreeRef(IntPtr nat, bool unrefs)
237     {
238         if (unrefs)
239         {
240             NativeFree(nat);
241         }
242     }
243
244     public void NativeFreeInlistNodeElement(IntPtr nat)
245     {
246         if (nat == IntPtr.Zero)
247         {
248             return;
249         }
250
251         var val = Marshal.PtrToStructure<IntPtr>
252             (nat + Marshal.SizeOf<InlistMem>());
253         NativeFree(val);
254     }
255
256     public void NativeFreeInlistNode(IntPtr nat, bool freeElement)
257     {
258         if (nat == IntPtr.Zero)
259         {
260             return;
261         }
262
263         if (freeElement)
264         {
265             NativeFreeInlistNodeElement(nat);
266         }
267
268         MemoryNative.Free(nat);
269     }
270
271     public void NativeFreeInplace(IntPtr nat)
272     {
273         NativeFree(nat);
274     }
275
276     public void ResidueFreeInplace(IntPtr nat)
277     {
278     }
279
280     public T NativeToManaged(IntPtr nat)
281     {
282         if (nat == IntPtr.Zero)
283         {
284             return default(T);
285         }
286
287         return (T) Efl.Eo.Globals.CreateWrapperFor(nat, shouldIncRef: true);
288     }
289
290     public T NativeToManagedRef(IntPtr nat)
291     {
292         if (nat == IntPtr.Zero)
293         {
294             return default(T);
295         }
296
297         return NativeToManaged(nat);
298     }
299
300     public T NativeToManagedInlistNode(IntPtr nat)
301     {
302         if (nat == IntPtr.Zero)
303         {
304             Eina.Log.Error("Null pointer for Inlist node.");
305             return default(T);
306         }
307
308         IntPtr ptr_location = nat + Marshal.SizeOf<InlistMem>();
309         return NativeToManaged(Marshal.ReadIntPtr(ptr_location));
310     }
311
312     // EFL objects inplaced are always a pointer, because they are variable-sized
313     public T NativeToManagedInplace(IntPtr nat)
314     {
315         if (nat == IntPtr.Zero)
316         {
317             return default(T);
318         }
319
320         nat = Marshal.ReadIntPtr(nat);
321         if (nat == IntPtr.Zero)
322         {
323             return default(T);
324         }
325
326         return NativeToManaged(nat);
327     }
328
329     public IntPtr EinaCompareCb()
330     {
331         return MemoryNative.PtrCompareFuncPtrGet();
332     }
333
334     public IntPtr EinaFreeCb()
335     {
336         return MemoryNative.EflUnrefFuncPtrGet();
337     }
338
339     public IntPtr EinaHashNew()
340     {
341         return eina_hash_pointer_new(IntPtr.Zero);
342     }
343
344     public IntPtr EinaInarrayNew(uint step)
345     {
346         return eina_inarray_new((uint)Marshal.SizeOf<IntPtr>(), step);
347     }
348
349     public IntPtr EinaHashIteratorKeyNew(IntPtr hash)
350     {
351         return eina_hash_iterator_ptr_key_wrapper_new_custom_export_mono(hash);
352     }
353 }
354
355 public abstract class PrimitiveElementTraits<T>
356 {
357     private Eina_Compare_Cb dlgt = null;
358
359     public IntPtr ManagedToNativeAlloc(T man)
360     {
361         return PrimitiveConversion.ManagedToPointerAlloc(man);
362     }
363
364     public IntPtr ManagedToNativeAllocInlistNode(T man)
365     {
366         var node = new InlistNode<T>();
367         node.Val = man;
368         GCHandle pinnedData = GCHandle.Alloc(node, GCHandleType.Pinned);
369         IntPtr ptr = pinnedData.AddrOfPinnedObject();
370         int Tsize = Marshal.SizeOf<T>() < Marshal.SizeOf<IntPtr>() ? Marshal.SizeOf<IntPtr>() : Marshal.SizeOf<T>();
371         IntPtr nat = MemoryNative.AllocCopy(ptr, Marshal.SizeOf<InlistMem>() + Tsize);
372         pinnedData.Free();
373         return nat;
374     }
375
376     public void NativeFree(IntPtr nat)
377     {
378         MemoryNative.Free(nat);
379     }
380
381     public void NativeFreeInlistNodeElement(IntPtr nat)
382     {
383         // Do nothing
384     }
385
386     public void NativeFreeInlistNode(IntPtr nat, bool freeElement)
387     {
388         MemoryNative.Free(nat);
389     }
390
391     public void NativeFreeInplace(IntPtr nat)
392     {
393         // Do nothing
394     }
395
396     public void ResidueFreeInplace(IntPtr nat)
397     {
398         NativeFree(nat);
399     }
400
401     public T NativeToManaged(IntPtr nat)
402     {
403         if (nat == IntPtr.Zero)
404         {
405             Eina.Log.Error("Null pointer on primitive/struct container.");
406             return default(T);
407         }
408
409         return PrimitiveConversion.PointerToManaged<T>(nat);
410     }
411
412     public T NativeToManagedRef(IntPtr nat)
413     {
414         return NativeToManaged(nat);
415     }
416
417
418     public T NativeToManagedInplace(IntPtr nat)
419     {
420         return NativeToManaged(nat);
421     }
422
423     private int PrimitiveCompareCb(IntPtr ptr1, IntPtr ptr2)
424     {
425         var m1 = (IComparable)NativeToManaged(ptr1);
426         var m2 = NativeToManaged(ptr2);
427         return m1.CompareTo(m2);
428     }
429
430     public IntPtr EinaCompareCb()
431     {
432         if (dlgt == null)
433         {
434             dlgt = new Eina_Compare_Cb(PrimitiveCompareCb);
435         }
436
437         return Marshal.GetFunctionPointerForDelegate(dlgt);
438     }
439
440     public IntPtr EinaFreeCb()
441     {
442         return MemoryNative.FreeFuncPtrGet();
443     }
444
445     public IntPtr EinaInarrayNew(uint step)
446     {
447         return eina_inarray_new((uint)Marshal.SizeOf<T>(), step);
448     }
449
450     public IntPtr EinaHashIteratorKeyNew(IntPtr hash)
451     {
452         return eina_hash_iterator_key_new(hash);
453     }
454 }
455
456 abstract public class Primitive32ElementTraits<T> : PrimitiveElementTraits<T>, IBaseElementTraits<T>
457 {
458     private static IBaseElementTraits<Int32> int32Traits = null;
459
460     public Primitive32ElementTraits()
461     {
462         if (int32Traits == null)
463         {
464             if (typeof(T) == typeof(Int32)) // avoid infinite recursion
465             {
466                 int32Traits = (IBaseElementTraits<Int32>)this;
467             }
468             else
469             {
470                 int32Traits = TraitFunctions.GetTypeTraits<Int32>();
471             }
472         }
473     }
474
475     public abstract void ManagedToNativeCopyTo(T man, IntPtr mem);
476     public abstract T NativeToManagedInlistNode(IntPtr nat);
477
478     public IntPtr ManagedToNativeAllocRef(T man, bool refs)
479     {
480         return int32Traits.ManagedToNativeAlloc(Convert.ToInt32((object)man));
481     }
482
483     public void NativeFreeRef(IntPtr nat, bool unrefs)
484     {
485         int32Traits.NativeFree(nat);
486     }
487
488     public IntPtr EinaHashNew()
489     {
490         return eina_hash_int32_new(IntPtr.Zero);
491     }
492 }
493
494 abstract public class Primitive64ElementTraits<T> : PrimitiveElementTraits<T>, IBaseElementTraits<T>
495 {
496     private static IBaseElementTraits<Int64> int64Traits = null;
497
498     public Primitive64ElementTraits()
499     {
500         if (int64Traits == null)
501         {
502             if (typeof(T) == typeof(Int64)) // avoid infinite recursion
503             {
504                 int64Traits = (IBaseElementTraits<Int64>)this;
505             }
506             else
507             {
508                 int64Traits = TraitFunctions.GetTypeTraits<Int64>();
509             }
510         }
511     }
512
513     public abstract void ManagedToNativeCopyTo(T man, IntPtr mem);
514     public abstract T NativeToManagedInlistNode(IntPtr nat);
515
516     public IntPtr ManagedToNativeAllocRef(T man, bool refs)
517     {
518         return int64Traits.ManagedToNativeAlloc(Convert.ToInt64((object)man));
519     }
520
521     public void NativeFreeRef(IntPtr nat, bool unrefs)
522     {
523         int64Traits.NativeFree(nat);
524     }
525
526     public IntPtr EinaHashNew()
527     {
528         return eina_hash_int64_new(IntPtr.Zero);
529     }
530 }
531
532 public class IntElementTraits : Primitive32ElementTraits<int>, IBaseElementTraits<int>
533 {
534     override public void ManagedToNativeCopyTo(int man, IntPtr mem)
535     {
536         var arr = new int[1];
537         arr[0] = man;
538         Marshal.Copy(arr, 0, mem, 1);
539     }
540
541     override public int NativeToManagedInlistNode(IntPtr nat)
542     {
543         if (nat == IntPtr.Zero)
544         {
545             Eina.Log.Error("Null pointer for Inlist node.");
546             return default(int);
547         }
548
549         IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
550         var v = new int[1];
551         Marshal.Copy(loc, v, 0, 1);
552         return v[0];
553     }
554 }
555
556 public class CharElementTraits : Primitive32ElementTraits<char>, IBaseElementTraits<char>
557 {
558     override public void ManagedToNativeCopyTo(char man, IntPtr mem)
559     {
560         var arr = new char[1];
561         arr[0] = man;
562         Marshal.Copy(arr, 0, mem, 1);
563     }
564
565     override public char NativeToManagedInlistNode(IntPtr nat)
566     {
567         if (nat == IntPtr.Zero)
568         {
569             Eina.Log.Error("Null pointer for Inlist node.");
570             return default(char);
571         }
572
573         IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
574         var v = new char[1];
575         Marshal.Copy(loc, v, 0, 1);
576         return v[0];
577     }
578 }
579
580 public class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTraits<long>
581 {
582     override public void ManagedToNativeCopyTo(long man, IntPtr mem)
583     {
584         var arr = new long[1];
585         arr[0] = man;
586         Marshal.Copy(arr, 0, mem, 1);
587     }
588
589     override public long NativeToManagedInlistNode(IntPtr nat)
590     {
591         if (nat == IntPtr.Zero)
592         {
593             Eina.Log.Error("Null pointer for Inlist node.");
594             return default(long);
595         }
596
597         IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
598         var v = new long[1];
599         Marshal.Copy(loc, v, 0, 1);
600         return v[0];
601     }
602 }
603
604 public class ShortElementTraits : Primitive32ElementTraits<short>, IBaseElementTraits<short>
605 {
606     override public void ManagedToNativeCopyTo(short man, IntPtr mem)
607     {
608         var arr = new short[1];
609         arr[0] = man;
610         Marshal.Copy(arr, 0, mem, 1);
611     }
612
613     override public short NativeToManagedInlistNode(IntPtr nat)
614     {
615         if (nat == IntPtr.Zero)
616         {
617             Eina.Log.Error("Null pointer for Inlist node.");
618             return default(short);
619         }
620
621         IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
622         var v = new short[1];
623         Marshal.Copy(loc, v, 0, 1);
624         return v[0];
625     }
626 }
627
628 public class FloatElementTraits : Primitive32ElementTraits<float>, IBaseElementTraits<float>
629 {
630     override public void ManagedToNativeCopyTo(float man, IntPtr mem)
631     {
632         var arr = new float[1];
633         arr[0] = man;
634         Marshal.Copy(arr, 0, mem, 1);
635     }
636
637     override public float NativeToManagedInlistNode(IntPtr nat)
638     {
639         if (nat == IntPtr.Zero)
640         {
641             Eina.Log.Error("Null pointer for Inlist node.");
642             return default(float);
643         }
644
645         IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
646         var v = new float[1];
647         Marshal.Copy(loc, v, 0, 1);
648         return v[0];
649     }
650 }
651
652 public class DoubleElementTraits : Primitive64ElementTraits<double>, IBaseElementTraits<double>
653 {
654     override public void ManagedToNativeCopyTo(double man, IntPtr mem)
655     {
656         var arr = new double[1];
657         arr[0] = man;
658         Marshal.Copy(arr, 0, mem, 1);
659     }
660
661     override public double NativeToManagedInlistNode(IntPtr nat)
662     {
663         if (nat == IntPtr.Zero)
664         {
665             Eina.Log.Error("Null pointer for Inlist node.");
666             return default(double);
667         }
668
669         IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
670         var v = new double[1];
671         Marshal.Copy(loc, v, 0, 1);
672         return v[0];
673     }
674 }
675
676 public class ByteElementTraits : Primitive32ElementTraits<byte>, IBaseElementTraits<byte>
677 {
678     override public void ManagedToNativeCopyTo(byte man, IntPtr mem)
679     {
680         var arr = new byte[1];
681         arr[0] = man;
682         Marshal.Copy(arr, 0, mem, 1);
683     }
684
685     override public byte NativeToManagedInlistNode(IntPtr nat)
686     {
687         if (nat == IntPtr.Zero)
688         {
689             Eina.Log.Error("Null pointer for Inlist node.");
690             return default(byte);
691         }
692
693         IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
694         var v = new byte[1];
695         Marshal.Copy(loc, v, 0, 1);
696         return v[0];
697     }
698 }
699
700 public static class TraitFunctions
701 {
702     public static bool IsEflObject(System.Type type)
703     {
704         return typeof(Efl.Eo.IWrapper).IsAssignableFrom(type);
705     }
706
707     public static bool IsString(System.Type type)
708     {
709         return type == typeof(string);
710     }
711
712     public static Eina.ElementType GetElementTypeCode(System.Type type)
713     {
714         if (IsEflObject(type))
715         {
716             return ElementType.ObjectType;
717         }
718         else if (IsString(type))
719         {
720             return ElementType.StringType;
721         }
722         else
723         {
724             return ElementType.NumericType;
725         }
726     }
727
728     private static IDictionary<System.Type, object> register = new Dictionary<System.Type, object>();
729
730     private static System.Type AsEflInstantiableType(System.Type type)
731     {
732         if (!IsEflObject(type))
733         {
734             return null;
735         }
736
737         if (type.IsInterface)
738         {
739             string fullName = type.FullName + "Concrete";
740             return type.Assembly.GetType(fullName); // That was our best guess...
741         }
742
743         return type; // Not interface, so it should be a concrete.
744     }
745
746     public static object RegisterTypeTraits<T>()
747     {
748         Eina.Log.Debug($"Finding TypeTraits for {typeof(T).Name}");
749         object traits;
750         var type = typeof(T);
751         if (IsEflObject(type))
752         {
753             System.Type concrete = AsEflInstantiableType(type);
754             if (concrete == null || !type.IsAssignableFrom(concrete))
755             {
756                 throw new Exception("Failed to get a suitable concrete class for this type.");
757             }
758
759             // No need to pass concrete as the traits class will use reflection to get the actually most
760             // derived type returned.
761             traits = new EflObjectElementTraits<T>();
762         }
763         else if (IsString(type))
764         {
765             traits = new StringElementTraits();
766         }
767         else if (type.IsValueType)
768         {
769             if (type == typeof(int))
770             {
771                 traits = new IntElementTraits();
772             }
773             else if (type == typeof(char))
774             {
775                 traits = new CharElementTraits();
776             }
777             else if (type == typeof(long))
778             {
779                 traits = new LongElementTraits();
780             }
781             else if (type == typeof(short))
782             {
783                 traits = new ShortElementTraits();
784             }
785             else if (type == typeof(float))
786             {
787                 traits = new FloatElementTraits();
788             }
789             else if (type == typeof(double))
790             {
791                 traits = new DoubleElementTraits();
792             }
793             else if (type == typeof(byte))
794             {
795                 traits = new ByteElementTraits();
796             }
797             else
798             {
799                 throw new Exception("No traits registered for this type");
800             }
801         }
802         else
803         {
804             throw new Exception("No traits registered for this type");
805         }
806
807         register[type] = traits;
808         return traits;
809     }
810
811     public static object RegisterTypeTraits<T>(IBaseElementTraits<T> traits)
812     {
813         register[typeof(T)] = traits;
814         return traits;
815     }
816
817     public static IBaseElementTraits<T> GetTypeTraits<T>()
818     {
819         object traits;
820         if (!register.TryGetValue(typeof(T), out traits))
821         {
822             traits = RegisterTypeTraits<T>();
823         }
824
825         return (IBaseElementTraits<T>)traits;
826     }
827
828     //                  //
829     // Traits functions //
830     //                  //
831
832     // Convertion functions //
833
834     public static IntPtr ManagedToNativeAlloc<T>(T man)
835     {
836         return GetTypeTraits<T>().ManagedToNativeAlloc(man);
837     }
838
839     public static void ManagedToNativeCopyTo<T>(T man, IntPtr mem)
840     {
841         GetTypeTraits<T>().ManagedToNativeCopyTo(man, mem);
842     }
843
844     public static IntPtr ManagedToNativeAllocInlistNode<T>(T man)
845     {
846         return GetTypeTraits<T>().ManagedToNativeAllocInlistNode(man);
847     }
848
849     public static void NativeFree<T>(IntPtr nat)
850     {
851         GetTypeTraits<T>().NativeFree(nat);
852     }
853
854     public static void NativeFreeInlistNodeElement<T>(IntPtr nat)
855     {
856         GetTypeTraits<T>().NativeFreeInlistNodeElement(nat);
857     }
858
859     public static void NativeFreeInlistNode<T>(IntPtr nat, bool freeElement = true)
860     {
861         GetTypeTraits<T>().NativeFreeInlistNode(nat, freeElement);
862     }
863
864     public static void NativeFreeInplace<T>(IntPtr nat)
865     {
866         GetTypeTraits<T>().NativeFreeInplace(nat);
867     }
868
869     public static void ResidueFreeInplace<T>(IntPtr nat)
870     {
871         GetTypeTraits<T>().ResidueFreeInplace(nat);
872     }
873
874     public static T NativeToManaged<T>(IntPtr nat)
875     {
876         return GetTypeTraits<T>().NativeToManaged(nat);
877     }
878
879     public static T NativeToManagedInlistNode<T>(IntPtr nat)
880     {
881         return GetTypeTraits<T>().NativeToManagedInlistNode(nat);
882     }
883
884     public static T NativeToManagedInplace<T>(IntPtr nat)
885     {
886         return GetTypeTraits<T>().NativeToManagedInplace(nat);
887     }
888
889     // Misc //
890
891     public static IntPtr EinaCompareCb<T>()
892     {
893         return GetTypeTraits<T>().EinaCompareCb();
894     }
895
896     public static IntPtr EinaFreeCb<T>()
897     {
898         return GetTypeTraits<T>().EinaFreeCb();
899     }
900
901     public static IntPtr EinaHashNew<TKey>()
902     {
903         return GetTypeTraits<TKey>().EinaHashNew();
904     }
905
906     public static IntPtr EinaInarrayNew<T>(uint step)
907     {
908         return GetTypeTraits<T>().EinaInarrayNew(step);
909     }
910
911     public static IntPtr EinaHashIteratorKeyNew<T>(IntPtr hash)
912     {
913         return GetTypeTraits<T>().EinaHashIteratorKeyNew(hash);
914     }
915 }
916
917 }