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 // ----------------------------------------------------------------------------
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 wxLongLongSuffix l
54 #define wxLongLongFmtSpec _T("l")
55 #define wxLongLongIsLong
56 #elif (defined(__VISUALC__) && defined(__WIN32__)) || defined( __VMS__ )
57 #define wxLongLong_t __int64
58 #define wxLongLongSuffix i64
59 #define wxLongLongFmtSpec _T("I64")
60 #elif defined(__BORLANDC__) && defined(__WIN32__) && (__BORLANDC__ >= 0x520)
61 #define wxLongLong_t __int64
62 #define wxLongLongSuffix i64
63 #define wxLongLongFmtSpec _T("Ld")
64 #elif (defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG >= 8) || \
65 defined(__MINGW32__) || \
66 defined(__GNUC__) || \
67 defined(__CYGWIN__) || \
68 defined(__WXMICROWIN__) || \
69 (defined(__DJGPP__) && __DJGPP__ >= 2)
70 #define wxLongLong_t long long
71 #define wxLongLongSuffix ll
72 #define wxLongLongFmtSpec _T("ll")
73 #elif defined(__MWERKS__)
74 #if __option(longlong)
75 #define wxLongLong_t long long
76 #define wxLongLongSuffix ll
77 #define wxLongLongFmtSpec _T("ll")
79 #error "The 64 bit integer support in CodeWarrior has been disabled."
80 #error "See the documentation on the 'longlong' pragma."
82 #elif defined(__VISAGECPP__) && __IBMCPP__ >= 400
83 #define wxLongLong_t long long
84 #else // no native long long type
85 // both warning and pragma warning are not portable, but at least an
86 // unknown pragma should never be an error -- except that, actually, some
87 // broken compilers don't like it, so we have to disable it in this case
89 #if !(defined(__WATCOMC__) || defined(__VISAGECPP__))
90 #pragma warning "Your compiler does not appear to support 64 bit "\
91 "integers, using emulation class instead.\n" \
92 "Please report your compiler version to " \
93 "wx-dev@lists.wxwindows.org!"
96 #define wxUSE_LONGLONG_WX 1
99 // this macro allows to definea 64 bit constant in a portable way
100 #define wxMakeLongLong(x, s) x ## s
101 #define wxMakeLongLong2(x, s) wxMakeLongLong(x, s)
102 #define wxLL(x) wxMakeLongLong2(x, wxLongLongSuffix)
104 // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
105 // to disable automatic testing (useful for the test program which defines
106 // both classes) but by default we only use one class
107 #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
108 // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
109 // this is useful in test programs and only there
110 #ifndef wxUSE_LONGLONG_NATIVE
111 #define wxUSE_LONGLONG_NATIVE 0
114 class WXDLLIMPEXP_BASE wxLongLongWx
;
115 class WXDLLIMPEXP_BASE wxULongLongWx
;
116 #if defined(__VISUALC__) && !defined(__WIN32__)
117 #define wxLongLong wxLongLongWx
118 #define wxULongLong wxULongLongWx
120 typedef wxLongLongWx wxLongLong
;
121 typedef wxULongLongWx wxULongLong
;
125 // if nothing is defined, use native implementation by default, of course
126 #ifndef wxUSE_LONGLONG_NATIVE
127 #define wxUSE_LONGLONG_NATIVE 1
131 #ifndef wxUSE_LONGLONG_WX
132 #define wxUSE_LONGLONG_WX 0
133 class WXDLLIMPEXP_BASE wxLongLongNative
;
134 class WXDLLIMPEXP_BASE wxULongLongNative
;
135 typedef wxLongLongNative wxLongLong
;
136 typedef wxULongLongNative wxULongLong
;
139 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
140 // typedef wxLongLong as it wants, we don't do it
142 // ----------------------------------------------------------------------------
143 // choose the appropriate class
144 // ----------------------------------------------------------------------------
146 // we use iostream for wxLongLong output
147 #include "wx/iosfwrap.h"
149 #if wxUSE_LONGLONG_NATIVE
151 class WXDLLIMPEXP_BASE wxLongLongNative
155 // default ctor initializes to 0
156 wxLongLongNative() : m_ll(0) { }
158 wxLongLongNative(wxLongLong_t ll
) : m_ll(ll
) { }
160 wxLongLongNative(long hi
, unsigned long lo
) : m_ll(0)
162 // assign first to avoid precision loss!
163 m_ll
= ((wxLongLong_t
) hi
) << 32;
164 m_ll
|= (wxLongLong_t
) lo
;
167 // default copy ctor is ok
171 // assignment operators
172 // from native 64 bit integer
173 wxLongLongNative
& operator=(wxLongLong_t ll
)
174 { m_ll
= ll
; return *this; }
176 // from double: this one has an explicit name because otherwise we
177 // would have ambiguity with "ll = int" and also because we don't want
178 // to have implicit conversions between doubles and wxLongLongs
179 wxLongLongNative
& Assign(double d
)
180 { m_ll
= (wxLongLong_t
)d
; return *this; }
182 // assignment operators from wxLongLongNative is ok
187 { return (long)(m_ll
>> 32); }
189 unsigned long GetLo() const
190 { return (unsigned long)m_ll
; }
192 // get absolute value
193 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
194 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
196 // convert to native long long
197 wxLongLong_t
GetValue() const { return m_ll
; }
199 // convert to long with range checking in the debug mode (only!)
202 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
203 _T("wxLongLong to long conversion loss of precision") );
208 // don't provide implicit conversion to wxLongLong_t or we will have an
209 // ambiguity for all arithmetic operations
210 //operator wxLongLong_t() const { return m_ll; }
214 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
215 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
216 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
217 { m_ll
+= ll
.m_ll
; return *this; }
219 wxLongLongNative
operator+(const wxLongLong_t ll
) const
220 { return wxLongLongNative(m_ll
+ ll
); }
221 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
222 { m_ll
+= ll
; return *this; }
225 wxLongLongNative
& operator++()
226 { m_ll
++; return *this; }
229 wxLongLongNative
operator++(int)
230 { wxLongLongNative
value(*this); m_ll
++; return value
; }
233 wxLongLongNative
operator-() const
234 { return wxLongLongNative(-m_ll
); }
235 wxLongLongNative
& Negate() { m_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 wxLongLongNative
operator-(const wxLongLong_t ll
) const
244 { return wxLongLongNative(m_ll
- ll
); }
245 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
246 { m_ll
-= ll
; return *this; }
249 wxLongLongNative
& operator--()
250 { m_ll
--; return *this; }
253 wxLongLongNative
operator--(int)
254 { wxLongLongNative
value(*this); m_ll
--; return value
; }
258 wxLongLongNative
operator<<(int shift
) const
259 { return wxLongLongNative(m_ll
<< shift
);; }
260 wxLongLongNative
& operator<<=(int shift
)
261 { m_ll
<<= shift
; return *this; }
264 wxLongLongNative
operator>>(int shift
) const
265 { return wxLongLongNative(m_ll
>> shift
);; }
266 wxLongLongNative
& operator>>=(int shift
)
267 { m_ll
>>= shift
; return *this; }
270 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
271 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
272 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
273 { m_ll
&= ll
.m_ll
; return *this; }
275 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
276 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
277 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
278 { m_ll
|= ll
.m_ll
; return *this; }
280 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
281 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
282 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
283 { m_ll
^= ll
.m_ll
; return *this; }
285 // multiplication/division
286 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
287 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
288 wxLongLongNative
operator*(long l
) const
289 { return wxLongLongNative(m_ll
* l
); }
290 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
291 { m_ll
*= ll
.m_ll
; return *this; }
292 wxLongLongNative
& operator*=(long l
)
293 { m_ll
*= l
; return *this; }
295 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
296 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
297 wxLongLongNative
operator/(long l
) const
298 { return wxLongLongNative(m_ll
/ l
); }
299 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
300 { m_ll
/= ll
.m_ll
; return *this; }
301 wxLongLongNative
& operator/=(long l
)
302 { m_ll
/= l
; return *this; }
304 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
305 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
306 wxLongLongNative
operator%(long l
) const
307 { return wxLongLongNative(m_ll
% l
); }
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
; }
318 bool operator<(const wxLongLongNative
& ll
) const
319 { return m_ll
< ll
.m_ll
; }
320 bool operator<(long l
) const
322 bool operator>(const wxLongLongNative
& ll
) const
323 { return m_ll
> ll
.m_ll
; }
324 bool operator>(long l
) const
326 bool operator<=(const wxLongLongNative
& ll
) const
327 { return m_ll
<= ll
.m_ll
; }
328 bool operator<=(long l
) const
329 { return m_ll
<= l
; }
330 bool operator>=(const wxLongLongNative
& ll
) const
331 { return m_ll
>= ll
.m_ll
; }
332 bool operator>=(long l
) const
333 { return m_ll
>= l
; }
337 // return the string representation of this number
338 wxString
ToString() const;
340 // conversion to byte array: returns a pointer to static buffer!
341 void *asArray() const;
343 #if wxUSE_STD_IOSTREAM
345 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
353 class WXDLLIMPEXP_BASE wxULongLongNative
357 // default ctor initializes to 0
358 wxULongLongNative() : m_ll(0) { }
360 wxULongLongNative(unsigned wxLongLong_t ll
) : m_ll(ll
) { }
362 wxULongLongNative(unsigned long hi
, unsigned long lo
) : m_ll(0)
364 // assign first to avoid precision loss!
365 m_ll
= ((unsigned wxLongLong_t
) hi
) << 32;
366 m_ll
|= (unsigned wxLongLong_t
) lo
;
369 // default copy ctor is ok
373 // assignment operators
374 // from native 64 bit integer
375 wxULongLongNative
& operator=(unsigned wxLongLong_t ll
)
376 { m_ll
= ll
; return *this; }
378 // assignment operators from wxULongLongNative is ok
382 unsigned long GetHi() const
383 { return (unsigned long)(m_ll
>> 32); }
385 unsigned long GetLo() const
386 { return (unsigned long)m_ll
; }
388 // convert to native ulong long
389 unsigned wxLongLong_t
GetValue() const { return m_ll
; }
391 // convert to ulong with range checking in the debug mode (only!)
392 unsigned long ToULong() const
394 wxASSERT_MSG( m_ll
<= LONG_MAX
,
395 _T("wxULongLong to long conversion loss of precision") );
397 return (unsigned long)m_ll
;
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 { wxULongLongNative
value(*this); m_ll
++; return value
; }
421 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
422 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
423 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
424 { m_ll
-= ll
.m_ll
; return *this; }
426 wxULongLongNative
operator-(const unsigned wxLongLong_t ll
) const
427 { return wxULongLongNative(m_ll
- ll
); }
428 wxULongLongNative
& operator-=(const unsigned wxLongLong_t ll
)
429 { m_ll
-= ll
; return *this; }
432 wxULongLongNative
& operator--()
433 { m_ll
--; return *this; }
436 wxULongLongNative
operator--(int)
437 { wxULongLongNative
value(*this); m_ll
--; return value
; }
441 wxULongLongNative
operator<<(int shift
) const
442 { return wxULongLongNative(m_ll
<< shift
);; }
443 wxULongLongNative
& operator<<=(int shift
)
444 { m_ll
<<= shift
; return *this; }
447 wxULongLongNative
operator>>(int shift
) const
448 { return wxULongLongNative(m_ll
>> shift
);; }
449 wxULongLongNative
& operator>>=(int shift
)
450 { m_ll
>>= shift
; return *this; }
453 wxULongLongNative
operator&(const wxULongLongNative
& ll
) const
454 { return wxULongLongNative(m_ll
& ll
.m_ll
); }
455 wxULongLongNative
& operator&=(const wxULongLongNative
& ll
)
456 { m_ll
&= ll
.m_ll
; return *this; }
458 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
459 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
460 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
461 { m_ll
|= ll
.m_ll
; return *this; }
463 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
464 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
465 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
466 { m_ll
^= ll
.m_ll
; return *this; }
468 // multiplication/division
469 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
470 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
471 wxULongLongNative
operator*(unsigned long l
) const
472 { return wxULongLongNative(m_ll
* l
); }
473 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
474 { m_ll
*= ll
.m_ll
; return *this; }
475 wxULongLongNative
& operator*=(unsigned long l
)
476 { m_ll
*= l
; return *this; }
478 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
479 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
480 wxULongLongNative
operator/(unsigned long l
) const
481 { return wxULongLongNative(m_ll
/ l
); }
482 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
483 { m_ll
/= ll
.m_ll
; return *this; }
484 wxULongLongNative
& operator/=(unsigned long l
)
485 { m_ll
/= l
; return *this; }
487 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
488 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
489 wxULongLongNative
operator%(unsigned long l
) const
490 { return wxULongLongNative(m_ll
% l
); }
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
; }
501 bool operator<(const wxULongLongNative
& ll
) const
502 { return m_ll
< ll
.m_ll
; }
503 bool operator<(unsigned long l
) const
505 bool operator>(const wxULongLongNative
& ll
) const
506 { return m_ll
> ll
.m_ll
; }
507 bool operator>(unsigned long l
) const
509 bool operator<=(const wxULongLongNative
& ll
) const
510 { return m_ll
<= ll
.m_ll
; }
511 bool operator<=(unsigned long l
) const
512 { return m_ll
<= l
; }
513 bool operator>=(const wxULongLongNative
& ll
) const
514 { return m_ll
>= ll
.m_ll
; }
515 bool operator>=(unsigned long l
) const
516 { return m_ll
>= l
; }
520 // return the string representation of this number
521 wxString
ToString() const;
523 // conversion to byte array: returns a pointer to static buffer!
524 void *asArray() const;
526 #if wxUSE_STD_IOSTREAM
528 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
532 unsigned wxLongLong_t m_ll
;
535 #endif // wxUSE_LONGLONG_NATIVE
537 #if wxUSE_LONGLONG_WX
539 class WXDLLIMPEXP_BASE wxLongLongWx
543 // default ctor initializes to 0
548 #ifdef wxLONGLONG_TEST_MODE
552 #endif // wxLONGLONG_TEST_MODE
555 wxLongLongWx(long l
) { *this = l
; }
557 wxLongLongWx(long hi
, unsigned long lo
)
562 #ifdef wxLONGLONG_TEST_MODE
568 #endif // wxLONGLONG_TEST_MODE
571 // default copy ctor is ok in both cases
575 // assignment operators
577 wxLongLongWx
& operator=(long l
)
580 m_hi
= (l
< 0 ? -1l : 0l);
582 #ifdef wxLONGLONG_TEST_MODE
586 #endif // wxLONGLONG_TEST_MODE
591 wxLongLongWx
& Assign(double d
);
592 // can't have assignment operator from 2 longs
596 long GetHi() const { return m_hi
; }
598 unsigned long GetLo() const { return m_lo
; }
600 // get absolute value
601 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
607 #ifdef wxLONGLONG_TEST_MODE
612 #endif // wxLONGLONG_TEST_MODE
617 // convert to long with range checking in the debug mode (only!)
620 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
621 _T("wxLongLong to long conversion loss of precision") );
628 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
629 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
630 wxLongLongWx
operator+(long l
) const;
631 wxLongLongWx
& operator+=(long l
);
633 // pre increment operator
634 wxLongLongWx
& operator++();
636 // post increment operator
637 wxLongLongWx
& operator++(int) { return ++(*this); }
640 wxLongLongWx
operator-() const;
641 wxLongLongWx
& Negate();
644 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
645 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
647 // pre decrement operator
648 wxLongLongWx
& operator--();
650 // post decrement operator
651 wxLongLongWx
& operator--(int) { return --(*this); }
655 wxLongLongWx
operator<<(int shift
) const;
656 wxLongLongWx
& operator<<=(int shift
);
659 wxLongLongWx
operator>>(int shift
) const;
660 wxLongLongWx
& operator>>=(int shift
);
663 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
664 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
665 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
666 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
667 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
668 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
669 wxLongLongWx
operator~() const;
672 bool operator==(const wxLongLongWx
& ll
) const
673 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
674 bool operator!=(const wxLongLongWx
& ll
) const
675 { return !(*this == ll
); }
676 bool operator<(const wxLongLongWx
& ll
) const;
677 bool operator>(const wxLongLongWx
& ll
) const;
678 bool operator<=(const wxLongLongWx
& ll
) const
679 { return *this < ll
|| *this == ll
; }
680 bool operator>=(const wxLongLongWx
& ll
) const
681 { return *this > ll
|| *this == ll
; }
683 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
684 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
685 bool operator==(long l
) const
687 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
688 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
691 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
692 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
695 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
696 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
699 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
700 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
702 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
704 void Divide(const wxLongLongWx
& divisor
,
705 wxLongLongWx
& quotient
,
706 wxLongLongWx
& remainder
) const;
710 // return the string representation of this number
711 wxString
ToString() const;
713 void *asArray() const;
715 #if wxUSE_STD_IOSTREAM
716 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
717 #endif // wxUSE_STD_IOSTREAM
720 // long is at least 32 bits, so represent our 64bit number as 2 longs
722 long m_hi
; // signed bit is in the high part
725 #ifdef wxLONGLONG_TEST_MODE
728 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
732 #endif // wxLONGLONG_TEST_MODE
736 class WXDLLIMPEXP_BASE wxULongLongWx
740 // default ctor initializes to 0
745 #ifdef wxLONGLONG_TEST_MODE
749 #endif // wxLONGLONG_TEST_MODE
752 wxULongLongWx(unsigned long l
) { *this = l
; }
754 wxULongLongWx(unsigned long hi
, unsigned long lo
)
759 #ifdef wxLONGLONG_TEST_MODE
765 #endif // wxLONGLONG_TEST_MODE
768 // default copy ctor is ok in both cases
772 // assignment operators
774 wxULongLongWx
& operator=(unsigned long l
)
779 #ifdef wxLONGLONG_TEST_MODE
783 #endif // wxLONGLONG_TEST_MODE
788 // can't have assignment operator from 2 longs
792 unsigned long GetHi() const { return m_hi
; }
794 unsigned long GetLo() const { return m_lo
; }
796 // convert to long with range checking in the debug mode (only!)
797 unsigned long ToULong() const
799 wxASSERT_MSG( m_hi
== 0ul,
800 _T("wxULongLong to long conversion loss of precision") );
802 return (unsigned long)m_lo
;
807 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
808 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
809 wxULongLongWx
operator+(unsigned long l
) const;
810 wxULongLongWx
& operator+=(unsigned long l
);
812 // pre increment operator
813 wxULongLongWx
& operator++();
815 // post increment operator
816 wxULongLongWx
& operator++(int) { return ++(*this); }
818 // subraction (FIXME: should return wxLongLong)
819 wxULongLongWx
operator-(const wxULongLongWx
& ll
) const;
820 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
822 // pre decrement operator
823 wxULongLongWx
& operator--();
825 // post decrement operator
826 wxULongLongWx
& operator--(int) { return --(*this); }
830 wxULongLongWx
operator<<(int shift
) const;
831 wxULongLongWx
& operator<<=(int shift
);
834 wxULongLongWx
operator>>(int shift
) const;
835 wxULongLongWx
& operator>>=(int shift
);
838 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
839 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
840 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
841 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
842 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
843 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
844 wxULongLongWx
operator~() const;
847 bool operator==(const wxULongLongWx
& ll
) const
848 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
849 bool operator!=(const wxULongLongWx
& ll
) const
850 { return !(*this == ll
); }
851 bool operator<(const wxULongLongWx
& ll
) const;
852 bool operator>(const wxULongLongWx
& ll
) const;
853 bool operator<=(const wxULongLongWx
& ll
) const
854 { return *this < ll
|| *this == ll
; }
855 bool operator>=(const wxULongLongWx
& ll
) const
856 { return *this > ll
|| *this == ll
; }
858 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
859 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
860 bool operator==(unsigned long l
) const
862 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
865 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
866 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
869 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
870 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
873 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
874 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
876 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
878 void Divide(const wxULongLongWx
& divisor
,
879 wxULongLongWx
& quotient
,
880 wxULongLongWx
& remainder
) const;
884 // return the string representation of this number
885 wxString
ToString() const;
887 void *asArray() const;
889 #if wxUSE_STD_IOSTREAM
890 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
891 #endif // wxUSE_STD_IOSTREAM
894 // long is at least 32 bits, so represent our 64bit number as 2 longs
899 #ifdef wxLONGLONG_TEST_MODE
902 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
905 unsigned wxLongLong_t m_ll
;
906 #endif // wxLONGLONG_TEST_MODE
909 #endif // wxUSE_LONGLONG_WX
911 // ----------------------------------------------------------------------------
913 // ----------------------------------------------------------------------------
915 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
916 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
< l
; }
917 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
>= l
; }
918 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
<= l
; }
919 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
920 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
922 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
923 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
925 return wxLongLong(l
) - ll
;
928 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
929 inline bool operator>(unsigned long l
, const wxULongLong
& ull
) { return ull
< l
; }
930 inline bool operator<=(unsigned long l
, const wxULongLong
& ull
) { return ull
>= l
; }
931 inline bool operator>=(unsigned long l
, const wxULongLong
& ull
) { return ull
<= l
; }
932 inline bool operator==(unsigned long l
, const wxULongLong
& ull
) { return ull
== l
; }
933 inline bool operator!=(unsigned long l
, const wxULongLong
& ull
) { return ull
!= l
; }
935 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
937 // FIXME: this should return wxLongLong
938 inline wxULongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
940 return wxULongLong(l
) - ull
;
943 #endif // _WX_LONGLONG_H