longlong.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: longlong.h
  3. // Purpose: interface of wxLongLong
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxLongLong
  9. This class represents a signed 64 bit long number. It is implemented using the
  10. native 64 bit type where available (machines with 64 bit longs or compilers
  11. which have (an analog of) @e long long type) and uses the emulation code in
  12. the other cases which ensures that it is the most efficient solution for
  13. working with 64 bit integers independently of the architecture.
  14. wxLongLong defines all usual arithmetic operations such as addition,
  15. subtraction, bitwise shifts and logical operations as well as multiplication
  16. and division (not yet for the machines without native @e long long).
  17. It also has operators for implicit construction from and conversion to the native
  18. @e long long type if it exists and @e long.
  19. You would usually use this type in exactly the same manner as any other
  20. (built-in) arithmetic type. Note that wxLongLong is a signed type, if you
  21. want unsigned values use wxULongLong which has exactly the same API as
  22. wxLongLong except when explicitly mentioned otherwise.
  23. If a native (i.e. supported directly by the compiler) 64 bit integer type was
  24. found to exist, @e wxLongLong_t macro will be defined to correspond to it.
  25. Also, in this case only, two additional macros will be defined:
  26. - wxLongLongFmtSpec() for printing 64 bit integers using the standard @c printf()
  27. function (but see also wxLongLong::ToString for a more portable solution);
  28. - wxLL() for defining 64 bit integer compile-time constants.
  29. @library{wxbase}
  30. @category{data}
  31. */
  32. class wxLongLong
  33. {
  34. public:
  35. /**
  36. Default constructor initializes the object to 0.
  37. */
  38. wxLongLong();
  39. /**
  40. Constructor from native long long (only for compilers supporting it).
  41. */
  42. wxLongLong(wxLongLong_t ll);
  43. /**
  44. Constructor from 2 longs: the high and low part are combined into one
  45. wxLongLong.
  46. */
  47. wxLongLong(long hi, unsigned long lo);
  48. //@{
  49. /**
  50. Returns an absolute value of wxLongLong - either making a copy (const version)
  51. or modifying it in place (the second one). Not in wxULongLong.
  52. */
  53. wxLongLong Abs() const;
  54. wxLongLong& Abs();
  55. //@}
  56. /**
  57. This allows to convert a double value to wxLongLong type.
  58. Such conversion is not always possible in which case the result will be
  59. silently truncated in a platform-dependent way. Not in wxULongLong.
  60. */
  61. wxLongLong Assign(double d);
  62. /**
  63. Returns the high 32 bits of 64 bit integer.
  64. */
  65. long GetHi() const;
  66. /**
  67. Returns the low 32 bits of 64 bit integer.
  68. */
  69. unsigned long GetLo() const;
  70. /**
  71. Convert to native long long (only for compilers supporting it).
  72. */
  73. wxLongLong_t GetValue() const;
  74. /**
  75. Returns the value as @c double.
  76. */
  77. double ToDouble() const;
  78. /**
  79. Truncate wxLongLong to long. If the conversion loses data (i.e. the wxLongLong
  80. value is outside the range of built-in long type), an assert will be triggered
  81. in debug mode.
  82. */
  83. long ToLong() const;
  84. /**
  85. Returns the string representation of a wxLongLong.
  86. */
  87. wxString ToString() const;
  88. /**
  89. Adds 2 wxLongLongs together and returns the result.
  90. */
  91. wxLongLong operator+(const wxLongLong& ll) const;
  92. /**
  93. Add another wxLongLong to this one.
  94. */
  95. wxLongLong& operator+(const wxLongLong& ll);
  96. /**
  97. Subtracts 2 wxLongLongs and returns the result.
  98. */
  99. wxLongLong operator-(const wxLongLong& ll) const;
  100. /**
  101. Subtracts another wxLongLong from this one.
  102. */
  103. wxLongLong& operator-(const wxLongLong& ll);
  104. //@{
  105. /**
  106. Pre/post increment operator.
  107. */
  108. wxLongLong operator++();
  109. wxLongLong operator++(int);
  110. //@}
  111. //@{
  112. /**
  113. Pre/post decrement operator.
  114. */
  115. wxLongLong operator--();
  116. wxLongLong operator--(int);
  117. //@}
  118. /**
  119. Returns the value of this wxLongLong with opposite sign. Not in wxULongLong.
  120. */
  121. wxLongLong operator-() const;
  122. /**
  123. Assignment operator from unsigned long long. The sign bit will be copied too.
  124. @since 2.7.0
  125. */
  126. wxLongLong& operator=(const wxULongLong& ll);
  127. /**
  128. Assignment operator from native long long (only for compilers supporting it).
  129. */
  130. wxLongLong& operator=(wxLongLong_t ll);
  131. /**
  132. Assignment operator from native unsigned long long (only for compilers supporting it).
  133. @since 2.7.0
  134. */
  135. wxLongLong& operator=(wxULongLong_t ll);
  136. /**
  137. Assignment operator from long.
  138. @since 2.7.0
  139. */
  140. wxLongLong& operator=(long l);
  141. /**
  142. Assignment operator from unsigned long.
  143. @since 2.7.0
  144. */
  145. wxLongLong& operator=(unsigned long l);
  146. };
  147. /**
  148. @class wxULongLong
  149. This class represents an unsigned 64 bit long number.
  150. Since wxULongLong has exactly the same API as wxLongLong, please refer
  151. to wxLongLong documentation (this page exists only as redirection).
  152. @library{wxbase}
  153. @category{data}
  154. */
  155. class wxULongLong
  156. {
  157. };
  158. // ============================================================================
  159. // Global functions/macros
  160. // ============================================================================
  161. /** @addtogroup group_funcmacro_misc */
  162. //@{
  163. /**
  164. This macro is defined to contain the @c printf() format specifier using
  165. which 64 bit integer numbers (i.e. those of type @c wxLongLong_t) can be
  166. printed. Example of using it:
  167. @code
  168. #ifdef wxLongLong_t
  169. wxLongLong_t ll = wxLL(0x1234567890abcdef);
  170. printf("Long long = %" wxLongLongFmtSpec "x\n", ll);
  171. #endif
  172. @endcode
  173. @see wxLL()
  174. @header{wx/longlong.h}
  175. */
  176. #define wxLongLongFmtSpec
  177. /**
  178. This macro is defined for the platforms with a native 64 bit integer type
  179. and allow the use of 64 bit compile time constants:
  180. @code
  181. #ifdef wxLongLong_t
  182. wxLongLong_t ll = wxLL(0x1234567890abcdef);
  183. #endif
  184. @endcode
  185. @see wxULL(), wxLongLong
  186. @header{wx/longlong.h}
  187. */
  188. wxLongLong_t wxLL(number);
  189. /**
  190. This macro is defined for the platforms with a native 64 bit integer type
  191. and allow the use of 64 bit compile time constants:
  192. @code
  193. #ifdef wxLongLong_t
  194. unsigned wxLongLong_t ll = wxULL(0x1234567890abcdef);
  195. #endif
  196. @endcode
  197. @see wxLL(), wxLongLong
  198. @header{wx/longlong.h}
  199. */
  200. wxLongLong_t wxULL(number);
  201. //@}