using System; using CeresSharp.Native; namespace CeresSharp.Native.SafeHandles; /// /// Safe handle for Ceres Covariance. /// 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); } }