// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // ============================================= THIS FILE IS AUTOGENERATED ============================================ // ============================ Please make any edits in eng/pointergen/PointerGenerator.cs! =========================== // ============================================= THIS FILE IS AUTOGENERATED ============================================ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using InlineIL; namespace Silk.NET.Core; /// /// A pointer wrapper class /// public unsafe readonly ref struct PTRMUTPTR where T : unmanaged { /// /// Creates a pointer with the given underlying ref. /// /// The underlying ref. public PTRMUTPTR(ref PTRMUT @Ref) { IL.Emit.Ldarg_0(); IL.Emit.Ldarg_1(); IL.Emit.Stfld( FieldRef.Field( TypeRef.Type(typeof(PTRMUTPTR<>).MakeGenericType(typeof(T))), nameof(InteriorRef) ) ); IL.Emit.Ret(); throw IL.Unreachable(); } /// /// The underlying reference /// public readonly ref T Ref { [MethodImpl( MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization )] get { // Would use the delegate* trick but this isn't optimised in JIT yet or necessarily safe IL.Emit.Ldarg_0(); IL.Emit.Ldfld( FieldRef.Field( TypeRef.Type(typeof(PTRMUTPTR<>).MakeGenericType(typeof(T))), nameof(InteriorRef) ) ); IL.Emit.Ret(); throw IL.Unreachable(); } } private readonly ref byte InteriorRef; /// /// Gets the item at the given offset from this pointer. /// /// The index. public ref PTRMUT this[nuint index] { [MethodImpl( MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization )] get { IL.Emit.Ldarg_0(); IL.Emit.Ldfld( FieldRef.Field( TypeRef.Type(typeof(PTRMUTPTR<>).MakeGenericType(typeof(T))), nameof(InteriorRef) ) ); IL.Emit.Ldarg_1(); IL.Emit.Sizeof(); IL.Emit.Mul(); IL.Emit.Add(); IL.Emit.Ret(); throw IL.Unreachable(); } } /// /// Gets the underlying reference. /// /// The underlying reference. /// /// This function allows a to be used in a fixed statement. /// public ref PTRMUT* GetPinnableReference() { IL.Emit.Ldarg_0(); IL.Emit.Ldfld( FieldRef.Field( TypeRef.Type(typeof(PTRMUTPTR<>).MakeGenericType(typeof(T))), nameof(InteriorRef) ) ); IL.Emit.Ret(); throw IL.Unreachable(); } /// /// Creates a span with the given length from this pointer. /// /// the span length /// the span public ReadOnlySpan> AsSpan(int length) => MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AsRef(in InteriorRef), length); /// /// Determines if this equals another object /// /// /// Whether this object is the same as [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public override bool Equals([NotNullWhen(true)] object? obj) => this == obj; /// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public override int GetHashCode() => InteriorRef.GetHashCode(); /// /// Determines if two objects are equivalent /// /// /// /// Whether the pointers are equal [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static bool operator ==(PTRMUTPTR lh, PTRMUTPTRrh) => (void*)lh == (void*)rh; /// /// Determines if two objects are not equivalent /// /// /// /// Whether the pointers are not equal [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static bool operator !=(PTRMUTPTRlh, PTRMUTPTRrh) => (void*)lh != (void*)rh; /// /// Determines whether a pointer and an object are equal /// /// /// /// Whether the pointer and object are equal [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static bool operator ==(PTRMUTPTRlh, object? rh) => rh == null ? (void*)lh == null : false; /// /// Determines whether a pointer and an object are not equal /// /// /// /// Whether the pointer and object are not equal [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static bool operator !=(PTRMUTPTRlh, object? rh) => rh == null ? (void*)lh != null : true; /// /// Determines whether an object and a pointer are equal /// /// /// /// Whether the object and pointer are equal [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static bool operator ==(object? lh, PTRMUTPTRrh) => lh == null ? (void*)rh == null : false; /// /// Determines whether an object and a pointer are not equal /// /// /// /// Whether the object and pointer are not equal [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static bool operator !=(object? lh, PTRMUTPTRrh) => lh == null ? (void*)rh != null : true; /// /// Creates a from a Nullptr /// /// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public unsafe static implicit operator PTRMUTPTR(NullPtr ptr) => (void*)ptr; /// /// Creates a from a span /// /// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static implicit operator PTRMUTPTR(Span> span) => new(ref span.GetPinnableReference()); /// /// Creates a from a ReadOnlySpan /// /// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static implicit operator PTRMUTPTR(ReadOnlySpan> span) => new(in span.GetPinnableReference()); /// /// Creates a from a void pointer /// /// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static implicit operator PTRMUTPTR(void* ptr) => new(in Unsafe.AsRef(ptr)); /// /// Creates a void pointer from a /// /// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static implicit operator void*(PTRMUTPTR ptr) => Unsafe.AsPointer(ref Unsafe.AsRef(in ptr.Ref)); /// /// Creates a from a pointer /// /// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static implicit operator PTRMUTPTR(T*** ptr) => new(in Unsafe.AsRef(ptr)); /// /// Creates a pointer from a /// /// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static implicit operator T******(PTRMUTPTR ptr) => (T******)Unsafe.AsPointer(ref Unsafe.AsRef(in ptr.Ref)); /// /// Creates a from a pointer /// /// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static implicit operator PTRMUTPTR(T*** ptr) => new(in Unsafe.AsRef(ptr)); /// /// Creates a pointer from a /// /// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static implicit operator T******(PTRMUTPTR ptr) => (T******)Unsafe.AsPointer(ref Unsafe.AsRef(in ptr.Ref)); /// /// Creates a from a void pointer /// /// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static implicit operator PTRMUTPTR(void*** ptr) => new(in Unsafe.AsRef(ptr)); /// /// Creates a void pointer from a /// /// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static implicit operator void***(PTRMUTPTR ptr) => (void***)Unsafe.AsPointer(ref Unsafe.AsRef(in ptr.Ref)); /// /// creates a from an array /// /// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static implicit operator PTRMUTPTR(T[][][] array) => new(in array.AsSpan().GetPinnableReference()); public static implicit operator Ptr(Ptr ptr) => new Ptr(in ptr.InteriorRef); }