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.wxwindows.org!"
53 #define wxUSE_LONGLONG_WX 1
56 // this macro allows to definea 64 bit constant in a portable way
57 #define wxMakeLongLong(x, s) x ## s
58 #define wxMakeLongLong2(x, s) wxMakeLongLong(x, s)
59 #define wxLL(x) wxMakeLongLong2(x, wxLongLongSuffix)
61 // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
62 // to disable automatic testing (useful for the test program which defines
63 // both classes) but by default we only use one class
64 #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
65 // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
66 // this is useful in test programs and only there
67 #ifndef wxUSE_LONGLONG_NATIVE
68 #define wxUSE_LONGLONG_NATIVE 0
71 class WXDLLIMPEXP_BASE wxLongLongWx
;
72 class WXDLLIMPEXP_BASE wxULongLongWx
;
73 #if defined(__VISUALC__) && !defined(__WIN32__)
74 #define wxLongLong wxLongLongWx
75 #define wxULongLong wxULongLongWx
77 typedef wxLongLongWx wxLongLong
;
78 typedef wxULongLongWx wxULongLong
;
82 // if nothing is defined, use native implementation by default, of course
83 #ifndef wxUSE_LONGLONG_NATIVE
84 #define wxUSE_LONGLONG_NATIVE 1
88 #ifndef wxUSE_LONGLONG_WX
89 #define wxUSE_LONGLONG_WX 0
90 class WXDLLIMPEXP_BASE wxLongLongNative
;
91 class WXDLLIMPEXP_BASE wxULongLongNative
;
92 typedef wxLongLongNative wxLongLong
;
93 typedef wxULongLongNative wxULongLong
;
96 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
97 // typedef wxLongLong as it wants, we don't do it
99 // ----------------------------------------------------------------------------
100 // choose the appropriate class
101 // ----------------------------------------------------------------------------
103 // we use iostream for wxLongLong output
104 #include "wx/iosfwrap.h"
106 #if wxUSE_LONGLONG_NATIVE
108 class WXDLLIMPEXP_BASE wxLongLongNative
112 // default ctor initializes to 0
113 wxLongLongNative() : m_ll(0) { }
115 wxLongLongNative(wxLongLong_t ll
) : m_ll(ll
) { }
117 wxLongLongNative(long hi
, unsigned long lo
) : m_ll(0)
119 // assign first to avoid precision loss!
120 m_ll
= ((wxLongLong_t
) hi
) << 32;
121 m_ll
|= (wxLongLong_t
) lo
;
124 // default copy ctor is ok
128 // assignment operators
129 // from native 64 bit integer
130 wxLongLongNative
& operator=(wxLongLong_t ll
)
131 { m_ll
= ll
; return *this; }
133 // from double: this one has an explicit name because otherwise we
134 // would have ambiguity with "ll = int" and also because we don't want
135 // to have implicit conversions between doubles and wxLongLongs
136 wxLongLongNative
& Assign(double d
)
137 { m_ll
= (wxLongLong_t
)d
; return *this; }
139 // assignment operators from wxLongLongNative is ok
144 { return (long)(m_ll
>> 32); }
146 unsigned long GetLo() const
147 { return (unsigned long)m_ll
; }
149 // get absolute value
150 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
151 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
153 // convert to native long long
154 wxLongLong_t
GetValue() const { return m_ll
; }
156 // convert to long with range checking in the debug mode (only!)
159 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
160 _T("wxLongLong to long conversion loss of precision") );
165 // don't provide implicit conversion to wxLongLong_t or we will have an
166 // ambiguity for all arithmetic operations
167 //operator wxLongLong_t() const { return m_ll; }
171 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
172 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
173 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
174 { m_ll
+= ll
.m_ll
; return *this; }
176 wxLongLongNative
operator+(const wxLongLong_t ll
) const
177 { return wxLongLongNative(m_ll
+ ll
); }
178 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
179 { m_ll
+= ll
; return *this; }
182 wxLongLongNative
& operator++()
183 { m_ll
++; return *this; }
186 wxLongLongNative
operator++(int)
187 { wxLongLongNative
value(*this); m_ll
++; return value
; }
190 wxLongLongNative
operator-() const
191 { return wxLongLongNative(-m_ll
); }
192 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
195 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
196 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
197 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
198 { m_ll
-= ll
.m_ll
; return *this; }
200 wxLongLongNative
operator-(const wxLongLong_t ll
) const
201 { return wxLongLongNative(m_ll
- ll
); }
202 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
203 { m_ll
-= ll
; return *this; }
206 wxLongLongNative
& operator--()
207 { m_ll
--; return *this; }
210 wxLongLongNative
operator--(int)
211 { wxLongLongNative
value(*this); m_ll
--; return value
; }
215 wxLongLongNative
operator<<(int shift
) const
216 { return wxLongLongNative(m_ll
<< shift
);; }
217 wxLongLongNative
& operator<<=(int shift
)
218 { m_ll
<<= shift
; return *this; }
221 wxLongLongNative
operator>>(int shift
) const
222 { return wxLongLongNative(m_ll
>> shift
);; }
223 wxLongLongNative
& operator>>=(int shift
)
224 { m_ll
>>= shift
; return *this; }
227 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
228 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
229 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
230 { m_ll
&= ll
.m_ll
; return *this; }
232 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
233 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
234 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
235 { m_ll
|= ll
.m_ll
; return *this; }
237 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
238 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
239 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
240 { m_ll
^= ll
.m_ll
; return *this; }
242 // multiplication/division
243 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
244 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
245 wxLongLongNative
operator*(long l
) const
246 { return wxLongLongNative(m_ll
* l
); }
247 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
248 { m_ll
*= ll
.m_ll
; return *this; }
249 wxLongLongNative
& operator*=(long l
)
250 { m_ll
*= l
; return *this; }
252 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
253 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
254 wxLongLongNative
operator/(long l
) const
255 { return wxLongLongNative(m_ll
/ l
); }
256 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
257 { m_ll
/= ll
.m_ll
; return *this; }
258 wxLongLongNative
& operator/=(long l
)
259 { m_ll
/= l
; return *this; }
261 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
262 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
263 wxLongLongNative
operator%(long l
) const
264 { return wxLongLongNative(m_ll
% l
); }
267 bool operator==(const wxLongLongNative
& ll
) const
268 { return m_ll
== ll
.m_ll
; }
269 bool operator==(long l
) const
270 { return m_ll
== l
; }
271 bool operator!=(const wxLongLongNative
& ll
) const
272 { return m_ll
!= ll
.m_ll
; }
273 bool operator!=(long l
) const
274 { return m_ll
!= l
; }
275 bool operator<(const wxLongLongNative
& ll
) const
276 { return m_ll
< ll
.m_ll
; }
277 bool operator<(long l
) const
279 bool operator>(const wxLongLongNative
& ll
) const
280 { return m_ll
> ll
.m_ll
; }
281 bool operator>(long l
) const
283 bool operator<=(const wxLongLongNative
& ll
) const
284 { return m_ll
<= ll
.m_ll
; }
285 bool operator<=(long l
) const
286 { return m_ll
<= l
; }
287 bool operator>=(const wxLongLongNative
& ll
) const
288 { return m_ll
>= ll
.m_ll
; }
289 bool operator>=(long l
) const
290 { return m_ll
>= l
; }
294 // return the string representation of this number
295 wxString
ToString() const;
297 // conversion to byte array: returns a pointer to static buffer!
298 void *asArray() const;
300 #if wxUSE_STD_IOSTREAM
302 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
310 class WXDLLIMPEXP_BASE wxULongLongNative
314 // default ctor initializes to 0
315 wxULongLongNative() : m_ll(0) { }
317 wxULongLongNative(unsigned wxLongLong_t ll
) : m_ll(ll
) { }
319 wxULongLongNative(unsigned long hi
, unsigned long lo
) : m_ll(0)
321 // assign first to avoid precision loss!
322 m_ll
= ((unsigned wxLongLong_t
) hi
) << 32;
323 m_ll
|= (unsigned wxLongLong_t
) lo
;
326 // default copy ctor is ok
330 // assignment operators
331 // from native 64 bit integer
332 wxULongLongNative
& operator=(unsigned wxLongLong_t ll
)
333 { m_ll
= ll
; return *this; }
335 // assignment operators from wxULongLongNative is ok
339 unsigned long GetHi() const
340 { return (unsigned long)(m_ll
>> 32); }
342 unsigned long GetLo() const
343 { return (unsigned long)m_ll
; }
345 // convert to native ulong long
346 unsigned wxLongLong_t
GetValue() const { return m_ll
; }
348 // convert to ulong with range checking in the debug mode (only!)
349 unsigned long ToULong() const
351 wxASSERT_MSG( m_ll
<= LONG_MAX
,
352 _T("wxULongLong to long conversion loss of precision") );
354 return (unsigned long)m_ll
;
359 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
360 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
361 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
362 { m_ll
+= ll
.m_ll
; return *this; }
364 wxULongLongNative
operator+(const unsigned wxLongLong_t ll
) const
365 { return wxULongLongNative(m_ll
+ ll
); }
366 wxULongLongNative
& operator+=(const unsigned wxLongLong_t ll
)
367 { m_ll
+= ll
; return *this; }
370 wxULongLongNative
& operator++()
371 { m_ll
++; return *this; }
374 wxULongLongNative
operator++(int)
375 { wxULongLongNative
value(*this); m_ll
++; return value
; }
378 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
379 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
380 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
381 { m_ll
-= ll
.m_ll
; return *this; }
383 wxULongLongNative
operator-(const unsigned wxLongLong_t ll
) const
384 { return wxULongLongNative(m_ll
- ll
); }
385 wxULongLongNative
& operator-=(const unsigned wxLongLong_t ll
)
386 { m_ll
-= ll
; return *this; }
389 wxULongLongNative
& operator--()
390 { m_ll
--; return *this; }
393 wxULongLongNative
operator--(int)
394 { wxULongLongNative
value(*this); m_ll
--; return value
; }
398 wxULongLongNative
operator<<(int shift
) const
399 { return wxULongLongNative(m_ll
<< shift
);; }
400 wxULongLongNative
& operator<<=(int shift
)
401 { m_ll
<<= shift
; return *this; }
404 wxULongLongNative
operator>>(int shift
) const
405 { return wxULongLongNative(m_ll
>> shift
);; }
406 wxULongLongNative
& operator>>=(int shift
)
407 { m_ll
>>= shift
; return *this; }
410 wxULongLongNative
operator&(const wxULongLongNative
& ll
) const
411 { return wxULongLongNative(m_ll
& ll
.m_ll
); }
412 wxULongLongNative
& operator&=(const wxULongLongNative
& ll
)
413 { m_ll
&= ll
.m_ll
; return *this; }
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; }
420 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
421 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
422 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
423 { m_ll
^= ll
.m_ll
; return *this; }
425 // multiplication/division
426 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
427 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
428 wxULongLongNative
operator*(unsigned long l
) const
429 { return wxULongLongNative(m_ll
* l
); }
430 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
431 { m_ll
*= ll
.m_ll
; return *this; }
432 wxULongLongNative
& operator*=(unsigned long l
)
433 { m_ll
*= l
; return *this; }
435 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
436 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
437 wxULongLongNative
operator/(unsigned long l
) const
438 { return wxULongLongNative(m_ll
/ l
); }
439 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
440 { m_ll
/= ll
.m_ll
; return *this; }
441 wxULongLongNative
& operator/=(unsigned long l
)
442 { m_ll
/= l
; return *this; }
444 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
445 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
446 wxULongLongNative
operator%(unsigned long l
) const
447 { return wxULongLongNative(m_ll
% l
); }
450 bool operator==(const wxULongLongNative
& ll
) const
451 { return m_ll
== ll
.m_ll
; }
452 bool operator==(unsigned long l
) const
453 { return m_ll
== l
; }
454 bool operator!=(const wxULongLongNative
& ll
) const
455 { return m_ll
!= ll
.m_ll
; }
456 bool operator!=(unsigned long l
) const
457 { return m_ll
!= l
; }
458 bool operator<(const wxULongLongNative
& ll
) const
459 { return m_ll
< ll
.m_ll
; }
460 bool operator<(unsigned long l
) const
462 bool operator>(const wxULongLongNative
& ll
) const
463 { return m_ll
> ll
.m_ll
; }
464 bool operator>(unsigned long l
) const
466 bool operator<=(const wxULongLongNative
& ll
) const
467 { return m_ll
<= ll
.m_ll
; }
468 bool operator<=(unsigned long l
) const
469 { return m_ll
<= l
; }
470 bool operator>=(const wxULongLongNative
& ll
) const
471 { return m_ll
>= ll
.m_ll
; }
472 bool operator>=(unsigned long l
) const
473 { return m_ll
>= l
; }
477 // return the string representation of this number
478 wxString
ToString() const;
480 // conversion to byte array: returns a pointer to static buffer!
481 void *asArray() const;
483 #if wxUSE_STD_IOSTREAM
485 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
489 unsigned wxLongLong_t m_ll
;
492 #endif // wxUSE_LONGLONG_NATIVE
494 #if wxUSE_LONGLONG_WX
496 class WXDLLIMPEXP_BASE wxLongLongWx
500 // default ctor initializes to 0
505 #ifdef wxLONGLONG_TEST_MODE
509 #endif // wxLONGLONG_TEST_MODE
512 wxLongLongWx(long l
) { *this = l
; }
514 wxLongLongWx(long hi
, unsigned long lo
)
519 #ifdef wxLONGLONG_TEST_MODE
525 #endif // wxLONGLONG_TEST_MODE
528 // default copy ctor is ok in both cases
532 // assignment operators
534 wxLongLongWx
& operator=(long l
)
537 m_hi
= (l
< 0 ? -1l : 0l);
539 #ifdef wxLONGLONG_TEST_MODE
543 #endif // wxLONGLONG_TEST_MODE
548 wxLongLongWx
& Assign(double d
);
549 // can't have assignment operator from 2 longs
553 long GetHi() const { return m_hi
; }
555 unsigned long GetLo() const { return m_lo
; }
557 // get absolute value
558 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
564 #ifdef wxLONGLONG_TEST_MODE
569 #endif // wxLONGLONG_TEST_MODE
574 // convert to long with range checking in the debug mode (only!)
577 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
578 _T("wxLongLong to long conversion loss of precision") );
585 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
586 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
587 wxLongLongWx
operator+(long l
) const;
588 wxLongLongWx
& operator+=(long l
);
590 // pre increment operator
591 wxLongLongWx
& operator++();
593 // post increment operator
594 wxLongLongWx
& operator++(int) { return ++(*this); }
597 wxLongLongWx
operator-() const;
598 wxLongLongWx
& Negate();
601 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
602 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
604 // pre decrement operator
605 wxLongLongWx
& operator--();
607 // post decrement operator
608 wxLongLongWx
& operator--(int) { return --(*this); }
612 wxLongLongWx
operator<<(int shift
) const;
613 wxLongLongWx
& operator<<=(int shift
);
616 wxLongLongWx
operator>>(int shift
) const;
617 wxLongLongWx
& operator>>=(int shift
);
620 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
621 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
622 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
623 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
624 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
625 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
626 wxLongLongWx
operator~() const;
629 bool operator==(const wxLongLongWx
& ll
) const
630 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
631 bool operator!=(const wxLongLongWx
& ll
) const
632 { return !(*this == ll
); }
633 bool operator<(const wxLongLongWx
& ll
) const;
634 bool operator>(const wxLongLongWx
& ll
) const;
635 bool operator<=(const wxLongLongWx
& ll
) const
636 { return *this < ll
|| *this == ll
; }
637 bool operator>=(const wxLongLongWx
& ll
) const
638 { return *this > ll
|| *this == ll
; }
640 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
641 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
642 bool operator==(long l
) const
644 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
645 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
648 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
649 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
652 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
653 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
656 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
657 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
659 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
661 void Divide(const wxLongLongWx
& divisor
,
662 wxLongLongWx
& quotient
,
663 wxLongLongWx
& remainder
) const;
667 // return the string representation of this number
668 wxString
ToString() const;
670 void *asArray() const;
672 #if wxUSE_STD_IOSTREAM
673 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
674 #endif // wxUSE_STD_IOSTREAM
677 // long is at least 32 bits, so represent our 64bit number as 2 longs
679 long m_hi
; // signed bit is in the high part
682 #ifdef wxLONGLONG_TEST_MODE
685 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
689 #endif // wxLONGLONG_TEST_MODE
693 class WXDLLIMPEXP_BASE wxULongLongWx
697 // default ctor initializes to 0
702 #ifdef wxLONGLONG_TEST_MODE
706 #endif // wxLONGLONG_TEST_MODE
709 wxULongLongWx(unsigned long l
) { *this = l
; }
711 wxULongLongWx(unsigned long hi
, unsigned long lo
)
716 #ifdef wxLONGLONG_TEST_MODE
722 #endif // wxLONGLONG_TEST_MODE
725 // default copy ctor is ok in both cases
729 // assignment operators
731 wxULongLongWx
& operator=(unsigned long l
)
736 #ifdef wxLONGLONG_TEST_MODE
740 #endif // wxLONGLONG_TEST_MODE
745 // can't have assignment operator from 2 longs
749 unsigned long GetHi() const { return m_hi
; }
751 unsigned long GetLo() const { return m_lo
; }
753 // convert to long with range checking in the debug mode (only!)
754 unsigned long ToULong() const
756 wxASSERT_MSG( m_hi
== 0ul,
757 _T("wxULongLong to long conversion loss of precision") );
759 return (unsigned long)m_lo
;
764 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
765 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
766 wxULongLongWx
operator+(unsigned long l
) const;
767 wxULongLongWx
& operator+=(unsigned long l
);
769 // pre increment operator
770 wxULongLongWx
& operator++();
772 // post increment operator
773 wxULongLongWx
& operator++(int) { return ++(*this); }
775 // subraction (FIXME: should return wxLongLong)
776 wxULongLongWx
operator-(const wxULongLongWx
& ll
) const;
777 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
779 // pre decrement operator
780 wxULongLongWx
& operator--();
782 // post decrement operator
783 wxULongLongWx
& operator--(int) { return --(*this); }
787 wxULongLongWx
operator<<(int shift
) const;
788 wxULongLongWx
& operator<<=(int shift
);
791 wxULongLongWx
operator>>(int shift
) const;
792 wxULongLongWx
& operator>>=(int shift
);
795 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
796 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
797 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
798 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
799 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
800 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
801 wxULongLongWx
operator~() const;
804 bool operator==(const wxULongLongWx
& ll
) const
805 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
806 bool operator!=(const wxULongLongWx
& ll
) const
807 { return !(*this == ll
); }
808 bool operator<(const wxULongLongWx
& ll
) const;
809 bool operator>(const wxULongLongWx
& ll
) const;
810 bool operator<=(const wxULongLongWx
& ll
) const
811 { return *this < ll
|| *this == ll
; }
812 bool operator>=(const wxULongLongWx
& ll
) const
813 { return *this > ll
|| *this == ll
; }
815 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
816 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
817 bool operator==(unsigned long l
) const
819 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
822 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
823 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
826 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
827 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
830 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
831 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
833 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
835 void Divide(const wxULongLongWx
& divisor
,
836 wxULongLongWx
& quotient
,
837 wxULongLongWx
& remainder
) const;
841 // return the string representation of this number
842 wxString
ToString() const;
844 void *asArray() const;
846 #if wxUSE_STD_IOSTREAM
847 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
848 #endif // wxUSE_STD_IOSTREAM
851 // long is at least 32 bits, so represent our 64bit number as 2 longs
856 #ifdef wxLONGLONG_TEST_MODE
859 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
862 unsigned wxLongLong_t m_ll
;
863 #endif // wxLONGLONG_TEST_MODE
866 #endif // wxUSE_LONGLONG_WX
868 // ----------------------------------------------------------------------------
870 // ----------------------------------------------------------------------------
872 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
873 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
< l
; }
874 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
>= l
; }
875 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
<= l
; }
876 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
877 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
879 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
880 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
882 return wxLongLong(l
) - ll
;
885 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
886 inline bool operator>(unsigned long l
, const wxULongLong
& ull
) { return ull
< l
; }
887 inline bool operator<=(unsigned long l
, const wxULongLong
& ull
) { return ull
>= l
; }
888 inline bool operator>=(unsigned long l
, const wxULongLong
& ull
) { return ull
<= l
; }
889 inline bool operator==(unsigned long l
, const wxULongLong
& ull
) { return ull
== l
; }
890 inline bool operator!=(unsigned long l
, const wxULongLong
& ull
) { return ull
!= l
; }
892 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
894 // FIXME: this should return wxLongLong
895 inline wxULongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
897 return wxULongLong(l
) - ull
;
900 #endif // _WX_LONGLONG_H