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 // don't provide implicit conversion to wxLongLong_t or we will have an
168 // ambiguity for all arithmetic operations
169 //operator wxLongLong_t() const { return m_ll; }
173 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
174 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
175 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
176 { m_ll
+= ll
.m_ll
; return *this; }
178 wxLongLongNative
operator+(const wxLongLong_t ll
) const
179 { return wxLongLongNative(m_ll
+ ll
); }
180 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
181 { m_ll
+= ll
; return *this; }
184 wxLongLongNative
& operator++()
185 { m_ll
++; return *this; }
188 wxLongLongNative
operator++(int)
189 { wxLongLongNative
value(*this); m_ll
++; return value
; }
192 wxLongLongNative
operator-() const
193 { return wxLongLongNative(-m_ll
); }
194 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
197 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
198 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
199 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
200 { m_ll
-= ll
.m_ll
; return *this; }
202 wxLongLongNative
operator-(const wxLongLong_t ll
) const
203 { return wxLongLongNative(m_ll
- ll
); }
204 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
205 { m_ll
-= ll
; return *this; }
208 wxLongLongNative
& operator--()
209 { m_ll
--; return *this; }
212 wxLongLongNative
operator--(int)
213 { wxLongLongNative
value(*this); m_ll
--; return value
; }
217 wxLongLongNative
operator<<(int shift
) const
218 { return wxLongLongNative(m_ll
<< shift
);; }
219 wxLongLongNative
& operator<<=(int shift
)
220 { m_ll
<<= shift
; return *this; }
223 wxLongLongNative
operator>>(int shift
) const
224 { return wxLongLongNative(m_ll
>> shift
);; }
225 wxLongLongNative
& operator>>=(int shift
)
226 { m_ll
>>= shift
; return *this; }
229 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
230 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
231 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
232 { m_ll
&= ll
.m_ll
; 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 // multiplication/division
245 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
246 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
247 wxLongLongNative
operator*(long l
) const
248 { return wxLongLongNative(m_ll
* l
); }
249 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
250 { m_ll
*= ll
.m_ll
; return *this; }
251 wxLongLongNative
& operator*=(long l
)
252 { m_ll
*= l
; return *this; }
254 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
255 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
256 wxLongLongNative
operator/(long l
) const
257 { return wxLongLongNative(m_ll
/ l
); }
258 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
259 { m_ll
/= ll
.m_ll
; return *this; }
260 wxLongLongNative
& operator/=(long l
)
261 { m_ll
/= l
; return *this; }
263 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
264 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
265 wxLongLongNative
operator%(long l
) const
266 { return wxLongLongNative(m_ll
% l
); }
269 bool operator==(const wxLongLongNative
& ll
) const
270 { return m_ll
== ll
.m_ll
; }
271 bool operator==(long l
) const
272 { return m_ll
== l
; }
273 bool operator!=(const wxLongLongNative
& ll
) const
274 { return m_ll
!= ll
.m_ll
; }
275 bool operator!=(long l
) const
276 { return m_ll
!= l
; }
277 bool operator<(const wxLongLongNative
& ll
) const
278 { return m_ll
< ll
.m_ll
; }
279 bool operator<(long l
) const
281 bool operator>(const wxLongLongNative
& ll
) const
282 { return m_ll
> ll
.m_ll
; }
283 bool operator>(long l
) const
285 bool operator<=(const wxLongLongNative
& ll
) const
286 { return m_ll
<= ll
.m_ll
; }
287 bool operator<=(long l
) const
288 { return m_ll
<= l
; }
289 bool operator>=(const wxLongLongNative
& ll
) const
290 { return m_ll
>= ll
.m_ll
; }
291 bool operator>=(long l
) const
292 { return m_ll
>= l
; }
296 // return the string representation of this number
297 wxString
ToString() const;
299 // conversion to byte array: returns a pointer to static buffer!
300 void *asArray() const;
302 #if wxUSE_STD_IOSTREAM
304 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
312 class WXDLLIMPEXP_BASE wxULongLongNative
316 // default ctor initializes to 0
317 wxULongLongNative() : m_ll(0) { }
319 wxULongLongNative(unsigned wxLongLong_t ll
) : m_ll(ll
) { }
321 wxULongLongNative(unsigned long hi
, unsigned long lo
) : m_ll(0)
323 // assign first to avoid precision loss!
324 m_ll
= ((unsigned wxLongLong_t
) hi
) << 32;
325 m_ll
|= (unsigned wxLongLong_t
) lo
;
328 // default copy ctor is ok
332 // assignment operators
333 // from native 64 bit integer
334 wxULongLongNative
& operator=(unsigned wxLongLong_t ll
)
335 { m_ll
= ll
; return *this; }
337 // assignment operators from wxULongLongNative is ok
341 unsigned long GetHi() const
342 { return (unsigned long)(m_ll
>> 32); }
344 unsigned long GetLo() const
345 { return (unsigned long)m_ll
; }
347 // convert to native ulong long
348 unsigned wxLongLong_t
GetValue() const { return m_ll
; }
350 // convert to ulong with range checking in the debug mode (only!)
351 unsigned long ToULong() const
353 wxASSERT_MSG( m_ll
<= LONG_MAX
,
354 _T("wxULongLong to long conversion loss of precision") );
356 return (unsigned long)m_ll
;
361 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
362 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
363 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
364 { m_ll
+= ll
.m_ll
; return *this; }
366 wxULongLongNative
operator+(const unsigned wxLongLong_t ll
) const
367 { return wxULongLongNative(m_ll
+ ll
); }
368 wxULongLongNative
& operator+=(const unsigned wxLongLong_t ll
)
369 { m_ll
+= ll
; return *this; }
372 wxULongLongNative
& operator++()
373 { m_ll
++; return *this; }
376 wxULongLongNative
operator++(int)
377 { wxULongLongNative
value(*this); m_ll
++; return value
; }
380 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
381 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
382 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
383 { m_ll
-= ll
.m_ll
; return *this; }
385 wxULongLongNative
operator-(const unsigned wxLongLong_t ll
) const
386 { return wxULongLongNative(m_ll
- ll
); }
387 wxULongLongNative
& operator-=(const unsigned wxLongLong_t ll
)
388 { m_ll
-= ll
; return *this; }
391 wxULongLongNative
& operator--()
392 { m_ll
--; return *this; }
395 wxULongLongNative
operator--(int)
396 { wxULongLongNative
value(*this); m_ll
--; return value
; }
400 wxULongLongNative
operator<<(int shift
) const
401 { return wxULongLongNative(m_ll
<< shift
);; }
402 wxULongLongNative
& operator<<=(int shift
)
403 { m_ll
<<= shift
; return *this; }
406 wxULongLongNative
operator>>(int shift
) const
407 { return wxULongLongNative(m_ll
>> shift
);; }
408 wxULongLongNative
& operator>>=(int shift
)
409 { m_ll
>>= shift
; return *this; }
412 wxULongLongNative
operator&(const wxULongLongNative
& ll
) const
413 { return wxULongLongNative(m_ll
& ll
.m_ll
); }
414 wxULongLongNative
& operator&=(const wxULongLongNative
& ll
)
415 { m_ll
&= ll
.m_ll
; return *this; }
417 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
418 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
419 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
420 { m_ll
|= ll
.m_ll
; return *this; }
422 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
423 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
424 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
425 { m_ll
^= ll
.m_ll
; return *this; }
427 // multiplication/division
428 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
429 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
430 wxULongLongNative
operator*(unsigned long l
) const
431 { return wxULongLongNative(m_ll
* l
); }
432 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
433 { m_ll
*= ll
.m_ll
; return *this; }
434 wxULongLongNative
& operator*=(unsigned long l
)
435 { m_ll
*= l
; return *this; }
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
); }
452 bool operator==(const wxULongLongNative
& ll
) const
453 { return m_ll
== ll
.m_ll
; }
454 bool operator==(unsigned long l
) const
455 { return m_ll
== l
; }
456 bool operator!=(const wxULongLongNative
& ll
) const
457 { return m_ll
!= ll
.m_ll
; }
458 bool operator!=(unsigned long l
) const
459 { return m_ll
!= l
; }
460 bool operator<(const wxULongLongNative
& ll
) const
461 { return m_ll
< ll
.m_ll
; }
462 bool operator<(unsigned long l
) const
464 bool operator>(const wxULongLongNative
& ll
) const
465 { return m_ll
> ll
.m_ll
; }
466 bool operator>(unsigned long l
) const
468 bool operator<=(const wxULongLongNative
& ll
) const
469 { return m_ll
<= ll
.m_ll
; }
470 bool operator<=(unsigned long l
) const
471 { return m_ll
<= l
; }
472 bool operator>=(const wxULongLongNative
& ll
) const
473 { return m_ll
>= ll
.m_ll
; }
474 bool operator>=(unsigned long l
) const
475 { return m_ll
>= l
; }
479 // return the string representation of this number
480 wxString
ToString() const;
482 // conversion to byte array: returns a pointer to static buffer!
483 void *asArray() const;
485 #if wxUSE_STD_IOSTREAM
487 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
491 unsigned wxLongLong_t m_ll
;
494 #endif // wxUSE_LONGLONG_NATIVE
496 #if wxUSE_LONGLONG_WX
498 class WXDLLIMPEXP_BASE wxLongLongWx
502 // default ctor initializes to 0
507 #ifdef wxLONGLONG_TEST_MODE
511 #endif // wxLONGLONG_TEST_MODE
514 wxLongLongWx(long l
) { *this = l
; }
516 wxLongLongWx(long hi
, unsigned long lo
)
521 #ifdef wxLONGLONG_TEST_MODE
527 #endif // wxLONGLONG_TEST_MODE
530 // default copy ctor is ok in both cases
534 // assignment operators
536 wxLongLongWx
& operator=(long l
)
539 m_hi
= (l
< 0 ? -1l : 0l);
541 #ifdef wxLONGLONG_TEST_MODE
545 #endif // wxLONGLONG_TEST_MODE
550 wxLongLongWx
& Assign(double d
);
551 // can't have assignment operator from 2 longs
555 long GetHi() const { return m_hi
; }
557 unsigned long GetLo() const { return m_lo
; }
559 // get absolute value
560 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
566 #ifdef wxLONGLONG_TEST_MODE
571 #endif // wxLONGLONG_TEST_MODE
576 // convert to long with range checking in the debug mode (only!)
579 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
580 _T("wxLongLong to long conversion loss of precision") );
587 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
588 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
589 wxLongLongWx
operator+(long l
) const;
590 wxLongLongWx
& operator+=(long l
);
592 // pre increment operator
593 wxLongLongWx
& operator++();
595 // post increment operator
596 wxLongLongWx
& operator++(int) { return ++(*this); }
599 wxLongLongWx
operator-() const;
600 wxLongLongWx
& Negate();
603 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
604 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
606 // pre decrement operator
607 wxLongLongWx
& operator--();
609 // post decrement operator
610 wxLongLongWx
& operator--(int) { return --(*this); }
614 wxLongLongWx
operator<<(int shift
) const;
615 wxLongLongWx
& operator<<=(int shift
);
618 wxLongLongWx
operator>>(int shift
) const;
619 wxLongLongWx
& operator>>=(int shift
);
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 wxLongLongWx
& ll
) const;
627 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
628 wxLongLongWx
operator~() const;
631 bool operator==(const wxLongLongWx
& ll
) const
632 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
633 #if wxUSE_LONGLONG_NATIVE
634 bool operator==(const wxLongLongNative
& ll
) const
635 { return m_lo
== ll
.GetLo() && m_hi
== ll
.GetHi(); }
637 bool operator!=(const wxLongLongWx
& ll
) const
638 { return !(*this == ll
); }
639 bool operator<(const wxLongLongWx
& ll
) const;
640 bool operator>(const wxLongLongWx
& ll
) const;
641 bool operator<=(const wxLongLongWx
& ll
) const
642 { return *this < ll
|| *this == ll
; }
643 bool operator>=(const wxLongLongWx
& ll
) const
644 { return *this > ll
|| *this == ll
; }
646 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
647 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
648 bool operator==(long l
) const
650 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
651 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
654 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
655 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
658 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
659 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
662 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
663 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
665 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
667 void Divide(const wxLongLongWx
& divisor
,
668 wxLongLongWx
& quotient
,
669 wxLongLongWx
& remainder
) const;
673 // return the string representation of this number
674 wxString
ToString() const;
676 void *asArray() const;
678 #if wxUSE_STD_IOSTREAM
679 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
680 #endif // wxUSE_STD_IOSTREAM
683 // long is at least 32 bits, so represent our 64bit number as 2 longs
685 long m_hi
; // signed bit is in the high part
688 #ifdef wxLONGLONG_TEST_MODE
691 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
695 #endif // wxLONGLONG_TEST_MODE
699 class WXDLLIMPEXP_BASE wxULongLongWx
703 // default ctor initializes to 0
708 #ifdef wxLONGLONG_TEST_MODE
712 #endif // wxLONGLONG_TEST_MODE
715 wxULongLongWx(unsigned long l
) { *this = l
; }
717 wxULongLongWx(unsigned long hi
, unsigned long lo
)
722 #ifdef wxLONGLONG_TEST_MODE
728 #endif // wxLONGLONG_TEST_MODE
731 // from signed to unsigned
732 wxULongLongWx(wxLongLongWx ll
)
734 wxASSERT(ll
.GetHi() >= 0);
735 m_hi
= (unsigned long)ll
.GetHi();
739 // default copy ctor is ok in both cases
743 // assignment operators
745 wxULongLongWx
& operator=(unsigned long l
)
750 #ifdef wxLONGLONG_TEST_MODE
754 #endif // wxLONGLONG_TEST_MODE
759 // can't have assignment operator from 2 longs
763 unsigned long GetHi() const { return m_hi
; }
765 unsigned long GetLo() const { return m_lo
; }
767 // convert to long with range checking in the debug mode (only!)
768 unsigned long ToULong() const
770 wxASSERT_MSG( m_hi
== 0ul,
771 _T("wxULongLong to long conversion loss of precision") );
773 return (unsigned long)m_lo
;
778 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
779 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
780 wxULongLongWx
operator+(unsigned long l
) const;
781 wxULongLongWx
& operator+=(unsigned long l
);
783 // pre increment operator
784 wxULongLongWx
& operator++();
786 // post increment operator
787 wxULongLongWx
& operator++(int) { return ++(*this); }
790 wxLongLongWx
operator-(const wxULongLongWx
& ll
) const;
791 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
793 // pre decrement operator
794 wxULongLongWx
& operator--();
796 // post decrement operator
797 wxULongLongWx
& operator--(int) { return --(*this); }
801 wxULongLongWx
operator<<(int shift
) const;
802 wxULongLongWx
& operator<<=(int shift
);
805 wxULongLongWx
operator>>(int shift
) const;
806 wxULongLongWx
& operator>>=(int shift
);
809 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
810 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
811 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
812 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
813 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
814 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
815 wxULongLongWx
operator~() const;
818 bool operator==(const wxULongLongWx
& ll
) const
819 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
820 bool operator!=(const wxULongLongWx
& ll
) const
821 { return !(*this == ll
); }
822 bool operator<(const wxULongLongWx
& ll
) const;
823 bool operator>(const wxULongLongWx
& ll
) const;
824 bool operator<=(const wxULongLongWx
& ll
) const
825 { return *this < ll
|| *this == ll
; }
826 bool operator>=(const wxULongLongWx
& ll
) const
827 { return *this > ll
|| *this == ll
; }
829 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
830 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
831 bool operator==(unsigned long l
) const
833 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
836 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
837 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
840 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
841 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
844 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
845 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
847 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
849 void Divide(const wxULongLongWx
& divisor
,
850 wxULongLongWx
& quotient
,
851 wxULongLongWx
& remainder
) const;
855 // return the string representation of this number
856 wxString
ToString() const;
858 void *asArray() const;
860 #if wxUSE_STD_IOSTREAM
861 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
862 #endif // wxUSE_STD_IOSTREAM
865 // long is at least 32 bits, so represent our 64bit number as 2 longs
870 #ifdef wxLONGLONG_TEST_MODE
873 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
876 unsigned wxLongLong_t m_ll
;
877 #endif // wxLONGLONG_TEST_MODE
880 #endif // wxUSE_LONGLONG_WX
882 // ----------------------------------------------------------------------------
884 // ----------------------------------------------------------------------------
886 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
887 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
< l
; }
888 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
>= l
; }
889 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
<= l
; }
890 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
891 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
893 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
894 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
896 return wxLongLong(l
) - ll
;
899 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
900 inline bool operator>(unsigned long l
, const wxULongLong
& ull
) { return ull
< l
; }
901 inline bool operator<=(unsigned long l
, const wxULongLong
& ull
) { return ull
>= l
; }
902 inline bool operator>=(unsigned long l
, const wxULongLong
& ull
) { return ull
<= l
; }
903 inline bool operator==(unsigned long l
, const wxULongLong
& ull
) { return ull
== l
; }
904 inline bool operator!=(unsigned long l
, const wxULongLong
& ull
) { return ull
!= l
; }
906 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
908 inline wxLongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
910 wxULongLong ret
= wxULongLong(l
) - ull
;
911 return wxLongLong((long)ret
.GetHi(),ret
.GetLo());
914 #endif // _WX_LONGLONG_H