servicepoint/crates/servicepoint_binding_cs/ServicePoint/BitVec.g.cs

327 lines
11 KiB
C#
Raw Permalink Normal View History

2024-10-16 21:59:35 +02:00
// <auto-generated>
// This code is generated by csbindgen.
// DON'T CHANGE THIS DIRECTLY.
// </auto-generated>
#pragma warning disable CS8500
#pragma warning disable CS8981
using System;
using System.Runtime.InteropServices;
namespace ServicePoint
2024-10-16 21:59:35 +02:00
{
public unsafe sealed partial class BitVec: IDisposable
2024-10-16 21:59:35 +02:00
{
#nullable enable
2024-10-16 21:59:35 +02:00
/// <summary>
/// Creates a new [SPBitVec] instance.
///
/// # Arguments
///
/// - `size`: size in bits.
///
/// returns: [SPBitVec] with all bits set to false. Will never return NULL.
///
/// # Panics
///
/// - when `size` is not divisible by 8.
///
/// # Safety
///
/// The caller has to make sure that:
///
/// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_bitvec_free`.
/// </summary>
public BitVec(nuint size) : this(sp_bitvec_new(size)) {}
2024-10-16 21:59:35 +02:00
/// <summary>
/// Interpret the data as a series of bits and load then into a new [SPBitVec] instance.
///
/// returns: [SPBitVec] instance containing data. Will never return NULL.
///
/// # Panics
///
/// - when `data` is NULL
///
/// # Safety
///
/// The caller has to make sure that:
///
/// - `data` points to a valid memory location of at least `data_length`
/// bytes in size.
/// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_bitvec_free`.
/// </summary>
2024-10-19 16:19:09 +02:00
[System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static BitVec Load(byte* data, nuint data_length)
{
return new BitVec(BitVec.sp_bitvec_load(data, data_length));
}
2024-10-16 21:59:35 +02:00
/// <summary>
/// Clones a [SPBitVec].
///
/// returns: new [SPBitVec] instance. Will never return NULL.
///
/// # Panics
///
/// - when `bit_vec` is NULL
///
/// # Safety
///
/// The caller has to make sure that:
///
/// - `bit_vec` points to a valid [SPBitVec]
/// - `bit_vec` is not written to concurrently
/// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_bitvec_free`.
/// </summary>
2024-10-19 16:19:09 +02:00
[System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public BitVec Clone()
{
2024-10-20 12:08:19 +02:00
return new BitVec(BitVec.sp_bitvec_clone(this.__Instance));
}
2024-10-16 21:59:35 +02:00
/// <summary>
/// Gets the value of a bit from the [SPBitVec].
///
/// # Arguments
///
/// - `bit_vec`: instance to read from
/// - `index`: the bit index to read
///
/// returns: value of the bit
///
/// # Panics
///
/// - when `bit_vec` is NULL
/// - when accessing `index` out of bounds
///
/// # Safety
///
/// The caller has to make sure that:
///
/// - `bit_vec` points to a valid [SPBitVec]
/// - `bit_vec` is not written to concurrently
/// </summary>
2024-10-19 16:19:09 +02:00
[System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public bool Get(nuint index)
{
2024-10-20 12:08:19 +02:00
return BitVec.sp_bitvec_get(this.__Instance, index);
}
2024-10-16 21:59:35 +02:00
/// <summary>
/// Sets the value of a bit in the [SPBitVec].
///
/// # Arguments
///
/// - `bit_vec`: instance to write to
/// - `index`: the bit index to edit
/// - `value`: the value to set the bit to
///
/// # Panics
///
/// - when `bit_vec` is NULL
/// - when accessing `index` out of bounds
///
/// # Safety
///
/// The caller has to make sure that:
///
/// - `bit_vec` points to a valid [SPBitVec]
/// - `bit_vec` is not written to or read from concurrently
/// </summary>
2024-10-19 16:19:09 +02:00
[System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public void Set(nuint index, bool value)
{
2024-10-20 12:08:19 +02:00
BitVec.sp_bitvec_set(this.__Instance, index, value);
}
2024-10-16 21:59:35 +02:00
/// <summary>
/// Sets the value of all bits in the [SPBitVec].
///
/// # Arguments
///
/// - `bit_vec`: instance to write to
/// - `value`: the value to set all bits to
///
/// # Panics
///
/// - when `bit_vec` is NULL
///
/// # Safety
///
/// The caller has to make sure that:
///
/// - `bit_vec` points to a valid [SPBitVec]
/// - `bit_vec` is not written to or read from concurrently
/// </summary>
2024-10-19 16:19:09 +02:00
[System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public void Fill(bool value)
{
2024-10-20 12:08:19 +02:00
BitVec.sp_bitvec_fill(this.__Instance, value);
}
2024-10-16 21:59:35 +02:00
/// <summary>
/// Gets the length of the [SPBitVec] in bits.
///
/// # Arguments
///
/// - `bit_vec`: instance to write to
///
/// # Panics
///
/// - when `bit_vec` is NULL
///
/// # Safety
///
/// The caller has to make sure that:
///
/// - `bit_vec` points to a valid [SPBitVec]
/// </summary>
2024-10-19 16:19:09 +02:00
[System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public nuint Len()
{
2024-10-20 12:08:19 +02:00
return BitVec.sp_bitvec_len(this.__Instance);
}
2024-10-16 21:59:35 +02:00
/// <summary>
/// Returns true if length is 0.
///
/// # Arguments
///
/// - `bit_vec`: instance to write to
///
/// # Panics
///
/// - when `bit_vec` is NULL
///
/// # Safety
///
/// The caller has to make sure that:
///
/// - `bit_vec` points to a valid [SPBitVec]
/// </summary>
2024-10-19 16:19:09 +02:00
[System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public bool IsEmpty()
{
2024-10-20 12:08:19 +02:00
return BitVec.sp_bitvec_is_empty(this.__Instance);
}
2024-10-16 21:59:35 +02:00
/// <summary>
/// Gets an unsafe reference to the data of the [SPBitVec] instance.
///
/// # Arguments
///
/// - `bit_vec`: instance to write to
///
/// # Panics
///
/// - when `bit_vec` is NULL
///
/// ## Safety
///
/// The caller has to make sure that:
///
/// - `bit_vec` points to a valid [SPBitVec]
/// - the returned memory range is never accessed after the passed [SPBitVec] has been freed
/// - the returned memory range is never accessed concurrently, either via the [SPBitVec] or directly
/// </summary>
2024-10-19 16:19:09 +02:00
[System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public SPByteSlice UnsafeDataRef()
{
2024-10-20 12:08:19 +02:00
return BitVec.sp_bitvec_unsafe_data_ref(this.__Instance);
}
#region internal machinery
private SPBitVec* _instance;
2024-10-20 12:08:19 +02:00
internal SPBitVec* __Instance
{
get
{
if (_instance == null)
throw new NullReferenceException("instance is null");
return _instance;
}
}
private BitVec(SPBitVec* instance)
{
ArgumentNullException.ThrowIfNull(instance);
_instance = instance;
}
2024-10-20 12:08:19 +02:00
internal SPBitVec* __Into()
{
2024-10-20 12:08:19 +02:00
var instance = __Instance;
_instance = null;
return instance;
}
2024-10-20 12:08:19 +02:00
private void __Free()
{
if (_instance != null)
2024-10-20 12:08:19 +02:00
BitVec.sp_bitvec_free(__Into());
}
public void Dispose()
{
2024-10-20 12:08:19 +02:00
__Free();
GC.SuppressFinalize(this);
}
2024-10-20 12:08:19 +02:00
~BitVec() => __Free();
#endregion
#nullable restore
#region native methods
const string __DllName = "servicepoint_binding_c";
[DllImport(__DllName, EntryPoint = "sp_bitvec_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern SPBitVec* sp_bitvec_new(nuint size);
[DllImport(__DllName, EntryPoint = "sp_bitvec_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern SPBitVec* sp_bitvec_load(byte* data, nuint data_length);
[DllImport(__DllName, EntryPoint = "sp_bitvec_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern SPBitVec* sp_bitvec_clone(SPBitVec* bit_vec);
[DllImport(__DllName, EntryPoint = "sp_bitvec_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern void sp_bitvec_free(SPBitVec* bit_vec);
[DllImport(__DllName, EntryPoint = "sp_bitvec_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.U1)]
private static extern bool sp_bitvec_get(SPBitVec* bit_vec, nuint index);
[DllImport(__DllName, EntryPoint = "sp_bitvec_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern void sp_bitvec_set(SPBitVec* bit_vec, nuint index, [MarshalAs(UnmanagedType.U1)] bool value);
[DllImport(__DllName, EntryPoint = "sp_bitvec_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern void sp_bitvec_fill(SPBitVec* bit_vec, [MarshalAs(UnmanagedType.U1)] bool value);
[DllImport(__DllName, EntryPoint = "sp_bitvec_len", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern nuint sp_bitvec_len(SPBitVec* bit_vec);
[DllImport(__DllName, EntryPoint = "sp_bitvec_is_empty", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.U1)]
private static extern bool sp_bitvec_is_empty(SPBitVec* bit_vec);
2024-10-16 21:59:35 +02:00
[DllImport(__DllName, EntryPoint = "sp_bitvec_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern SPByteSlice sp_bitvec_unsafe_data_ref(SPBitVec* bit_vec);
2024-10-16 21:59:35 +02:00
#endregion
2024-10-16 21:59:35 +02:00
}
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct SPBitVec
2024-10-16 21:59:35 +02:00
{
}
}