Files
I150/srcs/RobotNet10/RobotApp/Communication/CeresSharp/Native/SafeHandles/CovarianceHandle.cs
2026-07-03 16:37:12 +07:00

44 lines
1.3 KiB
C#

using System;
using CeresSharp.Native;
namespace CeresSharp.Native.SafeHandles;
/// <summary>
/// Safe handle for Ceres Covariance.
/// </summary>
internal sealed class CovarianceHandle : BaseSafeHandle
{
private CovarianceHandle() : base()
{
}
private CovarianceHandle(IntPtr handle, bool ownsHandle) : base(handle, ownsHandle)
{
}
public static CovarianceHandle Create()
{
var handle = CeresNative.ceres_wrapper_create_covariance();
if (handle == IntPtr.Zero)
{
throw new Exceptions.CeresException(Exceptions.CeresErrorCode.OutOfMemory, "Failed to create covariance");
}
return new CovarianceHandle(handle, true);
}
public static CovarianceHandle CreateWithOptions(IntPtr options)
{
var handle = CeresNative.ceres_wrapper_create_covariance_with_options(options);
if (handle == IntPtr.Zero)
{
throw new Exceptions.CeresException(Exceptions.CeresErrorCode.OutOfMemory, "Failed to create covariance with options");
}
return new CovarianceHandle(handle, true);
}
protected override void ReleaseNativeHandle(IntPtr handle)
{
CeresNative.ceres_wrapper_free_covariance(handle);
}
}