DictValue.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #if !UNITY_WSA_10_0
  2. using OpenCVForUnity.CoreModule;
  3. using OpenCVForUnity.UtilsModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.DnnModule
  8. {
  9. // C++: class DictValue
  10. /**
  11. * This struct stores the scalar value (or array) of one of the following type: double, cv::String or int64.
  12. * TODO: Maybe int64 is useless because double type exactly stores at least 2^52 integers.
  13. */
  14. public class DictValue : DisposableOpenCVObject
  15. {
  16. protected override void Dispose(bool disposing)
  17. {
  18. try
  19. {
  20. if (disposing)
  21. {
  22. }
  23. if (IsEnabledDispose)
  24. {
  25. if (nativeObj != IntPtr.Zero)
  26. dnn_DictValue_delete(nativeObj);
  27. nativeObj = IntPtr.Zero;
  28. }
  29. }
  30. finally
  31. {
  32. base.Dispose(disposing);
  33. }
  34. }
  35. protected internal DictValue(IntPtr addr) : base(addr) { }
  36. public IntPtr getNativeObjAddr() { return nativeObj; }
  37. // internal usage only
  38. public static DictValue __fromPtr__(IntPtr addr) { return new DictValue(addr); }
  39. //
  40. // C++: cv::dnn::DictValue::DictValue(int i)
  41. //
  42. public DictValue(int i)
  43. {
  44. nativeObj = DisposableObject.ThrowIfNullIntPtr(dnn_DictValue_DictValue_10(i));
  45. }
  46. //
  47. // C++: cv::dnn::DictValue::DictValue(double p)
  48. //
  49. public DictValue(double p)
  50. {
  51. nativeObj = DisposableObject.ThrowIfNullIntPtr(dnn_DictValue_DictValue_11(p));
  52. }
  53. //
  54. // C++: cv::dnn::DictValue::DictValue(String s)
  55. //
  56. public DictValue(string s)
  57. {
  58. nativeObj = DisposableObject.ThrowIfNullIntPtr(dnn_DictValue_DictValue_12(s));
  59. }
  60. //
  61. // C++: bool cv::dnn::DictValue::isInt()
  62. //
  63. public bool isInt()
  64. {
  65. ThrowIfDisposed();
  66. return dnn_DictValue_isInt_10(nativeObj);
  67. }
  68. //
  69. // C++: bool cv::dnn::DictValue::isString()
  70. //
  71. public bool isString()
  72. {
  73. ThrowIfDisposed();
  74. return dnn_DictValue_isString_10(nativeObj);
  75. }
  76. //
  77. // C++: bool cv::dnn::DictValue::isReal()
  78. //
  79. public bool isReal()
  80. {
  81. ThrowIfDisposed();
  82. return dnn_DictValue_isReal_10(nativeObj);
  83. }
  84. //
  85. // C++: int cv::dnn::DictValue::getIntValue(int idx = -1)
  86. //
  87. public int getIntValue(int idx)
  88. {
  89. ThrowIfDisposed();
  90. return dnn_DictValue_getIntValue_10(nativeObj, idx);
  91. }
  92. public int getIntValue()
  93. {
  94. ThrowIfDisposed();
  95. return dnn_DictValue_getIntValue_11(nativeObj);
  96. }
  97. //
  98. // C++: double cv::dnn::DictValue::getRealValue(int idx = -1)
  99. //
  100. public double getRealValue(int idx)
  101. {
  102. ThrowIfDisposed();
  103. return dnn_DictValue_getRealValue_10(nativeObj, idx);
  104. }
  105. public double getRealValue()
  106. {
  107. ThrowIfDisposed();
  108. return dnn_DictValue_getRealValue_11(nativeObj);
  109. }
  110. //
  111. // C++: String cv::dnn::DictValue::getStringValue(int idx = -1)
  112. //
  113. public string getStringValue(int idx)
  114. {
  115. ThrowIfDisposed();
  116. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(dnn_DictValue_getStringValue_10(nativeObj, idx)));
  117. return retVal;
  118. }
  119. public string getStringValue()
  120. {
  121. ThrowIfDisposed();
  122. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(dnn_DictValue_getStringValue_11(nativeObj)));
  123. return retVal;
  124. }
  125. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  126. const string LIBNAME = "__Internal";
  127. #else
  128. const string LIBNAME = "opencvforunity";
  129. #endif
  130. // C++: cv::dnn::DictValue::DictValue(int i)
  131. [DllImport(LIBNAME)]
  132. private static extern IntPtr dnn_DictValue_DictValue_10(int i);
  133. // C++: cv::dnn::DictValue::DictValue(double p)
  134. [DllImport(LIBNAME)]
  135. private static extern IntPtr dnn_DictValue_DictValue_11(double p);
  136. // C++: cv::dnn::DictValue::DictValue(String s)
  137. [DllImport(LIBNAME)]
  138. private static extern IntPtr dnn_DictValue_DictValue_12(string s);
  139. // C++: bool cv::dnn::DictValue::isInt()
  140. [DllImport(LIBNAME)]
  141. [return: MarshalAs(UnmanagedType.U1)]
  142. private static extern bool dnn_DictValue_isInt_10(IntPtr nativeObj);
  143. // C++: bool cv::dnn::DictValue::isString()
  144. [DllImport(LIBNAME)]
  145. [return: MarshalAs(UnmanagedType.U1)]
  146. private static extern bool dnn_DictValue_isString_10(IntPtr nativeObj);
  147. // C++: bool cv::dnn::DictValue::isReal()
  148. [DllImport(LIBNAME)]
  149. [return: MarshalAs(UnmanagedType.U1)]
  150. private static extern bool dnn_DictValue_isReal_10(IntPtr nativeObj);
  151. // C++: int cv::dnn::DictValue::getIntValue(int idx = -1)
  152. [DllImport(LIBNAME)]
  153. private static extern int dnn_DictValue_getIntValue_10(IntPtr nativeObj, int idx);
  154. [DllImport(LIBNAME)]
  155. private static extern int dnn_DictValue_getIntValue_11(IntPtr nativeObj);
  156. // C++: double cv::dnn::DictValue::getRealValue(int idx = -1)
  157. [DllImport(LIBNAME)]
  158. private static extern double dnn_DictValue_getRealValue_10(IntPtr nativeObj, int idx);
  159. [DllImport(LIBNAME)]
  160. private static extern double dnn_DictValue_getRealValue_11(IntPtr nativeObj);
  161. // C++: String cv::dnn::DictValue::getStringValue(int idx = -1)
  162. [DllImport(LIBNAME)]
  163. private static extern IntPtr dnn_DictValue_getStringValue_10(IntPtr nativeObj, int idx);
  164. [DllImport(LIBNAME)]
  165. private static extern IntPtr dnn_DictValue_getStringValue_11(IntPtr nativeObj);
  166. // native support for java finalize()
  167. [DllImport(LIBNAME)]
  168. private static extern void dnn_DictValue_delete(IntPtr nativeObj);
  169. }
  170. }
  171. #endif