]>
Commit | Line | Data |
---|---|---|
8b81872f VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/longlong.h | |
3 | // Purpose: declaration of wxLongLong class - best implementation of a 64 | |
4 | // bit integer for the current platform. | |
5 | // Author: Jeffrey C. Ollie <jeff@ollie.clive.ia.us>, Vadim Zeitlin | |
8b81872f VZ |
6 | // Modified by: |
7 | // Created: 10.02.99 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
65571936 | 10 | // Licence: wxWindows licence |
8b81872f VZ |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
13 | #ifndef _WX_LONGLONG_H | |
14 | #define _WX_LONGLONG_H | |
15 | ||
1ef54dcf | 16 | #include "wx/defs.h" |
216a72f3 VZ |
17 | |
18 | #if wxUSE_LONGLONG | |
19 | ||
3a994742 | 20 | #include "wx/string.h" |
1ef54dcf VZ |
21 | |
22 | #include <limits.h> // for LONG_MAX | |
23 | ||
2a310492 VZ |
24 | // define this to compile wxLongLongWx in "test" mode: the results of all |
25 | // calculations will be compared with the real results taken from | |
617ec456 VZ |
26 | // wxLongLongNative -- this is extremely useful to find the bugs in |
27 | // wxLongLongWx class! | |
28 | ||
f6bcfd97 | 29 | // #define wxLONGLONG_TEST_MODE |
2a310492 VZ |
30 | |
31 | #ifdef wxLONGLONG_TEST_MODE | |
32 | #define wxUSE_LONGLONG_WX 1 | |
33 | #define wxUSE_LONGLONG_NATIVE 1 | |
34 | #endif // wxLONGLONG_TEST_MODE | |
2ea24d9f | 35 | |
8b81872f VZ |
36 | // ---------------------------------------------------------------------------- |
37 | // decide upon which class we will use | |
38 | // ---------------------------------------------------------------------------- | |
39 | ||
8fb37472 | 40 | #ifndef wxLongLong_t |
9c2882d9 | 41 | // both warning and pragma warning are not portable, but at least an |
2b5f62a0 | 42 | // unknown pragma should never be an error -- except that, actually, some |
58ef67ab VZ |
43 | // broken compilers don't like it, so we have to disable it in this case |
44 | // <sigh> | |
216a72f3 VZ |
45 | #ifdef __GNUC__ |
46 | #warning "Your compiler does not appear to support 64 bit "\ | |
47 | "integers, using emulation class instead.\n" \ | |
48 | "Please report your compiler version to " \ | |
49 | "wx-dev@lists.wxwidgets.org!" | |
50 | #elif !(defined(__WATCOMC__) || defined(__VISAGECPP__)) | |
8fb37472 VZ |
51 | #pragma warning "Your compiler does not appear to support 64 bit "\ |
52 | "integers, using emulation class instead.\n" \ | |
53 | "Please report your compiler version to " \ | |
77ffb593 | 54 | "wx-dev@lists.wxwidgets.org!" |
8fb37472 | 55 | #endif |
8db6ac55 | 56 | |
8b81872f VZ |
57 | #define wxUSE_LONGLONG_WX 1 |
58 | #endif // compiler | |
59 | ||
60 | // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE | |
61 | // to disable automatic testing (useful for the test program which defines | |
62 | // both classes) but by default we only use one class | |
2ea24d9f | 63 | #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t) |
2a310492 | 64 | // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set: |
384223b3 | 65 | // this is useful in test programs and only there |
2a310492 VZ |
66 | #ifndef wxUSE_LONGLONG_NATIVE |
67 | #define wxUSE_LONGLONG_NATIVE 0 | |
68 | #endif | |
69 | ||
bddd7a8d VZ |
70 | class WXDLLIMPEXP_BASE wxLongLongWx; |
71 | class WXDLLIMPEXP_BASE wxULongLongWx; | |
92f5ff59 JS |
72 | #if defined(__VISUALC__) && !defined(__WIN32__) |
73 | #define wxLongLong wxLongLongWx | |
8e38fd1f | 74 | #define wxULongLong wxULongLongWx |
92f5ff59 | 75 | #else |
8b81872f | 76 | typedef wxLongLongWx wxLongLong; |
8e38fd1f | 77 | typedef wxULongLongWx wxULongLong; |
92f5ff59 JS |
78 | #endif |
79 | ||
b76b015e VZ |
80 | #else |
81 | // if nothing is defined, use native implementation by default, of course | |
82 | #ifndef wxUSE_LONGLONG_NATIVE | |
83 | #define wxUSE_LONGLONG_NATIVE 1 | |
84 | #endif | |
8b81872f VZ |
85 | #endif |
86 | ||
87 | #ifndef wxUSE_LONGLONG_WX | |
88 | #define wxUSE_LONGLONG_WX 0 | |
bddd7a8d VZ |
89 | class WXDLLIMPEXP_BASE wxLongLongNative; |
90 | class WXDLLIMPEXP_BASE wxULongLongNative; | |
8b81872f | 91 | typedef wxLongLongNative wxLongLong; |
8e38fd1f | 92 | typedef wxULongLongNative wxULongLong; |
8b81872f VZ |
93 | #endif |
94 | ||
95 | // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should | |
96 | // typedef wxLongLong as it wants, we don't do it | |
97 | ||
98 | // ---------------------------------------------------------------------------- | |
99 | // choose the appropriate class | |
100 | // ---------------------------------------------------------------------------- | |
101 | ||
102 | // we use iostream for wxLongLong output | |
65f19af1 | 103 | #include "wx/iosfwrap.h" |
8b81872f VZ |
104 | |
105 | #if wxUSE_LONGLONG_NATIVE | |
106 | ||
bddd7a8d | 107 | class WXDLLIMPEXP_BASE wxLongLongNative |
8b81872f VZ |
108 | { |
109 | public: | |
110 | // ctors | |
111 | // default ctor initializes to 0 | |
2e403d6d | 112 | wxLongLongNative() : m_ll(0) { } |
8b81872f | 113 | // from long long |
2e403d6d | 114 | wxLongLongNative(wxLongLong_t ll) : m_ll(ll) { } |
8b81872f | 115 | // from 2 longs |
2e403d6d | 116 | wxLongLongNative(long hi, unsigned long lo) : m_ll(0) |
8b81872f VZ |
117 | { |
118 | // assign first to avoid precision loss! | |
119 | m_ll = ((wxLongLong_t) hi) << 32; | |
120 | m_ll |= (wxLongLong_t) lo; | |
121 | } | |
842215bb WS |
122 | #if wxUSE_LONGLONG_WX |
123 | wxLongLongNative(wxLongLongWx ll); | |
124 | #endif | |
8b81872f | 125 | |
2f02cb89 | 126 | // default copy ctor is ok |
8b81872f VZ |
127 | |
128 | // no dtor | |
129 | ||
130 | // assignment operators | |
131 | // from native 64 bit integer | |
38b2e0de | 132 | #ifndef wxLongLongIsLong |
8b81872f VZ |
133 | wxLongLongNative& operator=(wxLongLong_t ll) |
134 | { m_ll = ll; return *this; } | |
216a72f3 VZ |
135 | wxLongLongNative& operator=(wxULongLong_t ll) |
136 | { m_ll = ll; return *this; } | |
38b2e0de | 137 | #endif // !wxLongLongNative |
216a72f3 | 138 | wxLongLongNative& operator=(const wxULongLongNative &ll); |
a4d2944e VZ |
139 | wxLongLongNative& operator=(int l) |
140 | { m_ll = l; return *this; } | |
216a72f3 VZ |
141 | wxLongLongNative& operator=(long l) |
142 | { m_ll = l; return *this; } | |
62675f1e VZ |
143 | wxLongLongNative& operator=(unsigned int l) |
144 | { m_ll = l; return *this; } | |
216a72f3 VZ |
145 | wxLongLongNative& operator=(unsigned long l) |
146 | { m_ll = l; return *this; } | |
842215bb WS |
147 | #if wxUSE_LONGLONG_WX |
148 | wxLongLongNative& operator=(wxLongLongWx ll); | |
216a72f3 | 149 | wxLongLongNative& operator=(const class wxULongLongWx &ll); |
842215bb WS |
150 | #endif |
151 | ||
8b81872f | 152 | |
cd0b1709 VZ |
153 | // from double: this one has an explicit name because otherwise we |
154 | // would have ambiguity with "ll = int" and also because we don't want | |
155 | // to have implicit conversions between doubles and wxLongLongs | |
156 | wxLongLongNative& Assign(double d) | |
157 | { m_ll = (wxLongLong_t)d; return *this; } | |
158 | ||
8b81872f VZ |
159 | // assignment operators from wxLongLongNative is ok |
160 | ||
161 | // accessors | |
162 | // get high part | |
163 | long GetHi() const | |
17a1ebd1 | 164 | { return wx_truncate_cast(long, m_ll >> 32); } |
8b81872f VZ |
165 | // get low part |
166 | unsigned long GetLo() const | |
17a1ebd1 | 167 | { return wx_truncate_cast(unsigned long, m_ll); } |
8b81872f | 168 | |
b76b015e | 169 | // get absolute value |
2ea24d9f | 170 | wxLongLongNative Abs() const { return wxLongLongNative(*this).Abs(); } |
b76b015e VZ |
171 | wxLongLongNative& Abs() { if ( m_ll < 0 ) m_ll = -m_ll; return *this; } |
172 | ||
8b81872f VZ |
173 | // convert to native long long |
174 | wxLongLong_t GetValue() const { return m_ll; } | |
175 | ||
90e572f1 | 176 | // convert to long with range checking in debug mode (only!) |
1ef54dcf VZ |
177 | long ToLong() const |
178 | { | |
179 | wxASSERT_MSG( (m_ll >= LONG_MIN) && (m_ll <= LONG_MAX), | |
180 | _T("wxLongLong to long conversion loss of precision") ); | |
181 | ||
17a1ebd1 | 182 | return wx_truncate_cast(long, m_ll); |
1ef54dcf VZ |
183 | } |
184 | ||
e7aaf2de | 185 | // convert to double |
17a1ebd1 | 186 | double ToDouble() const { return wx_truncate_cast(double, m_ll); } |
e7aaf2de | 187 | |
2f02cb89 VZ |
188 | // don't provide implicit conversion to wxLongLong_t or we will have an |
189 | // ambiguity for all arithmetic operations | |
b76b015e | 190 | //operator wxLongLong_t() const { return m_ll; } |
8b81872f VZ |
191 | |
192 | // operations | |
193 | // addition | |
194 | wxLongLongNative operator+(const wxLongLongNative& ll) const | |
195 | { return wxLongLongNative(m_ll + ll.m_ll); } | |
196 | wxLongLongNative& operator+=(const wxLongLongNative& ll) | |
197 | { m_ll += ll.m_ll; return *this; } | |
198 | ||
199 | wxLongLongNative operator+(const wxLongLong_t ll) const | |
200 | { return wxLongLongNative(m_ll + ll); } | |
201 | wxLongLongNative& operator+=(const wxLongLong_t ll) | |
202 | { m_ll += ll; return *this; } | |
203 | ||
204 | // pre increment | |
205 | wxLongLongNative& operator++() | |
206 | { m_ll++; return *this; } | |
207 | ||
208 | // post increment | |
2e403d6d GD |
209 | wxLongLongNative operator++(int) |
210 | { wxLongLongNative value(*this); m_ll++; return value; } | |
8b81872f VZ |
211 | |
212 | // negation operator | |
213 | wxLongLongNative operator-() const | |
214 | { return wxLongLongNative(-m_ll); } | |
3a994742 | 215 | wxLongLongNative& Negate() { m_ll = -m_ll; return *this; } |
8b81872f VZ |
216 | |
217 | // subtraction | |
218 | wxLongLongNative operator-(const wxLongLongNative& ll) const | |
219 | { return wxLongLongNative(m_ll - ll.m_ll); } | |
220 | wxLongLongNative& operator-=(const wxLongLongNative& ll) | |
221 | { m_ll -= ll.m_ll; return *this; } | |
222 | ||
223 | wxLongLongNative operator-(const wxLongLong_t ll) const | |
224 | { return wxLongLongNative(m_ll - ll); } | |
225 | wxLongLongNative& operator-=(const wxLongLong_t ll) | |
226 | { m_ll -= ll; return *this; } | |
227 | ||
228 | // pre decrement | |
229 | wxLongLongNative& operator--() | |
230 | { m_ll--; return *this; } | |
231 | ||
232 | // post decrement | |
2e403d6d GD |
233 | wxLongLongNative operator--(int) |
234 | { wxLongLongNative value(*this); m_ll--; return value; } | |
8b81872f VZ |
235 | |
236 | // shifts | |
237 | // left shift | |
238 | wxLongLongNative operator<<(int shift) const | |
d0ee33f5 | 239 | { return wxLongLongNative(m_ll << shift); } |
8b81872f VZ |
240 | wxLongLongNative& operator<<=(int shift) |
241 | { m_ll <<= shift; return *this; } | |
242 | ||
243 | // right shift | |
244 | wxLongLongNative operator>>(int shift) const | |
d0ee33f5 | 245 | { return wxLongLongNative(m_ll >> shift); } |
8b81872f VZ |
246 | wxLongLongNative& operator>>=(int shift) |
247 | { m_ll >>= shift; return *this; } | |
248 | ||
249 | // bitwise operators | |
250 | wxLongLongNative operator&(const wxLongLongNative& ll) const | |
251 | { return wxLongLongNative(m_ll & ll.m_ll); } | |
252 | wxLongLongNative& operator&=(const wxLongLongNative& ll) | |
253 | { m_ll &= ll.m_ll; return *this; } | |
254 | ||
255 | wxLongLongNative operator|(const wxLongLongNative& ll) const | |
256 | { return wxLongLongNative(m_ll | ll.m_ll); } | |
257 | wxLongLongNative& operator|=(const wxLongLongNative& ll) | |
258 | { m_ll |= ll.m_ll; return *this; } | |
259 | ||
260 | wxLongLongNative operator^(const wxLongLongNative& ll) const | |
261 | { return wxLongLongNative(m_ll ^ ll.m_ll); } | |
262 | wxLongLongNative& operator^=(const wxLongLongNative& ll) | |
263 | { m_ll ^= ll.m_ll; return *this; } | |
264 | ||
b76b015e | 265 | // multiplication/division |
8b81872f VZ |
266 | wxLongLongNative operator*(const wxLongLongNative& ll) const |
267 | { return wxLongLongNative(m_ll * ll.m_ll); } | |
2f02cb89 VZ |
268 | wxLongLongNative operator*(long l) const |
269 | { return wxLongLongNative(m_ll * l); } | |
8b81872f VZ |
270 | wxLongLongNative& operator*=(const wxLongLongNative& ll) |
271 | { m_ll *= ll.m_ll; return *this; } | |
2f02cb89 VZ |
272 | wxLongLongNative& operator*=(long l) |
273 | { m_ll *= l; return *this; } | |
8b81872f VZ |
274 | |
275 | wxLongLongNative operator/(const wxLongLongNative& ll) const | |
276 | { return wxLongLongNative(m_ll / ll.m_ll); } | |
b76b015e VZ |
277 | wxLongLongNative operator/(long l) const |
278 | { return wxLongLongNative(m_ll / l); } | |
8b81872f VZ |
279 | wxLongLongNative& operator/=(const wxLongLongNative& ll) |
280 | { m_ll /= ll.m_ll; return *this; } | |
2f02cb89 VZ |
281 | wxLongLongNative& operator/=(long l) |
282 | { m_ll /= l; return *this; } | |
8b81872f VZ |
283 | |
284 | wxLongLongNative operator%(const wxLongLongNative& ll) const | |
285 | { return wxLongLongNative(m_ll % ll.m_ll); } | |
b76b015e VZ |
286 | wxLongLongNative operator%(long l) const |
287 | { return wxLongLongNative(m_ll % l); } | |
8b81872f VZ |
288 | |
289 | // comparison | |
290 | bool operator==(const wxLongLongNative& ll) const | |
291 | { return m_ll == ll.m_ll; } | |
b76b015e VZ |
292 | bool operator==(long l) const |
293 | { return m_ll == l; } | |
8b81872f VZ |
294 | bool operator!=(const wxLongLongNative& ll) const |
295 | { return m_ll != ll.m_ll; } | |
b76b015e VZ |
296 | bool operator!=(long l) const |
297 | { return m_ll != l; } | |
8b81872f VZ |
298 | bool operator<(const wxLongLongNative& ll) const |
299 | { return m_ll < ll.m_ll; } | |
b76b015e VZ |
300 | bool operator<(long l) const |
301 | { return m_ll < l; } | |
8b81872f VZ |
302 | bool operator>(const wxLongLongNative& ll) const |
303 | { return m_ll > ll.m_ll; } | |
b76b015e VZ |
304 | bool operator>(long l) const |
305 | { return m_ll > l; } | |
8b81872f VZ |
306 | bool operator<=(const wxLongLongNative& ll) const |
307 | { return m_ll <= ll.m_ll; } | |
b76b015e VZ |
308 | bool operator<=(long l) const |
309 | { return m_ll <= l; } | |
8b81872f VZ |
310 | bool operator>=(const wxLongLongNative& ll) const |
311 | { return m_ll >= ll.m_ll; } | |
b76b015e VZ |
312 | bool operator>=(long l) const |
313 | { return m_ll >= l; } | |
8b81872f VZ |
314 | |
315 | // miscellaneous | |
3a994742 VZ |
316 | |
317 | // return the string representation of this number | |
318 | wxString ToString() const; | |
319 | ||
8b81872f VZ |
320 | // conversion to byte array: returns a pointer to static buffer! |
321 | void *asArray() const; | |
322 | ||
fcc3d7cb | 323 | #if wxUSE_STD_IOSTREAM |
8b81872f | 324 | // input/output |
a353dc98 VZ |
325 | friend WXDLLIMPEXP_BASE |
326 | wxSTD ostream& operator<<(wxSTD ostream&, const wxLongLongNative&); | |
fcc3d7cb | 327 | #endif |
8b81872f | 328 | |
a353dc98 VZ |
329 | friend WXDLLIMPEXP_BASE |
330 | wxString& operator<<(wxString&, const wxLongLongNative&); | |
51496782 | 331 | |
216a72f3 VZ |
332 | #if wxUSE_STREAMS |
333 | friend WXDLLIMPEXP_BASE | |
334 | class wxTextOutputStream& operator<<(class wxTextOutputStream&, const wxLongLongNative&); | |
335 | friend WXDLLIMPEXP_BASE | |
336 | class wxTextInputStream& operator>>(class wxTextInputStream&, wxLongLongNative&); | |
337 | #endif | |
338 | ||
8b81872f VZ |
339 | private: |
340 | wxLongLong_t m_ll; | |
341 | }; | |
342 | ||
8e38fd1f | 343 | |
bddd7a8d | 344 | class WXDLLIMPEXP_BASE wxULongLongNative |
8e38fd1f RL |
345 | { |
346 | public: | |
347 | // ctors | |
348 | // default ctor initializes to 0 | |
2e403d6d | 349 | wxULongLongNative() : m_ll(0) { } |
8e38fd1f | 350 | // from long long |
60582201 | 351 | wxULongLongNative(wxULongLong_t ll) : m_ll(ll) { } |
8e38fd1f | 352 | // from 2 longs |
2e403d6d | 353 | wxULongLongNative(unsigned long hi, unsigned long lo) : m_ll(0) |
8e38fd1f RL |
354 | { |
355 | // assign first to avoid precision loss! | |
60582201 WS |
356 | m_ll = ((wxULongLong_t) hi) << 32; |
357 | m_ll |= (wxULongLong_t) lo; | |
8e38fd1f RL |
358 | } |
359 | ||
216a72f3 VZ |
360 | #if wxUSE_LONGLONG_WX |
361 | wxULongLongNative(const class wxULongLongWx &ll); | |
362 | #endif | |
363 | ||
8e38fd1f RL |
364 | // default copy ctor is ok |
365 | ||
366 | // no dtor | |
367 | ||
368 | // assignment operators | |
369 | // from native 64 bit integer | |
38b2e0de | 370 | #ifndef wxLongLongIsLong |
60582201 | 371 | wxULongLongNative& operator=(wxULongLong_t ll) |
8e38fd1f | 372 | { m_ll = ll; return *this; } |
216a72f3 VZ |
373 | wxULongLongNative& operator=(wxLongLong_t ll) |
374 | { m_ll = ll; return *this; } | |
38b2e0de | 375 | #endif // !wxLongLongNative |
a4d2944e VZ |
376 | wxULongLongNative& operator=(int l) |
377 | { m_ll = l; return *this; } | |
216a72f3 VZ |
378 | wxULongLongNative& operator=(long l) |
379 | { m_ll = l; return *this; } | |
62675f1e VZ |
380 | wxULongLongNative& operator=(unsigned int l) |
381 | { m_ll = l; return *this; } | |
216a72f3 VZ |
382 | wxULongLongNative& operator=(unsigned long l) |
383 | { m_ll = l; return *this; } | |
384 | wxULongLongNative& operator=(const wxLongLongNative &ll) | |
385 | { m_ll = ll.GetValue(); return *this; } | |
386 | #if wxUSE_LONGLONG_WX | |
387 | wxULongLongNative& operator=(wxLongLongWx ll); | |
388 | wxULongLongNative& operator=(const class wxULongLongWx &ll); | |
389 | #endif | |
8e38fd1f RL |
390 | |
391 | // assignment operators from wxULongLongNative is ok | |
392 | ||
393 | // accessors | |
394 | // get high part | |
395 | unsigned long GetHi() const | |
17a1ebd1 | 396 | { return wx_truncate_cast(unsigned long, m_ll >> 32); } |
8e38fd1f RL |
397 | // get low part |
398 | unsigned long GetLo() const | |
17a1ebd1 | 399 | { return wx_truncate_cast(unsigned long, m_ll); } |
8e38fd1f RL |
400 | |
401 | // convert to native ulong long | |
60582201 | 402 | wxULongLong_t GetValue() const { return m_ll; } |
8e38fd1f | 403 | |
90e572f1 | 404 | // convert to ulong with range checking in debug mode (only!) |
8e38fd1f RL |
405 | unsigned long ToULong() const |
406 | { | |
0ba9f867 | 407 | wxASSERT_MSG( m_ll <= LONG_MAX, |
8e38fd1f RL |
408 | _T("wxULongLong to long conversion loss of precision") ); |
409 | ||
17a1ebd1 | 410 | return wx_truncate_cast(unsigned long, m_ll); |
8e38fd1f RL |
411 | } |
412 | ||
8e38fd1f RL |
413 | // operations |
414 | // addition | |
415 | wxULongLongNative operator+(const wxULongLongNative& ll) const | |
416 | { return wxULongLongNative(m_ll + ll.m_ll); } | |
417 | wxULongLongNative& operator+=(const wxULongLongNative& ll) | |
418 | { m_ll += ll.m_ll; return *this; } | |
419 | ||
60582201 | 420 | wxULongLongNative operator+(const wxULongLong_t ll) const |
8e38fd1f | 421 | { return wxULongLongNative(m_ll + ll); } |
60582201 | 422 | wxULongLongNative& operator+=(const wxULongLong_t ll) |
8e38fd1f RL |
423 | { m_ll += ll; return *this; } |
424 | ||
425 | // pre increment | |
426 | wxULongLongNative& operator++() | |
427 | { m_ll++; return *this; } | |
428 | ||
429 | // post increment | |
2e403d6d GD |
430 | wxULongLongNative operator++(int) |
431 | { wxULongLongNative value(*this); m_ll++; return value; } | |
8e38fd1f RL |
432 | |
433 | // subtraction | |
434 | wxULongLongNative operator-(const wxULongLongNative& ll) const | |
435 | { return wxULongLongNative(m_ll - ll.m_ll); } | |
436 | wxULongLongNative& operator-=(const wxULongLongNative& ll) | |
437 | { m_ll -= ll.m_ll; return *this; } | |
438 | ||
60582201 | 439 | wxULongLongNative operator-(const wxULongLong_t ll) const |
8e38fd1f | 440 | { return wxULongLongNative(m_ll - ll); } |
60582201 | 441 | wxULongLongNative& operator-=(const wxULongLong_t ll) |
8e38fd1f RL |
442 | { m_ll -= ll; return *this; } |
443 | ||
444 | // pre decrement | |
445 | wxULongLongNative& operator--() | |
446 | { m_ll--; return *this; } | |
447 | ||
448 | // post decrement | |
2e403d6d GD |
449 | wxULongLongNative operator--(int) |
450 | { wxULongLongNative value(*this); m_ll--; return value; } | |
8e38fd1f RL |
451 | |
452 | // shifts | |
453 | // left shift | |
454 | wxULongLongNative operator<<(int shift) const | |
d0ee33f5 | 455 | { return wxULongLongNative(m_ll << shift); } |
8e38fd1f RL |
456 | wxULongLongNative& operator<<=(int shift) |
457 | { m_ll <<= shift; return *this; } | |
458 | ||
459 | // right shift | |
460 | wxULongLongNative operator>>(int shift) const | |
d0ee33f5 | 461 | { return wxULongLongNative(m_ll >> shift); } |
8e38fd1f RL |
462 | wxULongLongNative& operator>>=(int shift) |
463 | { m_ll >>= shift; return *this; } | |
464 | ||
465 | // bitwise operators | |
466 | wxULongLongNative operator&(const wxULongLongNative& ll) const | |
467 | { return wxULongLongNative(m_ll & ll.m_ll); } | |
468 | wxULongLongNative& operator&=(const wxULongLongNative& ll) | |
469 | { m_ll &= ll.m_ll; return *this; } | |
470 | ||
471 | wxULongLongNative operator|(const wxULongLongNative& ll) const | |
472 | { return wxULongLongNative(m_ll | ll.m_ll); } | |
473 | wxULongLongNative& operator|=(const wxULongLongNative& ll) | |
474 | { m_ll |= ll.m_ll; return *this; } | |
475 | ||
476 | wxULongLongNative operator^(const wxULongLongNative& ll) const | |
477 | { return wxULongLongNative(m_ll ^ ll.m_ll); } | |
478 | wxULongLongNative& operator^=(const wxULongLongNative& ll) | |
479 | { m_ll ^= ll.m_ll; return *this; } | |
480 | ||
481 | // multiplication/division | |
482 | wxULongLongNative operator*(const wxULongLongNative& ll) const | |
483 | { return wxULongLongNative(m_ll * ll.m_ll); } | |
484 | wxULongLongNative operator*(unsigned long l) const | |
485 | { return wxULongLongNative(m_ll * l); } | |
486 | wxULongLongNative& operator*=(const wxULongLongNative& ll) | |
487 | { m_ll *= ll.m_ll; return *this; } | |
488 | wxULongLongNative& operator*=(unsigned long l) | |
489 | { m_ll *= l; return *this; } | |
490 | ||
491 | wxULongLongNative operator/(const wxULongLongNative& ll) const | |
492 | { return wxULongLongNative(m_ll / ll.m_ll); } | |
493 | wxULongLongNative operator/(unsigned long l) const | |
494 | { return wxULongLongNative(m_ll / l); } | |
495 | wxULongLongNative& operator/=(const wxULongLongNative& ll) | |
496 | { m_ll /= ll.m_ll; return *this; } | |
497 | wxULongLongNative& operator/=(unsigned long l) | |
498 | { m_ll /= l; return *this; } | |
499 | ||
500 | wxULongLongNative operator%(const wxULongLongNative& ll) const | |
501 | { return wxULongLongNative(m_ll % ll.m_ll); } | |
502 | wxULongLongNative operator%(unsigned long l) const | |
503 | { return wxULongLongNative(m_ll % l); } | |
504 | ||
505 | // comparison | |
506 | bool operator==(const wxULongLongNative& ll) const | |
507 | { return m_ll == ll.m_ll; } | |
508 | bool operator==(unsigned long l) const | |
509 | { return m_ll == l; } | |
510 | bool operator!=(const wxULongLongNative& ll) const | |
511 | { return m_ll != ll.m_ll; } | |
512 | bool operator!=(unsigned long l) const | |
513 | { return m_ll != l; } | |
514 | bool operator<(const wxULongLongNative& ll) const | |
515 | { return m_ll < ll.m_ll; } | |
516 | bool operator<(unsigned long l) const | |
517 | { return m_ll < l; } | |
518 | bool operator>(const wxULongLongNative& ll) const | |
519 | { return m_ll > ll.m_ll; } | |
520 | bool operator>(unsigned long l) const | |
521 | { return m_ll > l; } | |
522 | bool operator<=(const wxULongLongNative& ll) const | |
523 | { return m_ll <= ll.m_ll; } | |
524 | bool operator<=(unsigned long l) const | |
525 | { return m_ll <= l; } | |
526 | bool operator>=(const wxULongLongNative& ll) const | |
527 | { return m_ll >= ll.m_ll; } | |
528 | bool operator>=(unsigned long l) const | |
529 | { return m_ll >= l; } | |
530 | ||
531 | // miscellaneous | |
532 | ||
533 | // return the string representation of this number | |
534 | wxString ToString() const; | |
535 | ||
536 | // conversion to byte array: returns a pointer to static buffer! | |
537 | void *asArray() const; | |
538 | ||
539 | #if wxUSE_STD_IOSTREAM | |
540 | // input/output | |
7fcdf88f VZ |
541 | friend WXDLLIMPEXP_BASE |
542 | wxSTD ostream& operator<<(wxSTD ostream&, const wxULongLongNative&); | |
8e38fd1f RL |
543 | #endif |
544 | ||
7fcdf88f VZ |
545 | friend WXDLLIMPEXP_BASE |
546 | wxString& operator<<(wxString&, const wxULongLongNative&); | |
51496782 | 547 | |
216a72f3 VZ |
548 | #if wxUSE_STREAMS |
549 | friend WXDLLIMPEXP_BASE | |
550 | class wxTextOutputStream& operator<<(class wxTextOutputStream&, const wxULongLongNative&); | |
551 | friend WXDLLIMPEXP_BASE | |
552 | class wxTextInputStream& operator>>(class wxTextInputStream&, wxULongLongNative&); | |
553 | #endif | |
554 | ||
8e38fd1f | 555 | private: |
60582201 | 556 | wxULongLong_t m_ll; |
8e38fd1f RL |
557 | }; |
558 | ||
216a72f3 VZ |
559 | inline |
560 | wxLongLongNative& wxLongLongNative::operator=(const wxULongLongNative &ll) | |
561 | { | |
562 | m_ll = ll.GetValue(); | |
563 | return *this; | |
564 | } | |
565 | ||
8b81872f VZ |
566 | #endif // wxUSE_LONGLONG_NATIVE |
567 | ||
568 | #if wxUSE_LONGLONG_WX | |
569 | ||
bddd7a8d | 570 | class WXDLLIMPEXP_BASE wxLongLongWx |
8b81872f VZ |
571 | { |
572 | public: | |
573 | // ctors | |
574 | // default ctor initializes to 0 | |
2a310492 VZ |
575 | wxLongLongWx() |
576 | { | |
577 | m_lo = m_hi = 0; | |
578 | ||
579 | #ifdef wxLONGLONG_TEST_MODE | |
580 | m_ll = 0; | |
581 | ||
582 | Check(); | |
583 | #endif // wxLONGLONG_TEST_MODE | |
584 | } | |
8b81872f | 585 | // from long |
2a310492 | 586 | wxLongLongWx(long l) { *this = l; } |
8b81872f VZ |
587 | // from 2 longs |
588 | wxLongLongWx(long hi, unsigned long lo) | |
2a310492 VZ |
589 | { |
590 | m_hi = hi; | |
591 | m_lo = lo; | |
592 | ||
593 | #ifdef wxLONGLONG_TEST_MODE | |
594 | m_ll = hi; | |
595 | m_ll <<= 32; | |
596 | m_ll |= lo; | |
597 | ||
598 | Check(); | |
599 | #endif // wxLONGLONG_TEST_MODE | |
600 | } | |
8b81872f VZ |
601 | |
602 | // default copy ctor is ok in both cases | |
603 | ||
604 | // no dtor | |
605 | ||
606 | // assignment operators | |
607 | // from long | |
608 | wxLongLongWx& operator=(long l) | |
2a310492 VZ |
609 | { |
610 | m_lo = l; | |
611 | m_hi = (l < 0 ? -1l : 0l); | |
612 | ||
613 | #ifdef wxLONGLONG_TEST_MODE | |
614 | m_ll = l; | |
615 | ||
616 | Check(); | |
617 | #endif // wxLONGLONG_TEST_MODE | |
618 | ||
619 | return *this; | |
620 | } | |
a4d2944e VZ |
621 | // from int |
622 | wxLongLongWx& operator=(int l) | |
623 | { | |
624 | return operator=((long)l); | |
625 | } | |
626 | ||
216a72f3 VZ |
627 | wxLongLongWx& operator=(unsigned long l) |
628 | { | |
629 | m_lo = l; | |
630 | m_hi = 0; | |
631 | ||
632 | #ifdef wxLONGLONG_TEST_MODE | |
633 | m_ll = l; | |
634 | ||
635 | Check(); | |
636 | #endif // wxLONGLONG_TEST_MODE | |
637 | ||
638 | return *this; | |
639 | } | |
62675f1e VZ |
640 | |
641 | wxLongLongWx& operator=(unsigned int l) | |
642 | { | |
643 | return operator=((unsigned long)l); | |
644 | } | |
645 | ||
216a72f3 VZ |
646 | wxLongLongWx& operator=(const class wxULongLongWx &ll); |
647 | ||
648 | // from double | |
cd0b1709 | 649 | wxLongLongWx& Assign(double d); |
8b81872f VZ |
650 | // can't have assignment operator from 2 longs |
651 | ||
652 | // accessors | |
653 | // get high part | |
654 | long GetHi() const { return m_hi; } | |
655 | // get low part | |
656 | unsigned long GetLo() const { return m_lo; } | |
657 | ||
cd0b1709 | 658 | // get absolute value |
2ea24d9f | 659 | wxLongLongWx Abs() const { return wxLongLongWx(*this).Abs(); } |
2a310492 VZ |
660 | wxLongLongWx& Abs() |
661 | { | |
662 | if ( m_hi < 0 ) | |
663 | m_hi = -m_hi; | |
664 | ||
665 | #ifdef wxLONGLONG_TEST_MODE | |
666 | if ( m_ll < 0 ) | |
667 | m_ll = -m_ll; | |
668 | ||
669 | Check(); | |
670 | #endif // wxLONGLONG_TEST_MODE | |
671 | ||
672 | return *this; | |
673 | } | |
cd0b1709 | 674 | |
90e572f1 | 675 | // convert to long with range checking in debug mode (only!) |
cd0b1709 VZ |
676 | long ToLong() const |
677 | { | |
2a310492 | 678 | wxASSERT_MSG( (m_hi == 0l) || (m_hi == -1l), |
cd0b1709 VZ |
679 | _T("wxLongLong to long conversion loss of precision") ); |
680 | ||
681 | return (long)m_lo; | |
682 | } | |
683 | ||
e7aaf2de VZ |
684 | // convert to double |
685 | double ToDouble() const; | |
686 | ||
8b81872f VZ |
687 | // operations |
688 | // addition | |
689 | wxLongLongWx operator+(const wxLongLongWx& ll) const; | |
690 | wxLongLongWx& operator+=(const wxLongLongWx& ll); | |
691 | wxLongLongWx operator+(long l) const; | |
692 | wxLongLongWx& operator+=(long l); | |
693 | ||
694 | // pre increment operator | |
695 | wxLongLongWx& operator++(); | |
696 | ||
697 | // post increment operator | |
2a310492 | 698 | wxLongLongWx& operator++(int) { return ++(*this); } |
8b81872f VZ |
699 | |
700 | // negation operator | |
701 | wxLongLongWx operator-() const; | |
2a310492 | 702 | wxLongLongWx& Negate(); |
8b81872f VZ |
703 | |
704 | // subraction | |
705 | wxLongLongWx operator-(const wxLongLongWx& ll) const; | |
706 | wxLongLongWx& operator-=(const wxLongLongWx& ll); | |
707 | ||
708 | // pre decrement operator | |
709 | wxLongLongWx& operator--(); | |
710 | ||
711 | // post decrement operator | |
2a310492 | 712 | wxLongLongWx& operator--(int) { return --(*this); } |
8b81872f VZ |
713 | |
714 | // shifts | |
715 | // left shift | |
716 | wxLongLongWx operator<<(int shift) const; | |
717 | wxLongLongWx& operator<<=(int shift); | |
718 | ||
719 | // right shift | |
720 | wxLongLongWx operator>>(int shift) const; | |
721 | wxLongLongWx& operator>>=(int shift); | |
722 | ||
723 | // bitwise operators | |
724 | wxLongLongWx operator&(const wxLongLongWx& ll) const; | |
725 | wxLongLongWx& operator&=(const wxLongLongWx& ll); | |
726 | wxLongLongWx operator|(const wxLongLongWx& ll) const; | |
727 | wxLongLongWx& operator|=(const wxLongLongWx& ll); | |
728 | wxLongLongWx operator^(const wxLongLongWx& ll) const; | |
729 | wxLongLongWx& operator^=(const wxLongLongWx& ll); | |
730 | wxLongLongWx operator~() const; | |
731 | ||
732 | // comparison | |
2ea24d9f VZ |
733 | bool operator==(const wxLongLongWx& ll) const |
734 | { return m_lo == ll.m_lo && m_hi == ll.m_hi; } | |
842215bb WS |
735 | #if wxUSE_LONGLONG_NATIVE |
736 | bool operator==(const wxLongLongNative& ll) const | |
737 | { return m_lo == ll.GetLo() && m_hi == ll.GetHi(); } | |
738 | #endif | |
2ea24d9f VZ |
739 | bool operator!=(const wxLongLongWx& ll) const |
740 | { return !(*this == ll); } | |
8b81872f VZ |
741 | bool operator<(const wxLongLongWx& ll) const; |
742 | bool operator>(const wxLongLongWx& ll) const; | |
2ea24d9f VZ |
743 | bool operator<=(const wxLongLongWx& ll) const |
744 | { return *this < ll || *this == ll; } | |
745 | bool operator>=(const wxLongLongWx& ll) const | |
746 | { return *this > ll || *this == ll; } | |
8b81872f | 747 | |
f6bcfd97 BP |
748 | bool operator<(long l) const { return *this < wxLongLongWx(l); } |
749 | bool operator>(long l) const { return *this > wxLongLongWx(l); } | |
750 | bool operator==(long l) const | |
751 | { | |
752 | return l >= 0 ? (m_hi == 0 && m_lo == (unsigned long)l) | |
753 | : (m_hi == -1 && m_lo == (unsigned long)l); | |
754 | } | |
755 | ||
756 | bool operator<=(long l) const { return *this < l || *this == l; } | |
757 | bool operator>=(long l) const { return *this > l || *this == l; } | |
758 | ||
8b81872f VZ |
759 | // multiplication |
760 | wxLongLongWx operator*(const wxLongLongWx& ll) const; | |
761 | wxLongLongWx& operator*=(const wxLongLongWx& ll); | |
8b81872f VZ |
762 | |
763 | // division | |
cd0b1709 VZ |
764 | wxLongLongWx operator/(const wxLongLongWx& ll) const; |
765 | wxLongLongWx& operator/=(const wxLongLongWx& ll); | |
766 | ||
767 | wxLongLongWx operator%(const wxLongLongWx& ll) const; | |
768 | ||
8b81872f VZ |
769 | void Divide(const wxLongLongWx& divisor, |
770 | wxLongLongWx& quotient, | |
771 | wxLongLongWx& remainder) const; | |
772 | ||
773 | // input/output | |
3a994742 VZ |
774 | |
775 | // return the string representation of this number | |
776 | wxString ToString() const; | |
777 | ||
778 | void *asArray() const; | |
779 | ||
cd0b1709 | 780 | #if wxUSE_STD_IOSTREAM |
a353dc98 VZ |
781 | friend WXDLLIMPEXP_BASE |
782 | wxSTD ostream& operator<<(wxSTD ostream&, const wxLongLongWx&); | |
fcc3d7cb | 783 | #endif // wxUSE_STD_IOSTREAM |
8b81872f | 784 | |
a353dc98 VZ |
785 | friend WXDLLIMPEXP_BASE |
786 | wxString& operator<<(wxString&, const wxLongLongWx&); | |
51496782 | 787 | |
216a72f3 VZ |
788 | #if wxUSE_STREAMS |
789 | friend WXDLLIMPEXP_BASE | |
790 | class wxTextOutputStream& operator<<(class wxTextOutputStream&, const wxLongLongWx&); | |
791 | friend WXDLLIMPEXP_BASE | |
792 | class wxTextInputStream& operator>>(class wxTextInputStream&, wxLongLongWx&); | |
793 | #endif | |
794 | ||
8b81872f VZ |
795 | private: |
796 | // long is at least 32 bits, so represent our 64bit number as 2 longs | |
797 | ||
798 | long m_hi; // signed bit is in the high part | |
799 | unsigned long m_lo; | |
2a310492 VZ |
800 | |
801 | #ifdef wxLONGLONG_TEST_MODE | |
802 | void Check() | |
803 | { | |
804 | wxASSERT( (m_ll >> 32) == m_hi && (unsigned long)m_ll == m_lo ); | |
805 | } | |
806 | ||
807 | wxLongLong_t m_ll; | |
808 | #endif // wxLONGLONG_TEST_MODE | |
8b81872f VZ |
809 | }; |
810 | ||
8e38fd1f | 811 | |
bddd7a8d | 812 | class WXDLLIMPEXP_BASE wxULongLongWx |
8e38fd1f RL |
813 | { |
814 | public: | |
815 | // ctors | |
816 | // default ctor initializes to 0 | |
817 | wxULongLongWx() | |
818 | { | |
819 | m_lo = m_hi = 0; | |
820 | ||
821 | #ifdef wxLONGLONG_TEST_MODE | |
822 | m_ll = 0; | |
823 | ||
824 | Check(); | |
825 | #endif // wxLONGLONG_TEST_MODE | |
826 | } | |
827 | // from ulong | |
828 | wxULongLongWx(unsigned long l) { *this = l; } | |
829 | // from 2 ulongs | |
830 | wxULongLongWx(unsigned long hi, unsigned long lo) | |
831 | { | |
832 | m_hi = hi; | |
833 | m_lo = lo; | |
834 | ||
835 | #ifdef wxLONGLONG_TEST_MODE | |
836 | m_ll = hi; | |
837 | m_ll <<= 32; | |
838 | m_ll |= lo; | |
839 | ||
840 | Check(); | |
841 | #endif // wxLONGLONG_TEST_MODE | |
842 | } | |
843 | ||
842215bb WS |
844 | // from signed to unsigned |
845 | wxULongLongWx(wxLongLongWx ll) | |
846 | { | |
847 | wxASSERT(ll.GetHi() >= 0); | |
848 | m_hi = (unsigned long)ll.GetHi(); | |
849 | m_lo = ll.GetLo(); | |
850 | } | |
851 | ||
8e38fd1f RL |
852 | // default copy ctor is ok in both cases |
853 | ||
854 | // no dtor | |
855 | ||
856 | // assignment operators | |
857 | // from long | |
858 | wxULongLongWx& operator=(unsigned long l) | |
859 | { | |
860 | m_lo = l; | |
861 | m_hi = 0; | |
862 | ||
863 | #ifdef wxLONGLONG_TEST_MODE | |
864 | m_ll = l; | |
865 | ||
866 | Check(); | |
867 | #endif // wxLONGLONG_TEST_MODE | |
868 | ||
869 | return *this; | |
870 | } | |
216a72f3 VZ |
871 | wxULongLongWx& operator=(long l) |
872 | { | |
873 | m_lo = l; | |
874 | m_hi = (unsigned long) ((l<0) ? -1l : 0); | |
875 | ||
876 | #ifdef wxLONGLONG_TEST_MODE | |
877 | m_ll = (wxULongLong_t) (wxLongLong_t) l; | |
878 | ||
879 | Check(); | |
880 | #endif // wxLONGLONG_TEST_MODE | |
881 | ||
882 | return *this; | |
883 | } | |
884 | wxULongLongWx& operator=(const class wxLongLongWx &ll) { | |
885 | // Should we use an assert like it was before in the constructor? | |
886 | // wxASSERT(ll.GetHi() >= 0); | |
887 | m_hi = (unsigned long)ll.GetHi(); | |
888 | m_lo = ll.GetLo(); | |
889 | return *this; | |
890 | } | |
8e38fd1f RL |
891 | |
892 | // can't have assignment operator from 2 longs | |
893 | ||
894 | // accessors | |
895 | // get high part | |
896 | unsigned long GetHi() const { return m_hi; } | |
897 | // get low part | |
898 | unsigned long GetLo() const { return m_lo; } | |
899 | ||
90e572f1 | 900 | // convert to long with range checking in debug mode (only!) |
8e38fd1f RL |
901 | unsigned long ToULong() const |
902 | { | |
d7997e1a | 903 | wxASSERT_MSG( m_hi == 0ul, |
8e38fd1f RL |
904 | _T("wxULongLong to long conversion loss of precision") ); |
905 | ||
906 | return (unsigned long)m_lo; | |
907 | } | |
908 | ||
909 | // operations | |
910 | // addition | |
911 | wxULongLongWx operator+(const wxULongLongWx& ll) const; | |
912 | wxULongLongWx& operator+=(const wxULongLongWx& ll); | |
913 | wxULongLongWx operator+(unsigned long l) const; | |
914 | wxULongLongWx& operator+=(unsigned long l); | |
915 | ||
916 | // pre increment operator | |
917 | wxULongLongWx& operator++(); | |
918 | ||
919 | // post increment operator | |
920 | wxULongLongWx& operator++(int) { return ++(*this); } | |
921 | ||
43e8916f | 922 | // subtraction |
842215bb | 923 | wxLongLongWx operator-(const wxULongLongWx& ll) const; |
8e38fd1f RL |
924 | wxULongLongWx& operator-=(const wxULongLongWx& ll); |
925 | ||
926 | // pre decrement operator | |
927 | wxULongLongWx& operator--(); | |
928 | ||
929 | // post decrement operator | |
930 | wxULongLongWx& operator--(int) { return --(*this); } | |
931 | ||
932 | // shifts | |
933 | // left shift | |
934 | wxULongLongWx operator<<(int shift) const; | |
935 | wxULongLongWx& operator<<=(int shift); | |
936 | ||
937 | // right shift | |
938 | wxULongLongWx operator>>(int shift) const; | |
939 | wxULongLongWx& operator>>=(int shift); | |
940 | ||
941 | // bitwise operators | |
942 | wxULongLongWx operator&(const wxULongLongWx& ll) const; | |
943 | wxULongLongWx& operator&=(const wxULongLongWx& ll); | |
944 | wxULongLongWx operator|(const wxULongLongWx& ll) const; | |
945 | wxULongLongWx& operator|=(const wxULongLongWx& ll); | |
946 | wxULongLongWx operator^(const wxULongLongWx& ll) const; | |
947 | wxULongLongWx& operator^=(const wxULongLongWx& ll); | |
948 | wxULongLongWx operator~() const; | |
949 | ||
950 | // comparison | |
951 | bool operator==(const wxULongLongWx& ll) const | |
952 | { return m_lo == ll.m_lo && m_hi == ll.m_hi; } | |
953 | bool operator!=(const wxULongLongWx& ll) const | |
954 | { return !(*this == ll); } | |
955 | bool operator<(const wxULongLongWx& ll) const; | |
956 | bool operator>(const wxULongLongWx& ll) const; | |
957 | bool operator<=(const wxULongLongWx& ll) const | |
958 | { return *this < ll || *this == ll; } | |
959 | bool operator>=(const wxULongLongWx& ll) const | |
960 | { return *this > ll || *this == ll; } | |
961 | ||
962 | bool operator<(unsigned long l) const { return *this < wxULongLongWx(l); } | |
963 | bool operator>(unsigned long l) const { return *this > wxULongLongWx(l); } | |
964 | bool operator==(unsigned long l) const | |
965 | { | |
966 | return (m_hi == 0 && m_lo == (unsigned long)l); | |
967 | } | |
968 | ||
969 | bool operator<=(unsigned long l) const { return *this < l || *this == l; } | |
970 | bool operator>=(unsigned long l) const { return *this > l || *this == l; } | |
971 | ||
972 | // multiplication | |
973 | wxULongLongWx operator*(const wxULongLongWx& ll) const; | |
974 | wxULongLongWx& operator*=(const wxULongLongWx& ll); | |
975 | ||
976 | // division | |
977 | wxULongLongWx operator/(const wxULongLongWx& ll) const; | |
978 | wxULongLongWx& operator/=(const wxULongLongWx& ll); | |
979 | ||
980 | wxULongLongWx operator%(const wxULongLongWx& ll) const; | |
981 | ||
982 | void Divide(const wxULongLongWx& divisor, | |
983 | wxULongLongWx& quotient, | |
984 | wxULongLongWx& remainder) const; | |
985 | ||
986 | // input/output | |
987 | ||
988 | // return the string representation of this number | |
989 | wxString ToString() const; | |
990 | ||
991 | void *asArray() const; | |
992 | ||
993 | #if wxUSE_STD_IOSTREAM | |
a353dc98 VZ |
994 | friend WXDLLIMPEXP_BASE |
995 | wxSTD ostream& operator<<(wxSTD ostream&, const wxULongLongWx&); | |
8e38fd1f RL |
996 | #endif // wxUSE_STD_IOSTREAM |
997 | ||
a353dc98 VZ |
998 | friend WXDLLIMPEXP_BASE |
999 | wxString& operator<<(wxString&, const wxULongLongWx&); | |
51496782 | 1000 | |
216a72f3 VZ |
1001 | #if wxUSE_STREAMS |
1002 | friend WXDLLIMPEXP_BASE | |
1003 | class wxTextOutputStream& operator<<(class wxTextOutputStream&, const wxULongLongWx&); | |
1004 | friend WXDLLIMPEXP_BASE | |
1005 | class wxTextInputStream& operator>>(class wxTextInputStream&, wxULongLongWx&); | |
1006 | #endif | |
1007 | ||
8e38fd1f RL |
1008 | private: |
1009 | // long is at least 32 bits, so represent our 64bit number as 2 longs | |
1010 | ||
d2ce649b | 1011 | unsigned long m_hi; |
8e38fd1f RL |
1012 | unsigned long m_lo; |
1013 | ||
1014 | #ifdef wxLONGLONG_TEST_MODE | |
1015 | void Check() | |
1016 | { | |
1017 | wxASSERT( (m_ll >> 32) == m_hi && (unsigned long)m_ll == m_lo ); | |
1018 | } | |
1019 | ||
60582201 | 1020 | wxULongLong_t m_ll; |
8e38fd1f RL |
1021 | #endif // wxLONGLONG_TEST_MODE |
1022 | }; | |
1023 | ||
8b81872f VZ |
1024 | #endif // wxUSE_LONGLONG_WX |
1025 | ||
2ea24d9f VZ |
1026 | // ---------------------------------------------------------------------------- |
1027 | // binary operators | |
1028 | // ---------------------------------------------------------------------------- | |
1029 | ||
6d56eb5c | 1030 | inline bool operator<(long l, const wxLongLong& ll) { return ll > l; } |
d7997e1a VZ |
1031 | inline bool operator>(long l, const wxLongLong& ll) { return ll < l; } |
1032 | inline bool operator<=(long l, const wxLongLong& ll) { return ll >= l; } | |
1033 | inline bool operator>=(long l, const wxLongLong& ll) { return ll <= l; } | |
1034 | inline bool operator==(long l, const wxLongLong& ll) { return ll == l; } | |
1035 | inline bool operator!=(long l, const wxLongLong& ll) { return ll != l; } | |
b01fb5c3 | 1036 | |
d7997e1a | 1037 | inline wxLongLong operator+(long l, const wxLongLong& ll) { return ll + l; } |
b01fb5c3 VZ |
1038 | inline wxLongLong operator-(long l, const wxLongLong& ll) |
1039 | { | |
d7997e1a | 1040 | return wxLongLong(l) - ll; |
b01fb5c3 | 1041 | } |
2ea24d9f | 1042 | |
d7997e1a VZ |
1043 | inline bool operator<(unsigned long l, const wxULongLong& ull) { return ull > l; } |
1044 | inline bool operator>(unsigned long l, const wxULongLong& ull) { return ull < l; } | |
1045 | inline bool operator<=(unsigned long l, const wxULongLong& ull) { return ull >= l; } | |
1046 | inline bool operator>=(unsigned long l, const wxULongLong& ull) { return ull <= l; } | |
1047 | inline bool operator==(unsigned long l, const wxULongLong& ull) { return ull == l; } | |
1048 | inline bool operator!=(unsigned long l, const wxULongLong& ull) { return ull != l; } | |
1049 | ||
1050 | inline wxULongLong operator+(unsigned long l, const wxULongLong& ull) { return ull + l; } | |
8e38fd1f | 1051 | |
842215bb | 1052 | inline wxLongLong operator-(unsigned long l, const wxULongLong& ull) |
d7997e1a | 1053 | { |
842215bb WS |
1054 | wxULongLong ret = wxULongLong(l) - ull; |
1055 | return wxLongLong((long)ret.GetHi(),ret.GetLo()); | |
d7997e1a | 1056 | } |
8e38fd1f | 1057 | |
216a72f3 VZ |
1058 | #if wxUSE_LONGLONG_NATIVE && wxUSE_STREAMS |
1059 | ||
1060 | WXDLLIMPEXP_BASE class wxTextOutputStream &operator<<(class wxTextOutputStream &stream, wxULongLong_t value); | |
1061 | WXDLLIMPEXP_BASE class wxTextOutputStream &operator<<(class wxTextOutputStream &stream, wxLongLong_t value); | |
1062 | ||
1063 | WXDLLIMPEXP_BASE class wxTextInputStream &operator>>(class wxTextInputStream &stream, wxULongLong_t &value); | |
1064 | WXDLLIMPEXP_BASE class wxTextInputStream &operator>>(class wxTextInputStream &stream, wxLongLong_t &value); | |
1065 | ||
1066 | #endif | |
1067 | ||
1068 | #endif // wxUSE_LONGLONG | |
1069 | ||
8b81872f | 1070 | #endif // _WX_LONGLONG_H |