HTuple.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  1. /*****************************************************************************
  2. * HTuple.h
  3. *****************************************************************************
  4. *
  5. * Project: HALCON/C++
  6. * Description: Tuple data used for control parameters of HALCON operators
  7. * Generated via HTuple1.hop and HTuple2.hop
  8. *
  9. * (c) 2010-2018 by MVTec Software GmbH
  10. * www.mvtec.com
  11. *
  12. *****************************************************************************/
  13. #ifndef HCPP_TUPLE_H
  14. # define HCPP_TUPLE_H
  15. # include <new>
  16. namespace HalconCpp
  17. {
  18. enum HTupleType
  19. {
  20. // The empty tuple does not yet have a defined data type
  21. eTupleTypeEmpty = UNDEF_PAR,
  22. // The tuple is a pure array of integers
  23. eTupleTypeLong = LONG_PAR,
  24. // The tuple is a pure array of floating point values
  25. eTupleTypeDouble = DOUBLE_PAR,
  26. // The tuple is a pure array of strings
  27. eTupleTypeString = STRING_PAR,
  28. // The tuple is a pure array of handles
  29. eTupleTypeHandle = HANDLE_PAR,
  30. // The tuple is an array of Hcpar. Each element can have a different type
  31. eTupleTypeMixed = MIXED_PAR
  32. };
  33. }
  34. # include "halconcpp/HTupleElement.h"
  35. namespace HalconCpp
  36. {
  37. // Smart pointer to internal data representation
  38. template<class T> class HSmartPtr;
  39. typedef HSmartPtr<HTupleData> HTupleDataPtr;
  40. // Tuple data used for control parameters of HALCON operators
  41. class LIntExport HTuple
  42. {
  43. friend class HalconAPI;
  44. friend class HTupleElement;
  45. public:
  46. /***************************************************************************/
  47. /* Constructors / Destructor */
  48. /***************************************************************************/
  49. // Empty tuple
  50. HTuple();
  51. // Integer (machine pointer size)
  52. HTuple(Hlong l);
  53. // Integer array (machine pointer size)
  54. HTuple(const Hlong* l, Hlong num);
  55. # if defined(HCPP_INT_OVERLOADS)
  56. // Integer (possibly smaller size than pointer)
  57. HTuple(int i);
  58. // Integer array (possibly smaller size than pointer)
  59. HTuple(const int* i, Hlong num);
  60. # endif
  61. // Single precision floating point value
  62. HTuple(float f);
  63. // Single precision floating point array
  64. HTuple(const float* f, Hlong num);
  65. // Double precision floating point value
  66. HTuple(double d);
  67. // Double precision floating point array
  68. HTuple(const double* d, Hlong num);
  69. // String (C style)
  70. HTuple(const char* s);
  71. # ifdef _WIN32
  72. // String (C style wide character string)
  73. HTuple(const wchar_t* s);
  74. # endif
  75. // String (object)
  76. HTuple(const HString& s);
  77. // Handle
  78. # if defined(HCPP_LEGACY_HANDLE_API)
  79. // Implicit conversion from new handle type may cause ambiguities or
  80. // incompatibilies with legacy code (especially HMatrix to HTuple). Instead
  81. // conversion is handled by cast from HHandle to HTuple
  82. explicit HTuple(const HHandle& h);
  83. # else
  84. HTuple(const HHandle& h);
  85. # endif
  86. // Mixed
  87. HTuple(Hcpar* p, Hlong num);
  88. // Constant tuple
  89. HTuple(const HTuple& length, const HTuple& value);
  90. // Element of another tuple
  91. HTuple(const HTupleElement& element);
  92. // HTuple copy constructor
  93. HTuple(const HTuple& tuple);
  94. // Destructor
  95. virtual ~HTuple();
  96. /***************************************************************************/
  97. /* General members */
  98. /***************************************************************************/
  99. // Clear all data inside this tuple
  100. void Clear();
  101. // The number of elements of this tuple
  102. Hlong Length() const;
  103. // The data type of this tuple (pure data types or mixed tuple)
  104. HTupleType Type() const;
  105. // Create a detached copy duplicating the underlying tuple data
  106. HTuple Clone() const;
  107. // Append data to existing tuple
  108. HTuple& Append(const HTuple& tuple);
  109. // Returns a simple string representation of the tuple contents,
  110. // mainly intended for debugging purposes
  111. HString ToString() const;
  112. /***************************************************************************/
  113. /* Data access */
  114. /***************************************************************************/
  115. // Direct array access will raise an exception if tuple type does not match!
  116. // Modifications to array will affect data in tuples as well.
  117. Hlong* LArr();
  118. double* DArr();
  119. char** SArr();
  120. Hcpar* PArr();
  121. // Safer but less efficient access is provided by copying the data.
  122. // Mismatched elements will be initialized with default values. Caller
  123. // is responsible for using HTuple::DeleteArr() to free the array (do
  124. // not use "delete []" directly as transferring memory ownership
  125. // across DLL boundaries may cause problems with the C++ runtime)
  126. // Returns the tuple data as an array of Hlong. Release using DeleteArr()!
  127. Hlong* ToLArr() const;
  128. // Returns the tuple data as an array of double. Release using DeleteArr()!
  129. double* ToDArr() const;
  130. // Returns the tuple data as an array of HString. Release using DeleteArr()!
  131. HString* ToSArr() const;
  132. static void DeleteArr(Hlong* arr);
  133. static void DeleteArr(double* arr);
  134. static void DeleteArr(HString* arr);
  135. // Intentionally no ToPArr() as correctly releasing memory
  136. // for a Hcpar* array is problematic for the library user.
  137. // Assignment operator
  138. HTuple& operator=(const HTuple& obj);
  139. // Element access
  140. HTupleElement operator[](Hlong index);
  141. const HTupleElement operator[](Hlong index) const;
  142. HTupleElement operator[](const HTuple& index);
  143. const HTupleElement operator[](const HTuple& index) const;
  144. // Convenience access for first element
  145. # if defined(HCPP_INT_OVERLOADS)
  146. // Access integer value in first tuple element
  147. int I() const
  148. {
  149. return (*this)[0].I();
  150. }
  151. # endif
  152. // Access integer value in first tuple element
  153. Hlong L() const
  154. {
  155. return (*this)[0].L();
  156. }
  157. // Access floating-point value in first tuple element
  158. double D() const
  159. {
  160. return (*this)[0].D();
  161. }
  162. // Access string value in first tuple element
  163. HString S() const
  164. {
  165. return (*this)[0].S();
  166. }
  167. // Access handle value in first tuple element
  168. HHandle H() const
  169. {
  170. return (*this)[0].H();
  171. }
  172. /***************************************************************************
  173. * Operators *
  174. ***************************************************************************/
  175. // Compute the union set of two input tuples.
  176. HTuple TupleUnion(const HTuple& Set2) const;
  177. // Compute the intersection set of two input tuples.
  178. HTuple TupleIntersection(const HTuple& Set2) const;
  179. // Compute the difference set of two input tuples.
  180. HTuple TupleDifference(const HTuple& Set2) const;
  181. // Compute the symmetric difference set of two input tuples.
  182. HTuple TupleSymmdiff(const HTuple& Set2) const;
  183. // Test whether the types of the elements of a tuple are of type string.
  184. HTuple TupleIsStringElem() const;
  185. // Test whether the types of the elements of a tuple are of type real.
  186. HTuple TupleIsRealElem() const;
  187. // Test whether the types of the elements of a tuple are of type integer.
  188. HTuple TupleIsIntElem() const;
  189. // Return the types of the elements of a tuple.
  190. HTuple TupleTypeElem() const;
  191. // Test whether a tuple is of type mixed.
  192. HTuple TupleIsMixed() const;
  193. // Test if the internal representation of a tuple is of type string.
  194. HTuple TupleIsString() const;
  195. // Test if the internal representation of a tuple is of type real.
  196. HTuple TupleIsReal() const;
  197. // Test if the internal representation of a tuple is of type integer.
  198. HTuple TupleIsInt() const;
  199. // Return the type of a tuple.
  200. HTuple TupleType() const;
  201. // Calculate the value distribution of a tuple within a certain value range.
  202. HTuple TupleHistoRange(const HTuple& Min, const HTuple& Max, const HTuple& NumBins, HTuple* BinSize) const;
  203. // Select tuple elements matching a regular expression.
  204. HTuple TupleRegexpSelect(const HTuple& Expression) const;
  205. // Test if a string matches a regular expression.
  206. HTuple TupleRegexpTest(const HTuple& Expression) const;
  207. // Replace a substring using regular expressions.
  208. HTuple TupleRegexpReplace(const HTuple& Expression, const HTuple& Replace) const;
  209. // Extract substrings using regular expressions.
  210. HTuple TupleRegexpMatch(const HTuple& Expression) const;
  211. // Return a tuple of random numbers between 0 and 1.
  212. static HTuple TupleRand(const HTuple& Length);
  213. // Return the number of elements of a tuple.
  214. HTuple TupleLength() const;
  215. // Calculate the sign of a tuple.
  216. HTuple TupleSgn() const;
  217. // Calculate the elementwise maximum of two tuples.
  218. HTuple TupleMax2(const HTuple& T2) const;
  219. // Calculate the elementwise minimum of two tuples.
  220. HTuple TupleMin2(const HTuple& T2) const;
  221. // Return the maximal element of a tuple.
  222. HTuple TupleMax() const;
  223. // Return the minimal element of a tuple.
  224. HTuple TupleMin() const;
  225. // Calculate the cumulative sums of a tuple.
  226. HTuple TupleCumul() const;
  227. // Select the element of rank n of a tuple.
  228. HTuple TupleSelectRank(const HTuple& RankIndex) const;
  229. // Return the median of the elements of a tuple.
  230. HTuple TupleMedian() const;
  231. // Return the sum of all elements of a tuple.
  232. HTuple TupleSum() const;
  233. // Return the mean value of a tuple of numbers.
  234. HTuple TupleMean() const;
  235. // Return the standard deviation of the elements of a tuple.
  236. HTuple TupleDeviation() const;
  237. // Discard all but one of successive identical elements of a tuple.
  238. HTuple TupleUniq() const;
  239. // Return the index of the last occurrence of a tuple within another tuple.
  240. HTuple TupleFindLast(const HTuple& ToFind) const;
  241. // Return the index of the first occurrence of a tuple within another tuple.
  242. HTuple TupleFindFirst(const HTuple& ToFind) const;
  243. // Return the indices of all occurrences of a tuple within another tuple.
  244. HTuple TupleFind(const HTuple& ToFind) const;
  245. // Sort the elements of a tuple and return the indices of the sorted tuple.
  246. HTuple TupleSortIndex() const;
  247. // Sort the elements of a tuple in ascending order.
  248. HTuple TupleSort() const;
  249. // Invert a tuple.
  250. HTuple TupleInverse() const;
  251. // Concatenate two tuples to a new one.
  252. HTuple TupleConcat(const HTuple& T2) const;
  253. // Select several elements of a tuple.
  254. HTuple TupleSelectRange(const HTuple& Leftindex, const HTuple& Rightindex) const;
  255. // Select all elements from index "n" to the end of a tuple.
  256. HTuple TupleLastN(const HTuple& Index) const;
  257. // Select the first elements of a tuple up to the index "n".
  258. HTuple TupleFirstN(const HTuple& Index) const;
  259. // Inserts one or more elements into a tuple at index.
  260. HTuple TupleInsert(const HTuple& Index, const HTuple& InsertTuple) const;
  261. // Replaces one or more elements of a tuple.
  262. HTuple TupleReplace(const HTuple& Index, const HTuple& ReplaceTuple) const;
  263. // Remove elements from a tuple.
  264. HTuple TupleRemove(const HTuple& Index) const;
  265. // Select in mask specified elements of a tuple.
  266. HTuple TupleSelectMask(const HTuple& Mask) const;
  267. // Select single elements of a tuple.
  268. HTuple TupleSelect(const HTuple& Index) const;
  269. // Select single character or bit from a tuple.
  270. HTuple TupleStrBitSelect(const HTuple& Index) const;
  271. // Generate a tuple with a sequence of equidistant values.
  272. static HTuple TupleGenSequence(const HTuple& Start, const HTuple& End, const HTuple& Step);
  273. // Generate a tuple of a specific length and initialize its elements.
  274. static HTuple TupleGenConst(const HTuple& Length, const HTuple& Const);
  275. // Read one or more environment variables.
  276. HTuple TupleEnvironment() const;
  277. // Split strings into substrings using predefined separator symbol(s).
  278. HTuple TupleSplit(const HTuple& Separator) const;
  279. // Cut characters from position "n1" through "n2" out of a string tuple.
  280. HTuple TupleSubstr(const HTuple& Position1, const HTuple& Position2) const;
  281. // Cut all characters starting at position "n" out of a string tuple.
  282. HTuple TupleStrLastN(const HTuple& Position) const;
  283. // Cut the first characters up to position "n" out of a string tuple.
  284. HTuple TupleStrFirstN(const HTuple& Position) const;
  285. // Backward search for characters within a string tuple.
  286. HTuple TupleStrrchr(const HTuple& ToFind) const;
  287. // Forward search for characters within a string tuple.
  288. HTuple TupleStrchr(const HTuple& ToFind) const;
  289. // Backward search for strings within a string tuple.
  290. HTuple TupleStrrstr(const HTuple& ToFind) const;
  291. // Forward search for strings within a string tuple.
  292. HTuple TupleStrstr(const HTuple& ToFind) const;
  293. // Determine the length of every string within a tuple of strings.
  294. HTuple TupleStrlen() const;
  295. // Test, whether a tuple is elementwise less or equal to another tuple.
  296. HTuple TupleLessEqualElem(const HTuple& T2) const;
  297. // Test, whether a tuple is elementwise less than another tuple.
  298. HTuple TupleLessElem(const HTuple& T2) const;
  299. // Test, whether a tuple is elementwise greater or equal to another tuple.
  300. HTuple TupleGreaterEqualElem(const HTuple& T2) const;
  301. // Test, whether a tuple is elementwise greater than another tuple.
  302. HTuple TupleGreaterElem(const HTuple& T2) const;
  303. // Test, whether two tuples are elementwise not equal.
  304. HTuple TupleNotEqualElem(const HTuple& T2) const;
  305. // Test, whether two tuples are elementwise equal.
  306. HTuple TupleEqualElem(const HTuple& T2) const;
  307. // Test whether a tuple is less or equal to another tuple.
  308. HTuple TupleLessEqual(const HTuple& T2) const;
  309. // Test whether a tuple is less than another tuple.
  310. HTuple TupleLess(const HTuple& T2) const;
  311. // Test whether a tuple is greater or equal to another tuple.
  312. HTuple TupleGreaterEqual(const HTuple& T2) const;
  313. // Test whether a tuple is greater than another tuple.
  314. HTuple TupleGreater(const HTuple& T2) const;
  315. // Test whether two tuples are not equal.
  316. HTuple TupleNotEqual(const HTuple& T2) const;
  317. // Test whether two tuples are equal.
  318. HTuple TupleEqual(const HTuple& T2) const;
  319. // Compute the logical not of a tuple.
  320. HTuple TupleNot() const;
  321. // Compute the logical exclusive or of two tuples.
  322. HTuple TupleXor(const HTuple& T2) const;
  323. // Compute the logical or of two tuples.
  324. HTuple TupleOr(const HTuple& T2) const;
  325. // Compute the logical and of two tuples.
  326. HTuple TupleAnd(const HTuple& T2) const;
  327. // Compute the bitwise not of a tuple.
  328. HTuple TupleBnot() const;
  329. // Compute the bitwise exclusive or of two tuples.
  330. HTuple TupleBxor(const HTuple& T2) const;
  331. // Compute the bitwise or of two tuples.
  332. HTuple TupleBor(const HTuple& T2) const;
  333. // Compute the bitwise and of two tuples.
  334. HTuple TupleBand(const HTuple& T2) const;
  335. // Shift a tuple bitwise to the right.
  336. HTuple TupleRsh(const HTuple& Shift) const;
  337. // Shift a tuple bitwise to the left.
  338. HTuple TupleLsh(const HTuple& Shift) const;
  339. // Convert a tuple of integer numbers into strings.
  340. HTuple TupleChrt() const;
  341. // Convert a tuple of strings into a tuple of integer numbers.
  342. HTuple TupleOrds() const;
  343. // Convert a tuple of integer numbers into strings.
  344. HTuple TupleChr() const;
  345. // Convert a tuple of strings of length 1 into a tuple of integer numbers.
  346. HTuple TupleOrd() const;
  347. // Convert a tuple into a tuple of strings.
  348. HTuple TupleString(const HTuple& Format) const;
  349. // Check a tuple (of strings) whether it represents numbers.
  350. HTuple TupleIsNumber() const;
  351. // Convert a tuple (of strings) into a tuple of numbers.
  352. HTuple TupleNumber() const;
  353. // Convert a tuple into a tuple of integer numbers.
  354. HTuple TupleRound() const;
  355. // Convert a tuple into a tuple of integer numbers.
  356. HTuple TupleInt() const;
  357. // Convert a tuple into a tuple of floating point numbers.
  358. HTuple TupleReal() const;
  359. // Calculate the ldexp function of two tuples.
  360. HTuple TupleLdexp(const HTuple& T2) const;
  361. // Calculate the remainder of the floating point division of two tuples.
  362. HTuple TupleFmod(const HTuple& T2) const;
  363. // Calculate the remainder of the integer division of two tuples.
  364. HTuple TupleMod(const HTuple& T2) const;
  365. // Compute the ceiling function of a tuple.
  366. HTuple TupleCeil() const;
  367. // Compute the floor function of a tuple.
  368. HTuple TupleFloor() const;
  369. // Calculate the power function of two tuples.
  370. HTuple TuplePow(const HTuple& T2) const;
  371. // Compute the base 10 logarithm of a tuple.
  372. HTuple TupleLog10() const;
  373. // Compute the natural logarithm of a tuple.
  374. HTuple TupleLog() const;
  375. // Compute the exponential of a tuple.
  376. HTuple TupleExp() const;
  377. // Compute the hyperbolic tangent of a tuple.
  378. HTuple TupleTanh() const;
  379. // Compute the hyperbolic cosine of a tuple.
  380. HTuple TupleCosh() const;
  381. // Compute the hyperbolic sine of a tuple.
  382. HTuple TupleSinh() const;
  383. // Convert a tuple from degrees to radians.
  384. HTuple TupleRad() const;
  385. // Convert a tuple from radians to degrees.
  386. HTuple TupleDeg() const;
  387. // Compute the arctangent of a tuple for all four quadrants.
  388. HTuple TupleAtan2(const HTuple& X) const;
  389. // Compute the arctangent of a tuple.
  390. HTuple TupleAtan() const;
  391. // Compute the arccosine of a tuple.
  392. HTuple TupleAcos() const;
  393. // Compute the arcsine of a tuple.
  394. HTuple TupleAsin() const;
  395. // Compute the tangent of a tuple.
  396. HTuple TupleTan() const;
  397. // Compute the cosine of a tuple.
  398. HTuple TupleCos() const;
  399. // Compute the sine of a tuple.
  400. HTuple TupleSin() const;
  401. // Compute the absolute value of a tuple (as floating point numbers).
  402. HTuple TupleFabs() const;
  403. // Compute the square root of a tuple.
  404. HTuple TupleSqrt() const;
  405. // Compute the absolute value of a tuple.
  406. HTuple TupleAbs() const;
  407. // Negate a tuple.
  408. HTuple TupleNeg() const;
  409. // Divide two tuples.
  410. HTuple TupleDiv(const HTuple& Q2) const;
  411. // Multiply two tuples.
  412. HTuple TupleMult(const HTuple& P2) const;
  413. // Subtract two tuples.
  414. HTuple TupleSub(const HTuple& D2) const;
  415. // Add two tuples.
  416. HTuple TupleAdd(const HTuple& S2) const;
  417. // Deserialize a serialized tuple.
  418. static HTuple DeserializeTuple(const HSerializedItem& SerializedItemHandle);
  419. // Serialize a tuple.
  420. HSerializedItem SerializeTuple() const;
  421. // Write a tuple to a file.
  422. void WriteTuple(const HTuple& FileName) const;
  423. // Read a tuple from a file.
  424. static HTuple ReadTuple(const HTuple& FileName);
  425. // Clear the content of a handle.
  426. void ClearHandle() const;
  427. // Test if the internal representation of a tuple is of type handle.
  428. HTuple TupleIsHandle() const;
  429. // Test whether the elements of a tuple are of type handle.
  430. HTuple TupleIsHandleElem() const;
  431. // Test if a tuple is serializable.
  432. HTuple TupleIsSerializable() const;
  433. // Test if the elements of a tuple are serializable.
  434. HTuple TupleIsSerializableElem() const;
  435. // Check if a handle is valid.
  436. HTuple TupleIsValidHandle() const;
  437. // Return the semantic type of a tuple.
  438. HTuple TupleSemType() const;
  439. // Return the semantic type of the elements of a tuple.
  440. HTuple TupleSemTypeElem() const;
  441. // Compute the inverse hyperbolic cosine of a tuple.
  442. HTuple TupleAcosh() const;
  443. // Compute the inverse hyperbolic sine of a tuple.
  444. HTuple TupleAsinh() const;
  445. // Compute the inverse hyperbolic tangent of a tuple.
  446. HTuple TupleAtanh() const;
  447. // Compute the cube root of a tuple.
  448. HTuple TupleCbrt() const;
  449. // Compute the error function of a tuple.
  450. HTuple TupleErf() const;
  451. // Compute the complementary error function of a tuple.
  452. HTuple TupleErfc() const;
  453. // Compute the base 10 exponential of a tuple.
  454. HTuple TupleExp10() const;
  455. // Compute the base 2 exponential of a tuple.
  456. HTuple TupleExp2() const;
  457. // Calculate the hypotenuse of two tuples.
  458. HTuple TupleHypot(const HTuple& T2) const;
  459. // Compute the logarithm of the absolute value of the gamma function of a tuple.
  460. HTuple TupleLgamma() const;
  461. // Compute the base 2 logarithm of a tuple.
  462. HTuple TupleLog2() const;
  463. // Compute the gamma function of a tuple.
  464. HTuple TupleTgamma() const;
  465. // Join strings using separator symbol(s).
  466. HTuple TupleJoin(const HTuple& Separators) const;
  467. /***************************************************************************/
  468. /* Compatibility Layer */
  469. /***************************************************************************/
  470. #if defined(HCPP_LEGACY_API)
  471. # include "halconcpp/HTupleLegacy.h"
  472. #endif
  473. #if (!defined(HCPP_LEGACY_API) || defined(_LIntDLL))
  474. // Casts from a HTuple to element data types are disabled in legacy mode,
  475. // as they may lead to ambiguous operator calls in existing user code
  476. # if defined(HCPP_INT_OVERLOADS)
  477. // Access integer value in first tuple element
  478. operator int() const
  479. {
  480. return I();
  481. }
  482. # endif
  483. // Access integer value in first tuple element
  484. operator Hlong() const
  485. {
  486. return L();
  487. }
  488. // Access floating-point value in first tuple element
  489. operator float() const
  490. {
  491. return (float)D();
  492. }
  493. // Access floating-point value in first tuple element
  494. operator double() const
  495. {
  496. return D();
  497. }
  498. // Access string value in first tuple element
  499. operator HString() const
  500. {
  501. return S();
  502. }
  503. # if (!defined(HCPP_LEGACY_HANDLE_API) || defined(_LIntDLL))
  504. // Access handle value in first tuple element
  505. operator HHandle() const
  506. {
  507. return H();
  508. }
  509. # endif
  510. #endif
  511. /***************************************************************************/
  512. /* Operator overloads */
  513. /***************************************************************************/
  514. /* Unary operators */
  515. bool operator!(void) const;
  516. HTuple operator~(void) const;
  517. HTuple operator-(void) const;
  518. HTuple& operator++(void);
  519. /* Binary operators are declared below outside class HTuple */
  520. /* Selected compound operators */
  521. HTuple& operator+=(const HTuple& val);
  522. H_COMPOUND_OP_OVERLOAD_DECLARATION(HTuple, +=);
  523. HTuple& operator-=(const HTuple& val);
  524. H_COMPOUND_OP_OVERLOAD_DECLARATION(HTuple, -=);
  525. HTuple& operator*=(const HTuple& val);
  526. H_COMPOUND_OP_OVERLOAD_DECLARATION(HTuple, *=);
  527. /***************************************************************************/
  528. /* Helpers for code export or extension packages, do not call in used code */
  529. /***************************************************************************/
  530. bool Continue(const HTuple& final_value, const HTuple& increment);
  531. // Internal use, exposed for extension packages / hdevengine / export only
  532. HTuple(const Hctuple& tuple, bool copy = true);
  533. Hctuple GetHctuple(bool copy) const;
  534. const Hctuple& GetHctupleRef() const;
  535. void TranscodeFromUtf8ToInterfaceEncoding();
  536. HTuple TupleGetDictTuple(const HTuple& key);
  537. HObject TupleGetDictObject(const HTuple& key);
  538. HTuple TupleTestEqualDictItem(const HTuple& keys);
  539. protected:
  540. // Create tuple wrapping internal representation
  541. HTuple(HTupleData* data);
  542. // Initialize during construction or from cleared tuple state
  543. void InitFromTupleData(HTupleData* data);
  544. void InitFromTuple(const HTuple& tuple);
  545. // Internal use, exposed for C++ language interface only
  546. void MoveFromHctuple(Hctuple& tuple);
  547. // Internal use, exposed for extension packages and hdevengine only
  548. void SetFromHctuple(const Hctuple& tuple, bool copy /*=true*/);
  549. // Revert internal representation to mixed tuple
  550. void ConvertToMixed();
  551. // Resolve lazy copying on write access
  552. bool AssertOwnership();
  553. protected:
  554. // Smart pointer to typed data container
  555. HTupleDataPtr* mData;
  556. // Direct pointer for small tuple optimizations
  557. HTupleData* mDataPtr;
  558. }
  559. ;
  560. /***************************************************************************/
  561. /* Operator overloads */
  562. /***************************************************************************/
  563. #if defined(HCPP_OVERLOAD_TUPLE_OPERATORS)
  564. # ifdef _WIN32
  565. # define H_BIN_OP_WCHAR_OVERLOAD_DECLARATION(RET, OP) \
  566. LIntExport RET operator OP(const wchar_t* op1, const HTuple& op2); \
  567. LIntExport RET operator OP(const HTuple& op1, const wchar_t* op2); \
  568. LIntExport RET operator OP(const wchar_t* op1, \
  569. const HTupleElement& op2); \
  570. LIntExport RET operator OP(const HTupleElement& op1, const wchar_t* op2);
  571. # else
  572. # define H_BIN_OP_WCHAR_OVERLOAD_DECLARATION(RET, OP)
  573. # endif
  574. # define H_BIN_OP_OVERLOAD_DECLARATION(RET, OP) \
  575. H_BIN_OP_WCHAR_OVERLOAD_DECLARATION(RET, OP) \
  576. LIntExport RET operator OP(const HTuple& op1, int op2); \
  577. LIntExport RET operator OP(const HTuple& op1, Hlong op2); \
  578. LIntExport RET operator OP(const HTuple& op1, float op2); \
  579. LIntExport RET operator OP(const HTuple& op1, double op2); \
  580. LIntExport RET operator OP(const HTuple& op1, const HString& op2); \
  581. LIntExport RET operator OP(const HTuple& op1, const char* op2); \
  582. LIntExport RET operator OP(const HTuple& op1, const HHandle& op2); \
  583. LIntExport RET operator OP(const HTuple& op1, const HTupleElement& op2); \
  584. \
  585. LIntExport RET operator OP(const HTupleElement& op1, int op2); \
  586. LIntExport RET operator OP(const HTupleElement& op1, Hlong op2); \
  587. LIntExport RET operator OP(const HTupleElement& op1, float op2); \
  588. LIntExport RET operator OP(const HTupleElement& op1, double op2); \
  589. LIntExport RET operator OP(const HTupleElement& op1, const HString& op2); \
  590. LIntExport RET operator OP(const HTupleElement& op1, const char* op2); \
  591. LIntExport RET operator OP(const HTupleElement& op1, const HHandle& op2); \
  592. LIntExport RET operator OP(const HTupleElement& op1, \
  593. const HTupleElement& op2); \
  594. LIntExport RET operator OP(const HTupleElement& op1, const HTuple& op2); \
  595. \
  596. LIntExport RET operator OP(int op1, const HTuple& op2); \
  597. LIntExport RET operator OP(Hlong op1, const HTuple& op2); \
  598. LIntExport RET operator OP(float op1, const HTuple& op2); \
  599. LIntExport RET operator OP(double op1, const HTuple& op2); \
  600. LIntExport RET operator OP(const HString& op1, const HTuple& op2); \
  601. LIntExport RET operator OP(const HHandle& op1, const HTuple& op2); \
  602. LIntExport RET operator OP(const char* op1, const HTuple& op2); \
  603. \
  604. LIntExport RET operator OP(int op1, const HTupleElement& op2); \
  605. LIntExport RET operator OP(Hlong op1, const HTupleElement& op2); \
  606. LIntExport RET operator OP(float op1, const HTupleElement& op2); \
  607. LIntExport RET operator OP(double op1, const HTupleElement& op2); \
  608. LIntExport RET operator OP(const HString& op1, const HTupleElement& op2); \
  609. LIntExport RET operator OP(const char* op1, const HTupleElement& op2); \
  610. LIntExport RET operator OP(const HHandle& op1, const HTupleElement& op2);
  611. #else
  612. # define H_BIN_OP_OVERLOAD_DECLARATION(RET, OP)
  613. #endif
  614. /* Arithmetic operators */
  615. LIntExport HTuple operator+(const HTuple& val1, const HTuple& val2);
  616. H_BIN_OP_OVERLOAD_DECLARATION(HTuple, +)
  617. LIntExport HTuple operator-(const HTuple& val1, const HTuple& val2);
  618. H_BIN_OP_OVERLOAD_DECLARATION(HTuple, -)
  619. LIntExport HTuple operator*(const HTuple& val1, const HTuple& val2);
  620. H_BIN_OP_OVERLOAD_DECLARATION(HTuple, *)
  621. LIntExport HTuple operator/(const HTuple& val1, const HTuple& val2);
  622. H_BIN_OP_OVERLOAD_DECLARATION(HTuple, /)
  623. LIntExport HTuple operator%(const HTuple& val1, const HTuple& val2);
  624. H_BIN_OP_OVERLOAD_DECLARATION(HTuple, %)
  625. /* Boolean operators */
  626. LIntExport bool operator==(const HTuple& val1, const HTuple& val2);
  627. H_BIN_OP_OVERLOAD_DECLARATION(bool, ==)
  628. LIntExport bool operator!=(const HTuple& val1, const HTuple& val2);
  629. H_BIN_OP_OVERLOAD_DECLARATION(bool, !=)
  630. LIntExport bool operator>=(const HTuple& val1, const HTuple& val2);
  631. H_BIN_OP_OVERLOAD_DECLARATION(bool, >=)
  632. LIntExport bool operator<=(const HTuple& val1, const HTuple& val2);
  633. H_BIN_OP_OVERLOAD_DECLARATION(bool, <=)
  634. LIntExport bool operator>(const HTuple& val1, const HTuple& val2);
  635. H_BIN_OP_OVERLOAD_DECLARATION(bool, >)
  636. LIntExport bool operator<(const HTuple& val1, const HTuple& val2);
  637. H_BIN_OP_OVERLOAD_DECLARATION(bool, <)
  638. LIntExport bool operator&&(const HTuple& val1, const HTuple& val2);
  639. // it is regarded as bad practice to overload logical operators as this leeds
  640. // to the unexpected behaviour that both operands must be evaluated
  641. // H_BIN_OP_OVERLOAD_DECLARATION(bool,&&)
  642. LIntExport bool operator||(const HTuple& val1, const HTuple& val2);
  643. // H_BIN_OP_OVERLOAD_DECLARATION(bool,||)
  644. /* Bitwise operators */
  645. LIntExport HTuple operator|(const HTuple& val1, const HTuple& val2);
  646. H_BIN_OP_OVERLOAD_DECLARATION(HTuple, |)
  647. LIntExport HTuple operator&(const HTuple& val1, const HTuple& val2);
  648. H_BIN_OP_OVERLOAD_DECLARATION(HTuple, &)
  649. LIntExport HTuple operator^(const HTuple& val1, const HTuple& val2);
  650. H_BIN_OP_OVERLOAD_DECLARATION(HTuple, ^)
  651. LIntExport HTuple operator<<(const HTuple& val1, const HTuple& val2);
  652. H_BIN_OP_OVERLOAD_DECLARATION(HTuple, <<)
  653. LIntExport HTuple operator>>(const HTuple& val1, const HTuple& val2);
  654. H_BIN_OP_OVERLOAD_DECLARATION(HTuple, >>)
  655. }
  656. #endif