HTuple.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  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(Hlong* l, Hlong num);
  55. # if defined(HCPP_INT_OVERLOADS)
  56. // Integer (possibly smaller size than pointer)
  57. HTuple(HINT i);
  58. // Integer array (possibly smaller size than pointer)
  59. HTuple(HINT* i, Hlong num);
  60. # endif
  61. // Single precision floating point value
  62. HTuple(float f);
  63. // Single precision floating point array
  64. HTuple(float* f, Hlong num);
  65. // Double precision floating point value
  66. HTuple(double d);
  67. // Double precision floating point array
  68. HTuple(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 { return (*this)[0].I(); }
  148. #endif
  149. // Access integer value in first tuple element
  150. Hlong L() const { return (*this)[0].L(); }
  151. // Access floating-point value in first tuple element
  152. double D() const { return (*this)[0].D(); }
  153. // Access string value in first tuple element
  154. HString S() const { return (*this)[0].S(); }
  155. // Access handle value in first tuple element
  156. HHandle H() const { return (*this)[0].H(); }
  157. /***************************************************************************
  158. * Operators *
  159. ***************************************************************************/
  160. // Compute the union set of two input tuples.
  161. HTuple TupleUnion(const HTuple& Set2) const;
  162. // Compute the intersection set of two input tuples.
  163. HTuple TupleIntersection(const HTuple& Set2) const;
  164. // Compute the difference set of two input tuples.
  165. HTuple TupleDifference(const HTuple& Set2) const;
  166. // Compute the symmetric difference set of two input tuples.
  167. HTuple TupleSymmdiff(const HTuple& Set2) const;
  168. // Test whether the types of the elements of a tuple are of type string.
  169. HTuple TupleIsStringElem() const;
  170. // Test whether the types of the elements of a tuple are of type real.
  171. HTuple TupleIsRealElem() const;
  172. // Test whether the types of the elements of a tuple are of type integer.
  173. HTuple TupleIsIntElem() const;
  174. // Return the types of the elements of a tuple.
  175. HTuple TupleTypeElem() const;
  176. // Test whether a tuple is of type mixed.
  177. HTuple TupleIsMixed() const;
  178. // Test if the internal representation of a tuple is of type string.
  179. HTuple TupleIsString() const;
  180. // Test if the internal representation of a tuple is of type real.
  181. HTuple TupleIsReal() const;
  182. // Test if the internal representation of a tuple is of type integer.
  183. HTuple TupleIsInt() const;
  184. // Return the type of a tuple.
  185. HTuple TupleType() const;
  186. // Calculate the value distribution of a tuple within a certain value range.
  187. HTuple TupleHistoRange(const HTuple& Min, const HTuple& Max, const HTuple& NumBins, HTuple* BinSize) const;
  188. // Select tuple elements matching a regular expression.
  189. HTuple TupleRegexpSelect(const HTuple& Expression) const;
  190. // Test if a string matches a regular expression.
  191. HTuple TupleRegexpTest(const HTuple& Expression) const;
  192. // Replace a substring using regular expressions.
  193. HTuple TupleRegexpReplace(const HTuple& Expression, const HTuple& Replace) const;
  194. // Extract substrings using regular expressions.
  195. HTuple TupleRegexpMatch(const HTuple& Expression) const;
  196. // Return a tuple of random numbers between 0 and 1.
  197. static HTuple TupleRand(const HTuple& Length);
  198. // Return the number of elements of a tuple.
  199. HTuple TupleLength() const;
  200. // Calculate the sign of a tuple.
  201. HTuple TupleSgn() const;
  202. // Calculate the elementwise maximum of two tuples.
  203. HTuple TupleMax2(const HTuple& T2) const;
  204. // Calculate the elementwise minimum of two tuples.
  205. HTuple TupleMin2(const HTuple& T2) const;
  206. // Return the maximal element of a tuple.
  207. HTuple TupleMax() const;
  208. // Return the minimal element of a tuple.
  209. HTuple TupleMin() const;
  210. // Calculate the cumulative sums of a tuple.
  211. HTuple TupleCumul() const;
  212. // Select the element of rank n of a tuple.
  213. HTuple TupleSelectRank(const HTuple& RankIndex) const;
  214. // Return the median of the elements of a tuple.
  215. HTuple TupleMedian() const;
  216. // Return the sum of all elements of a tuple.
  217. HTuple TupleSum() const;
  218. // Return the mean value of a tuple of numbers.
  219. HTuple TupleMean() const;
  220. // Return the standard deviation of the elements of a tuple.
  221. HTuple TupleDeviation() const;
  222. // Discard all but one of successive identical elements of a tuple.
  223. HTuple TupleUniq() const;
  224. // Return the index of the last occurrence of a tuple within another tuple.
  225. HTuple TupleFindLast(const HTuple& ToFind) const;
  226. // Return the index of the first occurrence of a tuple within another tuple.
  227. HTuple TupleFindFirst(const HTuple& ToFind) const;
  228. // Return the indices of all occurrences of a tuple within another tuple.
  229. HTuple TupleFind(const HTuple& ToFind) const;
  230. // Sort the elements of a tuple and return the indices of the sorted tuple.
  231. HTuple TupleSortIndex() const;
  232. // Sort the elements of a tuple in ascending order.
  233. HTuple TupleSort() const;
  234. // Invert a tuple.
  235. HTuple TupleInverse() const;
  236. // Concatenate two tuples to a new one.
  237. HTuple TupleConcat(const HTuple& T2) const;
  238. // Select several elements of a tuple.
  239. HTuple TupleSelectRange(const HTuple& Leftindex, const HTuple& Rightindex) const;
  240. // Select all elements from index "n" to the end of a tuple.
  241. HTuple TupleLastN(const HTuple& Index) const;
  242. // Select the first elements of a tuple up to the index "n".
  243. HTuple TupleFirstN(const HTuple& Index) const;
  244. // Inserts one or more elements into a tuple at index.
  245. HTuple TupleInsert(const HTuple& Index, const HTuple& InsertTuple) const;
  246. // Replaces one or more elements of a tuple.
  247. HTuple TupleReplace(const HTuple& Index, const HTuple& ReplaceTuple) const;
  248. // Remove elements from a tuple.
  249. HTuple TupleRemove(const HTuple& Index) const;
  250. // Select in mask specified elements of a tuple.
  251. HTuple TupleSelectMask(const HTuple& Mask) const;
  252. // Select single elements of a tuple.
  253. HTuple TupleSelect(const HTuple& Index) const;
  254. // Select single character or bit from a tuple.
  255. HTuple TupleStrBitSelect(const HTuple& Index) const;
  256. // Generate a tuple with a sequence of equidistant values.
  257. static HTuple TupleGenSequence(const HTuple& Start, const HTuple& End, const HTuple& Step);
  258. // Generate a tuple of a specific length and initialize its elements.
  259. static HTuple TupleGenConst(const HTuple& Length, const HTuple& Const);
  260. // Read one or more environment variables.
  261. HTuple TupleEnvironment() const;
  262. // Split strings into substrings using predefined separator symbol(s).
  263. HTuple TupleSplit(const HTuple& Separator) const;
  264. // Cut characters from position "n1" through "n2" out of a string tuple.
  265. HTuple TupleSubstr(const HTuple& Position1, const HTuple& Position2) const;
  266. // Cut all characters starting at position "n" out of a string tuple.
  267. HTuple TupleStrLastN(const HTuple& Position) const;
  268. // Cut the first characters up to position "n" out of a string tuple.
  269. HTuple TupleStrFirstN(const HTuple& Position) const;
  270. // Backward search for characters within a string tuple.
  271. HTuple TupleStrrchr(const HTuple& ToFind) const;
  272. // Forward search for characters within a string tuple.
  273. HTuple TupleStrchr(const HTuple& ToFind) const;
  274. // Backward search for strings within a string tuple.
  275. HTuple TupleStrrstr(const HTuple& ToFind) const;
  276. // Forward search for strings within a string tuple.
  277. HTuple TupleStrstr(const HTuple& ToFind) const;
  278. // Determine the length of every string within a tuple of strings.
  279. HTuple TupleStrlen() const;
  280. // Test, whether a tuple is elementwise less or equal to another tuple.
  281. HTuple TupleLessEqualElem(const HTuple& T2) const;
  282. // Test, whether a tuple is elementwise less than another tuple.
  283. HTuple TupleLessElem(const HTuple& T2) const;
  284. // Test, whether a tuple is elementwise greater or equal to another tuple.
  285. HTuple TupleGreaterEqualElem(const HTuple& T2) const;
  286. // Test, whether a tuple is elementwise greater than another tuple.
  287. HTuple TupleGreaterElem(const HTuple& T2) const;
  288. // Test, whether two tuples are elementwise not equal.
  289. HTuple TupleNotEqualElem(const HTuple& T2) const;
  290. // Test, whether two tuples are elementwise equal.
  291. HTuple TupleEqualElem(const HTuple& T2) const;
  292. // Test whether a tuple is less or equal to another tuple.
  293. HTuple TupleLessEqual(const HTuple& T2) const;
  294. // Test whether a tuple is less than another tuple.
  295. HTuple TupleLess(const HTuple& T2) const;
  296. // Test whether a tuple is greater or equal to another tuple.
  297. HTuple TupleGreaterEqual(const HTuple& T2) const;
  298. // Test whether a tuple is greater than another tuple.
  299. HTuple TupleGreater(const HTuple& T2) const;
  300. // Test whether two tuples are not equal.
  301. HTuple TupleNotEqual(const HTuple& T2) const;
  302. // Test whether two tuples are equal.
  303. HTuple TupleEqual(const HTuple& T2) const;
  304. // Compute the logical not of a tuple.
  305. HTuple TupleNot() const;
  306. // Compute the logical exclusive or of two tuples.
  307. HTuple TupleXor(const HTuple& T2) const;
  308. // Compute the logical or of two tuples.
  309. HTuple TupleOr(const HTuple& T2) const;
  310. // Compute the logical and of two tuples.
  311. HTuple TupleAnd(const HTuple& T2) const;
  312. // Compute the bitwise not of a tuple.
  313. HTuple TupleBnot() const;
  314. // Compute the bitwise exclusive or of two tuples.
  315. HTuple TupleBxor(const HTuple& T2) const;
  316. // Compute the bitwise or of two tuples.
  317. HTuple TupleBor(const HTuple& T2) const;
  318. // Compute the bitwise and of two tuples.
  319. HTuple TupleBand(const HTuple& T2) const;
  320. // Shift a tuple bitwise to the right.
  321. HTuple TupleRsh(const HTuple& Shift) const;
  322. // Shift a tuple bitwise to the left.
  323. HTuple TupleLsh(const HTuple& Shift) const;
  324. // Convert a tuple of integer numbers into strings.
  325. HTuple TupleChrt() const;
  326. // Convert a tuple of strings into a tuple of integer numbers.
  327. HTuple TupleOrds() const;
  328. // Convert a tuple of integer numbers into strings.
  329. HTuple TupleChr() const;
  330. // Convert a tuple of strings of length 1 into a tuple of integer numbers.
  331. HTuple TupleOrd() const;
  332. // Convert a tuple into a tuple of strings.
  333. HTuple TupleString(const HTuple& Format) const;
  334. // Check a tuple (of strings) whether it represents numbers.
  335. HTuple TupleIsNumber() const;
  336. // Convert a tuple (of strings) into a tuple of numbers.
  337. HTuple TupleNumber() const;
  338. // Convert a tuple into a tuple of integer numbers.
  339. HTuple TupleRound() const;
  340. // Convert a tuple into a tuple of integer numbers.
  341. HTuple TupleInt() const;
  342. // Convert a tuple into a tuple of floating point numbers.
  343. HTuple TupleReal() const;
  344. // Calculate the ldexp function of two tuples.
  345. HTuple TupleLdexp(const HTuple& T2) const;
  346. // Calculate the remainder of the floating point division of two tuples.
  347. HTuple TupleFmod(const HTuple& T2) const;
  348. // Calculate the remainder of the integer division of two tuples.
  349. HTuple TupleMod(const HTuple& T2) const;
  350. // Compute the ceiling function of a tuple.
  351. HTuple TupleCeil() const;
  352. // Compute the floor function of a tuple.
  353. HTuple TupleFloor() const;
  354. // Calculate the power function of two tuples.
  355. HTuple TuplePow(const HTuple& T2) const;
  356. // Compute the base 10 logarithm of a tuple.
  357. HTuple TupleLog10() const;
  358. // Compute the natural logarithm of a tuple.
  359. HTuple TupleLog() const;
  360. // Compute the exponential of a tuple.
  361. HTuple TupleExp() const;
  362. // Compute the hyperbolic tangent of a tuple.
  363. HTuple TupleTanh() const;
  364. // Compute the hyperbolic cosine of a tuple.
  365. HTuple TupleCosh() const;
  366. // Compute the hyperbolic sine of a tuple.
  367. HTuple TupleSinh() const;
  368. // Convert a tuple from degrees to radians.
  369. HTuple TupleRad() const;
  370. // Convert a tuple from radians to degrees.
  371. HTuple TupleDeg() const;
  372. // Compute the arctangent of a tuple for all four quadrants.
  373. HTuple TupleAtan2(const HTuple& X) const;
  374. // Compute the arctangent of a tuple.
  375. HTuple TupleAtan() const;
  376. // Compute the arccosine of a tuple.
  377. HTuple TupleAcos() const;
  378. // Compute the arcsine of a tuple.
  379. HTuple TupleAsin() const;
  380. // Compute the tangent of a tuple.
  381. HTuple TupleTan() const;
  382. // Compute the cosine of a tuple.
  383. HTuple TupleCos() const;
  384. // Compute the sine of a tuple.
  385. HTuple TupleSin() const;
  386. // Compute the absolute value of a tuple (as floating point numbers).
  387. HTuple TupleFabs() const;
  388. // Compute the square root of a tuple.
  389. HTuple TupleSqrt() const;
  390. // Compute the absolute value of a tuple.
  391. HTuple TupleAbs() const;
  392. // Negate a tuple.
  393. HTuple TupleNeg() const;
  394. // Divide two tuples.
  395. HTuple TupleDiv(const HTuple& Q2) const;
  396. // Multiply two tuples.
  397. HTuple TupleMult(const HTuple& P2) const;
  398. // Subtract two tuples.
  399. HTuple TupleSub(const HTuple& D2) const;
  400. // Add two tuples.
  401. HTuple TupleAdd(const HTuple& S2) const;
  402. // Deserialize a serialized tuple.
  403. static HTuple DeserializeTuple(const HSerializedItem& SerializedItemHandle);
  404. // Serialize a tuple.
  405. HSerializedItem SerializeTuple() const;
  406. // Write a tuple to a file.
  407. void WriteTuple(const HTuple& FileName) const;
  408. // Read a tuple from a file.
  409. static HTuple ReadTuple(const HTuple& FileName);
  410. // Clear the content of a handle.
  411. void ClearHandle() const;
  412. // Test if the internal representation of a tuple is of type handle.
  413. HTuple TupleIsHandle() const;
  414. // Test whether the elements of a tuple are of type handle.
  415. HTuple TupleIsHandleElem() const;
  416. // Test if a tuple is serializable.
  417. HTuple TupleIsSerializable() const;
  418. // Test if the elements of a tuple are serializable.
  419. HTuple TupleIsSerializableElem() const;
  420. // Check if a handle is valid.
  421. HTuple TupleIsValidHandle() const;
  422. // Return the semantic type of a tuple.
  423. HTuple TupleSemType() const;
  424. // Return the semantic type of the elements of a tuple.
  425. HTuple TupleSemTypeElem() const;
  426. // Compute the inverse hyperbolic cosine of a tuple.
  427. HTuple TupleAcosh() const;
  428. // Compute the inverse hyperbolic sine of a tuple.
  429. HTuple TupleAsinh() const;
  430. // Compute the inverse hyperbolic tangent of a tuple.
  431. HTuple TupleAtanh() const;
  432. // Compute the cube root of a tuple.
  433. HTuple TupleCbrt() const;
  434. // Compute the error function of a tuple.
  435. HTuple TupleErf() const;
  436. // Compute the complementary error function of a tuple.
  437. HTuple TupleErfc() const;
  438. // Compute the base 10 exponential of a tuple.
  439. HTuple TupleExp10() const;
  440. // Compute the base 2 exponential of a tuple.
  441. HTuple TupleExp2() const;
  442. // Calculate the hypotenuse of two tuples.
  443. HTuple TupleHypot(const HTuple& T2) const;
  444. // Compute the logarithm of the absolute value of the gamma function of a tuple.
  445. HTuple TupleLgamma() const;
  446. // Compute the base 2 logarithm of a tuple.
  447. HTuple TupleLog2() const;
  448. // Compute the gamma function of a tuple.
  449. HTuple TupleTgamma() const;
  450. /***************************************************************************/
  451. /* Compatibility Layer */
  452. /***************************************************************************/
  453. #if defined(HCPP_LEGACY_API)
  454. #include "halconcpp/HTupleLegacy.h"
  455. #endif
  456. #if (!defined(HCPP_LEGACY_API) || defined(_LIntDLL))
  457. // Casts from a HTuple to element data types are disabled in legacy mode,
  458. // as they may lead to ambiguous operator calls in existing user code
  459. #if defined(HCPP_INT_OVERLOADS)
  460. // Access integer value in first tuple element
  461. operator int() const { return I(); }
  462. #endif
  463. // Access integer value in first tuple element
  464. operator Hlong() const { return L(); }
  465. // Access floating-point value in first tuple element
  466. operator float() const { return (float) D(); }
  467. // Access floating-point value in first tuple element
  468. operator double() const { return D(); }
  469. // Access string value in first tuple element
  470. operator HString() const { return S(); }
  471. #if (!defined(HCPP_LEGACY_HANDLE_API) || defined(_LIntDLL))
  472. // Access handle value in first tuple element
  473. operator HHandle() const { return H(); }
  474. #endif
  475. #endif
  476. /***************************************************************************/
  477. /* Operator overloads */
  478. /***************************************************************************/
  479. /* Unary operators */
  480. bool operator ! (void) const;
  481. HTuple operator ~ (void) const;
  482. HTuple operator - (void) const;
  483. HTuple &operator ++ (void);
  484. /* Binary operators are declared below outside class HTuple */
  485. /* Selected compound operators */
  486. HTuple& operator += (const HTuple &val);
  487. H_COMPOUND_OP_OVERLOAD_DECLARATION(HTuple,+=);
  488. HTuple& operator -= (const HTuple &val);
  489. H_COMPOUND_OP_OVERLOAD_DECLARATION(HTuple,-=);
  490. HTuple& operator *= (const HTuple &val);
  491. H_COMPOUND_OP_OVERLOAD_DECLARATION(HTuple,*=);
  492. /***************************************************************************/
  493. /* Helpers for code export or extension packages, do not call in used code */
  494. /***************************************************************************/
  495. bool Continue(const HTuple &final_value, const HTuple &increment);
  496. // Internal use, exposed for extension packages and hdevengine only
  497. HTuple(const Hctuple& tuple, bool copy=true);
  498. Hctuple GetHctuple(bool copy) const;
  499. const Hctuple &GetHctupleRef() const;
  500. void TranscodeFromUtf8ToInterfaceEncoding();
  501. protected:
  502. // Create tuple wrapping internal representation
  503. HTuple(HTupleData* data);
  504. // Initialize during construction or from cleared tuple state
  505. void InitFromTupleData(HTupleData* data);
  506. void InitFromTuple(const HTuple& tuple);
  507. // Internal use, exposed for C++ language interface only
  508. void MoveFromHctuple(Hctuple& tuple);
  509. // Internal use, exposed for extension packages and hdevengine only
  510. void SetFromHctuple(const Hctuple& tuple, bool copy/*=true*/);
  511. // Revert internal representation to mixed tuple
  512. void ConvertToMixed();
  513. // Resolve lazy copying on write access
  514. bool AssertOwnership();
  515. protected:
  516. // Smart pointer to typed data container
  517. HTupleDataPtr* mData;
  518. // Direct pointer for small tuple optimizations
  519. HTupleData* mDataPtr;
  520. };
  521. /***************************************************************************/
  522. /* Operator overloads */
  523. /***************************************************************************/
  524. #if defined(HCPP_OVERLOAD_TUPLE_OPERATORS)
  525. # ifdef _WIN32
  526. # define H_BIN_OP_WCHAR_OVERLOAD_DECLARATION(RET, OP) \
  527. LIntExport RET operator OP(const wchar_t* op1, const HTuple& op2); \
  528. LIntExport RET operator OP(const HTuple& op1, const wchar_t* op2); \
  529. LIntExport RET operator OP(const wchar_t* op1, \
  530. const HTupleElement& op2); \
  531. LIntExport RET operator OP(const HTupleElement& op1, const wchar_t* op2);
  532. # else
  533. # define H_BIN_OP_WCHAR_OVERLOAD_DECLARATION(RET, OP)
  534. # endif
  535. # define H_BIN_OP_OVERLOAD_DECLARATION(RET, OP) \
  536. H_BIN_OP_WCHAR_OVERLOAD_DECLARATION(RET, OP) \
  537. LIntExport RET operator OP(const HTuple& op1, int op2); \
  538. LIntExport RET operator OP(const HTuple& op1, Hlong op2); \
  539. LIntExport RET operator OP(const HTuple& op1, float op2); \
  540. LIntExport RET operator OP(const HTuple& op1, double op2); \
  541. LIntExport RET operator OP(const HTuple& op1, const HString& op2); \
  542. LIntExport RET operator OP(const HTuple& op1, const char* op2); \
  543. LIntExport RET operator OP(const HTuple& op1, const HHandle& op2); \
  544. LIntExport RET operator OP(const HTuple& op1, const HTupleElement& op2); \
  545. \
  546. LIntExport RET operator OP(const HTupleElement& op1, int op2); \
  547. LIntExport RET operator OP(const HTupleElement& op1, Hlong op2); \
  548. LIntExport RET operator OP(const HTupleElement& op1, float op2); \
  549. LIntExport RET operator OP(const HTupleElement& op1, double op2); \
  550. LIntExport RET operator OP(const HTupleElement& op1, const HString& op2); \
  551. LIntExport RET operator OP(const HTupleElement& op1, const char* op2); \
  552. LIntExport RET operator OP(const HTupleElement& op1, const HHandle& op2); \
  553. LIntExport RET operator OP(const HTupleElement& op1, \
  554. const HTupleElement& op2); \
  555. LIntExport RET operator OP(const HTupleElement& op1, const HTuple& op2); \
  556. \
  557. LIntExport RET operator OP(int op1, const HTuple& op2); \
  558. LIntExport RET operator OP(Hlong op1, const HTuple& op2); \
  559. LIntExport RET operator OP(float op1, const HTuple& op2); \
  560. LIntExport RET operator OP(double op1, const HTuple& op2); \
  561. LIntExport RET operator OP(const HString& op1, const HTuple& op2); \
  562. LIntExport RET operator OP(const HHandle& op1, const HTuple& op2); \
  563. LIntExport RET operator OP(const char* op1, const HTuple& op2); \
  564. \
  565. LIntExport RET operator OP(int op1, const HTupleElement& op2); \
  566. LIntExport RET operator OP(Hlong op1, const HTupleElement& op2); \
  567. LIntExport RET operator OP(float op1, const HTupleElement& op2); \
  568. LIntExport RET operator OP(double op1, const HTupleElement& op2); \
  569. LIntExport RET operator OP(const HString& op1, const HTupleElement& op2); \
  570. LIntExport RET operator OP(const char* op1, const HTupleElement& op2); \
  571. LIntExport RET operator OP(const HHandle& op1, const HTupleElement& op2);
  572. #else
  573. #define H_BIN_OP_OVERLOAD_DECLARATION(RET,OP)
  574. #endif
  575. /* Arithmetic operators */
  576. LIntExport HTuple operator +(const HTuple& val1, const HTuple &val2);
  577. H_BIN_OP_OVERLOAD_DECLARATION(HTuple,+)
  578. LIntExport HTuple operator - (const HTuple& val1, const HTuple &val2);
  579. H_BIN_OP_OVERLOAD_DECLARATION(HTuple,-)
  580. LIntExport HTuple operator * (const HTuple& val1, const HTuple &val2);
  581. H_BIN_OP_OVERLOAD_DECLARATION(HTuple,*)
  582. LIntExport HTuple operator / (const HTuple& val1, const HTuple &val2);
  583. H_BIN_OP_OVERLOAD_DECLARATION(HTuple,/)
  584. LIntExport HTuple operator % (const HTuple& val1, const HTuple &val2);
  585. H_BIN_OP_OVERLOAD_DECLARATION(HTuple,%)
  586. /* Boolean operators */
  587. LIntExport bool operator == (const HTuple& val1, const HTuple &val2);
  588. H_BIN_OP_OVERLOAD_DECLARATION(bool,==)
  589. LIntExport bool operator != (const HTuple& val1, const HTuple &val2);
  590. H_BIN_OP_OVERLOAD_DECLARATION(bool,!=)
  591. LIntExport bool operator >= (const HTuple& val1, const HTuple &val2);
  592. H_BIN_OP_OVERLOAD_DECLARATION(bool,>=)
  593. LIntExport bool operator <= (const HTuple& val1, const HTuple &val2);
  594. H_BIN_OP_OVERLOAD_DECLARATION(bool,<=)
  595. LIntExport bool operator > (const HTuple& val1, const HTuple &val2);
  596. H_BIN_OP_OVERLOAD_DECLARATION(bool,>)
  597. LIntExport bool operator < (const HTuple& val1, const HTuple &val2);
  598. H_BIN_OP_OVERLOAD_DECLARATION(bool,<)
  599. LIntExport bool operator && (const HTuple& val1, const HTuple &val2);
  600. // it is regarded as bad practice to overload logical operators as this leeds
  601. // to the unexpected behaviour that both operands must be evaluated
  602. // H_BIN_OP_OVERLOAD_DECLARATION(bool,&&)
  603. LIntExport bool operator || (const HTuple& val1, const HTuple &val2);
  604. // H_BIN_OP_OVERLOAD_DECLARATION(bool,||)
  605. /* Bitwise operators */
  606. LIntExport HTuple operator | (const HTuple& val1, const HTuple &val2);
  607. H_BIN_OP_OVERLOAD_DECLARATION(HTuple,|)
  608. LIntExport HTuple operator & (const HTuple& val1, const HTuple &val2);
  609. H_BIN_OP_OVERLOAD_DECLARATION(HTuple,&)
  610. LIntExport HTuple operator ^ (const HTuple& val1, const HTuple &val2);
  611. H_BIN_OP_OVERLOAD_DECLARATION(HTuple,^)
  612. LIntExport HTuple operator << (const HTuple& val1, const HTuple &val2);
  613. H_BIN_OP_OVERLOAD_DECLARATION(HTuple,<<)
  614. LIntExport HTuple operator >> (const HTuple& val1, const HTuple &val2);
  615. H_BIN_OP_OVERLOAD_DECLARATION(HTuple,>>)
  616. }
  617. #endif