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
17 #include "wx/string.h"
19 #include <limits.h> // for LONG_MAX
21 // define this to compile wxLongLongWx in "test" mode: the results of all
22 // calculations will be compared with the real results taken from
23 // wxLongLongNative -- this is extremely useful to find the bugs in
24 // wxLongLongWx class!
26 // #define wxLONGLONG_TEST_MODE
28 #ifdef wxLONGLONG_TEST_MODE
29 #define wxUSE_LONGLONG_WX 1
30 #define wxUSE_LONGLONG_NATIVE 1
31 #endif // wxLONGLONG_TEST_MODE
33 // ----------------------------------------------------------------------------
34 // decide upon which class we will use
35 // ----------------------------------------------------------------------------
38 // both warning and pragma warning are not portable, but at least an
39 // unknown pragma should never be an error -- except that, actually, some
40 // broken compilers don't like it, so we have to disable it in this case
42 #if !(defined(__WATCOMC__) || defined(__VISAGECPP__))
43 #pragma warning "Your compiler does not appear to support 64 bit "\
44 "integers, using emulation class instead.\n" \
45 "Please report your compiler version to " \
46 "wx-dev@lists.wxwidgets.org!"
49 #define wxUSE_LONGLONG_WX 1
52 // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
53 // to disable automatic testing (useful for the test program which defines
54 // both classes) but by default we only use one class
55 #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
56 // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
57 // this is useful in test programs and only there
58 #ifndef wxUSE_LONGLONG_NATIVE
59 #define wxUSE_LONGLONG_NATIVE 0
62 class WXDLLIMPEXP_BASE wxLongLongWx
;
63 class WXDLLIMPEXP_BASE wxULongLongWx
;
64 #if defined(__VISUALC__) && !defined(__WIN32__)
65 #define wxLongLong wxLongLongWx
66 #define wxULongLong wxULongLongWx
68 typedef wxLongLongWx wxLongLong
;
69 typedef wxULongLongWx wxULongLong
;
73 // if nothing is defined, use native implementation by default, of course
74 #ifndef wxUSE_LONGLONG_NATIVE
75 #define wxUSE_LONGLONG_NATIVE 1
79 #ifndef wxUSE_LONGLONG_WX
80 #define wxUSE_LONGLONG_WX 0
81 class WXDLLIMPEXP_BASE wxLongLongNative
;
82 class WXDLLIMPEXP_BASE wxULongLongNative
;
83 typedef wxLongLongNative wxLongLong
;
84 typedef wxULongLongNative wxULongLong
;
87 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
88 // typedef wxLongLong as it wants, we don't do it
90 // ----------------------------------------------------------------------------
91 // choose the appropriate class
92 // ----------------------------------------------------------------------------
94 // we use iostream for wxLongLong output
95 #include "wx/iosfwrap.h"
97 #if wxUSE_LONGLONG_NATIVE
99 class WXDLLIMPEXP_BASE wxLongLongNative
103 // default ctor initializes to 0
104 wxLongLongNative() : m_ll(0) { }
106 wxLongLongNative(wxLongLong_t ll
) : m_ll(ll
) { }
108 wxLongLongNative(long hi
, unsigned long lo
) : m_ll(0)
110 // assign first to avoid precision loss!
111 m_ll
= ((wxLongLong_t
) hi
) << 32;
112 m_ll
|= (wxLongLong_t
) lo
;
114 #if wxUSE_LONGLONG_WX
115 wxLongLongNative(wxLongLongWx ll
);
118 // default copy ctor is ok
122 // assignment operators
123 // from native 64 bit integer
124 wxLongLongNative
& operator=(wxLongLong_t ll
)
125 { m_ll
= ll
; return *this; }
126 #if wxUSE_LONGLONG_WX
127 wxLongLongNative
& operator=(wxLongLongWx ll
);
131 // from double: this one has an explicit name because otherwise we
132 // would have ambiguity with "ll = int" and also because we don't want
133 // to have implicit conversions between doubles and wxLongLongs
134 wxLongLongNative
& Assign(double d
)
135 { m_ll
= (wxLongLong_t
)d
; return *this; }
137 // assignment operators from wxLongLongNative is ok
142 { return wx_truncate_cast(long, m_ll
>> 32); }
144 unsigned long GetLo() const
145 { return wx_truncate_cast(unsigned long, m_ll
); }
147 // get absolute value
148 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
149 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
151 // convert to native long long
152 wxLongLong_t
GetValue() const { return m_ll
; }
154 // convert to long with range checking in debug mode (only!)
157 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
158 _T("wxLongLong to long conversion loss of precision") );
160 return wx_truncate_cast(long, m_ll
);
164 double ToDouble() const { return wx_truncate_cast(double, m_ll
); }
166 // don't provide implicit conversion to wxLongLong_t or we will have an
167 // ambiguity for all arithmetic operations
168 //operator wxLongLong_t() const { return m_ll; }
172 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
173 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
174 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
175 { m_ll
+= ll
.m_ll
; return *this; }
177 wxLongLongNative
operator+(const wxLongLong_t ll
) const
178 { return wxLongLongNative(m_ll
+ ll
); }
179 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
180 { m_ll
+= ll
; return *this; }
183 wxLongLongNative
& operator++()
184 { m_ll
++; return *this; }
187 wxLongLongNative
operator++(int)
188 { wxLongLongNative
value(*this); m_ll
++; return value
; }
191 wxLongLongNative
operator-() const
192 { return wxLongLongNative(-m_ll
); }
193 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
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 { wxLongLongNative
value(*this); m_ll
--; return value
; }
216 wxLongLongNative
operator<<(int shift
) const
217 { return wxLongLongNative(m_ll
<< shift
); }
218 wxLongLongNative
& operator<<=(int shift
)
219 { m_ll
<<= shift
; return *this; }
222 wxLongLongNative
operator>>(int shift
) const
223 { return wxLongLongNative(m_ll
>> shift
); }
224 wxLongLongNative
& operator>>=(int shift
)
225 { m_ll
>>= shift
; return *this; }
228 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
229 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
230 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
231 { m_ll
&= ll
.m_ll
; return *this; }
233 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
234 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
235 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
236 { m_ll
|= ll
.m_ll
; return *this; }
238 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
239 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
240 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
241 { m_ll
^= ll
.m_ll
; return *this; }
243 // multiplication/division
244 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
245 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
246 wxLongLongNative
operator*(long l
) const
247 { return wxLongLongNative(m_ll
* l
); }
248 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
249 { m_ll
*= ll
.m_ll
; return *this; }
250 wxLongLongNative
& operator*=(long l
)
251 { m_ll
*= l
; return *this; }
253 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
254 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
255 wxLongLongNative
operator/(long l
) const
256 { return wxLongLongNative(m_ll
/ l
); }
257 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
258 { m_ll
/= ll
.m_ll
; return *this; }
259 wxLongLongNative
& operator/=(long l
)
260 { m_ll
/= l
; return *this; }
262 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
263 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
264 wxLongLongNative
operator%(long l
) const
265 { return wxLongLongNative(m_ll
% l
); }
268 bool operator==(const wxLongLongNative
& ll
) const
269 { return m_ll
== ll
.m_ll
; }
270 bool operator==(long l
) const
271 { return m_ll
== l
; }
272 bool operator!=(const wxLongLongNative
& ll
) const
273 { return m_ll
!= ll
.m_ll
; }
274 bool operator!=(long l
) const
275 { return m_ll
!= l
; }
276 bool operator<(const wxLongLongNative
& ll
) const
277 { return m_ll
< ll
.m_ll
; }
278 bool operator<(long l
) const
280 bool operator>(const wxLongLongNative
& ll
) const
281 { return m_ll
> ll
.m_ll
; }
282 bool operator>(long l
) const
284 bool operator<=(const wxLongLongNative
& ll
) const
285 { return m_ll
<= ll
.m_ll
; }
286 bool operator<=(long l
) const
287 { return m_ll
<= l
; }
288 bool operator>=(const wxLongLongNative
& ll
) const
289 { return m_ll
>= ll
.m_ll
; }
290 bool operator>=(long l
) const
291 { return m_ll
>= l
; }
295 // return the string representation of this number
296 wxString
ToString() const;
298 // conversion to byte array: returns a pointer to static buffer!
299 void *asArray() const;
301 #if wxUSE_STD_IOSTREAM
303 friend WXDLLIMPEXP_BASE
304 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
307 friend WXDLLIMPEXP_BASE
308 wxString
& operator<<(wxString
&, const wxLongLongNative
&);
315 class WXDLLIMPEXP_BASE wxULongLongNative
319 // default ctor initializes to 0
320 wxULongLongNative() : m_ll(0) { }
322 wxULongLongNative(wxULongLong_t ll
) : m_ll(ll
) { }
324 wxULongLongNative(unsigned long hi
, unsigned long lo
) : m_ll(0)
326 // assign first to avoid precision loss!
327 m_ll
= ((wxULongLong_t
) hi
) << 32;
328 m_ll
|= (wxULongLong_t
) lo
;
331 // default copy ctor is ok
335 // assignment operators
336 // from native 64 bit integer
337 wxULongLongNative
& operator=(wxULongLong_t ll
)
338 { m_ll
= ll
; return *this; }
340 // assignment operators from wxULongLongNative is ok
344 unsigned long GetHi() const
345 { return wx_truncate_cast(unsigned long, m_ll
>> 32); }
347 unsigned long GetLo() const
348 { return wx_truncate_cast(unsigned long, m_ll
); }
350 // convert to native ulong long
351 wxULongLong_t
GetValue() const { return m_ll
; }
353 // convert to ulong with range checking in debug mode (only!)
354 unsigned long ToULong() const
356 wxASSERT_MSG( m_ll
<= LONG_MAX
,
357 _T("wxULongLong to long conversion loss of precision") );
359 return wx_truncate_cast(unsigned long, m_ll
);
364 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
365 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
366 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
367 { m_ll
+= ll
.m_ll
; return *this; }
369 wxULongLongNative
operator+(const wxULongLong_t ll
) const
370 { return wxULongLongNative(m_ll
+ ll
); }
371 wxULongLongNative
& operator+=(const wxULongLong_t ll
)
372 { m_ll
+= ll
; return *this; }
375 wxULongLongNative
& operator++()
376 { m_ll
++; return *this; }
379 wxULongLongNative
operator++(int)
380 { wxULongLongNative
value(*this); m_ll
++; return value
; }
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 wxULongLong_t ll
) const
389 { return wxULongLongNative(m_ll
- ll
); }
390 wxULongLongNative
& operator-=(const wxULongLong_t ll
)
391 { m_ll
-= ll
; return *this; }
394 wxULongLongNative
& operator--()
395 { m_ll
--; return *this; }
398 wxULongLongNative
operator--(int)
399 { wxULongLongNative
value(*this); m_ll
--; return value
; }
403 wxULongLongNative
operator<<(int shift
) const
404 { return wxULongLongNative(m_ll
<< shift
); }
405 wxULongLongNative
& operator<<=(int shift
)
406 { m_ll
<<= shift
; return *this; }
409 wxULongLongNative
operator>>(int shift
) const
410 { return wxULongLongNative(m_ll
>> shift
); }
411 wxULongLongNative
& operator>>=(int shift
)
412 { m_ll
>>= shift
; return *this; }
415 wxULongLongNative
operator&(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 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
426 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
427 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
428 { m_ll
^= ll
.m_ll
; return *this; }
430 // multiplication/division
431 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
432 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
433 wxULongLongNative
operator*(unsigned long l
) const
434 { return wxULongLongNative(m_ll
* l
); }
435 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
436 { m_ll
*= ll
.m_ll
; return *this; }
437 wxULongLongNative
& operator*=(unsigned long l
)
438 { m_ll
*= l
; return *this; }
440 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
441 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
442 wxULongLongNative
operator/(unsigned long l
) const
443 { return wxULongLongNative(m_ll
/ l
); }
444 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
445 { m_ll
/= ll
.m_ll
; return *this; }
446 wxULongLongNative
& operator/=(unsigned long l
)
447 { m_ll
/= l
; return *this; }
449 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
450 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
451 wxULongLongNative
operator%(unsigned long l
) const
452 { return wxULongLongNative(m_ll
% l
); }
455 bool operator==(const wxULongLongNative
& ll
) const
456 { return m_ll
== ll
.m_ll
; }
457 bool operator==(unsigned long l
) const
458 { return m_ll
== l
; }
459 bool operator!=(const wxULongLongNative
& ll
) const
460 { return m_ll
!= ll
.m_ll
; }
461 bool operator!=(unsigned long l
) const
462 { return m_ll
!= l
; }
463 bool operator<(const wxULongLongNative
& ll
) const
464 { return m_ll
< ll
.m_ll
; }
465 bool operator<(unsigned long l
) const
467 bool operator>(const wxULongLongNative
& ll
) const
468 { return m_ll
> ll
.m_ll
; }
469 bool operator>(unsigned long l
) const
471 bool operator<=(const wxULongLongNative
& ll
) const
472 { return m_ll
<= ll
.m_ll
; }
473 bool operator<=(unsigned long l
) const
474 { return 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
; }
482 // return the string representation of this number
483 wxString
ToString() const;
485 // conversion to byte array: returns a pointer to static buffer!
486 void *asArray() const;
488 #if wxUSE_STD_IOSTREAM
490 friend WXDLLIMPEXP_BASE
491 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
494 friend WXDLLIMPEXP_BASE
495 wxString
& operator<<(wxString
&, const wxULongLongNative
&);
501 #endif // wxUSE_LONGLONG_NATIVE
503 #if wxUSE_LONGLONG_WX
505 class WXDLLIMPEXP_BASE wxLongLongWx
509 // default ctor initializes to 0
514 #ifdef wxLONGLONG_TEST_MODE
518 #endif // wxLONGLONG_TEST_MODE
521 wxLongLongWx(long l
) { *this = l
; }
523 wxLongLongWx(long hi
, unsigned long lo
)
528 #ifdef wxLONGLONG_TEST_MODE
534 #endif // wxLONGLONG_TEST_MODE
537 // default copy ctor is ok in both cases
541 // assignment operators
543 wxLongLongWx
& operator=(long l
)
546 m_hi
= (l
< 0 ? -1l : 0l);
548 #ifdef wxLONGLONG_TEST_MODE
552 #endif // wxLONGLONG_TEST_MODE
557 wxLongLongWx
& Assign(double d
);
558 // can't have assignment operator from 2 longs
562 long GetHi() const { return m_hi
; }
564 unsigned long GetLo() const { return m_lo
; }
566 // get absolute value
567 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
573 #ifdef wxLONGLONG_TEST_MODE
578 #endif // wxLONGLONG_TEST_MODE
583 // convert to long with range checking in debug mode (only!)
586 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
587 _T("wxLongLong to long conversion loss of precision") );
593 double ToDouble() const;
597 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
598 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
599 wxLongLongWx
operator+(long l
) const;
600 wxLongLongWx
& operator+=(long l
);
602 // pre increment operator
603 wxLongLongWx
& operator++();
605 // post increment operator
606 wxLongLongWx
& operator++(int) { return ++(*this); }
609 wxLongLongWx
operator-() const;
610 wxLongLongWx
& Negate();
613 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
614 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
616 // pre decrement operator
617 wxLongLongWx
& operator--();
619 // post decrement operator
620 wxLongLongWx
& operator--(int) { return --(*this); }
624 wxLongLongWx
operator<<(int shift
) const;
625 wxLongLongWx
& operator<<=(int shift
);
628 wxLongLongWx
operator>>(int shift
) const;
629 wxLongLongWx
& operator>>=(int shift
);
632 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
633 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
634 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
635 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
636 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
637 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
638 wxLongLongWx
operator~() const;
641 bool operator==(const wxLongLongWx
& ll
) const
642 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
643 #if wxUSE_LONGLONG_NATIVE
644 bool operator==(const wxLongLongNative
& ll
) const
645 { return m_lo
== ll
.GetLo() && m_hi
== ll
.GetHi(); }
647 bool operator!=(const wxLongLongWx
& ll
) const
648 { return !(*this == ll
); }
649 bool operator<(const wxLongLongWx
& ll
) const;
650 bool operator>(const wxLongLongWx
& ll
) const;
651 bool operator<=(const wxLongLongWx
& ll
) const
652 { return *this < ll
|| *this == ll
; }
653 bool operator>=(const wxLongLongWx
& ll
) const
654 { return *this > ll
|| *this == ll
; }
656 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
657 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
658 bool operator==(long l
) const
660 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
661 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
664 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
665 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
668 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
669 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
672 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
673 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
675 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
677 void Divide(const wxLongLongWx
& divisor
,
678 wxLongLongWx
& quotient
,
679 wxLongLongWx
& remainder
) const;
683 // return the string representation of this number
684 wxString
ToString() const;
686 void *asArray() const;
688 #if wxUSE_STD_IOSTREAM
689 friend WXDLLIMPEXP_BASE
690 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
691 #endif // wxUSE_STD_IOSTREAM
693 friend WXDLLIMPEXP_BASE
694 wxString
& operator<<(wxString
&, const wxLongLongWx
&);
697 // long is at least 32 bits, so represent our 64bit number as 2 longs
699 long m_hi
; // signed bit is in the high part
702 #ifdef wxLONGLONG_TEST_MODE
705 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
709 #endif // wxLONGLONG_TEST_MODE
713 class WXDLLIMPEXP_BASE wxULongLongWx
717 // default ctor initializes to 0
722 #ifdef wxLONGLONG_TEST_MODE
726 #endif // wxLONGLONG_TEST_MODE
729 wxULongLongWx(unsigned long l
) { *this = l
; }
731 wxULongLongWx(unsigned long hi
, unsigned long lo
)
736 #ifdef wxLONGLONG_TEST_MODE
742 #endif // wxLONGLONG_TEST_MODE
745 // from signed to unsigned
746 wxULongLongWx(wxLongLongWx ll
)
748 wxASSERT(ll
.GetHi() >= 0);
749 m_hi
= (unsigned long)ll
.GetHi();
753 // default copy ctor is ok in both cases
757 // assignment operators
759 wxULongLongWx
& operator=(unsigned long l
)
764 #ifdef wxLONGLONG_TEST_MODE
768 #endif // wxLONGLONG_TEST_MODE
773 // can't have assignment operator from 2 longs
777 unsigned long GetHi() const { return m_hi
; }
779 unsigned long GetLo() const { return m_lo
; }
781 // convert to long with range checking in debug mode (only!)
782 unsigned long ToULong() const
784 wxASSERT_MSG( m_hi
== 0ul,
785 _T("wxULongLong to long conversion loss of precision") );
787 return (unsigned long)m_lo
;
792 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
793 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
794 wxULongLongWx
operator+(unsigned long l
) const;
795 wxULongLongWx
& operator+=(unsigned long l
);
797 // pre increment operator
798 wxULongLongWx
& operator++();
800 // post increment operator
801 wxULongLongWx
& operator++(int) { return ++(*this); }
804 wxLongLongWx
operator-(const wxULongLongWx
& ll
) const;
805 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
807 // pre decrement operator
808 wxULongLongWx
& operator--();
810 // post decrement operator
811 wxULongLongWx
& operator--(int) { return --(*this); }
815 wxULongLongWx
operator<<(int shift
) const;
816 wxULongLongWx
& operator<<=(int shift
);
819 wxULongLongWx
operator>>(int shift
) const;
820 wxULongLongWx
& operator>>=(int shift
);
823 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
824 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
825 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
826 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
827 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
828 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
829 wxULongLongWx
operator~() const;
832 bool operator==(const wxULongLongWx
& ll
) const
833 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
834 bool operator!=(const wxULongLongWx
& ll
) const
835 { return !(*this == ll
); }
836 bool operator<(const wxULongLongWx
& ll
) const;
837 bool operator>(const wxULongLongWx
& ll
) const;
838 bool operator<=(const wxULongLongWx
& ll
) const
839 { return *this < ll
|| *this == ll
; }
840 bool operator>=(const wxULongLongWx
& ll
) const
841 { return *this > ll
|| *this == ll
; }
843 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
844 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
845 bool operator==(unsigned long l
) const
847 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
850 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
851 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
854 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
855 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
858 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
859 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
861 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
863 void Divide(const wxULongLongWx
& divisor
,
864 wxULongLongWx
& quotient
,
865 wxULongLongWx
& remainder
) const;
869 // return the string representation of this number
870 wxString
ToString() const;
872 void *asArray() const;
874 #if wxUSE_STD_IOSTREAM
875 friend WXDLLIMPEXP_BASE
876 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
877 #endif // wxUSE_STD_IOSTREAM
879 friend WXDLLIMPEXP_BASE
880 wxString
& operator<<(wxString
&, const wxULongLongWx
&);
883 // long is at least 32 bits, so represent our 64bit number as 2 longs
888 #ifdef wxLONGLONG_TEST_MODE
891 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
895 #endif // wxLONGLONG_TEST_MODE
898 #endif // wxUSE_LONGLONG_WX
900 // ----------------------------------------------------------------------------
902 // ----------------------------------------------------------------------------
904 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
905 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
< l
; }
906 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
>= l
; }
907 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
<= l
; }
908 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
909 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
911 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
912 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
914 return wxLongLong(l
) - ll
;
917 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
918 inline bool operator>(unsigned long l
, const wxULongLong
& ull
) { return ull
< l
; }
919 inline bool operator<=(unsigned long l
, const wxULongLong
& ull
) { return ull
>= l
; }
920 inline bool operator>=(unsigned long l
, const wxULongLong
& ull
) { return ull
<= l
; }
921 inline bool operator==(unsigned long l
, const wxULongLong
& ull
) { return ull
== l
; }
922 inline bool operator!=(unsigned long l
, const wxULongLong
& ull
) { return ull
!= l
; }
924 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
926 inline wxLongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
928 wxULongLong ret
= wxULongLong(l
) - ull
;
929 return wxLongLong((long)ret
.GetHi(),ret
.GetLo());
932 #endif // _WX_LONGLONG_H