// 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/Generator.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 PTRMUT 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 T** 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();
}
///
/// 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, PTRMUTPTR rh) => (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 !=(PTRMUTPTR lh, PTRMUTPTR rh) => (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 ==(PTRMUTPTR lh, 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 !=(PTRMUTPTR lh, 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, PTRMUTPTR rh) => 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, PTRMUTPTR rh) => 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;
///
/// Determines whether a and a NullPtr are equal
///
///
///
/// Whether the and NullPtr are equal
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool operator ==(PTRMUTPTR lh, NullPtr rh) => lh == (PTRMUTPTR)rh;
///
/// Determines whether a and a NullPtr are not equal
///
///
///
/// Whether the and NullPtr are not equal
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool operator !=(PTRMUTPTR lh, NullPtr rh) => lh != (PTRMUTPTR)rh;
///
/// Determines whether a NullPtr and a are equal
///
///
///
/// Whether the NullPtr and are equal
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool operator ==(NullPtr lh, PTRMUTPTR rh) => (PTRMUTPTR)lh == rh;
///
/// Determines whether a NullPtr and a are not equal
///
///
///
/// Whether the NullPtr and are not equal
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool operator !=(NullPtr lh, PTRMUTPTR rh) => (PTRMUTPTR)lh != rh;
///
/// 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)
=> SilkMarshal.JaggedArrayToPointerArray(array);
public static implicit operator PTRMUTPTR(T**[] array)
{
IL.Emit.Ldarg_0();
IL.Emit.Ldc_I4_0();
IL.Emit.Ldelema(TypeRef.Type(typeof(T).MakePointerType()));
IL.Emit.Newobj(
MethodRef.Constructor(
TypeRef.Type(typeof(PTRMUTPTR<>).MakeGenericType(typeof(T))),
TypeRef.Type(typeof(PTRMUT<>).MakeGenericType(typeof(T)))
)
);
IL.Emit.Ret();
throw IL.Unreachable();
}
public static implicit operator PTRMUTPTR(PTRMUTPTR ptr) => new PTRMUTPTR(in ptr.InteriorRef);
}