Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ----------------------------------------------------------------------------
- // <auto-generated>
- // This is autogenerated code by CppSharp.
- // Do not edit this file or all your changes will be lost after re-generation.
- // </auto-generated>
- // ----------------------------------------------------------------------------
- using System;
- using System.Runtime.InteropServices;
- using System.Security;
- public unsafe abstract partial class Bar : IDisposable
- {
- [StructLayout(LayoutKind.Explicit, Size = 8)]
- public partial struct __Internal
- {
- [FieldOffset(0)]
- internal global::System.IntPtr vfptr_Bar;
- [SuppressUnmanagedCodeSecurity]
- [DllImport("Test", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
- EntryPoint="??0Bar@@QEAA@XZ")]
- internal static extern global::System.IntPtr ctor(global::System.IntPtr instance);
- [SuppressUnmanagedCodeSecurity]
- [DllImport("Test", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
- EntryPoint="??0Bar@@QEAA@AEBV0@@Z")]
- internal static extern global::System.IntPtr cctor(global::System.IntPtr instance, global::System.IntPtr _0);
- }
- public global::System.IntPtr __Instance { get; protected set; }
- protected int __PointerAdjustment;
- internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Bar> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Bar>();
- protected void*[] __OriginalVTables;
- protected bool __ownsNativeInstance;
- internal static global::Bar __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
- {
- return new global::BarInternal(native.ToPointer(), skipVTables);
- }
- internal static global::Bar __CreateInstance(global::Bar.__Internal native, bool skipVTables = false)
- {
- return new global::BarInternal(native, skipVTables);
- }
- protected Bar(void* native, bool skipVTables = false)
- {
- if (native == null)
- return;
- __Instance = new global::System.IntPtr(native);
- __OriginalVTables = new void*[] { *(void**) (__Instance + 0) };
- }
- protected Bar()
- {
- __Instance = Marshal.AllocHGlobal(sizeof(global::Bar.__Internal));
- __ownsNativeInstance = true;
- NativeToManagedMap[__Instance] = this;
- __Internal.ctor((__Instance + __PointerAdjustment));
- SetupVTables(GetType().FullName == "Bar");
- }
- protected Bar(global::Bar _0)
- {
- __Instance = Marshal.AllocHGlobal(sizeof(global::Bar.__Internal));
- __ownsNativeInstance = true;
- NativeToManagedMap[__Instance] = this;
- if (ReferenceEquals(_0, null))
- throw new global::System.ArgumentNullException("_0", "Cannot be null because it is a C++ reference (&).");
- var __arg0 = _0.__Instance;
- __Internal.cctor((__Instance + __PointerAdjustment), __arg0);
- SetupVTables(GetType().FullName == "Bar");
- }
- public void Dispose()
- {
- Dispose(disposing: true);
- }
- public virtual void Dispose(bool disposing)
- {
- if (__Instance == IntPtr.Zero)
- return;
- global::Bar __dummy;
- NativeToManagedMap.TryRemove(__Instance, out __dummy);
- ((global::Bar.__Internal*) __Instance)->vfptr_Bar = new global::System.IntPtr(__OriginalVTables[0]);
- if (__ownsNativeInstance)
- Marshal.FreeHGlobal(__Instance);
- __Instance = IntPtr.Zero;
- }
- public abstract void Foo(string a, string b);
- #region Virtual table interop
- // void Foo(const std::string &a, const std::string &b) = 0
- private static global::Delegates.Action_IntPtr_IntPtr_IntPtr _FooDelegateInstance;
- private static void _FooDelegateHook(global::System.IntPtr instance, global::System.IntPtr a, global::System.IntPtr b)
- {
- if (!NativeToManagedMap.ContainsKey(instance))
- throw new global::System.Exception("No managed instance was found");
- var __target = (global::Bar) NativeToManagedMap[instance];
- if (__target.__ownsNativeInstance)
- __target.SetupVTables();
- var __basicStringRet = global::Std.BasicString<char, global::Std.CharTraits<char>, global::Std.Allocator<char>>.__CreateInstance(a);
- var __basicStringRet = global::Std.BasicString<char, global::Std.CharTraits<char>, global::Std.Allocator<char>>.__CreateInstance(b);
- __target.Foo(global::Std.BasicStringExtensions.CStr(__basicStringRet), global::Std.BasicStringExtensions.CStr(__basicStringRet));
- }
- private static void*[] __ManagedVTables;
- private static void*[] _Thunks;
- private void SetupVTables(bool destructorOnly = false)
- {
- if (__OriginalVTables != null)
- return;
- __OriginalVTables = new void*[] { *(void**) (__Instance + 0) };
- if (destructorOnly)
- return;
- if (_Thunks == null)
- {
- _Thunks = new void*[1];
- _FooDelegateInstance += _FooDelegateHook;
- _Thunks[0] = Marshal.GetFunctionPointerForDelegate(_FooDelegateInstance).ToPointer();
- }
- if (__ManagedVTables == null)
- {
- __ManagedVTables = new void*[1];
- var vfptr0 = Marshal.AllocHGlobal(2 * 8);
- __ManagedVTables[0] = vfptr0.ToPointer();
- *(void**) (vfptr0 + 0) = *(void**) (new IntPtr(*(void**) __Instance) + 0 + 0);
- *(void**) (vfptr0 + 8) = _Thunks[0];
- }
- *(void**) (__Instance + 0) = __ManagedVTables[0];
- }
- #endregion
- }
- public unsafe partial class BarInternal : global::Bar, IDisposable
- {
- private static void* __CopyValue(global::Bar.__Internal native)
- {
- var ret = Marshal.AllocHGlobal(sizeof(global::Bar.__Internal));
- *(global::Bar.__Internal*) ret = native;
- return ret.ToPointer();
- }
- internal BarInternal(global::Bar.__Internal native, bool skipVTables = false)
- : this(__CopyValue(native), skipVTables)
- {
- __ownsNativeInstance = true;
- NativeToManagedMap[__Instance] = this;
- }
- internal BarInternal(void* native, bool skipVTables = false)
- : base((void*) null)
- {
- __PointerAdjustment = 0;
- __Instance = new global::System.IntPtr(native);
- __OriginalVTables = new void*[] { *(void**) (__Instance + 0) };
- }
- public override void Foo(string a, string b)
- {
- var __slot = *(void**) ((IntPtr) __OriginalVTables[0] + 1 * 8);
- var ___FooDelegate = (global::Delegates.Action_IntPtr_IntPtr_IntPtr) Marshal.GetDelegateForFunctionPointer(new IntPtr(__slot), typeof(global::Delegates.Action_IntPtr_IntPtr_IntPtr));
- var __allocator0 = new global::Std.Allocator<char>();
- var __basicString0 = global::Std.BasicStringExtensions.BasicString(a, __allocator0);
- var __arg0 = __basicString0.__Instance;
- var __allocator1 = new global::Std.Allocator<char>();
- var __basicString1 = global::Std.BasicStringExtensions.BasicString(b, __allocator1);
- var __arg1 = __basicString1.__Instance;
- ___FooDelegate((__Instance + __PointerAdjustment), __arg0, __arg1);
- __basicString0.Dispose(false);
- __allocator0.Dispose();
- __basicString1.Dispose(false);
- __allocator1.Dispose();
- }
- }
- namespace Delegates
- {
- [SuppressUnmanagedCodeSecurity, UnmanagedFunctionPointer(global::System.Runtime.InteropServices.CallingConvention.Cdecl)]
- internal unsafe delegate void Action_IntPtr_IntPtr_IntPtr(global::System.IntPtr _0, global::System.IntPtr _1, global::System.IntPtr _2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement