// 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 System.Text;
namespace Silk.NET.Core;
///
/// A single dimension pointer wrapper
///
public readonly ref struct MUT
{
///
/// Creates a pointer with the given underlying ref.
///
/// The underlying ref.
public MUT(ref byte @Ref)
{
this.Ref = ref @Ref;
}
///
/// The underlying reference.
///
public readonly ref byte Ref;
///
/// Gets the item at the given offset from this pointer.
///
/// The index.
public ref byte this[nuint index]
{
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
get => ref Unsafe.Add(ref Ref, index);
}
///
/// Creates a string from this as a c-style string
///
/// the string
public unsafe string ReadToString()
{
int len = 0;
byte* ptr = (byte*)Unsafe.AsPointer(ref Ref);
while (*ptr != 0 && len != int.MaxValue)
{
ptr++;
len++;
}
return ReadToString(len);
}
///
/// Creates a string from this with the given length
///
/// length of the string
/// the string
public unsafe string ReadToString(int length) => Encoding.UTF8.GetString(AsSpan(length));
///
/// Gets the underlying reference.
///
/// The underlying reference.
///
/// This function allows a to be used in a fixed statement.
///
public ref byte GetPinnableReference() => ref Ref;
///
/// Creates a span with the given length from this pointer.
///
/// the span length
/// the span
public ReadOnlySpan AsSpan(int length) => MemoryMarshal.CreateReadOnlySpan(ref Ref, 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() => Ref.GetHashCode();
///
/// Determines if two objects are equivalent
///
///
///
/// Whether the pointers are equal
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 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 from a byte pointer
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public unsafe static implicit operator MUT(byte* ptr) => new(in Unsafe.AsRef(ptr));
///
/// Creates a from a void pointer
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public unsafe static implicit operator MUT(void* ptr) => new(in Unsafe.AsRef(ptr));
///
/// Creates a byte pointer from a
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public unsafe static implicit operator byte*(MUT ptr) => (byte*)Unsafe.AsPointer(ref ptr.Ref);
///
/// Creates a void pointer from a
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public unsafe static implicit operator void*(MUT ptr) => Unsafe.AsPointer(ref ptr.Ref);
///
/// Creates a string from a
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static explicit operator string(MUT ptr) => ptr.ReadToString();
///
/// creates a from an array
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MUT(byte[] array) => array.AsSpan();
///
/// creates a from a 2D array
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MUT(byte[,] 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(byte[,,] array) => MemoryMarshal.CreateSpan(ref array[0, 0, 0], array.Length);
}