DisposableObject.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using UnityEngine;
  2. using System;
  3. namespace OpenCVForUnity
  4. {
  5. abstract public class DisposableObject : IDisposable
  6. {
  7. public bool IsDisposed { get; protected set; }
  8. public bool IsEnabledDispose { get; set; }
  9. protected DisposableObject()
  10. : this(true)
  11. {
  12. }
  13. protected DisposableObject(bool isEnabledDispose)
  14. {
  15. IsEnabledDispose = isEnabledDispose;
  16. IsDisposed = false;
  17. }
  18. public void Dispose()
  19. {
  20. Dispose(true);
  21. GC.SuppressFinalize(this);
  22. }
  23. protected virtual void Dispose(bool disposing)
  24. {
  25. if (!IsDisposed)
  26. {
  27. if (disposing)
  28. {
  29. }
  30. IsDisposed = true;
  31. }
  32. }
  33. ~DisposableObject()
  34. {
  35. Dispose(false);
  36. }
  37. public void ThrowIfDisposed()
  38. {
  39. if (IsDisposed)
  40. throw new ObjectDisposedException(GetType().FullName);
  41. }
  42. public static IntPtr ThrowIfNullIntPtr(IntPtr ptr)
  43. {
  44. if (ptr == IntPtr.Zero)
  45. throw new CoreModule.CvException("An error occurred on the C++ side, causing the class initialization to fail.Enclose the point where the error occurs in Utils.setDebugMode() method, and the error on the C++ side will be displayed on the console.");
  46. return ptr;
  47. }
  48. }
  49. }