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
20 #include "wx/string.h"
22 #include <limits.h> // for LONG_MAX
24 // define this to compile wxLongLongWx in "test" mode: the results of all
25 // calculations will be compared with the real results taken from
26 // wxLongLongNative -- this is extremely useful to find the bugs in
27 // wxLongLongWx class!
29 // #define wxLONGLONG_TEST_MODE
31 #ifdef wxLONGLONG_TEST_MODE
32 #define wxUSE_LONGLONG_WX 1
33 #define wxUSE_LONGLONG_NATIVE 1
34 #endif // wxLONGLONG_TEST_MODE
36 // ----------------------------------------------------------------------------
37 // decide upon which class we will use
38 // ----------------------------------------------------------------------------
41 // both warning and pragma warning are not portable, but at least an
42 // unknown pragma should never be an error -- except that, actually, some
43 // broken compilers don't like it, so we have to disable it in this case
46 #warning "Your compiler does not appear to support 64 bit "\
47 "integers, using emulation class instead.\n" \
48 "Please report your compiler version to " \
49 "wx-dev@lists.wxwidgets.org!"
50 #elif !(defined(__WATCOMC__) || defined(__VISAGECPP__))
51 #pragma warning "Your compiler does not appear to support 64 bit "\
52 "integers, using emulation class instead.\n" \
53 "Please report your compiler version to " \
54 "wx-dev@lists.wxwidgets.org!"
57 #define wxUSE_LONGLONG_WX 1
60 // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
61 // to disable automatic testing (useful for the test program which defines
62 // both classes) but by default we only use one class
63 #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
64 // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
65 // this is useful in test programs and only there
66 #ifndef wxUSE_LONGLONG_NATIVE
67 #define wxUSE_LONGLONG_NATIVE 0
70 class WXDLLIMPEXP_BASE wxLongLongWx
;
71 class WXDLLIMPEXP_BASE wxULongLongWx
;
72 #if defined(__VISUALC__) && !defined(__WIN32__)
73 #define wxLongLong wxLongLongWx
74 #define wxULongLong wxULongLongWx
76 typedef wxLongLongWx wxLongLong
;
77 typedef wxULongLongWx wxULongLong
;
81 // if nothing is defined, use native implementation by default, of course
82 #ifndef wxUSE_LONGLONG_NATIVE
83 #define wxUSE_LONGLONG_NATIVE 1
87 #ifndef wxUSE_LONGLONG_WX
88 #define wxUSE_LONGLONG_WX 0
89 class WXDLLIMPEXP_BASE wxLongLongNative
;
90 class WXDLLIMPEXP_BASE wxULongLongNative
;
91 typedef wxLongLongNative wxLongLong
;
92 typedef wxULongLongNative wxULongLong
;
95 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
96 // typedef wxLongLong as it wants, we don't do it
98 // ----------------------------------------------------------------------------
99 // choose the appropriate class
100 // ----------------------------------------------------------------------------
102 // we use iostream for wxLongLong output
103 #include "wx/iosfwrap.h"
105 #if wxUSE_LONGLONG_NATIVE
107 class WXDLLIMPEXP_BASE wxLongLongNative
111 // default ctor initializes to 0
112 wxLongLongNative() : m_ll(0) { }
114 wxLongLongNative(wxLongLong_t ll
) : m_ll(ll
) { }
116 wxLongLongNative(long hi
, unsigned long lo
) : m_ll(0)
118 // assign first to avoid precision loss!
119 m_ll
= ((wxLongLong_t
) hi
) << 32;
120 m_ll
|= (wxLongLong_t
) lo
;
122 #if wxUSE_LONGLONG_WX
123 wxLongLongNative(wxLongLongWx ll
);
126 // default copy ctor is ok
130 // assignment operators
131 // from native 64 bit integer
132 wxLongLongNative
& operator=(wxLongLong_t ll
)
133 { m_ll
= ll
; return *this; }
134 wxLongLongNative
& operator=(wxULongLong_t ll
)
135 { m_ll
= ll
; return *this; }
136 wxLongLongNative
& operator=(const wxULongLongNative
&ll
);
137 wxLongLongNative
& operator=(long l
)
138 { m_ll
= l
; return *this; }
139 wxLongLongNative
& operator=(unsigned long l
)
140 { m_ll
= l
; return *this; }
141 #if wxUSE_LONGLONG_WX
142 wxLongLongNative
& operator=(wxLongLongWx ll
);
143 wxLongLongNative
& operator=(const class wxULongLongWx
&ll
);
147 // from double: this one has an explicit name because otherwise we
148 // would have ambiguity with "ll = int" and also because we don't want
149 // to have implicit conversions between doubles and wxLongLongs
150 wxLongLongNative
& Assign(double d
)
151 { m_ll
= (wxLongLong_t
)d
; return *this; }
153 // assignment operators from wxLongLongNative is ok
158 { return wx_truncate_cast(long, m_ll
>> 32); }
160 unsigned long GetLo() const
161 { return wx_truncate_cast(unsigned long, m_ll
); }
163 // get absolute value
164 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
165 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
167 // convert to native long long
168 wxLongLong_t
GetValue() const { return m_ll
; }
170 // convert to long with range checking in debug mode (only!)
173 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
174 _T("wxLongLong to long conversion loss of precision") );
176 return wx_truncate_cast(long, m_ll
);
180 double ToDouble() const { return wx_truncate_cast(double, m_ll
); }
182 // don't provide implicit conversion to wxLongLong_t or we will have an
183 // ambiguity for all arithmetic operations
184 //operator wxLongLong_t() const { return m_ll; }
188 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
189 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
190 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
191 { m_ll
+= ll
.m_ll
; return *this; }
193 wxLongLongNative
operator+(const wxLongLong_t ll
) const
194 { return wxLongLongNative(m_ll
+ ll
); }
195 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
196 { m_ll
+= ll
; return *this; }
199 wxLongLongNative
& operator++()
200 { m_ll
++; return *this; }
203 wxLongLongNative
operator++(int)
204 { wxLongLongNative
value(*this); m_ll
++; return value
; }
207 wxLongLongNative
operator-() const
208 { return wxLongLongNative(-m_ll
); }
209 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
212 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
213 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
214 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
215 { m_ll
-= ll
.m_ll
; return *this; }
217 wxLongLongNative
operator-(const wxLongLong_t ll
) const
218 { return wxLongLongNative(m_ll
- ll
); }
219 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
220 { m_ll
-= ll
; return *this; }
223 wxLongLongNative
& operator--()
224 { m_ll
--; return *this; }
227 wxLongLongNative
operator--(int)
228 { wxLongLongNative
value(*this); m_ll
--; return value
; }
232 wxLongLongNative
operator<<(int shift
) const
233 { return wxLongLongNative(m_ll
<< shift
); }
234 wxLongLongNative
& operator<<=(int shift
)
235 { m_ll
<<= shift
; return *this; }
238 wxLongLongNative
operator>>(int shift
) const
239 { return wxLongLongNative(m_ll
>> shift
); }
240 wxLongLongNative
& operator>>=(int shift
)
241 { m_ll
>>= shift
; return *this; }
244 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
245 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
246 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
247 { m_ll
&= ll
.m_ll
; return *this; }
249 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
250 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
251 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
252 { m_ll
|= ll
.m_ll
; 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 // multiplication/division
260 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
261 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
262 wxLongLongNative
operator*(long l
) const
263 { return wxLongLongNative(m_ll
* l
); }
264 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
265 { m_ll
*= ll
.m_ll
; return *this; }
266 wxLongLongNative
& operator*=(long l
)
267 { m_ll
*= l
; return *this; }
269 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
270 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
271 wxLongLongNative
operator/(long l
) const
272 { return wxLongLongNative(m_ll
/ l
); }
273 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
274 { m_ll
/= ll
.m_ll
; return *this; }
275 wxLongLongNative
& operator/=(long l
)
276 { m_ll
/= l
; return *this; }
278 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
279 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
280 wxLongLongNative
operator%(long l
) const
281 { return wxLongLongNative(m_ll
% l
); }
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
; }
292 bool operator<(const wxLongLongNative
& ll
) const
293 { return m_ll
< ll
.m_ll
; }
294 bool operator<(long l
) const
296 bool operator>(const wxLongLongNative
& ll
) const
297 { return m_ll
> ll
.m_ll
; }
298 bool operator>(long l
) const
300 bool operator<=(const wxLongLongNative
& ll
) const
301 { return m_ll
<= ll
.m_ll
; }
302 bool operator<=(long l
) const
303 { return m_ll
<= l
; }
304 bool operator>=(const wxLongLongNative
& ll
) const
305 { return m_ll
>= ll
.m_ll
; }
306 bool operator>=(long l
) const
307 { return m_ll
>= l
; }
311 // return the string representation of this number
312 wxString
ToString() const;
314 // conversion to byte array: returns a pointer to static buffer!
315 void *asArray() const;
317 #if wxUSE_STD_IOSTREAM
319 friend WXDLLIMPEXP_BASE
320 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
323 friend WXDLLIMPEXP_BASE
324 wxString
& operator<<(wxString
&, const wxLongLongNative
&);
327 friend WXDLLIMPEXP_BASE
328 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxLongLongNative
&);
329 friend WXDLLIMPEXP_BASE
330 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxLongLongNative
&);
338 class WXDLLIMPEXP_BASE wxULongLongNative
342 // default ctor initializes to 0
343 wxULongLongNative() : m_ll(0) { }
345 wxULongLongNative(wxULongLong_t ll
) : m_ll(ll
) { }
347 wxULongLongNative(unsigned long hi
, unsigned long lo
) : m_ll(0)
349 // assign first to avoid precision loss!
350 m_ll
= ((wxULongLong_t
) hi
) << 32;
351 m_ll
|= (wxULongLong_t
) lo
;
354 #if wxUSE_LONGLONG_WX
355 wxULongLongNative(const class wxULongLongWx
&ll
);
358 // default copy ctor is ok
362 // assignment operators
363 // from native 64 bit integer
364 wxULongLongNative
& operator=(wxULongLong_t ll
)
365 { m_ll
= ll
; return *this; }
366 wxULongLongNative
& operator=(wxLongLong_t ll
)
367 { m_ll
= ll
; return *this; }
368 wxULongLongNative
& operator=(long l
)
369 { m_ll
= l
; return *this; }
370 wxULongLongNative
& operator=(unsigned long l
)
371 { m_ll
= l
; return *this; }
372 wxULongLongNative
& operator=(const wxLongLongNative
&ll
)
373 { m_ll
= ll
.GetValue(); return *this; }
374 #if wxUSE_LONGLONG_WX
375 wxULongLongNative
& operator=(wxLongLongWx ll
);
376 wxULongLongNative
& operator=(const class wxULongLongWx
&ll
);
379 // assignment operators from wxULongLongNative is ok
383 unsigned long GetHi() const
384 { return wx_truncate_cast(unsigned long, m_ll
>> 32); }
386 unsigned long GetLo() const
387 { return wx_truncate_cast(unsigned long, m_ll
); }
389 // convert to native ulong long
390 wxULongLong_t
GetValue() const { return m_ll
; }
392 // convert to ulong with range checking in debug mode (only!)
393 unsigned long ToULong() const
395 wxASSERT_MSG( m_ll
<= LONG_MAX
,
396 _T("wxULongLong to long conversion loss of precision") );
398 return wx_truncate_cast(unsigned long, m_ll
);
403 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
404 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
405 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
406 { m_ll
+= ll
.m_ll
; return *this; }
408 wxULongLongNative
operator+(const wxULongLong_t ll
) const
409 { return wxULongLongNative(m_ll
+ ll
); }
410 wxULongLongNative
& operator+=(const wxULongLong_t ll
)
411 { m_ll
+= ll
; return *this; }
414 wxULongLongNative
& operator++()
415 { m_ll
++; return *this; }
418 wxULongLongNative
operator++(int)
419 { wxULongLongNative
value(*this); m_ll
++; return value
; }
422 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
423 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
424 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
425 { m_ll
-= ll
.m_ll
; return *this; }
427 wxULongLongNative
operator-(const wxULongLong_t ll
) const
428 { return wxULongLongNative(m_ll
- ll
); }
429 wxULongLongNative
& operator-=(const wxULongLong_t ll
)
430 { m_ll
-= ll
; return *this; }
433 wxULongLongNative
& operator--()
434 { m_ll
--; return *this; }
437 wxULongLongNative
operator--(int)
438 { wxULongLongNative
value(*this); m_ll
--; return value
; }
442 wxULongLongNative
operator<<(int shift
) const
443 { return wxULongLongNative(m_ll
<< shift
); }
444 wxULongLongNative
& operator<<=(int shift
)
445 { m_ll
<<= shift
; return *this; }
448 wxULongLongNative
operator>>(int shift
) const
449 { return wxULongLongNative(m_ll
>> shift
); }
450 wxULongLongNative
& operator>>=(int shift
)
451 { m_ll
>>= shift
; return *this; }
454 wxULongLongNative
operator&(const wxULongLongNative
& ll
) const
455 { return wxULongLongNative(m_ll
& ll
.m_ll
); }
456 wxULongLongNative
& operator&=(const wxULongLongNative
& ll
)
457 { m_ll
&= ll
.m_ll
; return *this; }
459 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
460 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
461 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
462 { m_ll
|= ll
.m_ll
; return *this; }
464 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
465 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
466 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
467 { m_ll
^= ll
.m_ll
; return *this; }
469 // multiplication/division
470 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
471 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
472 wxULongLongNative
operator*(unsigned long l
) const
473 { return wxULongLongNative(m_ll
* l
); }
474 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
475 { m_ll
*= ll
.m_ll
; return *this; }
476 wxULongLongNative
& operator*=(unsigned long l
)
477 { m_ll
*= l
; return *this; }
479 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
480 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
481 wxULongLongNative
operator/(unsigned long l
) const
482 { return wxULongLongNative(m_ll
/ l
); }
483 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
484 { m_ll
/= ll
.m_ll
; return *this; }
485 wxULongLongNative
& operator/=(unsigned long l
)
486 { m_ll
/= l
; return *this; }
488 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
489 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
490 wxULongLongNative
operator%(unsigned long l
) const
491 { return wxULongLongNative(m_ll
% l
); }
494 bool operator==(const wxULongLongNative
& ll
) const
495 { return m_ll
== ll
.m_ll
; }
496 bool operator==(unsigned long l
) const
497 { return m_ll
== l
; }
498 bool operator!=(const wxULongLongNative
& ll
) const
499 { return m_ll
!= ll
.m_ll
; }
500 bool operator!=(unsigned long l
) const
501 { return m_ll
!= l
; }
502 bool operator<(const wxULongLongNative
& ll
) const
503 { return m_ll
< ll
.m_ll
; }
504 bool operator<(unsigned long l
) const
506 bool operator>(const wxULongLongNative
& ll
) const
507 { return m_ll
> ll
.m_ll
; }
508 bool operator>(unsigned long l
) const
510 bool operator<=(const wxULongLongNative
& ll
) const
511 { return m_ll
<= ll
.m_ll
; }
512 bool operator<=(unsigned long l
) const
513 { return m_ll
<= l
; }
514 bool operator>=(const wxULongLongNative
& ll
) const
515 { return m_ll
>= ll
.m_ll
; }
516 bool operator>=(unsigned long l
) const
517 { return m_ll
>= l
; }
521 // return the string representation of this number
522 wxString
ToString() const;
524 // conversion to byte array: returns a pointer to static buffer!
525 void *asArray() const;
527 #if wxUSE_STD_IOSTREAM
529 friend WXDLLIMPEXP_BASE
530 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
533 friend WXDLLIMPEXP_BASE
534 wxString
& operator<<(wxString
&, const wxULongLongNative
&);
537 friend WXDLLIMPEXP_BASE
538 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxULongLongNative
&);
539 friend WXDLLIMPEXP_BASE
540 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxULongLongNative
&);
548 wxLongLongNative
& wxLongLongNative::operator=(const wxULongLongNative
&ll
)
550 m_ll
= ll
.GetValue();
554 #endif // wxUSE_LONGLONG_NATIVE
556 #if wxUSE_LONGLONG_WX
558 class WXDLLIMPEXP_BASE wxLongLongWx
562 // default ctor initializes to 0
567 #ifdef wxLONGLONG_TEST_MODE
571 #endif // wxLONGLONG_TEST_MODE
574 wxLongLongWx(long l
) { *this = l
; }
576 wxLongLongWx(long hi
, unsigned long lo
)
581 #ifdef wxLONGLONG_TEST_MODE
587 #endif // wxLONGLONG_TEST_MODE
590 // default copy ctor is ok in both cases
594 // assignment operators
596 wxLongLongWx
& operator=(long l
)
599 m_hi
= (l
< 0 ? -1l : 0l);
601 #ifdef wxLONGLONG_TEST_MODE
605 #endif // wxLONGLONG_TEST_MODE
609 wxLongLongWx
& operator=(unsigned long l
)
614 #ifdef wxLONGLONG_TEST_MODE
618 #endif // wxLONGLONG_TEST_MODE
622 wxLongLongWx
& operator=(const class wxULongLongWx
&ll
);
625 wxLongLongWx
& Assign(double d
);
626 // can't have assignment operator from 2 longs
630 long GetHi() const { return m_hi
; }
632 unsigned long GetLo() const { return m_lo
; }
634 // get absolute value
635 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
641 #ifdef wxLONGLONG_TEST_MODE
646 #endif // wxLONGLONG_TEST_MODE
651 // convert to long with range checking in debug mode (only!)
654 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
655 _T("wxLongLong to long conversion loss of precision") );
661 double ToDouble() const;
665 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
666 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
667 wxLongLongWx
operator+(long l
) const;
668 wxLongLongWx
& operator+=(long l
);
670 // pre increment operator
671 wxLongLongWx
& operator++();
673 // post increment operator
674 wxLongLongWx
& operator++(int) { return ++(*this); }
677 wxLongLongWx
operator-() const;
678 wxLongLongWx
& Negate();
681 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
682 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
684 // pre decrement operator
685 wxLongLongWx
& operator--();
687 // post decrement operator
688 wxLongLongWx
& operator--(int) { return --(*this); }
692 wxLongLongWx
operator<<(int shift
) const;
693 wxLongLongWx
& operator<<=(int shift
);
696 wxLongLongWx
operator>>(int shift
) const;
697 wxLongLongWx
& operator>>=(int shift
);
700 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
701 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
702 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
703 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
704 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
705 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
706 wxLongLongWx
operator~() const;
709 bool operator==(const wxLongLongWx
& ll
) const
710 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
711 #if wxUSE_LONGLONG_NATIVE
712 bool operator==(const wxLongLongNative
& ll
) const
713 { return m_lo
== ll
.GetLo() && m_hi
== ll
.GetHi(); }
715 bool operator!=(const wxLongLongWx
& ll
) const
716 { return !(*this == ll
); }
717 bool operator<(const wxLongLongWx
& ll
) const;
718 bool operator>(const wxLongLongWx
& ll
) const;
719 bool operator<=(const wxLongLongWx
& ll
) const
720 { return *this < ll
|| *this == ll
; }
721 bool operator>=(const wxLongLongWx
& ll
) const
722 { return *this > ll
|| *this == ll
; }
724 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
725 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
726 bool operator==(long l
) const
728 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
729 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
732 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
733 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
736 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
737 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
740 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
741 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
743 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
745 void Divide(const wxLongLongWx
& divisor
,
746 wxLongLongWx
& quotient
,
747 wxLongLongWx
& remainder
) const;
751 // return the string representation of this number
752 wxString
ToString() const;
754 void *asArray() const;
756 #if wxUSE_STD_IOSTREAM
757 friend WXDLLIMPEXP_BASE
758 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
759 #endif // wxUSE_STD_IOSTREAM
761 friend WXDLLIMPEXP_BASE
762 wxString
& operator<<(wxString
&, const wxLongLongWx
&);
765 friend WXDLLIMPEXP_BASE
766 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxLongLongWx
&);
767 friend WXDLLIMPEXP_BASE
768 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxLongLongWx
&);
772 // long is at least 32 bits, so represent our 64bit number as 2 longs
774 long m_hi
; // signed bit is in the high part
777 #ifdef wxLONGLONG_TEST_MODE
780 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
784 #endif // wxLONGLONG_TEST_MODE
788 class WXDLLIMPEXP_BASE wxULongLongWx
792 // default ctor initializes to 0
797 #ifdef wxLONGLONG_TEST_MODE
801 #endif // wxLONGLONG_TEST_MODE
804 wxULongLongWx(unsigned long l
) { *this = l
; }
806 wxULongLongWx(unsigned long hi
, unsigned long lo
)
811 #ifdef wxLONGLONG_TEST_MODE
817 #endif // wxLONGLONG_TEST_MODE
820 // from signed to unsigned
821 wxULongLongWx(wxLongLongWx ll
)
823 wxASSERT(ll
.GetHi() >= 0);
824 m_hi
= (unsigned long)ll
.GetHi();
828 // default copy ctor is ok in both cases
832 // assignment operators
834 wxULongLongWx
& operator=(unsigned long l
)
839 #ifdef wxLONGLONG_TEST_MODE
843 #endif // wxLONGLONG_TEST_MODE
847 wxULongLongWx
& operator=(long l
)
850 m_hi
= (unsigned long) ((l
<0) ? -1l : 0);
852 #ifdef wxLONGLONG_TEST_MODE
853 m_ll
= (wxULongLong_t
) (wxLongLong_t
) l
;
856 #endif // wxLONGLONG_TEST_MODE
860 wxULongLongWx
& operator=(const class wxLongLongWx
&ll
) {
861 // Should we use an assert like it was before in the constructor?
862 // wxASSERT(ll.GetHi() >= 0);
863 m_hi
= (unsigned long)ll
.GetHi();
868 // can't have assignment operator from 2 longs
872 unsigned long GetHi() const { return m_hi
; }
874 unsigned long GetLo() const { return m_lo
; }
876 // convert to long with range checking in debug mode (only!)
877 unsigned long ToULong() const
879 wxASSERT_MSG( m_hi
== 0ul,
880 _T("wxULongLong to long conversion loss of precision") );
882 return (unsigned long)m_lo
;
887 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
888 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
889 wxULongLongWx
operator+(unsigned long l
) const;
890 wxULongLongWx
& operator+=(unsigned long l
);
892 // pre increment operator
893 wxULongLongWx
& operator++();
895 // post increment operator
896 wxULongLongWx
& operator++(int) { return ++(*this); }
899 wxLongLongWx
operator-(const wxULongLongWx
& ll
) const;
900 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
902 // pre decrement operator
903 wxULongLongWx
& operator--();
905 // post decrement operator
906 wxULongLongWx
& operator--(int) { return --(*this); }
910 wxULongLongWx
operator<<(int shift
) const;
911 wxULongLongWx
& operator<<=(int shift
);
914 wxULongLongWx
operator>>(int shift
) const;
915 wxULongLongWx
& operator>>=(int shift
);
918 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
919 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
920 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
921 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
922 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
923 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
924 wxULongLongWx
operator~() const;
927 bool operator==(const wxULongLongWx
& ll
) const
928 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
929 bool operator!=(const wxULongLongWx
& ll
) const
930 { return !(*this == ll
); }
931 bool operator<(const wxULongLongWx
& ll
) const;
932 bool operator>(const wxULongLongWx
& ll
) const;
933 bool operator<=(const wxULongLongWx
& ll
) const
934 { return *this < ll
|| *this == ll
; }
935 bool operator>=(const wxULongLongWx
& ll
) const
936 { return *this > ll
|| *this == ll
; }
938 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
939 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
940 bool operator==(unsigned long l
) const
942 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
945 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
946 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
949 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
950 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
953 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
954 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
956 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
958 void Divide(const wxULongLongWx
& divisor
,
959 wxULongLongWx
& quotient
,
960 wxULongLongWx
& remainder
) const;
964 // return the string representation of this number
965 wxString
ToString() const;
967 void *asArray() const;
969 #if wxUSE_STD_IOSTREAM
970 friend WXDLLIMPEXP_BASE
971 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
972 #endif // wxUSE_STD_IOSTREAM
974 friend WXDLLIMPEXP_BASE
975 wxString
& operator<<(wxString
&, const wxULongLongWx
&);
978 friend WXDLLIMPEXP_BASE
979 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxULongLongWx
&);
980 friend WXDLLIMPEXP_BASE
981 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxULongLongWx
&);
985 // long is at least 32 bits, so represent our 64bit number as 2 longs
990 #ifdef wxLONGLONG_TEST_MODE
993 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
997 #endif // wxLONGLONG_TEST_MODE
1000 #endif // wxUSE_LONGLONG_WX
1002 // ----------------------------------------------------------------------------
1004 // ----------------------------------------------------------------------------
1006 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
1007 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
< l
; }
1008 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
>= l
; }
1009 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
<= l
; }
1010 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
1011 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
1013 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
1014 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
1016 return wxLongLong(l
) - ll
;
1019 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
1020 inline bool operator>(unsigned long l
, const wxULongLong
& ull
) { return ull
< l
; }
1021 inline bool operator<=(unsigned long l
, const wxULongLong
& ull
) { return ull
>= l
; }
1022 inline bool operator>=(unsigned long l
, const wxULongLong
& ull
) { return ull
<= l
; }
1023 inline bool operator==(unsigned long l
, const wxULongLong
& ull
) { return ull
== l
; }
1024 inline bool operator!=(unsigned long l
, const wxULongLong
& ull
) { return ull
!= l
; }
1026 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
1028 inline wxLongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
1030 wxULongLong ret
= wxULongLong(l
) - ull
;
1031 return wxLongLong((long)ret
.GetHi(),ret
.GetLo());
1034 #if wxUSE_LONGLONG_NATIVE && wxUSE_STREAMS
1036 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&stream
, wxULongLong_t value
);
1037 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&stream
, wxLongLong_t value
);
1039 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&stream
, wxULongLong_t
&value
);
1040 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&stream
, wxLongLong_t
&value
);
1044 #endif // wxUSE_LONGLONG
1046 #endif // _WX_LONGLONG_H