1 /////////////////////////////////////////////////////////////////////////////
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
9 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_LONGLONG_H
14 #define _WX_LONGLONG_H
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma interface "longlong.h"
21 #include "wx/string.h"
23 #include <limits.h> // for LONG_MAX
25 // define this to compile wxLongLongWx in "test" mode: the results of all
26 // calculations will be compared with the real results taken from
27 // wxLongLongNative -- this is extremely useful to find the bugs in
28 // wxLongLongWx class!
30 // #define wxLONGLONG_TEST_MODE
32 #ifdef wxLONGLONG_TEST_MODE
33 #define wxUSE_LONGLONG_WX 1
34 #define wxUSE_LONGLONG_NATIVE 1
35 #endif // wxLONGLONG_TEST_MODE
37 // ----------------------------------------------------------------------------
38 // decide upon which class we will use
39 // ----------------------------------------------------------------------------
42 // both warning and pragma warning are not portable, but at least an
43 // unknown pragma should never be an error -- except that, actually, some
44 // broken compilers don't like it, so we have to disable it in this case
46 #if !(defined(__WATCOMC__) || defined(__VISAGECPP__))
47 #pragma warning "Your compiler does not appear to support 64 bit "\
48 "integers, using emulation class instead.\n" \
49 "Please report your compiler version to " \
50 "wx-dev@lists.wxwidgets.org!"
53 #define wxUSE_LONGLONG_WX 1
56 // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
57 // to disable automatic testing (useful for the test program which defines
58 // both classes) but by default we only use one class
59 #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
60 // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
61 // this is useful in test programs and only there
62 #ifndef wxUSE_LONGLONG_NATIVE
63 #define wxUSE_LONGLONG_NATIVE 0
66 class WXDLLIMPEXP_BASE wxLongLongWx
;
67 class WXDLLIMPEXP_BASE wxULongLongWx
;
68 #if defined(__VISUALC__) && !defined(__WIN32__)
69 #define wxLongLong wxLongLongWx
70 #define wxULongLong wxULongLongWx
72 typedef wxLongLongWx wxLongLong
;
73 typedef wxULongLongWx wxULongLong
;
77 // if nothing is defined, use native implementation by default, of course
78 #ifndef wxUSE_LONGLONG_NATIVE
79 #define wxUSE_LONGLONG_NATIVE 1
83 #ifndef wxUSE_LONGLONG_WX
84 #define wxUSE_LONGLONG_WX 0
85 class WXDLLIMPEXP_BASE wxLongLongNative
;
86 class WXDLLIMPEXP_BASE wxULongLongNative
;
87 typedef wxLongLongNative wxLongLong
;
88 typedef wxULongLongNative wxULongLong
;
91 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
92 // typedef wxLongLong as it wants, we don't do it
94 // ----------------------------------------------------------------------------
95 // choose the appropriate class
96 // ----------------------------------------------------------------------------
98 // we use iostream for wxLongLong output
99 #include "wx/iosfwrap.h"
101 #if wxUSE_LONGLONG_NATIVE
103 class WXDLLIMPEXP_BASE wxLongLongNative
107 // default ctor initializes to 0
108 wxLongLongNative() : m_ll(0) { }
110 wxLongLongNative(wxLongLong_t ll
) : m_ll(ll
) { }
112 wxLongLongNative(long hi
, unsigned long lo
) : m_ll(0)
114 // assign first to avoid precision loss!
115 m_ll
= ((wxLongLong_t
) hi
) << 32;
116 m_ll
|= (wxLongLong_t
) lo
;
118 #if wxUSE_LONGLONG_WX
119 wxLongLongNative(wxLongLongWx ll
);
122 // default copy ctor is ok
126 // assignment operators
127 // from native 64 bit integer
128 wxLongLongNative
& operator=(wxLongLong_t ll
)
129 { m_ll
= ll
; return *this; }
130 #if wxUSE_LONGLONG_WX
131 wxLongLongNative
& operator=(wxLongLongWx ll
);
135 // from double: this one has an explicit name because otherwise we
136 // would have ambiguity with "ll = int" and also because we don't want
137 // to have implicit conversions between doubles and wxLongLongs
138 wxLongLongNative
& Assign(double d
)
139 { m_ll
= (wxLongLong_t
)d
; return *this; }
141 // assignment operators from wxLongLongNative is ok
146 { return (long)(m_ll
>> 32); }
148 unsigned long GetLo() const
149 { return (unsigned long)m_ll
; }
151 // get absolute value
152 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
153 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
155 // convert to native long long
156 wxLongLong_t
GetValue() const { return m_ll
; }
158 // convert to long with range checking in the debug mode (only!)
161 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
162 _T("wxLongLong to long conversion loss of precision") );
167 #if wxABI_VERSION >= 20602
169 double ToDouble() const { return m_ll
; }
170 #endif // ABI >= 2.6.2
172 // don't provide implicit conversion to wxLongLong_t or we will have an
173 // ambiguity for all arithmetic operations
174 //operator wxLongLong_t() const { return m_ll; }
178 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
179 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
180 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
181 { m_ll
+= ll
.m_ll
; return *this; }
183 wxLongLongNative
operator+(const wxLongLong_t ll
) const
184 { return wxLongLongNative(m_ll
+ ll
); }
185 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
186 { m_ll
+= ll
; return *this; }
189 wxLongLongNative
& operator++()
190 { m_ll
++; return *this; }
193 wxLongLongNative
operator++(int)
194 { wxLongLongNative
value(*this); m_ll
++; return value
; }
197 wxLongLongNative
operator-() const
198 { return wxLongLongNative(-m_ll
); }
199 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
202 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
203 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
204 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
205 { m_ll
-= ll
.m_ll
; return *this; }
207 wxLongLongNative
operator-(const wxLongLong_t ll
) const
208 { return wxLongLongNative(m_ll
- ll
); }
209 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
210 { m_ll
-= ll
; return *this; }
213 wxLongLongNative
& operator--()
214 { m_ll
--; return *this; }
217 wxLongLongNative
operator--(int)
218 { wxLongLongNative
value(*this); m_ll
--; return value
; }
222 wxLongLongNative
operator<<(int shift
) const
223 { return wxLongLongNative(m_ll
<< shift
); }
224 wxLongLongNative
& operator<<=(int shift
)
225 { m_ll
<<= shift
; return *this; }
228 wxLongLongNative
operator>>(int shift
) const
229 { return wxLongLongNative(m_ll
>> shift
); }
230 wxLongLongNative
& operator>>=(int shift
)
231 { m_ll
>>= shift
; return *this; }
234 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
235 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
236 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
237 { m_ll
&= ll
.m_ll
; return *this; }
239 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
240 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
241 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
242 { m_ll
|= ll
.m_ll
; return *this; }
244 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
245 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
246 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
247 { m_ll
^= ll
.m_ll
; return *this; }
249 // multiplication/division
250 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
251 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
252 wxLongLongNative
operator*(long l
) const
253 { return wxLongLongNative(m_ll
* l
); }
254 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
255 { m_ll
*= ll
.m_ll
; return *this; }
256 wxLongLongNative
& operator*=(long l
)
257 { m_ll
*= l
; return *this; }
259 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
260 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
261 wxLongLongNative
operator/(long l
) const
262 { return wxLongLongNative(m_ll
/ l
); }
263 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
264 { m_ll
/= ll
.m_ll
; return *this; }
265 wxLongLongNative
& operator/=(long l
)
266 { m_ll
/= l
; return *this; }
268 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
269 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
270 wxLongLongNative
operator%(long l
) const
271 { return wxLongLongNative(m_ll
% l
); }
274 bool operator==(const wxLongLongNative
& ll
) const
275 { return m_ll
== ll
.m_ll
; }
276 bool operator==(long l
) const
277 { return m_ll
== l
; }
278 bool operator!=(const wxLongLongNative
& ll
) const
279 { return m_ll
!= ll
.m_ll
; }
280 bool operator!=(long l
) const
281 { return m_ll
!= l
; }
282 bool operator<(const wxLongLongNative
& ll
) const
283 { return m_ll
< ll
.m_ll
; }
284 bool operator<(long l
) const
286 bool operator>(const wxLongLongNative
& ll
) const
287 { return m_ll
> ll
.m_ll
; }
288 bool operator>(long l
) const
290 bool operator<=(const wxLongLongNative
& ll
) const
291 { return m_ll
<= ll
.m_ll
; }
292 bool operator<=(long l
) const
293 { return m_ll
<= l
; }
294 bool operator>=(const wxLongLongNative
& ll
) const
295 { return m_ll
>= ll
.m_ll
; }
296 bool operator>=(long l
) const
297 { return m_ll
>= l
; }
301 // return the string representation of this number
302 wxString
ToString() const;
304 // conversion to byte array: returns a pointer to static buffer!
305 void *asArray() const;
307 #if wxUSE_STD_IOSTREAM
309 friend WXDLLIMPEXP_BASE
310 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
313 friend WXDLLIMPEXP_BASE
314 wxString
& operator<<(wxString
&, const wxLongLongNative
&);
321 class WXDLLIMPEXP_BASE wxULongLongNative
325 // default ctor initializes to 0
326 wxULongLongNative() : m_ll(0) { }
328 wxULongLongNative(wxULongLong_t ll
) : m_ll(ll
) { }
330 wxULongLongNative(unsigned long hi
, unsigned long lo
) : m_ll(0)
332 // assign first to avoid precision loss!
333 m_ll
= ((wxULongLong_t
) hi
) << 32;
334 m_ll
|= (wxULongLong_t
) lo
;
337 // default copy ctor is ok
341 // assignment operators
342 // from native 64 bit integer
343 wxULongLongNative
& operator=(wxULongLong_t ll
)
344 { m_ll
= ll
; return *this; }
346 // assignment operators from wxULongLongNative is ok
350 unsigned long GetHi() const
351 { return (unsigned long)(m_ll
>> 32); }
353 unsigned long GetLo() const
354 { return (unsigned long)m_ll
; }
356 // convert to native ulong long
357 wxULongLong_t
GetValue() const { return m_ll
; }
359 // convert to ulong with range checking in the debug mode (only!)
360 unsigned long ToULong() const
362 wxASSERT_MSG( m_ll
<= LONG_MAX
,
363 _T("wxULongLong to long conversion loss of precision") );
365 return (unsigned long)m_ll
;
370 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
371 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
372 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
373 { m_ll
+= ll
.m_ll
; return *this; }
375 wxULongLongNative
operator+(const wxULongLong_t ll
) const
376 { return wxULongLongNative(m_ll
+ ll
); }
377 wxULongLongNative
& operator+=(const wxULongLong_t ll
)
378 { m_ll
+= ll
; return *this; }
381 wxULongLongNative
& operator++()
382 { m_ll
++; return *this; }
385 wxULongLongNative
operator++(int)
386 { wxULongLongNative
value(*this); m_ll
++; return value
; }
389 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
390 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
391 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
392 { m_ll
-= ll
.m_ll
; return *this; }
394 wxULongLongNative
operator-(const wxULongLong_t ll
) const
395 { return wxULongLongNative(m_ll
- ll
); }
396 wxULongLongNative
& operator-=(const wxULongLong_t ll
)
397 { m_ll
-= ll
; return *this; }
400 wxULongLongNative
& operator--()
401 { m_ll
--; return *this; }
404 wxULongLongNative
operator--(int)
405 { wxULongLongNative
value(*this); m_ll
--; return value
; }
409 wxULongLongNative
operator<<(int shift
) const
410 { return wxULongLongNative(m_ll
<< shift
); }
411 wxULongLongNative
& operator<<=(int shift
)
412 { m_ll
<<= shift
; return *this; }
415 wxULongLongNative
operator>>(int shift
) const
416 { return wxULongLongNative(m_ll
>> shift
); }
417 wxULongLongNative
& operator>>=(int shift
)
418 { m_ll
>>= shift
; return *this; }
421 wxULongLongNative
operator&(const wxULongLongNative
& ll
) const
422 { return wxULongLongNative(m_ll
& ll
.m_ll
); }
423 wxULongLongNative
& operator&=(const wxULongLongNative
& ll
)
424 { m_ll
&= ll
.m_ll
; return *this; }
426 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
427 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
428 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
429 { m_ll
|= ll
.m_ll
; return *this; }
431 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
432 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
433 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
434 { m_ll
^= ll
.m_ll
; return *this; }
436 // multiplication/division
437 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
438 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
439 wxULongLongNative
operator*(unsigned long l
) const
440 { return wxULongLongNative(m_ll
* l
); }
441 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
442 { m_ll
*= ll
.m_ll
; return *this; }
443 wxULongLongNative
& operator*=(unsigned long l
)
444 { m_ll
*= l
; return *this; }
446 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
447 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
448 wxULongLongNative
operator/(unsigned long l
) const
449 { return wxULongLongNative(m_ll
/ l
); }
450 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
451 { m_ll
/= ll
.m_ll
; return *this; }
452 wxULongLongNative
& operator/=(unsigned long l
)
453 { m_ll
/= l
; return *this; }
455 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
456 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
457 wxULongLongNative
operator%(unsigned long l
) const
458 { return wxULongLongNative(m_ll
% l
); }
461 bool operator==(const wxULongLongNative
& ll
) const
462 { return m_ll
== ll
.m_ll
; }
463 bool operator==(unsigned long l
) const
464 { return m_ll
== l
; }
465 bool operator!=(const wxULongLongNative
& ll
) const
466 { return m_ll
!= ll
.m_ll
; }
467 bool operator!=(unsigned long l
) const
468 { return m_ll
!= l
; }
469 bool operator<(const wxULongLongNative
& ll
) const
470 { return m_ll
< ll
.m_ll
; }
471 bool operator<(unsigned long l
) const
473 bool operator>(const wxULongLongNative
& ll
) const
474 { return m_ll
> ll
.m_ll
; }
475 bool operator>(unsigned long l
) const
477 bool operator<=(const wxULongLongNative
& ll
) const
478 { return m_ll
<= ll
.m_ll
; }
479 bool operator<=(unsigned long l
) const
480 { return m_ll
<= l
; }
481 bool operator>=(const wxULongLongNative
& ll
) const
482 { return m_ll
>= ll
.m_ll
; }
483 bool operator>=(unsigned long l
) const
484 { return m_ll
>= l
; }
488 // return the string representation of this number
489 wxString
ToString() const;
491 // conversion to byte array: returns a pointer to static buffer!
492 void *asArray() const;
494 #if wxUSE_STD_IOSTREAM
496 friend WXDLLIMPEXP_BASE
497 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
500 friend WXDLLIMPEXP_BASE
501 wxString
& operator<<(wxString
&, const wxULongLongNative
&);
507 #endif // wxUSE_LONGLONG_NATIVE
509 #if wxUSE_LONGLONG_WX
511 class WXDLLIMPEXP_BASE wxLongLongWx
515 // default ctor initializes to 0
520 #ifdef wxLONGLONG_TEST_MODE
524 #endif // wxLONGLONG_TEST_MODE
527 wxLongLongWx(long l
) { *this = l
; }
529 wxLongLongWx(long hi
, unsigned long lo
)
534 #ifdef wxLONGLONG_TEST_MODE
540 #endif // wxLONGLONG_TEST_MODE
543 // default copy ctor is ok in both cases
547 // assignment operators
549 wxLongLongWx
& operator=(long l
)
552 m_hi
= (l
< 0 ? -1l : 0l);
554 #ifdef wxLONGLONG_TEST_MODE
558 #endif // wxLONGLONG_TEST_MODE
563 wxLongLongWx
& Assign(double d
);
564 // can't have assignment operator from 2 longs
568 long GetHi() const { return m_hi
; }
570 unsigned long GetLo() const { return m_lo
; }
572 // get absolute value
573 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
579 #ifdef wxLONGLONG_TEST_MODE
584 #endif // wxLONGLONG_TEST_MODE
589 // convert to long with range checking in the debug mode (only!)
592 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
593 _T("wxLongLong to long conversion loss of precision") );
598 #if wxABI_VERSION >= 20602
600 double ToDouble() const;
601 #endif // ABI >= 2.6.2
605 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
606 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
607 wxLongLongWx
operator+(long l
) const;
608 wxLongLongWx
& operator+=(long l
);
610 // pre increment operator
611 wxLongLongWx
& operator++();
613 // post increment operator
614 wxLongLongWx
& operator++(int) { return ++(*this); }
617 wxLongLongWx
operator-() const;
618 wxLongLongWx
& Negate();
621 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
622 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
624 // pre decrement operator
625 wxLongLongWx
& operator--();
627 // post decrement operator
628 wxLongLongWx
& operator--(int) { return --(*this); }
632 wxLongLongWx
operator<<(int shift
) const;
633 wxLongLongWx
& operator<<=(int shift
);
636 wxLongLongWx
operator>>(int shift
) const;
637 wxLongLongWx
& operator>>=(int shift
);
640 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
641 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
642 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
643 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
644 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
645 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
646 wxLongLongWx
operator~() const;
649 bool operator==(const wxLongLongWx
& ll
) const
650 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
651 #if wxUSE_LONGLONG_NATIVE
652 bool operator==(const wxLongLongNative
& ll
) const
653 { return m_lo
== ll
.GetLo() && m_hi
== ll
.GetHi(); }
655 bool operator!=(const wxLongLongWx
& ll
) const
656 { return !(*this == ll
); }
657 bool operator<(const wxLongLongWx
& ll
) const;
658 bool operator>(const wxLongLongWx
& ll
) const;
659 bool operator<=(const wxLongLongWx
& ll
) const
660 { return *this < ll
|| *this == ll
; }
661 bool operator>=(const wxLongLongWx
& ll
) const
662 { return *this > ll
|| *this == ll
; }
664 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
665 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
666 bool operator==(long l
) const
668 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
669 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
672 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
673 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
676 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
677 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
680 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
681 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
683 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
685 void Divide(const wxLongLongWx
& divisor
,
686 wxLongLongWx
& quotient
,
687 wxLongLongWx
& remainder
) const;
691 // return the string representation of this number
692 wxString
ToString() const;
694 void *asArray() const;
696 #if wxUSE_STD_IOSTREAM
697 friend WXDLLIMPEXP_BASE
698 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
699 #endif // wxUSE_STD_IOSTREAM
701 friend WXDLLIMPEXP_BASE
702 wxString
& operator<<(wxString
&, const wxLongLongWx
&);
705 // long is at least 32 bits, so represent our 64bit number as 2 longs
707 long m_hi
; // signed bit is in the high part
710 #ifdef wxLONGLONG_TEST_MODE
713 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
717 #endif // wxLONGLONG_TEST_MODE
721 class WXDLLIMPEXP_BASE wxULongLongWx
725 // default ctor initializes to 0
730 #ifdef wxLONGLONG_TEST_MODE
734 #endif // wxLONGLONG_TEST_MODE
737 wxULongLongWx(unsigned long l
) { *this = l
; }
739 wxULongLongWx(unsigned long hi
, unsigned long lo
)
744 #ifdef wxLONGLONG_TEST_MODE
750 #endif // wxLONGLONG_TEST_MODE
753 // from signed to unsigned
754 wxULongLongWx(wxLongLongWx ll
)
756 wxASSERT(ll
.GetHi() >= 0);
757 m_hi
= (unsigned long)ll
.GetHi();
761 // default copy ctor is ok in both cases
765 // assignment operators
767 wxULongLongWx
& operator=(unsigned long l
)
772 #ifdef wxLONGLONG_TEST_MODE
776 #endif // wxLONGLONG_TEST_MODE
781 // can't have assignment operator from 2 longs
785 unsigned long GetHi() const { return m_hi
; }
787 unsigned long GetLo() const { return m_lo
; }
789 // convert to long with range checking in the debug mode (only!)
790 unsigned long ToULong() const
792 wxASSERT_MSG( m_hi
== 0ul,
793 _T("wxULongLong to long conversion loss of precision") );
795 return (unsigned long)m_lo
;
800 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
801 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
802 wxULongLongWx
operator+(unsigned long l
) const;
803 wxULongLongWx
& operator+=(unsigned long l
);
805 // pre increment operator
806 wxULongLongWx
& operator++();
808 // post increment operator
809 wxULongLongWx
& operator++(int) { return ++(*this); }
812 wxLongLongWx
operator-(const wxULongLongWx
& ll
) const;
813 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
815 // pre decrement operator
816 wxULongLongWx
& operator--();
818 // post decrement operator
819 wxULongLongWx
& operator--(int) { return --(*this); }
823 wxULongLongWx
operator<<(int shift
) const;
824 wxULongLongWx
& operator<<=(int shift
);
827 wxULongLongWx
operator>>(int shift
) const;
828 wxULongLongWx
& operator>>=(int shift
);
831 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
832 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
833 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
834 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
835 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
836 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
837 wxULongLongWx
operator~() const;
840 bool operator==(const wxULongLongWx
& ll
) const
841 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
842 bool operator!=(const wxULongLongWx
& ll
) const
843 { return !(*this == ll
); }
844 bool operator<(const wxULongLongWx
& ll
) const;
845 bool operator>(const wxULongLongWx
& ll
) const;
846 bool operator<=(const wxULongLongWx
& ll
) const
847 { return *this < ll
|| *this == ll
; }
848 bool operator>=(const wxULongLongWx
& ll
) const
849 { return *this > ll
|| *this == ll
; }
851 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
852 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
853 bool operator==(unsigned long l
) const
855 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
858 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
859 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
862 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
863 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
866 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
867 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
869 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
871 void Divide(const wxULongLongWx
& divisor
,
872 wxULongLongWx
& quotient
,
873 wxULongLongWx
& remainder
) const;
877 // return the string representation of this number
878 wxString
ToString() const;
880 void *asArray() const;
882 #if wxUSE_STD_IOSTREAM
883 friend WXDLLIMPEXP_BASE
884 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
885 #endif // wxUSE_STD_IOSTREAM
887 friend WXDLLIMPEXP_BASE
888 wxString
& operator<<(wxString
&, const wxULongLongWx
&);
891 // long is at least 32 bits, so represent our 64bit number as 2 longs
896 #ifdef wxLONGLONG_TEST_MODE
899 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
903 #endif // wxLONGLONG_TEST_MODE
906 #endif // wxUSE_LONGLONG_WX
908 // ----------------------------------------------------------------------------
910 // ----------------------------------------------------------------------------
912 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
913 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
< l
; }
914 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
>= l
; }
915 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
<= l
; }
916 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
917 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
919 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
920 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
922 return wxLongLong(l
) - ll
;
925 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
926 inline bool operator>(unsigned long l
, const wxULongLong
& ull
) { return ull
< l
; }
927 inline bool operator<=(unsigned long l
, const wxULongLong
& ull
) { return ull
>= l
; }
928 inline bool operator>=(unsigned long l
, const wxULongLong
& ull
) { return ull
<= l
; }
929 inline bool operator==(unsigned long l
, const wxULongLong
& ull
) { return ull
== l
; }
930 inline bool operator!=(unsigned long l
, const wxULongLong
& ull
) { return ull
!= l
; }
932 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
934 inline wxLongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
936 wxULongLong ret
= wxULongLong(l
) - ull
;
937 return wxLongLong((long)ret
.GetHi(),ret
.GetLo());
940 #endif // _WX_LONGLONG_H