// 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 MUT
where T : unmanaged
{
///
/// Creates a pointer with the given underlying ref.
///
/// The underlying ref.
public MUT(ref readonly T @Ref)
{
IL.Emit.Ldarg_0();
IL.Emit.Ldarg_1();
IL.Emit.Stfld(
FieldRef.Field(
TypeRef.Type(typeof(MUT<>).MakeGenericType(typeof(T))),
nameof(InteriorRef)
)
);
IL.Emit.Ret();
throw IL.Unreachable();
}
///
/// The underlying reference
///
public readonly ref readonly 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(MUT<>).MakeGenericType(typeof(T))),
nameof(InteriorRef)
)
);
IL.Emit.Ret();
throw IL.Unreachable();
}
}
private readonly ref readonly byte InteriorRef;
///
/// Gets the item at the given offset from this pointer.
///
/// The index.
public ref readonly T this[nuint index]
{
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
get
{
return ref Unsafe.Add(ref Unsafe.AsRef(in Ref), index);
}
}
///
/// Gets the underlying reference.
///
/// The underlying reference.
///
/// This function allows a to be used in a fixed statement.
///
public ref readonly T GetPinnableReference()
{
IL.Emit.Ldarg_0();
IL.Emit.Ldfld(
FieldRef.Field(
TypeRef.Type(typeof(MUT<>).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 ==(MUT lh, MUT 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 !=(MUT lh, MUT 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 ==(MUT 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 !=(MUT 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, MUT 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, MUT rh) => lh == null ? (void*)rh != null : true;
///
/// Creates a from a Nullptr
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public unsafe static implicit operator MUT(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 ==(MUT lh, NullPtr rh) => lh == (MUT)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 !=(MUT lh, NullPtr rh) => lh != (MUT)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, MUT rh) => (MUT)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, MUT rh) => (MUT)lh != rh;
///
/// Creates a from a void pointer
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MUT(void* ptr) => new(in Unsafe.AsRef(ptr));
///
/// Creates a void pointer from a
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator void*(MUT ptr) => Unsafe.AsPointer(ref Unsafe.AsRef(in ptr.Ref));
///
/// Creates a from a pointer
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MUT(T* ptr) => new(in Unsafe.AsRef(ptr));
///
/// Creates a pointer from a
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator T*(MUT ptr) => (T*)Unsafe.AsPointer(ref Unsafe.AsRef(in ptr.Ref));
///
/// Creates a from a pointer
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MUT(T* ptr) => new(in Unsafe.AsRef(ptr));
///
/// Creates a pointer from a
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator T*(MUT ptr) => (T*)Unsafe.AsPointer(ref Unsafe.AsRef(in ptr.Ref));
///
/// 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);
///
/// Creates a from a span
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MUT(Span span) => new(ref span.GetPinnableReference());
///
/// Creates a from a ReadOnlySpan
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MUT(ReadOnlySpan span) => new(in span.GetPinnableReference());
///
/// Creates a string from this as a c-style string
///
/// the string
public string ReadToString()
{
throw new NotImplementedException();
}
///
/// Creates a string from this with the given length
///
/// length of the string
/// the string
public string ReadToString(int length)
{
throw new NotImplementedException();
}
///
/// Creates a string from a
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static explicit operator string(MUTptr) => ptr.ReadToString();
///
/// creates a from an array
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MUT(T[] array) => array.AsSpan();
///
/// creates a from a 2D array
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MUT(T[,] array) => MemoryMarshal.CreateSpan(ref array[0, 0], array.Length);
///
/// creates a from a 3D array
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MUT(T[,,] array) => MemoryMarshal.CreateSpan(ref array[0, 0, 0], array.Length); public static implicit operator MUT(MUT ptr) => new MUT(in ptr.InteriorRef);
}