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
16 #if defined(__GNUG__) && !defined(__APPLE__)
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("I64")
64 #elif (defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG >= 8) || \
65 defined(__MINGW32__) || \
66 defined(__CYGWIN__) || \
67 defined(__WXMICROWIN__) || \
68 (defined(__DJGPP__) && __DJGPP__ >= 2)
69 #define wxLongLong_t long long
70 #define wxLongLongSuffix ll
71 #define wxLongLongFmtSpec _T("ll")
72 #elif defined(__MWERKS__)
73 #if __option(longlong)
74 #define wxLongLong_t long long
75 #define wxLongLongSuffix ll
76 #define wxLongLongFmtSpec _T("ll")
78 #error "The 64 bit integer support in CodeWarrior has been disabled."
79 #error "See the documentation on the 'longlong' pragma."
81 #elif defined(__VISAGECPP__) && __IBMCPP__ >= 400
82 #define wxLongLong_t long long
83 #else // no native long long type
84 // both warning and pragma warning are not portable, but at least an
85 // unknown pragma should never be an error -- except that, actually, some
86 // broken compilers don't like it, so we have to disable it in this case
88 #if !(defined(__WATCOMC__) || defined(__VISAGECPP__))
89 #pragma warning "Your compiler does not appear to support 64 bit "\
90 "integers, using emulation class instead.\n" \
91 "Please report your compiler version to " \
92 "wx-dev@lists.wxwindows.org!"
95 #define wxUSE_LONGLONG_WX 1
98 // this macro allows to definea 64 bit constant in a portable way
99 #define wxMakeLongLong(x, s) x ## s
100 #define wxMakeLongLong2(x, s) wxMakeLongLong(x, s)
101 #define wxLL(x) wxMakeLongLong2(x, wxLongLongSuffix)
103 // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
104 // to disable automatic testing (useful for the test program which defines
105 // both classes) but by default we only use one class
106 #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
107 // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
108 // this is useful in test programs and only there
109 #ifndef wxUSE_LONGLONG_NATIVE
110 #define wxUSE_LONGLONG_NATIVE 0
113 class WXDLLEXPORT wxLongLongWx
;
114 class WXDLLEXPORT wxULongLongWx
;
115 #if defined(__VISUALC__) && !defined(__WIN32__)
116 #define wxLongLong wxLongLongWx
117 #define wxULongLong wxULongLongWx
119 typedef wxLongLongWx wxLongLong
;
120 typedef wxULongLongWx wxULongLong
;
124 // if nothing is defined, use native implementation by default, of course
125 #ifndef wxUSE_LONGLONG_NATIVE
126 #define wxUSE_LONGLONG_NATIVE 1
130 #ifndef wxUSE_LONGLONG_WX
131 #define wxUSE_LONGLONG_WX 0
132 class WXDLLEXPORT wxLongLongNative
;
133 class WXDLLEXPORT wxULongLongNative
;
134 typedef wxLongLongNative wxLongLong
;
135 typedef wxULongLongNative wxULongLong
;
138 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
139 // typedef wxLongLong as it wants, we don't do it
141 // ----------------------------------------------------------------------------
142 // choose the appropriate class
143 // ----------------------------------------------------------------------------
145 // we use iostream for wxLongLong output
146 #include "wx/ioswrap.h"
148 #if wxUSE_LONGLONG_NATIVE
150 class WXDLLEXPORT wxLongLongNative
154 // default ctor initializes to 0
155 wxLongLongNative() : m_ll(0) { }
157 wxLongLongNative(wxLongLong_t ll
) : m_ll(ll
) { }
159 wxLongLongNative(long hi
, unsigned long lo
) : m_ll(0)
161 // assign first to avoid precision loss!
162 m_ll
= ((wxLongLong_t
) hi
) << 32;
163 m_ll
|= (wxLongLong_t
) lo
;
166 // default copy ctor is ok
170 // assignment operators
171 // from native 64 bit integer
172 wxLongLongNative
& operator=(wxLongLong_t ll
)
173 { m_ll
= ll
; return *this; }
175 // from double: this one has an explicit name because otherwise we
176 // would have ambiguity with "ll = int" and also because we don't want
177 // to have implicit conversions between doubles and wxLongLongs
178 wxLongLongNative
& Assign(double d
)
179 { m_ll
= (wxLongLong_t
)d
; return *this; }
181 // assignment operators from wxLongLongNative is ok
186 { return (long)(m_ll
>> 32); }
188 unsigned long GetLo() const
189 { return (unsigned long)m_ll
; }
191 // get absolute value
192 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
193 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
195 // convert to native long long
196 wxLongLong_t
GetValue() const { return m_ll
; }
198 // convert to long with range checking in the debug mode (only!)
201 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
202 _T("wxLongLong to long conversion loss of precision") );
207 // don't provide implicit conversion to wxLongLong_t or we will have an
208 // ambiguity for all arithmetic operations
209 //operator wxLongLong_t() const { return m_ll; }
213 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
214 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
215 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
216 { m_ll
+= ll
.m_ll
; return *this; }
218 wxLongLongNative
operator+(const wxLongLong_t ll
) const
219 { return wxLongLongNative(m_ll
+ ll
); }
220 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
221 { m_ll
+= ll
; return *this; }
224 wxLongLongNative
& operator++()
225 { m_ll
++; return *this; }
228 wxLongLongNative
operator++(int)
229 { wxLongLongNative
value(*this); m_ll
++; return value
; }
232 wxLongLongNative
operator-() const
233 { return wxLongLongNative(-m_ll
); }
234 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
237 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
238 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
239 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
240 { m_ll
-= ll
.m_ll
; return *this; }
242 wxLongLongNative
operator-(const wxLongLong_t ll
) const
243 { return wxLongLongNative(m_ll
- ll
); }
244 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
245 { m_ll
-= ll
; return *this; }
248 wxLongLongNative
& operator--()
249 { m_ll
--; return *this; }
252 wxLongLongNative
operator--(int)
253 { wxLongLongNative
value(*this); m_ll
--; return value
; }
257 wxLongLongNative
operator<<(int shift
) const
258 { return wxLongLongNative(m_ll
<< shift
);; }
259 wxLongLongNative
& operator<<=(int shift
)
260 { m_ll
<<= shift
; return *this; }
263 wxLongLongNative
operator>>(int shift
) const
264 { return wxLongLongNative(m_ll
>> shift
);; }
265 wxLongLongNative
& operator>>=(int shift
)
266 { m_ll
>>= shift
; return *this; }
269 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
270 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
271 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
272 { m_ll
&= ll
.m_ll
; return *this; }
274 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
275 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
276 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
277 { m_ll
|= ll
.m_ll
; return *this; }
279 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
280 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
281 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
282 { m_ll
^= ll
.m_ll
; return *this; }
284 // multiplication/division
285 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
286 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
287 wxLongLongNative
operator*(long l
) const
288 { return wxLongLongNative(m_ll
* l
); }
289 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
290 { m_ll
*= ll
.m_ll
; return *this; }
291 wxLongLongNative
& operator*=(long l
)
292 { m_ll
*= l
; return *this; }
294 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
295 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
296 wxLongLongNative
operator/(long l
) const
297 { return wxLongLongNative(m_ll
/ l
); }
298 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
299 { m_ll
/= ll
.m_ll
; return *this; }
300 wxLongLongNative
& operator/=(long l
)
301 { m_ll
/= l
; return *this; }
303 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
304 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
305 wxLongLongNative
operator%(long l
) const
306 { return wxLongLongNative(m_ll
% l
); }
309 bool operator==(const wxLongLongNative
& ll
) const
310 { return m_ll
== ll
.m_ll
; }
311 bool operator==(long l
) const
312 { return m_ll
== l
; }
313 bool operator!=(const wxLongLongNative
& ll
) const
314 { return m_ll
!= ll
.m_ll
; }
315 bool operator!=(long l
) const
316 { return m_ll
!= l
; }
317 bool operator<(const wxLongLongNative
& ll
) const
318 { return m_ll
< ll
.m_ll
; }
319 bool operator<(long l
) const
321 bool operator>(const wxLongLongNative
& ll
) const
322 { return m_ll
> ll
.m_ll
; }
323 bool operator>(long l
) const
325 bool operator<=(const wxLongLongNative
& ll
) const
326 { return m_ll
<= ll
.m_ll
; }
327 bool operator<=(long l
) const
328 { return m_ll
<= l
; }
329 bool operator>=(const wxLongLongNative
& ll
) const
330 { return m_ll
>= ll
.m_ll
; }
331 bool operator>=(long l
) const
332 { return m_ll
>= l
; }
336 // return the string representation of this number
337 wxString
ToString() const;
339 // conversion to byte array: returns a pointer to static buffer!
340 void *asArray() const;
342 #if wxUSE_STD_IOSTREAM
344 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
352 class WXDLLEXPORT wxULongLongNative
356 // default ctor initializes to 0
357 wxULongLongNative() : m_ll(0) { }
359 wxULongLongNative(unsigned wxLongLong_t ll
) : m_ll(ll
) { }
361 wxULongLongNative(unsigned long hi
, unsigned long lo
) : m_ll(0)
363 // assign first to avoid precision loss!
364 m_ll
= ((unsigned wxLongLong_t
) hi
) << 32;
365 m_ll
|= (unsigned wxLongLong_t
) lo
;
368 // default copy ctor is ok
372 // assignment operators
373 // from native 64 bit integer
374 wxULongLongNative
& operator=(unsigned wxLongLong_t ll
)
375 { m_ll
= ll
; return *this; }
377 // assignment operators from wxULongLongNative is ok
381 unsigned long GetHi() const
382 { return (unsigned long)(m_ll
>> 32); }
384 unsigned long GetLo() const
385 { return (unsigned long)m_ll
; }
387 // convert to native ulong long
388 unsigned wxLongLong_t
GetValue() const { return m_ll
; }
390 // convert to ulong with range checking in the debug mode (only!)
391 unsigned long ToULong() const
393 wxASSERT_MSG( m_ll
<= LONG_MAX
,
394 _T("wxULongLong to long conversion loss of precision") );
396 return (unsigned long)m_ll
;
401 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
402 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
403 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
404 { m_ll
+= ll
.m_ll
; return *this; }
406 wxULongLongNative
operator+(const unsigned wxLongLong_t ll
) const
407 { return wxULongLongNative(m_ll
+ ll
); }
408 wxULongLongNative
& operator+=(const unsigned wxLongLong_t ll
)
409 { m_ll
+= ll
; return *this; }
412 wxULongLongNative
& operator++()
413 { m_ll
++; return *this; }
416 wxULongLongNative
operator++(int)
417 { wxULongLongNative
value(*this); m_ll
++; return value
; }
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 unsigned wxLongLong_t ll
) const
426 { return wxULongLongNative(m_ll
- ll
); }
427 wxULongLongNative
& operator-=(const unsigned wxLongLong_t ll
)
428 { m_ll
-= ll
; return *this; }
431 wxULongLongNative
& operator--()
432 { m_ll
--; return *this; }
435 wxULongLongNative
operator--(int)
436 { wxULongLongNative
value(*this); m_ll
--; return value
; }
440 wxULongLongNative
operator<<(int shift
) const
441 { return wxULongLongNative(m_ll
<< shift
);; }
442 wxULongLongNative
& operator<<=(int shift
)
443 { m_ll
<<= shift
; return *this; }
446 wxULongLongNative
operator>>(int shift
) const
447 { return wxULongLongNative(m_ll
>> shift
);; }
448 wxULongLongNative
& operator>>=(int shift
)
449 { m_ll
>>= shift
; return *this; }
452 wxULongLongNative
operator&(const wxULongLongNative
& ll
) const
453 { return wxULongLongNative(m_ll
& ll
.m_ll
); }
454 wxULongLongNative
& operator&=(const wxULongLongNative
& ll
)
455 { m_ll
&= ll
.m_ll
; return *this; }
457 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
458 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
459 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
460 { m_ll
|= ll
.m_ll
; return *this; }
462 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
463 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
464 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
465 { m_ll
^= ll
.m_ll
; return *this; }
467 // multiplication/division
468 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
469 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
470 wxULongLongNative
operator*(unsigned long l
) const
471 { return wxULongLongNative(m_ll
* l
); }
472 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
473 { m_ll
*= ll
.m_ll
; return *this; }
474 wxULongLongNative
& operator*=(unsigned long l
)
475 { m_ll
*= l
; return *this; }
477 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
478 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
479 wxULongLongNative
operator/(unsigned long l
) const
480 { return wxULongLongNative(m_ll
/ l
); }
481 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
482 { m_ll
/= ll
.m_ll
; return *this; }
483 wxULongLongNative
& operator/=(unsigned long l
)
484 { m_ll
/= l
; return *this; }
486 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
487 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
488 wxULongLongNative
operator%(unsigned long l
) const
489 { return wxULongLongNative(m_ll
% l
); }
492 bool operator==(const wxULongLongNative
& ll
) const
493 { return m_ll
== ll
.m_ll
; }
494 bool operator==(unsigned long l
) const
495 { return m_ll
== l
; }
496 bool operator!=(const wxULongLongNative
& ll
) const
497 { return m_ll
!= ll
.m_ll
; }
498 bool operator!=(unsigned long l
) const
499 { return m_ll
!= l
; }
500 bool operator<(const wxULongLongNative
& ll
) const
501 { return m_ll
< ll
.m_ll
; }
502 bool operator<(unsigned long l
) const
504 bool operator>(const wxULongLongNative
& ll
) const
505 { return m_ll
> ll
.m_ll
; }
506 bool operator>(unsigned long l
) const
508 bool operator<=(const wxULongLongNative
& ll
) const
509 { return m_ll
<= ll
.m_ll
; }
510 bool operator<=(unsigned long l
) const
511 { return m_ll
<= l
; }
512 bool operator>=(const wxULongLongNative
& ll
) const
513 { return m_ll
>= ll
.m_ll
; }
514 bool operator>=(unsigned long l
) const
515 { return m_ll
>= l
; }
519 // return the string representation of this number
520 wxString
ToString() const;
522 // conversion to byte array: returns a pointer to static buffer!
523 void *asArray() const;
525 #if wxUSE_STD_IOSTREAM
527 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
531 unsigned wxLongLong_t m_ll
;
534 #endif // wxUSE_LONGLONG_NATIVE
536 #if wxUSE_LONGLONG_WX
538 class WXDLLEXPORT wxLongLongWx
542 // default ctor initializes to 0
547 #ifdef wxLONGLONG_TEST_MODE
551 #endif // wxLONGLONG_TEST_MODE
554 wxLongLongWx(long l
) { *this = l
; }
556 wxLongLongWx(long hi
, unsigned long lo
)
561 #ifdef wxLONGLONG_TEST_MODE
567 #endif // wxLONGLONG_TEST_MODE
570 // default copy ctor is ok in both cases
574 // assignment operators
576 wxLongLongWx
& operator=(long l
)
579 m_hi
= (l
< 0 ? -1l : 0l);
581 #ifdef wxLONGLONG_TEST_MODE
585 #endif // wxLONGLONG_TEST_MODE
590 wxLongLongWx
& Assign(double d
);
591 // can't have assignment operator from 2 longs
595 long GetHi() const { return m_hi
; }
597 unsigned long GetLo() const { return m_lo
; }
599 // get absolute value
600 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
606 #ifdef wxLONGLONG_TEST_MODE
611 #endif // wxLONGLONG_TEST_MODE
616 // convert to long with range checking in the debug mode (only!)
619 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
620 _T("wxLongLong to long conversion loss of precision") );
627 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
628 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
629 wxLongLongWx
operator+(long l
) const;
630 wxLongLongWx
& operator+=(long l
);
632 // pre increment operator
633 wxLongLongWx
& operator++();
635 // post increment operator
636 wxLongLongWx
& operator++(int) { return ++(*this); }
639 wxLongLongWx
operator-() const;
640 wxLongLongWx
& Negate();
643 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
644 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
646 // pre decrement operator
647 wxLongLongWx
& operator--();
649 // post decrement operator
650 wxLongLongWx
& operator--(int) { return --(*this); }
654 wxLongLongWx
operator<<(int shift
) const;
655 wxLongLongWx
& operator<<=(int shift
);
658 wxLongLongWx
operator>>(int shift
) const;
659 wxLongLongWx
& operator>>=(int shift
);
662 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
663 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
664 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
665 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
666 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
667 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
668 wxLongLongWx
operator~() const;
671 bool operator==(const wxLongLongWx
& ll
) const
672 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
673 bool operator!=(const wxLongLongWx
& ll
) const
674 { return !(*this == ll
); }
675 bool operator<(const wxLongLongWx
& ll
) const;
676 bool operator>(const wxLongLongWx
& ll
) const;
677 bool operator<=(const wxLongLongWx
& ll
) const
678 { return *this < ll
|| *this == ll
; }
679 bool operator>=(const wxLongLongWx
& ll
) const
680 { return *this > ll
|| *this == ll
; }
682 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
683 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
684 bool operator==(long l
) const
686 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
687 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
690 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
691 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
694 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
695 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
698 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
699 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
701 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
703 void Divide(const wxLongLongWx
& divisor
,
704 wxLongLongWx
& quotient
,
705 wxLongLongWx
& remainder
) const;
709 // return the string representation of this number
710 wxString
ToString() const;
712 void *asArray() const;
714 #if wxUSE_STD_IOSTREAM
715 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
716 #endif // wxUSE_STD_IOSTREAM
719 // long is at least 32 bits, so represent our 64bit number as 2 longs
721 long m_hi
; // signed bit is in the high part
724 #ifdef wxLONGLONG_TEST_MODE
727 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
731 #endif // wxLONGLONG_TEST_MODE
735 class WXDLLEXPORT wxULongLongWx
739 // default ctor initializes to 0
744 #ifdef wxLONGLONG_TEST_MODE
748 #endif // wxLONGLONG_TEST_MODE
751 wxULongLongWx(unsigned long l
) { *this = l
; }
753 wxULongLongWx(unsigned long hi
, unsigned long lo
)
758 #ifdef wxLONGLONG_TEST_MODE
764 #endif // wxLONGLONG_TEST_MODE
767 // default copy ctor is ok in both cases
771 // assignment operators
773 wxULongLongWx
& operator=(unsigned long l
)
778 #ifdef wxLONGLONG_TEST_MODE
782 #endif // wxLONGLONG_TEST_MODE
787 // can't have assignment operator from 2 longs
791 unsigned long GetHi() const { return m_hi
; }
793 unsigned long GetLo() const { return m_lo
; }
795 // convert to long with range checking in the debug mode (only!)
796 unsigned long ToULong() const
798 wxASSERT_MSG( m_hi
== 0ul,
799 _T("wxULongLong to long conversion loss of precision") );
801 return (unsigned long)m_lo
;
806 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
807 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
808 wxULongLongWx
operator+(unsigned long l
) const;
809 wxULongLongWx
& operator+=(unsigned long l
);
811 // pre increment operator
812 wxULongLongWx
& operator++();
814 // post increment operator
815 wxULongLongWx
& operator++(int) { return ++(*this); }
817 // subraction (FIXME: should return wxLongLong)
818 wxULongLongWx
operator-(const wxULongLongWx
& ll
) const;
819 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
821 // pre decrement operator
822 wxULongLongWx
& operator--();
824 // post decrement operator
825 wxULongLongWx
& operator--(int) { return --(*this); }
829 wxULongLongWx
operator<<(int shift
) const;
830 wxULongLongWx
& operator<<=(int shift
);
833 wxULongLongWx
operator>>(int shift
) const;
834 wxULongLongWx
& operator>>=(int shift
);
837 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
838 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
839 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
840 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
841 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
842 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
843 wxULongLongWx
operator~() const;
846 bool operator==(const wxULongLongWx
& ll
) const
847 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
848 bool operator!=(const wxULongLongWx
& ll
) const
849 { return !(*this == ll
); }
850 bool operator<(const wxULongLongWx
& ll
) const;
851 bool operator>(const wxULongLongWx
& ll
) const;
852 bool operator<=(const wxULongLongWx
& ll
) const
853 { return *this < ll
|| *this == ll
; }
854 bool operator>=(const wxULongLongWx
& ll
) const
855 { return *this > ll
|| *this == ll
; }
857 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
858 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
859 bool operator==(unsigned long l
) const
861 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
864 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
865 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
868 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
869 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
872 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
873 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
875 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
877 void Divide(const wxULongLongWx
& divisor
,
878 wxULongLongWx
& quotient
,
879 wxULongLongWx
& remainder
) const;
883 // return the string representation of this number
884 wxString
ToString() const;
886 void *asArray() const;
888 #if wxUSE_STD_IOSTREAM
889 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
890 #endif // wxUSE_STD_IOSTREAM
893 // long is at least 32 bits, so represent our 64bit number as 2 longs
898 #ifdef wxLONGLONG_TEST_MODE
901 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
904 unsigned wxLongLong_t m_ll
;
905 #endif // wxLONGLONG_TEST_MODE
908 #endif // wxUSE_LONGLONG_WX
910 // ----------------------------------------------------------------------------
912 // ----------------------------------------------------------------------------
914 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
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
; }
921 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
922 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
924 return wxLongLong(l
) - ll
;
927 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
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
; }
934 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
936 // FIXME: this should return wxLongLong
937 inline wxULongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
939 return wxULongLong(l
) - ull
;
942 #endif // _WX_LONGLONG_H