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 #elif defined(__DJGPP__) && __DJGPP__ >= 2
72 #define wxLongLong_t long long
73 #else // no native long long type
74 // both warning and pragma warning are not portable, but at least an
75 // unknown pragma should never be an error - except that, actually, some
76 // broken compilers don't like it, so we have to disable it in this case
78 #if !(defined(__WATCOMC__) || defined(__VISAGECPP__))
79 #pragma warning "Your compiler does not appear to support 64 bit "\
80 "integers, using emulation class instead.\n" \
81 "Please report your compiler version to " \
82 "wx-dev@lists.wxwindows.org!"
85 #define wxUSE_LONGLONG_WX 1
88 // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
89 // to disable automatic testing (useful for the test program which defines
90 // both classes) but by default we only use one class
91 #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
92 // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
93 // this is useful in test programs and only there
94 #ifndef wxUSE_LONGLONG_NATIVE
95 #define wxUSE_LONGLONG_NATIVE 0
98 class WXDLLEXPORT wxLongLongWx
;
99 class WXDLLEXPORT wxULongLongWx
;
100 #if defined(__VISUALC__) && !defined(__WIN32__)
101 #define wxLongLong wxLongLongWx
102 #define wxULongLong wxULongLongWx
104 typedef wxLongLongWx wxLongLong
;
105 typedef wxULongLongWx wxULongLong
;
109 // if nothing is defined, use native implementation by default, of course
110 #ifndef wxUSE_LONGLONG_NATIVE
111 #define wxUSE_LONGLONG_NATIVE 1
115 #ifndef wxUSE_LONGLONG_WX
116 #define wxUSE_LONGLONG_WX 0
117 class WXDLLEXPORT wxLongLongNative
;
118 class WXDLLEXPORT wxULongLongNative
;
119 typedef wxLongLongNative wxLongLong
;
120 typedef wxULongLongNative wxULongLong
;
123 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
124 // typedef wxLongLong as it wants, we don't do it
126 // ----------------------------------------------------------------------------
127 // choose the appropriate class
128 // ----------------------------------------------------------------------------
130 // we use iostream for wxLongLong output
131 #include "wx/ioswrap.h"
133 #if wxUSE_LONGLONG_NATIVE
135 class WXDLLEXPORT wxLongLongNative
139 // default ctor initializes to 0
140 wxLongLongNative() : m_ll(0) { }
142 wxLongLongNative(wxLongLong_t ll
) : m_ll(ll
) { }
144 wxLongLongNative(long hi
, unsigned long lo
) : m_ll(0)
146 // assign first to avoid precision loss!
147 m_ll
= ((wxLongLong_t
) hi
) << 32;
148 m_ll
|= (wxLongLong_t
) lo
;
151 // default copy ctor is ok
155 // assignment operators
156 // from native 64 bit integer
157 wxLongLongNative
& operator=(wxLongLong_t ll
)
158 { m_ll
= ll
; return *this; }
160 // from double: this one has an explicit name because otherwise we
161 // would have ambiguity with "ll = int" and also because we don't want
162 // to have implicit conversions between doubles and wxLongLongs
163 wxLongLongNative
& Assign(double d
)
164 { m_ll
= (wxLongLong_t
)d
; return *this; }
166 // assignment operators from wxLongLongNative is ok
171 { return (long)(m_ll
>> 32); }
173 unsigned long GetLo() const
174 { return (unsigned long)m_ll
; }
176 // get absolute value
177 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
178 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
180 // convert to native long long
181 wxLongLong_t
GetValue() const { return m_ll
; }
183 // convert to long with range checking in the debug mode (only!)
186 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
187 _T("wxLongLong to long conversion loss of precision") );
192 // don't provide implicit conversion to wxLongLong_t or we will have an
193 // ambiguity for all arithmetic operations
194 //operator wxLongLong_t() const { return m_ll; }
198 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
199 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
200 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
201 { m_ll
+= ll
.m_ll
; return *this; }
203 wxLongLongNative
operator+(const wxLongLong_t ll
) const
204 { return wxLongLongNative(m_ll
+ ll
); }
205 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
206 { m_ll
+= ll
; return *this; }
209 wxLongLongNative
& operator++()
210 { m_ll
++; return *this; }
213 wxLongLongNative
operator++(int)
214 { wxLongLongNative
value(*this); m_ll
++; return value
; }
217 wxLongLongNative
operator-() const
218 { return wxLongLongNative(-m_ll
); }
219 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
222 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
223 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
224 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
225 { m_ll
-= ll
.m_ll
; return *this; }
227 wxLongLongNative
operator-(const wxLongLong_t ll
) const
228 { return wxLongLongNative(m_ll
- ll
); }
229 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
230 { m_ll
-= ll
; return *this; }
233 wxLongLongNative
& operator--()
234 { m_ll
--; return *this; }
237 wxLongLongNative
operator--(int)
238 { wxLongLongNative
value(*this); m_ll
--; return value
; }
242 wxLongLongNative
operator<<(int shift
) const
243 { return wxLongLongNative(m_ll
<< shift
);; }
244 wxLongLongNative
& operator<<=(int shift
)
245 { m_ll
<<= shift
; return *this; }
248 wxLongLongNative
operator>>(int shift
) const
249 { return wxLongLongNative(m_ll
>> shift
);; }
250 wxLongLongNative
& operator>>=(int shift
)
251 { m_ll
>>= shift
; return *this; }
254 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
255 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
256 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
257 { m_ll
&= ll
.m_ll
; return *this; }
259 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
260 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
261 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
262 { m_ll
|= ll
.m_ll
; return *this; }
264 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
265 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
266 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
267 { m_ll
^= ll
.m_ll
; return *this; }
269 // multiplication/division
270 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
271 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
272 wxLongLongNative
operator*(long l
) const
273 { return wxLongLongNative(m_ll
* l
); }
274 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
275 { m_ll
*= ll
.m_ll
; return *this; }
276 wxLongLongNative
& operator*=(long l
)
277 { m_ll
*= l
; return *this; }
279 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
280 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
281 wxLongLongNative
operator/(long l
) const
282 { return wxLongLongNative(m_ll
/ l
); }
283 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
284 { m_ll
/= ll
.m_ll
; return *this; }
285 wxLongLongNative
& operator/=(long l
)
286 { m_ll
/= l
; return *this; }
288 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
289 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
290 wxLongLongNative
operator%(long l
) const
291 { return wxLongLongNative(m_ll
% l
); }
294 bool operator==(const wxLongLongNative
& ll
) const
295 { return m_ll
== ll
.m_ll
; }
296 bool operator==(long l
) const
297 { return m_ll
== l
; }
298 bool operator!=(const wxLongLongNative
& ll
) const
299 { return m_ll
!= ll
.m_ll
; }
300 bool operator!=(long l
) const
301 { return m_ll
!= l
; }
302 bool operator<(const wxLongLongNative
& ll
) const
303 { return m_ll
< ll
.m_ll
; }
304 bool operator<(long l
) const
306 bool operator>(const wxLongLongNative
& ll
) const
307 { return m_ll
> ll
.m_ll
; }
308 bool operator>(long l
) const
310 bool operator<=(const wxLongLongNative
& ll
) const
311 { return m_ll
<= ll
.m_ll
; }
312 bool operator<=(long l
) const
313 { return m_ll
<= l
; }
314 bool operator>=(const wxLongLongNative
& ll
) const
315 { return m_ll
>= ll
.m_ll
; }
316 bool operator>=(long l
) const
317 { return m_ll
>= l
; }
321 // return the string representation of this number
322 wxString
ToString() const;
324 // conversion to byte array: returns a pointer to static buffer!
325 void *asArray() const;
327 #if wxUSE_STD_IOSTREAM
329 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
337 class WXDLLEXPORT wxULongLongNative
341 // default ctor initializes to 0
342 wxULongLongNative() : m_ll(0) { }
344 wxULongLongNative(unsigned wxLongLong_t ll
) : m_ll(ll
) { }
346 wxULongLongNative(unsigned long hi
, unsigned long lo
) : m_ll(0)
348 // assign first to avoid precision loss!
349 m_ll
= ((unsigned wxLongLong_t
) hi
) << 32;
350 m_ll
|= (unsigned wxLongLong_t
) lo
;
353 // default copy ctor is ok
357 // assignment operators
358 // from native 64 bit integer
359 wxULongLongNative
& operator=(unsigned wxLongLong_t ll
)
360 { m_ll
= ll
; return *this; }
362 // assignment operators from wxULongLongNative is ok
366 unsigned long GetHi() const
367 { return (unsigned long)(m_ll
>> 32); }
369 unsigned long GetLo() const
370 { return (unsigned long)m_ll
; }
372 // convert to native ulong long
373 unsigned wxLongLong_t
GetValue() const { return m_ll
; }
375 // convert to ulong with range checking in the debug mode (only!)
376 unsigned long ToULong() const
378 wxASSERT_MSG( m_ll
<= LONG_MAX
,
379 _T("wxULongLong to long conversion loss of precision") );
381 return (unsigned long)m_ll
;
386 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
387 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
388 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
389 { m_ll
+= ll
.m_ll
; return *this; }
391 wxULongLongNative
operator+(const unsigned wxLongLong_t ll
) const
392 { return wxULongLongNative(m_ll
+ ll
); }
393 wxULongLongNative
& operator+=(const unsigned wxLongLong_t ll
)
394 { m_ll
+= ll
; return *this; }
397 wxULongLongNative
& operator++()
398 { m_ll
++; return *this; }
401 wxULongLongNative
operator++(int)
402 { wxULongLongNative
value(*this); m_ll
++; return value
; }
405 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
406 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
407 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
408 { m_ll
-= ll
.m_ll
; return *this; }
410 wxULongLongNative
operator-(const unsigned wxLongLong_t ll
) const
411 { return wxULongLongNative(m_ll
- ll
); }
412 wxULongLongNative
& operator-=(const unsigned wxLongLong_t ll
)
413 { m_ll
-= ll
; return *this; }
416 wxULongLongNative
& operator--()
417 { m_ll
--; return *this; }
420 wxULongLongNative
operator--(int)
421 { wxULongLongNative
value(*this); m_ll
--; return value
; }
425 wxULongLongNative
operator<<(int shift
) const
426 { return wxULongLongNative(m_ll
<< shift
);; }
427 wxULongLongNative
& operator<<=(int shift
)
428 { m_ll
<<= shift
; return *this; }
431 wxULongLongNative
operator>>(int shift
) const
432 { return wxULongLongNative(m_ll
>> shift
);; }
433 wxULongLongNative
& operator>>=(int shift
)
434 { m_ll
>>= shift
; return *this; }
437 wxULongLongNative
operator&(const wxULongLongNative
& ll
) const
438 { return wxULongLongNative(m_ll
& ll
.m_ll
); }
439 wxULongLongNative
& operator&=(const wxULongLongNative
& ll
)
440 { m_ll
&= ll
.m_ll
; return *this; }
442 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
443 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
444 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
445 { m_ll
|= ll
.m_ll
; return *this; }
447 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
448 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
449 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
450 { m_ll
^= ll
.m_ll
; return *this; }
452 // multiplication/division
453 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
454 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
455 wxULongLongNative
operator*(unsigned long l
) const
456 { return wxULongLongNative(m_ll
* l
); }
457 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
458 { m_ll
*= ll
.m_ll
; return *this; }
459 wxULongLongNative
& operator*=(unsigned long l
)
460 { m_ll
*= l
; return *this; }
462 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
463 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
464 wxULongLongNative
operator/(unsigned long l
) const
465 { return wxULongLongNative(m_ll
/ l
); }
466 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
467 { m_ll
/= ll
.m_ll
; return *this; }
468 wxULongLongNative
& operator/=(unsigned long l
)
469 { m_ll
/= l
; return *this; }
471 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
472 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
473 wxULongLongNative
operator%(unsigned long l
) const
474 { return wxULongLongNative(m_ll
% l
); }
477 bool operator==(const wxULongLongNative
& ll
) const
478 { return m_ll
== ll
.m_ll
; }
479 bool operator==(unsigned long l
) const
480 { return m_ll
== l
; }
481 bool operator!=(const wxULongLongNative
& ll
) const
482 { return m_ll
!= ll
.m_ll
; }
483 bool operator!=(unsigned long l
) const
484 { return m_ll
!= l
; }
485 bool operator<(const wxULongLongNative
& ll
) const
486 { return m_ll
< ll
.m_ll
; }
487 bool operator<(unsigned long l
) const
489 bool operator>(const wxULongLongNative
& ll
) const
490 { return m_ll
> ll
.m_ll
; }
491 bool operator>(unsigned long l
) const
493 bool operator<=(const wxULongLongNative
& ll
) const
494 { return m_ll
<= ll
.m_ll
; }
495 bool operator<=(unsigned long l
) const
496 { return m_ll
<= l
; }
497 bool operator>=(const wxULongLongNative
& ll
) const
498 { return m_ll
>= ll
.m_ll
; }
499 bool operator>=(unsigned long l
) const
500 { return m_ll
>= l
; }
504 // return the string representation of this number
505 wxString
ToString() const;
507 // conversion to byte array: returns a pointer to static buffer!
508 void *asArray() const;
510 #if wxUSE_STD_IOSTREAM
512 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
516 unsigned wxLongLong_t m_ll
;
519 #endif // wxUSE_LONGLONG_NATIVE
521 #if wxUSE_LONGLONG_WX
523 class WXDLLEXPORT wxLongLongWx
527 // default ctor initializes to 0
532 #ifdef wxLONGLONG_TEST_MODE
536 #endif // wxLONGLONG_TEST_MODE
539 wxLongLongWx(long l
) { *this = l
; }
541 wxLongLongWx(long hi
, unsigned long lo
)
546 #ifdef wxLONGLONG_TEST_MODE
552 #endif // wxLONGLONG_TEST_MODE
555 // default copy ctor is ok in both cases
559 // assignment operators
561 wxLongLongWx
& operator=(long l
)
564 m_hi
= (l
< 0 ? -1l : 0l);
566 #ifdef wxLONGLONG_TEST_MODE
570 #endif // wxLONGLONG_TEST_MODE
575 wxLongLongWx
& Assign(double d
);
576 // can't have assignment operator from 2 longs
580 long GetHi() const { return m_hi
; }
582 unsigned long GetLo() const { return m_lo
; }
584 // get absolute value
585 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
591 #ifdef wxLONGLONG_TEST_MODE
596 #endif // wxLONGLONG_TEST_MODE
601 // convert to long with range checking in the debug mode (only!)
604 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
605 _T("wxLongLong to long conversion loss of precision") );
612 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
613 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
614 wxLongLongWx
operator+(long l
) const;
615 wxLongLongWx
& operator+=(long l
);
617 // pre increment operator
618 wxLongLongWx
& operator++();
620 // post increment operator
621 wxLongLongWx
& operator++(int) { return ++(*this); }
624 wxLongLongWx
operator-() const;
625 wxLongLongWx
& Negate();
628 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
629 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
631 // pre decrement operator
632 wxLongLongWx
& operator--();
634 // post decrement operator
635 wxLongLongWx
& operator--(int) { return --(*this); }
639 wxLongLongWx
operator<<(int shift
) const;
640 wxLongLongWx
& operator<<=(int shift
);
643 wxLongLongWx
operator>>(int shift
) const;
644 wxLongLongWx
& operator>>=(int shift
);
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 wxLongLongWx
& ll
) const;
652 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
653 wxLongLongWx
operator~() const;
656 bool operator==(const wxLongLongWx
& ll
) const
657 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
658 bool operator!=(const wxLongLongWx
& ll
) const
659 { return !(*this == ll
); }
660 bool operator<(const wxLongLongWx
& ll
) const;
661 bool operator>(const wxLongLongWx
& ll
) const;
662 bool operator<=(const wxLongLongWx
& ll
) const
663 { return *this < ll
|| *this == ll
; }
664 bool operator>=(const wxLongLongWx
& ll
) const
665 { return *this > ll
|| *this == ll
; }
667 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
668 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
669 bool operator==(long l
) const
671 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
672 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
675 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
676 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
679 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
680 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
683 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
684 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
686 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
688 void Divide(const wxLongLongWx
& divisor
,
689 wxLongLongWx
& quotient
,
690 wxLongLongWx
& remainder
) const;
694 // return the string representation of this number
695 wxString
ToString() const;
697 void *asArray() const;
699 #if wxUSE_STD_IOSTREAM
700 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
701 #endif // wxUSE_STD_IOSTREAM
704 // long is at least 32 bits, so represent our 64bit number as 2 longs
706 long m_hi
; // signed bit is in the high part
709 #ifdef wxLONGLONG_TEST_MODE
712 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
716 #endif // wxLONGLONG_TEST_MODE
720 class WXDLLEXPORT wxULongLongWx
724 // default ctor initializes to 0
729 #ifdef wxLONGLONG_TEST_MODE
733 #endif // wxLONGLONG_TEST_MODE
736 wxULongLongWx(unsigned long l
) { *this = l
; }
738 wxULongLongWx(unsigned long hi
, unsigned long lo
)
743 #ifdef wxLONGLONG_TEST_MODE
749 #endif // wxLONGLONG_TEST_MODE
752 // default copy ctor is ok in both cases
756 // assignment operators
758 wxULongLongWx
& operator=(unsigned long l
)
763 #ifdef wxLONGLONG_TEST_MODE
767 #endif // wxLONGLONG_TEST_MODE
772 // can't have assignment operator from 2 longs
776 unsigned long GetHi() const { return m_hi
; }
778 unsigned long GetLo() const { return m_lo
; }
780 // convert to long with range checking in the debug mode (only!)
781 unsigned long ToULong() const
783 wxASSERT_MSG( m_hi
== 0ul,
784 _T("wxULongLong to long conversion loss of precision") );
786 return (unsigned long)m_lo
;
791 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
792 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
793 wxULongLongWx
operator+(unsigned long l
) const;
794 wxULongLongWx
& operator+=(unsigned long l
);
796 // pre increment operator
797 wxULongLongWx
& operator++();
799 // post increment operator
800 wxULongLongWx
& operator++(int) { return ++(*this); }
802 // subraction (FIXME: should return wxLongLong)
803 wxULongLongWx
operator-(const wxULongLongWx
& ll
) const;
804 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
806 // pre decrement operator
807 wxULongLongWx
& operator--();
809 // post decrement operator
810 wxULongLongWx
& operator--(int) { return --(*this); }
814 wxULongLongWx
operator<<(int shift
) const;
815 wxULongLongWx
& operator<<=(int shift
);
818 wxULongLongWx
operator>>(int shift
) const;
819 wxULongLongWx
& operator>>=(int shift
);
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 wxULongLongWx
& ll
) const;
827 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
828 wxULongLongWx
operator~() const;
831 bool operator==(const wxULongLongWx
& ll
) const
832 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
833 bool operator!=(const wxULongLongWx
& ll
) const
834 { return !(*this == ll
); }
835 bool operator<(const wxULongLongWx
& ll
) const;
836 bool operator>(const wxULongLongWx
& ll
) const;
837 bool operator<=(const wxULongLongWx
& ll
) const
838 { return *this < ll
|| *this == ll
; }
839 bool operator>=(const wxULongLongWx
& ll
) const
840 { return *this > ll
|| *this == ll
; }
842 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
843 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
844 bool operator==(unsigned long l
) const
846 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
849 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
850 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
853 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
854 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
857 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
858 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
860 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
862 void Divide(const wxULongLongWx
& divisor
,
863 wxULongLongWx
& quotient
,
864 wxULongLongWx
& remainder
) const;
868 // return the string representation of this number
869 wxString
ToString() const;
871 void *asArray() const;
873 #if wxUSE_STD_IOSTREAM
874 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
875 #endif // wxUSE_STD_IOSTREAM
878 // long is at least 32 bits, so represent our 64bit number as 2 longs
883 #ifdef wxLONGLONG_TEST_MODE
886 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
889 unsigned wxLongLong_t m_ll
;
890 #endif // wxLONGLONG_TEST_MODE
893 #endif // wxUSE_LONGLONG_WX
895 // ----------------------------------------------------------------------------
897 // ----------------------------------------------------------------------------
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
; }
903 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
904 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
906 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
907 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
909 return wxLongLong(l
) - ll
;
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
; }
916 inline bool operator==(unsigned long l
, const wxULongLong
& ull
) { return ull
== l
; }
917 inline bool operator!=(unsigned long l
, const wxULongLong
& ull
) { return ull
!= l
; }
919 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
921 // FIXME: this should return wxLongLong
922 inline wxULongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
924 return wxULongLong(l
) - ull
;
927 #endif // _WX_LONGLONG_H