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 #if defined(__VISUALC__) && !defined(__WIN32__)
98 #define wxLongLong wxLongLongWx
99 #define wxULongLong wxULongLongWx
101 typedef wxLongLongWx wxLongLong
;
102 typedef wxULongLongWx wxULongLong
;
106 // if nothing is defined, use native implementation by default, of course
107 #ifndef wxUSE_LONGLONG_NATIVE
108 #define wxUSE_LONGLONG_NATIVE 1
112 #ifndef wxUSE_LONGLONG_WX
113 #define wxUSE_LONGLONG_WX 0
114 class WXDLLEXPORT wxLongLongNative
;
115 class WXDLLEXPORT wxULongLongNative
;
116 typedef wxLongLongNative wxLongLong
;
117 typedef wxULongLongNative wxULongLong
;
120 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
121 // typedef wxLongLong as it wants, we don't do it
123 // ----------------------------------------------------------------------------
124 // choose the appropriate class
125 // ----------------------------------------------------------------------------
127 // we use iostream for wxLongLong output
128 #include "wx/ioswrap.h"
130 #if wxUSE_LONGLONG_NATIVE
132 class WXDLLEXPORT wxLongLongNative
136 // default ctor initializes to 0
137 wxLongLongNative() { m_ll
= 0; }
139 wxLongLongNative(wxLongLong_t ll
) { m_ll
= ll
; }
141 wxLongLongNative(long hi
, unsigned long lo
)
143 // assign first to avoid precision loss!
144 m_ll
= ((wxLongLong_t
) hi
) << 32;
145 m_ll
|= (wxLongLong_t
) lo
;
148 // default copy ctor is ok
152 // assignment operators
153 // from native 64 bit integer
154 wxLongLongNative
& operator=(wxLongLong_t ll
)
155 { m_ll
= ll
; return *this; }
157 // from double: this one has an explicit name because otherwise we
158 // would have ambiguity with "ll = int" and also because we don't want
159 // to have implicit conversions between doubles and wxLongLongs
160 wxLongLongNative
& Assign(double d
)
161 { m_ll
= (wxLongLong_t
)d
; return *this; }
163 // assignment operators from wxLongLongNative is ok
168 { return (long)(m_ll
>> 32); }
170 unsigned long GetLo() const
171 { return (unsigned long)m_ll
; }
173 // get absolute value
174 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
175 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
177 // convert to native long long
178 wxLongLong_t
GetValue() const { return m_ll
; }
180 // convert to long with range checking in the debug mode (only!)
183 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
184 _T("wxLongLong to long conversion loss of precision") );
189 // don't provide implicit conversion to wxLongLong_t or we will have an
190 // ambiguity for all arithmetic operations
191 //operator wxLongLong_t() const { return m_ll; }
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 { m_ll
++; return *this; }
214 wxLongLongNative
operator-() const
215 { return wxLongLongNative(-m_ll
); }
216 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
219 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
220 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
221 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
222 { m_ll
-= ll
.m_ll
; return *this; }
224 wxLongLongNative
operator-(const wxLongLong_t ll
) const
225 { return wxLongLongNative(m_ll
- ll
); }
226 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
227 { m_ll
-= ll
; return *this; }
230 wxLongLongNative
& operator--()
231 { m_ll
--; return *this; }
234 wxLongLongNative
& operator--(int)
235 { m_ll
--; return *this; }
239 wxLongLongNative
operator<<(int shift
) const
240 { return wxLongLongNative(m_ll
<< shift
);; }
241 wxLongLongNative
& operator<<=(int shift
)
242 { m_ll
<<= shift
; return *this; }
245 wxLongLongNative
operator>>(int shift
) const
246 { return wxLongLongNative(m_ll
>> shift
);; }
247 wxLongLongNative
& operator>>=(int shift
)
248 { m_ll
>>= shift
; return *this; }
251 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
252 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
253 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
254 { m_ll
&= ll
.m_ll
; return *this; }
256 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
257 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
258 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
259 { m_ll
|= ll
.m_ll
; return *this; }
261 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
262 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
263 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
264 { m_ll
^= ll
.m_ll
; return *this; }
266 // multiplication/division
267 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
268 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
269 wxLongLongNative
operator*(long l
) const
270 { return wxLongLongNative(m_ll
* l
); }
271 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
272 { m_ll
*= ll
.m_ll
; return *this; }
273 wxLongLongNative
& operator*=(long l
)
274 { m_ll
*= l
; return *this; }
276 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
277 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
278 wxLongLongNative
operator/(long l
) const
279 { return wxLongLongNative(m_ll
/ l
); }
280 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
281 { m_ll
/= ll
.m_ll
; return *this; }
282 wxLongLongNative
& operator/=(long l
)
283 { m_ll
/= l
; return *this; }
285 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
286 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
287 wxLongLongNative
operator%(long l
) const
288 { return wxLongLongNative(m_ll
% l
); }
291 bool operator==(const wxLongLongNative
& ll
) const
292 { return m_ll
== ll
.m_ll
; }
293 bool operator==(long l
) const
294 { return m_ll
== l
; }
295 bool operator!=(const wxLongLongNative
& ll
) const
296 { return m_ll
!= ll
.m_ll
; }
297 bool operator!=(long l
) const
298 { return m_ll
!= l
; }
299 bool operator<(const wxLongLongNative
& ll
) const
300 { return m_ll
< ll
.m_ll
; }
301 bool operator<(long l
) const
303 bool operator>(const wxLongLongNative
& ll
) const
304 { return m_ll
> ll
.m_ll
; }
305 bool operator>(long l
) const
307 bool operator<=(const wxLongLongNative
& ll
) const
308 { return m_ll
<= ll
.m_ll
; }
309 bool operator<=(long l
) const
310 { return m_ll
<= l
; }
311 bool operator>=(const wxLongLongNative
& ll
) const
312 { return m_ll
>= ll
.m_ll
; }
313 bool operator>=(long l
) const
314 { return m_ll
>= l
; }
318 // return the string representation of this number
319 wxString
ToString() const;
321 // conversion to byte array: returns a pointer to static buffer!
322 void *asArray() const;
324 #if wxUSE_STD_IOSTREAM
326 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
334 class WXDLLEXPORT wxULongLongNative
338 // default ctor initializes to 0
339 wxULongLongNative() { m_ll
= 0; }
341 wxULongLongNative(unsigned wxLongLong_t ll
) { m_ll
= ll
; }
343 wxULongLongNative(unsigned long hi
, unsigned long lo
)
345 // assign first to avoid precision loss!
346 m_ll
= ((unsigned wxLongLong_t
) hi
) << 32;
347 m_ll
|= (unsigned wxLongLong_t
) lo
;
350 // default copy ctor is ok
354 // assignment operators
355 // from native 64 bit integer
356 wxULongLongNative
& operator=(unsigned wxLongLong_t ll
)
357 { m_ll
= ll
; return *this; }
359 // assignment operators from wxULongLongNative is ok
363 unsigned long GetHi() const
364 { return (unsigned long)(m_ll
>> 32); }
366 unsigned long GetLo() const
367 { return (unsigned long)m_ll
; }
369 // convert to native ulong long
370 unsigned wxLongLong_t
GetValue() const { return m_ll
; }
372 // convert to ulong with range checking in the debug mode (only!)
373 unsigned long ToULong() const
375 wxASSERT_MSG( m_ll
<= LONG_MAX
,
376 _T("wxULongLong to long conversion loss of precision") );
378 return (unsigned long)m_ll
;
383 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
384 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
385 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
386 { m_ll
+= ll
.m_ll
; return *this; }
388 wxULongLongNative
operator+(const unsigned wxLongLong_t ll
) const
389 { return wxULongLongNative(m_ll
+ ll
); }
390 wxULongLongNative
& operator+=(const unsigned wxLongLong_t ll
)
391 { m_ll
+= ll
; return *this; }
394 wxULongLongNative
& operator++()
395 { m_ll
++; return *this; }
398 wxULongLongNative
& operator++(int)
399 { m_ll
++; return *this; }
402 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
403 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
404 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
405 { m_ll
-= ll
.m_ll
; return *this; }
407 wxULongLongNative
operator-(const unsigned wxLongLong_t ll
) const
408 { return wxULongLongNative(m_ll
- ll
); }
409 wxULongLongNative
& operator-=(const unsigned wxLongLong_t ll
)
410 { m_ll
-= ll
; return *this; }
413 wxULongLongNative
& operator--()
414 { m_ll
--; return *this; }
417 wxULongLongNative
& operator--(int)
418 { m_ll
--; return *this; }
422 wxULongLongNative
operator<<(int shift
) const
423 { return wxULongLongNative(m_ll
<< shift
);; }
424 wxULongLongNative
& operator<<=(int shift
)
425 { m_ll
<<= shift
; return *this; }
428 wxULongLongNative
operator>>(int shift
) const
429 { return wxULongLongNative(m_ll
>> shift
);; }
430 wxULongLongNative
& operator>>=(int shift
)
431 { m_ll
>>= shift
; return *this; }
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; }
439 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
440 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
441 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
442 { m_ll
|= ll
.m_ll
; return *this; }
444 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
445 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
446 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
447 { m_ll
^= ll
.m_ll
; return *this; }
449 // multiplication/division
450 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
451 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
452 wxULongLongNative
operator*(unsigned long l
) const
453 { return wxULongLongNative(m_ll
* l
); }
454 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
455 { m_ll
*= ll
.m_ll
; return *this; }
456 wxULongLongNative
& operator*=(unsigned long l
)
457 { m_ll
*= l
; return *this; }
459 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
460 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
461 wxULongLongNative
operator/(unsigned long l
) const
462 { return wxULongLongNative(m_ll
/ l
); }
463 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
464 { m_ll
/= ll
.m_ll
; return *this; }
465 wxULongLongNative
& operator/=(unsigned long l
)
466 { m_ll
/= l
; return *this; }
468 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
469 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
470 wxULongLongNative
operator%(unsigned long l
) const
471 { return wxULongLongNative(m_ll
% l
); }
474 bool operator==(const wxULongLongNative
& ll
) const
475 { return m_ll
== ll
.m_ll
; }
476 bool operator==(unsigned long l
) const
477 { return m_ll
== l
; }
478 bool operator!=(const wxULongLongNative
& ll
) const
479 { return m_ll
!= ll
.m_ll
; }
480 bool operator!=(unsigned long l
) const
481 { return m_ll
!= l
; }
482 bool operator<(const wxULongLongNative
& ll
) const
483 { return m_ll
< ll
.m_ll
; }
484 bool operator<(unsigned long l
) const
486 bool operator>(const wxULongLongNative
& ll
) const
487 { return m_ll
> ll
.m_ll
; }
488 bool operator>(unsigned long l
) const
490 bool operator<=(const wxULongLongNative
& ll
) const
491 { return m_ll
<= ll
.m_ll
; }
492 bool operator<=(unsigned long l
) const
493 { return m_ll
<= l
; }
494 bool operator>=(const wxULongLongNative
& ll
) const
495 { return m_ll
>= ll
.m_ll
; }
496 bool operator>=(unsigned long l
) const
497 { return m_ll
>= l
; }
501 // return the string representation of this number
502 wxString
ToString() const;
504 // conversion to byte array: returns a pointer to static buffer!
505 void *asArray() const;
507 #if wxUSE_STD_IOSTREAM
509 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
513 unsigned wxLongLong_t m_ll
;
516 #endif // wxUSE_LONGLONG_NATIVE
518 #if wxUSE_LONGLONG_WX
520 class WXDLLEXPORT wxLongLongWx
524 // default ctor initializes to 0
529 #ifdef wxLONGLONG_TEST_MODE
533 #endif // wxLONGLONG_TEST_MODE
536 wxLongLongWx(long l
) { *this = l
; }
538 wxLongLongWx(long hi
, unsigned long lo
)
543 #ifdef wxLONGLONG_TEST_MODE
549 #endif // wxLONGLONG_TEST_MODE
552 // default copy ctor is ok in both cases
556 // assignment operators
558 wxLongLongWx
& operator=(long l
)
561 m_hi
= (l
< 0 ? -1l : 0l);
563 #ifdef wxLONGLONG_TEST_MODE
567 #endif // wxLONGLONG_TEST_MODE
572 wxLongLongWx
& Assign(double d
);
573 // can't have assignment operator from 2 longs
577 long GetHi() const { return m_hi
; }
579 unsigned long GetLo() const { return m_lo
; }
581 // get absolute value
582 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
588 #ifdef wxLONGLONG_TEST_MODE
593 #endif // wxLONGLONG_TEST_MODE
598 // convert to long with range checking in the debug mode (only!)
601 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
602 _T("wxLongLong to long conversion loss of precision") );
609 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
610 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
611 wxLongLongWx
operator+(long l
) const;
612 wxLongLongWx
& operator+=(long l
);
614 // pre increment operator
615 wxLongLongWx
& operator++();
617 // post increment operator
618 wxLongLongWx
& operator++(int) { return ++(*this); }
621 wxLongLongWx
operator-() const;
622 wxLongLongWx
& Negate();
625 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
626 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
628 // pre decrement operator
629 wxLongLongWx
& operator--();
631 // post decrement operator
632 wxLongLongWx
& operator--(int) { return --(*this); }
636 wxLongLongWx
operator<<(int shift
) const;
637 wxLongLongWx
& operator<<=(int shift
);
640 wxLongLongWx
operator>>(int shift
) const;
641 wxLongLongWx
& operator>>=(int shift
);
644 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
645 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
646 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
647 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
648 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
649 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
650 wxLongLongWx
operator~() const;
653 bool operator==(const wxLongLongWx
& ll
) const
654 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
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 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
698 #endif // wxUSE_STD_IOSTREAM
701 // long is at least 32 bits, so represent our 64bit number as 2 longs
703 long m_hi
; // signed bit is in the high part
706 #ifdef wxLONGLONG_TEST_MODE
709 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
713 #endif // wxLONGLONG_TEST_MODE
717 class WXDLLEXPORT wxULongLongWx
721 // default ctor initializes to 0
726 #ifdef wxLONGLONG_TEST_MODE
730 #endif // wxLONGLONG_TEST_MODE
733 wxULongLongWx(unsigned long l
) { *this = l
; }
735 wxULongLongWx(unsigned long hi
, unsigned long lo
)
740 #ifdef wxLONGLONG_TEST_MODE
746 #endif // wxLONGLONG_TEST_MODE
749 // default copy ctor is ok in both cases
753 // assignment operators
755 wxULongLongWx
& operator=(unsigned long l
)
760 #ifdef wxLONGLONG_TEST_MODE
764 #endif // wxLONGLONG_TEST_MODE
769 // can't have assignment operator from 2 longs
773 unsigned long GetHi() const { return m_hi
; }
775 unsigned long GetLo() const { return m_lo
; }
777 // convert to long with range checking in the debug mode (only!)
778 unsigned long ToULong() const
780 wxASSERT_MSG( m_hi
== 0ul,
781 _T("wxULongLong to long conversion loss of precision") );
783 return (unsigned long)m_lo
;
788 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
789 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
790 wxULongLongWx
operator+(unsigned long l
) const;
791 wxULongLongWx
& operator+=(unsigned long l
);
793 // pre increment operator
794 wxULongLongWx
& operator++();
796 // post increment operator
797 wxULongLongWx
& operator++(int) { return ++(*this); }
799 // subraction (FIXME: should return wxLongLong)
800 wxULongLongWx
operator-(const wxULongLongWx
& ll
) const;
801 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
803 // pre decrement operator
804 wxULongLongWx
& operator--();
806 // post decrement operator
807 wxULongLongWx
& operator--(int) { return --(*this); }
811 wxULongLongWx
operator<<(int shift
) const;
812 wxULongLongWx
& operator<<=(int shift
);
815 wxULongLongWx
operator>>(int shift
) const;
816 wxULongLongWx
& operator>>=(int shift
);
819 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
820 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
821 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
822 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
823 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
824 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
825 wxULongLongWx
operator~() const;
828 bool operator==(const wxULongLongWx
& ll
) const
829 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
830 bool operator!=(const wxULongLongWx
& ll
) const
831 { return !(*this == ll
); }
832 bool operator<(const wxULongLongWx
& ll
) const;
833 bool operator>(const wxULongLongWx
& ll
) const;
834 bool operator<=(const wxULongLongWx
& ll
) const
835 { return *this < ll
|| *this == ll
; }
836 bool operator>=(const wxULongLongWx
& ll
) const
837 { return *this > ll
|| *this == ll
; }
839 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
840 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
841 bool operator==(unsigned long l
) const
843 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
846 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
847 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
850 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
851 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
854 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
855 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
857 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
859 void Divide(const wxULongLongWx
& divisor
,
860 wxULongLongWx
& quotient
,
861 wxULongLongWx
& remainder
) const;
865 // return the string representation of this number
866 wxString
ToString() const;
868 void *asArray() const;
870 #if wxUSE_STD_IOSTREAM
871 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
872 #endif // wxUSE_STD_IOSTREAM
875 // long is at least 32 bits, so represent our 64bit number as 2 longs
880 #ifdef wxLONGLONG_TEST_MODE
883 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
886 unsigned wxLongLong_t m_ll
;
887 #endif // wxLONGLONG_TEST_MODE
890 #endif // wxUSE_LONGLONG_WX
892 // ----------------------------------------------------------------------------
894 // ----------------------------------------------------------------------------
896 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
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
; }
903 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
904 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
906 return wxLongLong(l
) - ll
;
909 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
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
; }
916 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
918 // FIXME: this should return wxLongLong
919 inline wxULongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
921 return wxULongLong(l
) - ull
;
924 #endif // _WX_LONGLONG_H