Advertisement
mattparks5855

Generated C# output

May 21st, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.72 KB | None | 0 0
  1. // ----------------------------------------------------------------------------
  2. // <auto-generated>
  3. // This is autogenerated code by CppSharp.
  4. // Do not edit this file or all your changes will be lost after re-generation.
  5. // </auto-generated>
  6. // ----------------------------------------------------------------------------
  7. using System;
  8. using System.Runtime.InteropServices;
  9. using System.Security;
  10.  
  11. public unsafe abstract partial class Bar : IDisposable
  12. {
  13.     [StructLayout(LayoutKind.Explicit, Size = 8)]
  14.     public partial struct __Internal
  15.     {
  16.         [FieldOffset(0)]
  17.         internal global::System.IntPtr vfptr_Bar;
  18.  
  19.         [SuppressUnmanagedCodeSecurity]
  20.         [DllImport("Test", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
  21.             EntryPoint="??0Bar@@QEAA@XZ")]
  22.         internal static extern global::System.IntPtr ctor(global::System.IntPtr instance);
  23.  
  24.         [SuppressUnmanagedCodeSecurity]
  25.         [DllImport("Test", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
  26.             EntryPoint="??0Bar@@QEAA@AEBV0@@Z")]
  27.         internal static extern global::System.IntPtr cctor(global::System.IntPtr instance, global::System.IntPtr _0);
  28.     }
  29.  
  30.     public global::System.IntPtr __Instance { get; protected set; }
  31.  
  32.     protected int __PointerAdjustment;
  33.     internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Bar> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Bar>();
  34.     protected void*[] __OriginalVTables;
  35.  
  36.     protected bool __ownsNativeInstance;
  37.  
  38.     internal static global::Bar __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
  39.     {
  40.         return new global::BarInternal(native.ToPointer(), skipVTables);
  41.     }
  42.  
  43.     internal static global::Bar __CreateInstance(global::Bar.__Internal native, bool skipVTables = false)
  44.     {
  45.         return new global::BarInternal(native, skipVTables);
  46.     }
  47.  
  48.     protected Bar(void* native, bool skipVTables = false)
  49.     {
  50.         if (native == null)
  51.             return;
  52.         __Instance = new global::System.IntPtr(native);
  53.         __OriginalVTables = new void*[] { *(void**) (__Instance + 0) };
  54.     }
  55.  
  56.     protected Bar()
  57.     {
  58.         __Instance = Marshal.AllocHGlobal(sizeof(global::Bar.__Internal));
  59.         __ownsNativeInstance = true;
  60.         NativeToManagedMap[__Instance] = this;
  61.         __Internal.ctor((__Instance + __PointerAdjustment));
  62.         SetupVTables(GetType().FullName == "Bar");
  63.     }
  64.  
  65.     protected Bar(global::Bar _0)
  66.     {
  67.         __Instance = Marshal.AllocHGlobal(sizeof(global::Bar.__Internal));
  68.         __ownsNativeInstance = true;
  69.         NativeToManagedMap[__Instance] = this;
  70.         if (ReferenceEquals(_0, null))
  71.             throw new global::System.ArgumentNullException("_0", "Cannot be null because it is a C++ reference (&).");
  72.         var __arg0 = _0.__Instance;
  73.         __Internal.cctor((__Instance + __PointerAdjustment), __arg0);
  74.         SetupVTables(GetType().FullName == "Bar");
  75.     }
  76.  
  77.     public void Dispose()
  78.     {
  79.         Dispose(disposing: true);
  80.     }
  81.  
  82.     public virtual void Dispose(bool disposing)
  83.     {
  84.         if (__Instance == IntPtr.Zero)
  85.             return;
  86.         global::Bar __dummy;
  87.         NativeToManagedMap.TryRemove(__Instance, out __dummy);
  88.         ((global::Bar.__Internal*) __Instance)->vfptr_Bar = new global::System.IntPtr(__OriginalVTables[0]);
  89.         if (__ownsNativeInstance)
  90.             Marshal.FreeHGlobal(__Instance);
  91.         __Instance = IntPtr.Zero;
  92.     }
  93.  
  94.     public abstract void Foo(string a, string b);
  95.  
  96.     #region Virtual table interop
  97.  
  98.     // void Foo(const std::string &a, const std::string &b) = 0
  99.     private static global::Delegates.Action_IntPtr_IntPtr_IntPtr _FooDelegateInstance;
  100.  
  101.     private static void _FooDelegateHook(global::System.IntPtr instance, global::System.IntPtr a, global::System.IntPtr b)
  102.     {
  103.         if (!NativeToManagedMap.ContainsKey(instance))
  104.             throw new global::System.Exception("No managed instance was found");
  105.  
  106.         var __target = (global::Bar) NativeToManagedMap[instance];
  107.         if (__target.__ownsNativeInstance)
  108.             __target.SetupVTables();
  109.         var __basicStringRet = global::Std.BasicString<char, global::Std.CharTraits<char>, global::Std.Allocator<char>>.__CreateInstance(a);
  110.         var __basicStringRet = global::Std.BasicString<char, global::Std.CharTraits<char>, global::Std.Allocator<char>>.__CreateInstance(b);
  111.         __target.Foo(global::Std.BasicStringExtensions.CStr(__basicStringRet), global::Std.BasicStringExtensions.CStr(__basicStringRet));
  112.     }
  113.  
  114.     private static void*[] __ManagedVTables;
  115.     private static void*[] _Thunks;
  116.  
  117.     private void SetupVTables(bool destructorOnly = false)
  118.     {
  119.         if (__OriginalVTables != null)
  120.             return;
  121.         __OriginalVTables = new void*[] { *(void**) (__Instance + 0) };
  122.  
  123.         if (destructorOnly)
  124.             return;
  125.         if (_Thunks == null)
  126.         {
  127.             _Thunks = new void*[1];
  128.             _FooDelegateInstance += _FooDelegateHook;
  129.             _Thunks[0] = Marshal.GetFunctionPointerForDelegate(_FooDelegateInstance).ToPointer();
  130.         }
  131.  
  132.         if (__ManagedVTables == null)
  133.         {
  134.             __ManagedVTables = new void*[1];
  135.             var vfptr0 = Marshal.AllocHGlobal(2 * 8);
  136.             __ManagedVTables[0] = vfptr0.ToPointer();
  137.             *(void**) (vfptr0 + 0) = *(void**) (new IntPtr(*(void**) __Instance) + 0 + 0);
  138.             *(void**) (vfptr0 + 8) = _Thunks[0];
  139.         }
  140.  
  141.         *(void**) (__Instance + 0) = __ManagedVTables[0];
  142.     }
  143.  
  144.     #endregion
  145. }
  146.  
  147. public unsafe partial class BarInternal : global::Bar, IDisposable
  148. {
  149.     private static void* __CopyValue(global::Bar.__Internal native)
  150.     {
  151.         var ret = Marshal.AllocHGlobal(sizeof(global::Bar.__Internal));
  152.         *(global::Bar.__Internal*) ret = native;
  153.         return ret.ToPointer();
  154.     }
  155.  
  156.     internal BarInternal(global::Bar.__Internal native, bool skipVTables = false)
  157.         : this(__CopyValue(native), skipVTables)
  158.     {
  159.         __ownsNativeInstance = true;
  160.         NativeToManagedMap[__Instance] = this;
  161.     }
  162.  
  163.     internal BarInternal(void* native, bool skipVTables = false)
  164.         : base((void*) null)
  165.     {
  166.         __PointerAdjustment = 0;
  167.         __Instance = new global::System.IntPtr(native);
  168.         __OriginalVTables = new void*[] { *(void**) (__Instance + 0) };
  169.     }
  170.  
  171.     public override void Foo(string a, string b)
  172.     {
  173.         var __slot = *(void**) ((IntPtr) __OriginalVTables[0] + 1 * 8);
  174.         var ___FooDelegate = (global::Delegates.Action_IntPtr_IntPtr_IntPtr) Marshal.GetDelegateForFunctionPointer(new IntPtr(__slot), typeof(global::Delegates.Action_IntPtr_IntPtr_IntPtr));
  175.         var __allocator0 = new global::Std.Allocator<char>();
  176.         var __basicString0 = global::Std.BasicStringExtensions.BasicString(a, __allocator0);
  177.         var __arg0 = __basicString0.__Instance;
  178.         var __allocator1 = new global::Std.Allocator<char>();
  179.         var __basicString1 = global::Std.BasicStringExtensions.BasicString(b, __allocator1);
  180.         var __arg1 = __basicString1.__Instance;
  181.         ___FooDelegate((__Instance + __PointerAdjustment), __arg0, __arg1);
  182.         __basicString0.Dispose(false);
  183.         __allocator0.Dispose();
  184.         __basicString1.Dispose(false);
  185.         __allocator1.Dispose();
  186.     }
  187. }
  188.  
  189. namespace Delegates
  190. {
  191.     [SuppressUnmanagedCodeSecurity, UnmanagedFunctionPointer(global::System.Runtime.InteropServices.CallingConvention.Cdecl)]
  192.     internal unsafe delegate void Action_IntPtr_IntPtr_IntPtr(global::System.IntPtr _0, global::System.IntPtr _1, global::System.IntPtr _2);
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement