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 license
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_LONGLONG_H
14 #define _WX_LONGLONG_H
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 // ----------------------------------------------------------------------------
41 // to avoid compilation problems on 64bit machines with ambiguous method calls
42 // we will need to define this
43 #undef wxLongLongIsLong
45 // NB: we #define and not typedef wxLongLong_t because we want to be able to
46 // use 'unsigned wxLongLong_t' as well and because we use "#ifdef
47 // wxLongLong_t" below
49 // first check for generic cases which are long on 64bit machine and "long
50 // long", then check for specific compilers
51 #if defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
52 #define wxLongLong_t long
53 #define wxLongLongIsLong
54 #elif (defined(__VISUALC__) && defined(__WIN32__)) || defined( __VMS__ )
55 #define wxLongLong_t __int64
56 #elif defined(__BORLANDC__) && defined(__WIN32__) && (__BORLANDC__ >= 0x520)
57 #define wxLongLong_t __int64
58 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG >= 8
59 #define wxLongLong_t long long
60 #elif defined(__MINGW32__) || defined(__CYGWIN__) || defined(__WXMICROWIN__)
61 #define wxLongLong_t long long
62 #elif defined(__MWERKS__)
63 #if __option(longlong)
64 #define wxLongLong_t long long
66 #error "The 64 bit integer support in CodeWarrior has been disabled."
67 #error "See the documentation on the 'longlong' pragma."
69 #elif defined(__VISAGECPP__) && __IBMCPP__ >= 400
70 #define wxLongLong_t long long
71 #else // no native long long type
72 // both warning and pragma warning are not portable, but at least an
73 // unknown pragma should never be an error - except that, actually, some
74 // broken compilers don't like it, so we have to disable it in this case
76 #if !(defined(__WATCOMC__) || defined(__VISAGECPP__))
77 #pragma warning "Your compiler does not appear to support 64 bit "\
78 "integers, using emulation class instead.\n" \
79 "Please report your compiler version to " \
80 "wx-dev@lists.wxwindows.org!"
83 #define wxUSE_LONGLONG_WX 1
86 // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
87 // to disable automatic testing (useful for the test program which defines
88 // both classes) but by default we only use one class
89 #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
90 // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
91 // this is useful in test programs and only there
92 #ifndef wxUSE_LONGLONG_NATIVE
93 #define wxUSE_LONGLONG_NATIVE 0
96 class WXDLLEXPORT wxLongLongWx
;
97 class WXDLLEXPORT wxULongLongWx
;
98 #if defined(__VISUALC__) && !defined(__WIN32__)
99 #define wxLongLong wxLongLongWx
100 #define wxULongLong wxULongLongWx
102 typedef wxLongLongWx wxLongLong
;
103 typedef wxULongLongWx wxULongLong
;
107 // if nothing is defined, use native implementation by default, of course
108 #ifndef wxUSE_LONGLONG_NATIVE
109 #define wxUSE_LONGLONG_NATIVE 1
113 #ifndef wxUSE_LONGLONG_WX
114 #define wxUSE_LONGLONG_WX 0
115 class WXDLLEXPORT wxLongLongNative
;
116 class WXDLLEXPORT wxULongLongNative
;
117 typedef wxLongLongNative wxLongLong
;
118 typedef wxULongLongNative wxULongLong
;
121 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
122 // typedef wxLongLong as it wants, we don't do it
124 // ----------------------------------------------------------------------------
125 // choose the appropriate class
126 // ----------------------------------------------------------------------------
128 // we use iostream for wxLongLong output
129 #include "wx/ioswrap.h"
131 #if wxUSE_LONGLONG_NATIVE
133 class WXDLLEXPORT wxLongLongNative
137 // default ctor initializes to 0
138 wxLongLongNative() { m_ll
= 0; }
140 wxLongLongNative(wxLongLong_t ll
) { m_ll
= ll
; }
142 wxLongLongNative(long hi
, unsigned long lo
)
144 // assign first to avoid precision loss!
145 m_ll
= ((wxLongLong_t
) hi
) << 32;
146 m_ll
|= (wxLongLong_t
) lo
;
149 // default copy ctor is ok
153 // assignment operators
154 // from native 64 bit integer
155 wxLongLongNative
& operator=(wxLongLong_t ll
)
156 { m_ll
= ll
; return *this; }
158 // from double: this one has an explicit name because otherwise we
159 // would have ambiguity with "ll = int" and also because we don't want
160 // to have implicit conversions between doubles and wxLongLongs
161 wxLongLongNative
& Assign(double d
)
162 { m_ll
= (wxLongLong_t
)d
; return *this; }
164 // assignment operators from wxLongLongNative is ok
169 { return (long)(m_ll
>> 32); }
171 unsigned long GetLo() const
172 { return (unsigned long)m_ll
; }
174 // get absolute value
175 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
176 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
178 // convert to native long long
179 wxLongLong_t
GetValue() const { return m_ll
; }
181 // convert to long with range checking in the debug mode (only!)
184 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
185 _T("wxLongLong to long conversion loss of precision") );
190 // don't provide implicit conversion to wxLongLong_t or we will have an
191 // ambiguity for all arithmetic operations
192 //operator wxLongLong_t() const { return m_ll; }
196 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
197 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
198 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
199 { m_ll
+= ll
.m_ll
; return *this; }
201 wxLongLongNative
operator+(const wxLongLong_t ll
) const
202 { return wxLongLongNative(m_ll
+ ll
); }
203 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
204 { m_ll
+= ll
; return *this; }
207 wxLongLongNative
& operator++()
208 { m_ll
++; return *this; }
211 wxLongLongNative
& operator++(int)
212 { m_ll
++; return *this; }
215 wxLongLongNative
operator-() const
216 { return wxLongLongNative(-m_ll
); }
217 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
220 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
221 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
222 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
223 { m_ll
-= ll
.m_ll
; return *this; }
225 wxLongLongNative
operator-(const wxLongLong_t ll
) const
226 { return wxLongLongNative(m_ll
- ll
); }
227 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
228 { m_ll
-= ll
; return *this; }
231 wxLongLongNative
& operator--()
232 { m_ll
--; return *this; }
235 wxLongLongNative
& operator--(int)
236 { m_ll
--; return *this; }
240 wxLongLongNative
operator<<(int shift
) const
241 { return wxLongLongNative(m_ll
<< shift
);; }
242 wxLongLongNative
& operator<<=(int shift
)
243 { m_ll
<<= shift
; return *this; }
246 wxLongLongNative
operator>>(int shift
) const
247 { return wxLongLongNative(m_ll
>> shift
);; }
248 wxLongLongNative
& operator>>=(int shift
)
249 { m_ll
>>= shift
; return *this; }
252 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
253 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
254 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
255 { m_ll
&= ll
.m_ll
; return *this; }
257 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
258 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
259 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
260 { m_ll
|= ll
.m_ll
; return *this; }
262 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
263 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
264 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
265 { m_ll
^= ll
.m_ll
; return *this; }
267 // multiplication/division
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
); }
272 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
273 { m_ll
*= ll
.m_ll
; return *this; }
274 wxLongLongNative
& operator*=(long l
)
275 { m_ll
*= l
; return *this; }
277 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
278 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
279 wxLongLongNative
operator/(long l
) const
280 { return wxLongLongNative(m_ll
/ l
); }
281 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
282 { m_ll
/= ll
.m_ll
; return *this; }
283 wxLongLongNative
& operator/=(long l
)
284 { m_ll
/= l
; return *this; }
286 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
287 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
288 wxLongLongNative
operator%(long l
) const
289 { return wxLongLongNative(m_ll
% l
); }
292 bool operator==(const wxLongLongNative
& ll
) const
293 { return m_ll
== ll
.m_ll
; }
294 bool operator==(long l
) const
295 { return m_ll
== l
; }
296 bool operator!=(const wxLongLongNative
& ll
) const
297 { return m_ll
!= ll
.m_ll
; }
298 bool operator!=(long l
) const
299 { return m_ll
!= l
; }
300 bool operator<(const wxLongLongNative
& ll
) const
301 { return m_ll
< ll
.m_ll
; }
302 bool operator<(long l
) const
304 bool operator>(const wxLongLongNative
& ll
) const
305 { return m_ll
> ll
.m_ll
; }
306 bool operator>(long l
) const
308 bool operator<=(const wxLongLongNative
& ll
) const
309 { return m_ll
<= ll
.m_ll
; }
310 bool operator<=(long l
) const
311 { return m_ll
<= l
; }
312 bool operator>=(const wxLongLongNative
& ll
) const
313 { return m_ll
>= ll
.m_ll
; }
314 bool operator>=(long l
) const
315 { return m_ll
>= l
; }
319 // return the string representation of this number
320 wxString
ToString() const;
322 // conversion to byte array: returns a pointer to static buffer!
323 void *asArray() const;
325 #if wxUSE_STD_IOSTREAM
327 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
335 class WXDLLEXPORT wxULongLongNative
339 // default ctor initializes to 0
340 wxULongLongNative() { m_ll
= 0; }
342 wxULongLongNative(unsigned wxLongLong_t ll
) { m_ll
= ll
; }
344 wxULongLongNative(unsigned long hi
, unsigned long lo
)
346 // assign first to avoid precision loss!
347 m_ll
= ((unsigned wxLongLong_t
) hi
) << 32;
348 m_ll
|= (unsigned wxLongLong_t
) lo
;
351 // default copy ctor is ok
355 // assignment operators
356 // from native 64 bit integer
357 wxULongLongNative
& operator=(unsigned wxLongLong_t ll
)
358 { m_ll
= ll
; return *this; }
360 // assignment operators from wxULongLongNative is ok
364 unsigned long GetHi() const
365 { return (unsigned long)(m_ll
>> 32); }
367 unsigned long GetLo() const
368 { return (unsigned long)m_ll
; }
370 // convert to native ulong long
371 unsigned wxLongLong_t
GetValue() const { return m_ll
; }
373 // convert to ulong with range checking in the debug mode (only!)
374 unsigned long ToULong() const
376 wxASSERT_MSG( m_ll
<= LONG_MAX
,
377 _T("wxULongLong to long conversion loss of precision") );
379 return (unsigned long)m_ll
;
384 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
385 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
386 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
387 { m_ll
+= ll
.m_ll
; return *this; }
389 wxULongLongNative
operator+(const unsigned wxLongLong_t ll
) const
390 { return wxULongLongNative(m_ll
+ ll
); }
391 wxULongLongNative
& operator+=(const unsigned wxLongLong_t ll
)
392 { m_ll
+= ll
; return *this; }
395 wxULongLongNative
& operator++()
396 { m_ll
++; return *this; }
399 wxULongLongNative
& operator++(int)
400 { m_ll
++; return *this; }
403 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
404 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
405 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
406 { m_ll
-= ll
.m_ll
; return *this; }
408 wxULongLongNative
operator-(const unsigned wxLongLong_t ll
) const
409 { return wxULongLongNative(m_ll
- ll
); }
410 wxULongLongNative
& operator-=(const unsigned wxLongLong_t ll
)
411 { m_ll
-= ll
; return *this; }
414 wxULongLongNative
& operator--()
415 { m_ll
--; return *this; }
418 wxULongLongNative
& operator--(int)
419 { m_ll
--; return *this; }
423 wxULongLongNative
operator<<(int shift
) const
424 { return wxULongLongNative(m_ll
<< shift
);; }
425 wxULongLongNative
& operator<<=(int shift
)
426 { m_ll
<<= shift
; return *this; }
429 wxULongLongNative
operator>>(int shift
) const
430 { return wxULongLongNative(m_ll
>> shift
);; }
431 wxULongLongNative
& operator>>=(int shift
)
432 { m_ll
>>= shift
; return *this; }
435 wxULongLongNative
operator&(const wxULongLongNative
& ll
) const
436 { return wxULongLongNative(m_ll
& ll
.m_ll
); }
437 wxULongLongNative
& operator&=(const wxULongLongNative
& ll
)
438 { m_ll
&= ll
.m_ll
; return *this; }
440 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
441 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
442 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
443 { m_ll
|= ll
.m_ll
; return *this; }
445 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
446 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
447 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
448 { m_ll
^= ll
.m_ll
; return *this; }
450 // multiplication/division
451 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
452 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
453 wxULongLongNative
operator*(unsigned long l
) const
454 { return wxULongLongNative(m_ll
* l
); }
455 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
456 { m_ll
*= ll
.m_ll
; return *this; }
457 wxULongLongNative
& operator*=(unsigned long l
)
458 { m_ll
*= l
; return *this; }
460 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
461 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
462 wxULongLongNative
operator/(unsigned long l
) const
463 { return wxULongLongNative(m_ll
/ l
); }
464 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
465 { m_ll
/= ll
.m_ll
; return *this; }
466 wxULongLongNative
& operator/=(unsigned long l
)
467 { m_ll
/= l
; return *this; }
469 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
470 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
471 wxULongLongNative
operator%(unsigned long l
) const
472 { return wxULongLongNative(m_ll
% l
); }
475 bool operator==(const wxULongLongNative
& ll
) const
476 { return m_ll
== ll
.m_ll
; }
477 bool operator==(unsigned long l
) const
478 { return m_ll
== l
; }
479 bool operator!=(const wxULongLongNative
& ll
) const
480 { return m_ll
!= ll
.m_ll
; }
481 bool operator!=(unsigned long l
) const
482 { return m_ll
!= l
; }
483 bool operator<(const wxULongLongNative
& ll
) const
484 { return m_ll
< ll
.m_ll
; }
485 bool operator<(unsigned long l
) const
487 bool operator>(const wxULongLongNative
& ll
) const
488 { return m_ll
> ll
.m_ll
; }
489 bool operator>(unsigned long l
) const
491 bool operator<=(const wxULongLongNative
& ll
) const
492 { return m_ll
<= ll
.m_ll
; }
493 bool operator<=(unsigned long l
) const
494 { return m_ll
<= l
; }
495 bool operator>=(const wxULongLongNative
& ll
) const
496 { return m_ll
>= ll
.m_ll
; }
497 bool operator>=(unsigned long l
) const
498 { return m_ll
>= l
; }
502 // return the string representation of this number
503 wxString
ToString() const;
505 // conversion to byte array: returns a pointer to static buffer!
506 void *asArray() const;
508 #if wxUSE_STD_IOSTREAM
510 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
514 unsigned wxLongLong_t m_ll
;
517 #endif // wxUSE_LONGLONG_NATIVE
519 #if wxUSE_LONGLONG_WX
521 class WXDLLEXPORT wxLongLongWx
525 // default ctor initializes to 0
530 #ifdef wxLONGLONG_TEST_MODE
534 #endif // wxLONGLONG_TEST_MODE
537 wxLongLongWx(long l
) { *this = l
; }
539 wxLongLongWx(long hi
, unsigned long lo
)
544 #ifdef wxLONGLONG_TEST_MODE
550 #endif // wxLONGLONG_TEST_MODE
553 // default copy ctor is ok in both cases
557 // assignment operators
559 wxLongLongWx
& operator=(long l
)
562 m_hi
= (l
< 0 ? -1l : 0l);
564 #ifdef wxLONGLONG_TEST_MODE
568 #endif // wxLONGLONG_TEST_MODE
573 wxLongLongWx
& Assign(double d
);
574 // can't have assignment operator from 2 longs
578 long GetHi() const { return m_hi
; }
580 unsigned long GetLo() const { return m_lo
; }
582 // get absolute value
583 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
589 #ifdef wxLONGLONG_TEST_MODE
594 #endif // wxLONGLONG_TEST_MODE
599 // convert to long with range checking in the debug mode (only!)
602 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
603 _T("wxLongLong to long conversion loss of precision") );
610 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
611 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
612 wxLongLongWx
operator+(long l
) const;
613 wxLongLongWx
& operator+=(long l
);
615 // pre increment operator
616 wxLongLongWx
& operator++();
618 // post increment operator
619 wxLongLongWx
& operator++(int) { return ++(*this); }
622 wxLongLongWx
operator-() const;
623 wxLongLongWx
& Negate();
626 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
627 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
629 // pre decrement operator
630 wxLongLongWx
& operator--();
632 // post decrement operator
633 wxLongLongWx
& operator--(int) { return --(*this); }
637 wxLongLongWx
operator<<(int shift
) const;
638 wxLongLongWx
& operator<<=(int shift
);
641 wxLongLongWx
operator>>(int shift
) const;
642 wxLongLongWx
& operator>>=(int shift
);
645 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
646 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
647 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
648 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
649 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
650 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
651 wxLongLongWx
operator~() const;
654 bool operator==(const wxLongLongWx
& ll
) const
655 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
656 bool operator!=(const wxLongLongWx
& ll
) const
657 { return !(*this == ll
); }
658 bool operator<(const wxLongLongWx
& ll
) const;
659 bool operator>(const wxLongLongWx
& ll
) const;
660 bool operator<=(const wxLongLongWx
& ll
) const
661 { return *this < ll
|| *this == ll
; }
662 bool operator>=(const wxLongLongWx
& ll
) const
663 { return *this > ll
|| *this == ll
; }
665 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
666 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
667 bool operator==(long l
) const
669 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
670 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
673 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
674 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
677 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
678 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
681 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
682 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
684 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
686 void Divide(const wxLongLongWx
& divisor
,
687 wxLongLongWx
& quotient
,
688 wxLongLongWx
& remainder
) const;
692 // return the string representation of this number
693 wxString
ToString() const;
695 void *asArray() const;
697 #if wxUSE_STD_IOSTREAM
698 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
699 #endif // wxUSE_STD_IOSTREAM
702 // long is at least 32 bits, so represent our 64bit number as 2 longs
704 long m_hi
; // signed bit is in the high part
707 #ifdef wxLONGLONG_TEST_MODE
710 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
714 #endif // wxLONGLONG_TEST_MODE
718 class WXDLLEXPORT wxULongLongWx
722 // default ctor initializes to 0
727 #ifdef wxLONGLONG_TEST_MODE
731 #endif // wxLONGLONG_TEST_MODE
734 wxULongLongWx(unsigned long l
) { *this = l
; }
736 wxULongLongWx(unsigned long hi
, unsigned long lo
)
741 #ifdef wxLONGLONG_TEST_MODE
747 #endif // wxLONGLONG_TEST_MODE
750 // default copy ctor is ok in both cases
754 // assignment operators
756 wxULongLongWx
& operator=(unsigned long l
)
761 #ifdef wxLONGLONG_TEST_MODE
765 #endif // wxLONGLONG_TEST_MODE
770 // can't have assignment operator from 2 longs
774 unsigned long GetHi() const { return m_hi
; }
776 unsigned long GetLo() const { return m_lo
; }
778 // convert to long with range checking in the debug mode (only!)
779 unsigned long ToULong() const
781 wxASSERT_MSG( m_hi
== 0ul,
782 _T("wxULongLong to long conversion loss of precision") );
784 return (unsigned long)m_lo
;
789 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
790 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
791 wxULongLongWx
operator+(unsigned long l
) const;
792 wxULongLongWx
& operator+=(unsigned long l
);
794 // pre increment operator
795 wxULongLongWx
& operator++();
797 // post increment operator
798 wxULongLongWx
& operator++(int) { return ++(*this); }
800 // subraction (FIXME: should return wxLongLong)
801 wxULongLongWx
operator-(const wxULongLongWx
& ll
) const;
802 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
804 // pre decrement operator
805 wxULongLongWx
& operator--();
807 // post decrement operator
808 wxULongLongWx
& operator--(int) { return --(*this); }
812 wxULongLongWx
operator<<(int shift
) const;
813 wxULongLongWx
& operator<<=(int shift
);
816 wxULongLongWx
operator>>(int shift
) const;
817 wxULongLongWx
& operator>>=(int shift
);
820 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
821 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
822 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
823 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
824 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
825 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
826 wxULongLongWx
operator~() const;
829 bool operator==(const wxULongLongWx
& ll
) const
830 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
831 bool operator!=(const wxULongLongWx
& ll
) const
832 { return !(*this == ll
); }
833 bool operator<(const wxULongLongWx
& ll
) const;
834 bool operator>(const wxULongLongWx
& ll
) const;
835 bool operator<=(const wxULongLongWx
& ll
) const
836 { return *this < ll
|| *this == ll
; }
837 bool operator>=(const wxULongLongWx
& ll
) const
838 { return *this > ll
|| *this == ll
; }
840 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
841 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
842 bool operator==(unsigned long l
) const
844 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
847 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
848 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
851 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
852 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
855 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
856 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
858 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
860 void Divide(const wxULongLongWx
& divisor
,
861 wxULongLongWx
& quotient
,
862 wxULongLongWx
& remainder
) const;
866 // return the string representation of this number
867 wxString
ToString() const;
869 void *asArray() const;
871 #if wxUSE_STD_IOSTREAM
872 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
873 #endif // wxUSE_STD_IOSTREAM
876 // long is at least 32 bits, so represent our 64bit number as 2 longs
881 #ifdef wxLONGLONG_TEST_MODE
884 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
887 unsigned wxLongLong_t m_ll
;
888 #endif // wxLONGLONG_TEST_MODE
891 #endif // wxUSE_LONGLONG_WX
893 // ----------------------------------------------------------------------------
895 // ----------------------------------------------------------------------------
897 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
898 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
< l
; }
899 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
>= l
; }
900 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
<= l
; }
901 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
902 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
904 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
905 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
907 return wxLongLong(l
) - ll
;
910 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
911 inline bool operator>(unsigned long l
, const wxULongLong
& ull
) { return ull
< l
; }
912 inline bool operator<=(unsigned long l
, const wxULongLong
& ull
) { return ull
>= l
; }
913 inline bool operator>=(unsigned long l
, const wxULongLong
& ull
) { return ull
<= l
; }
914 inline bool operator==(unsigned long l
, const wxULongLong
& ull
) { return ull
== l
; }
915 inline bool operator!=(unsigned long l
, const wxULongLong
& ull
) { return ull
!= l
; }
917 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
919 // FIXME: this should return wxLongLong
920 inline wxULongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
922 return wxULongLong(l
) - ull
;
925 #endif // _WX_LONGLONG_H