HDict.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /***********************************************************
  2. * File generated by the HALCON-Compiler hcomp version 22.05
  3. * Usage: Interface to C++
  4. *
  5. * Software by: MVTec Software GmbH, www.mvtec.com
  6. ***********************************************************/
  7. #ifndef HCPP_HDICT
  8. #define HCPP_HDICT
  9. namespace HalconCpp
  10. {
  11. // Represents an instance of a Dictionary.
  12. class LIntExport HDict : public HHandle
  13. {
  14. public:
  15. // Copy constructor
  16. HDict(const HDict& source) : HHandle(source) {}
  17. // Copy constructor
  18. HDict(const HHandle& handle);
  19. // Create HDict from handle, taking ownership
  20. explicit HDict(Hlong handle);
  21. bool operator==(const HHandle& obj) const
  22. {
  23. return HHandleBase::operator==(obj);
  24. }
  25. bool operator!=(const HHandle& obj) const
  26. {
  27. return HHandleBase::operator!=(obj);
  28. }
  29. protected:
  30. // Verify matching semantic type ('dict')!
  31. virtual void AssertType(Hphandle handle) const;
  32. public:
  33. /*****************************************************************************
  34. * Operator-based class constructors
  35. *****************************************************************************/
  36. // create_dict: Create a new empty dictionary.
  37. explicit HDict();
  38. // read_dict: Read a dictionary from a file.
  39. explicit HDict(const HString& FileName, const HTuple& GenParamName, const HTuple& GenParamValue);
  40. // read_dict: Read a dictionary from a file.
  41. explicit HDict(const HString& FileName, const HString& GenParamName, const HString& GenParamValue);
  42. // read_dict: Read a dictionary from a file.
  43. explicit HDict(const char* FileName, const char* GenParamName, const char* GenParamValue);
  44. #ifdef _WIN32
  45. // read_dict: Read a dictionary from a file.
  46. explicit HDict(const wchar_t* FileName, const wchar_t* GenParamName, const wchar_t* GenParamValue);
  47. #endif
  48. /***************************************************************************
  49. * Operators *
  50. ***************************************************************************/
  51. // Copy a dictionary.
  52. HDict CopyDict(const HTuple& GenParamName, const HTuple& GenParamValue) const;
  53. // Copy a dictionary.
  54. HDict CopyDict(const HString& GenParamName, const HString& GenParamValue) const;
  55. // Copy a dictionary.
  56. HDict CopyDict(const char* GenParamName, const char* GenParamValue) const;
  57. #ifdef _WIN32
  58. // Copy a dictionary.
  59. HDict CopyDict(const wchar_t* GenParamName, const wchar_t* GenParamValue) const;
  60. #endif
  61. // Create a new empty dictionary.
  62. void CreateDict();
  63. // Retrieve an object associated with the key from the dictionary.
  64. HObject GetDictObject(const HTuple& Key) const;
  65. // Retrieve an object associated with the key from the dictionary.
  66. HObject GetDictObject(const HString& Key) const;
  67. // Retrieve an object associated with the key from the dictionary.
  68. HObject GetDictObject(const char* Key) const;
  69. #ifdef _WIN32
  70. // Retrieve an object associated with the key from the dictionary.
  71. HObject GetDictObject(const wchar_t* Key) const;
  72. #endif
  73. // Query dictionary parameters or information about a dictionary.
  74. HTuple GetDictParam(const HString& GenParamName, const HTuple& Key) const;
  75. // Query dictionary parameters or information about a dictionary.
  76. HTuple GetDictParam(const HString& GenParamName, const HString& Key) const;
  77. // Query dictionary parameters or information about a dictionary.
  78. HTuple GetDictParam(const char* GenParamName, const char* Key) const;
  79. #ifdef _WIN32
  80. // Query dictionary parameters or information about a dictionary.
  81. HTuple GetDictParam(const wchar_t* GenParamName, const wchar_t* Key) const;
  82. #endif
  83. // Retrieve a tuple associated with the key from the dictionary.
  84. HTuple GetDictTuple(const HTuple& Key) const;
  85. // Retrieve a tuple associated with the key from the dictionary.
  86. HTuple GetDictTuple(const HString& Key) const;
  87. // Retrieve a tuple associated with the key from the dictionary.
  88. HTuple GetDictTuple(const char* Key) const;
  89. #ifdef _WIN32
  90. // Retrieve a tuple associated with the key from the dictionary.
  91. HTuple GetDictTuple(const wchar_t* Key) const;
  92. #endif
  93. // Read a dictionary from a file.
  94. void ReadDict(const HString& FileName, const HTuple& GenParamName, const HTuple& GenParamValue);
  95. // Read a dictionary from a file.
  96. void ReadDict(const HString& FileName, const HString& GenParamName, const HString& GenParamValue);
  97. // Read a dictionary from a file.
  98. void ReadDict(const char* FileName, const char* GenParamName, const char* GenParamValue);
  99. #ifdef _WIN32
  100. // Read a dictionary from a file.
  101. void ReadDict(const wchar_t* FileName, const wchar_t* GenParamName, const wchar_t* GenParamValue);
  102. #endif
  103. // Remove keys from a dictionary.
  104. void RemoveDictKey(const HTuple& Key) const;
  105. // Remove keys from a dictionary.
  106. void RemoveDictKey(const HString& Key) const;
  107. // Remove keys from a dictionary.
  108. void RemoveDictKey(const char* Key) const;
  109. #ifdef _WIN32
  110. // Remove keys from a dictionary.
  111. void RemoveDictKey(const wchar_t* Key) const;
  112. #endif
  113. // Add a key/object pair to the dictionary.
  114. void SetDictObject(const HObject& Object, const HTuple& Key) const;
  115. // Add a key/object pair to the dictionary.
  116. void SetDictObject(const HObject& Object, const HString& Key) const;
  117. // Add a key/object pair to the dictionary.
  118. void SetDictObject(const HObject& Object, const char* Key) const;
  119. #ifdef _WIN32
  120. // Add a key/object pair to the dictionary.
  121. void SetDictObject(const HObject& Object, const wchar_t* Key) const;
  122. #endif
  123. // Add a key/tuple pair to the dictionary.
  124. void SetDictTuple(const HTuple& Key, const HTuple& Tuple) const;
  125. // Add a key/tuple pair to the dictionary.
  126. void SetDictTuple(const HString& Key, const HTuple& Tuple) const;
  127. // Add a key/tuple pair to the dictionary.
  128. void SetDictTuple(const char* Key, const HTuple& Tuple) const;
  129. #ifdef _WIN32
  130. // Add a key/tuple pair to the dictionary.
  131. void SetDictTuple(const wchar_t* Key, const HTuple& Tuple) const;
  132. #endif
  133. // Write a dictionary to a file.
  134. void WriteDict(const HString& FileName, const HTuple& GenParamName, const HTuple& GenParamValue) const;
  135. // Write a dictionary to a file.
  136. void WriteDict(const HString& FileName, const HString& GenParamName, const HString& GenParamValue) const;
  137. // Write a dictionary to a file.
  138. void WriteDict(const char* FileName, const char* GenParamName, const char* GenParamValue) const;
  139. #ifdef _WIN32
  140. // Write a dictionary to a file.
  141. void WriteDict(const wchar_t* FileName, const wchar_t* GenParamName, const wchar_t* GenParamValue) const;
  142. #endif
  143. // Transform a dictionary into a JSON string.
  144. static HTuple DictToJson(const HDictArray& DictHandle, const HTuple& GenParamName, const HTuple& GenParamValue);
  145. // Transform a dictionary into a JSON string.
  146. HString DictToJson(const HString& GenParamName, const HString& GenParamValue) const;
  147. // Transform a dictionary into a JSON string.
  148. HString DictToJson(const char* GenParamName, const char* GenParamValue) const;
  149. #ifdef _WIN32
  150. // Transform a dictionary into a JSON string.
  151. HString DictToJson(const wchar_t* GenParamName, const wchar_t* GenParamValue) const;
  152. #endif
  153. // Transform a JSON string into a dictionary.
  154. static HDictArray JsonToDict(const HTuple& JsonString, const HTuple& GenParamName, const HTuple& GenParamValue);
  155. // Transform a JSON string into a dictionary.
  156. void JsonToDict(const HString& JsonString, const HString& GenParamName, const HString& GenParamValue);
  157. // Transform a JSON string into a dictionary.
  158. void JsonToDict(const char* JsonString, const char* GenParamName, const char* GenParamValue);
  159. #ifdef _WIN32
  160. // Transform a JSON string into a dictionary.
  161. void JsonToDict(const wchar_t* JsonString, const wchar_t* GenParamName, const wchar_t* GenParamValue);
  162. #endif
  163. // Assignment of one or several values to one or several tuple elements in a dictionary
  164. void SetDictTupleAt(const HTuple& Key, const HTuple& Index, const HTuple& Value) const;
  165. // Assignment of one or several values to one or several tuple elements in a dictionary
  166. void SetDictTupleAt(const HString& Key, const HTuple& Index, const HTuple& Value) const;
  167. // Assignment of one or several values to one or several tuple elements in a dictionary
  168. void SetDictTupleAt(const char* Key, const HTuple& Index, const HTuple& Value) const;
  169. #ifdef _WIN32
  170. // Assignment of one or several values to one or several tuple elements in a dictionary
  171. void SetDictTupleAt(const wchar_t* Key, const HTuple& Index, const HTuple& Value) const;
  172. #endif
  173. };
  174. // forward declarations and types for internal array implementation
  175. template<class T> class HSmartPtr;
  176. template<class T> class HHandleBaseArrayRef;
  177. typedef HHandleBaseArrayRef<HDict> HDictArrayRef;
  178. typedef HSmartPtr< HDictArrayRef > HDictArrayPtr;
  179. // Represents multiple tool instances
  180. class LIntExport HDictArray : public HHandleBaseArray
  181. {
  182. public:
  183. // Create empty array
  184. HDictArray();
  185. // Create array from native array of tool instances
  186. HDictArray(const HDict* classes, Hlong length);
  187. // Copy constructor
  188. HDictArray(const HDictArray &tool_array);
  189. // Destructor
  190. virtual ~HDictArray();
  191. // Assignment operator
  192. HDictArray &operator=(const HDictArray &tool_array);
  193. // Clears array and all tool instances
  194. virtual void Clear();
  195. // Get array of native tool instances
  196. const HDict* Tools() const;
  197. // Get number of tools
  198. virtual Hlong Length() const;
  199. // Create tool array from tuple of handles
  200. virtual void SetFromTuple(const HTuple& handles);
  201. // Get tuple of handles for tool array
  202. virtual HTuple ConvertToTuple() const;
  203. protected:
  204. // Smart pointer to internal data container
  205. HDictArrayPtr *mArrayPtr;
  206. };
  207. }
  208. #endif