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 #ifndef wxLongLongIsLong
133 wxLongLongNative
& operator=(wxLongLong_t ll
)
134 { m_ll
= ll
; return *this; }
135 wxLongLongNative
& operator=(wxULongLong_t ll
)
136 { m_ll
= ll
; return *this; }
137 #endif // !wxLongLongNative
138 wxLongLongNative
& operator=(const wxULongLongNative
&ll
);
139 wxLongLongNative
& operator=(int l
)
140 { m_ll
= l
; return *this; }
141 wxLongLongNative
& operator=(long l
)
142 { m_ll
= l
; return *this; }
143 wxLongLongNative
& operator=(unsigned long l
)
144 { m_ll
= l
; return *this; }
145 #if wxUSE_LONGLONG_WX
146 wxLongLongNative
& operator=(wxLongLongWx ll
);
147 wxLongLongNative
& operator=(const class wxULongLongWx
&ll
);
151 // from double: this one has an explicit name because otherwise we
152 // would have ambiguity with "ll = int" and also because we don't want
153 // to have implicit conversions between doubles and wxLongLongs
154 wxLongLongNative
& Assign(double d
)
155 { m_ll
= (wxLongLong_t
)d
; return *this; }
157 // assignment operators from wxLongLongNative is ok
162 { return wx_truncate_cast(long, m_ll
>> 32); }
164 unsigned long GetLo() const
165 { return wx_truncate_cast(unsigned long, m_ll
); }
167 // get absolute value
168 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
169 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
171 // convert to native long long
172 wxLongLong_t
GetValue() const { return m_ll
; }
174 // convert to long with range checking in debug mode (only!)
177 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
178 _T("wxLongLong to long conversion loss of precision") );
180 return wx_truncate_cast(long, m_ll
);
184 double ToDouble() const { return wx_truncate_cast(double, m_ll
); }
186 // don't provide implicit conversion to wxLongLong_t or we will have an
187 // ambiguity for all arithmetic operations
188 //operator wxLongLong_t() const { return m_ll; }
192 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
193 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
194 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
195 { m_ll
+= ll
.m_ll
; return *this; }
197 wxLongLongNative
operator+(const wxLongLong_t ll
) const
198 { return wxLongLongNative(m_ll
+ ll
); }
199 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
200 { m_ll
+= ll
; return *this; }
203 wxLongLongNative
& operator++()
204 { m_ll
++; return *this; }
207 wxLongLongNative
operator++(int)
208 { wxLongLongNative
value(*this); m_ll
++; return value
; }
211 wxLongLongNative
operator-() const
212 { return wxLongLongNative(-m_ll
); }
213 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
216 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
217 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
218 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
219 { m_ll
-= ll
.m_ll
; return *this; }
221 wxLongLongNative
operator-(const wxLongLong_t ll
) const
222 { return wxLongLongNative(m_ll
- ll
); }
223 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
224 { m_ll
-= ll
; return *this; }
227 wxLongLongNative
& operator--()
228 { m_ll
--; return *this; }
231 wxLongLongNative
operator--(int)
232 { wxLongLongNative
value(*this); m_ll
--; return value
; }
236 wxLongLongNative
operator<<(int shift
) const
237 { return wxLongLongNative(m_ll
<< shift
); }
238 wxLongLongNative
& operator<<=(int shift
)
239 { m_ll
<<= shift
; return *this; }
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&(const wxLongLongNative
& ll
) const
249 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
250 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
251 { m_ll
&= ll
.m_ll
; return *this; }
253 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
254 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
255 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
256 { m_ll
|= ll
.m_ll
; return *this; }
258 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
259 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
260 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
261 { m_ll
^= ll
.m_ll
; return *this; }
263 // multiplication/division
264 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
265 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
266 wxLongLongNative
operator*(long l
) const
267 { return wxLongLongNative(m_ll
* l
); }
268 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
269 { m_ll
*= ll
.m_ll
; return *this; }
270 wxLongLongNative
& operator*=(long l
)
271 { m_ll
*= l
; return *this; }
273 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
274 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
275 wxLongLongNative
operator/(long l
) const
276 { return wxLongLongNative(m_ll
/ l
); }
277 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
278 { m_ll
/= ll
.m_ll
; return *this; }
279 wxLongLongNative
& operator/=(long l
)
280 { m_ll
/= l
; return *this; }
282 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
283 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
284 wxLongLongNative
operator%(long l
) const
285 { return wxLongLongNative(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
295 { return m_ll
!= l
; }
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
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
; }
308 bool operator>=(const wxLongLongNative
& ll
) const
309 { return m_ll
>= ll
.m_ll
; }
310 bool operator>=(long l
) const
311 { return m_ll
>= l
; }
315 // return the string representation of this number
316 wxString
ToString() const;
318 // conversion to byte array: returns a pointer to static buffer!
319 void *asArray() const;
321 #if wxUSE_STD_IOSTREAM
323 friend WXDLLIMPEXP_BASE
324 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
327 friend WXDLLIMPEXP_BASE
328 wxString
& operator<<(wxString
&, const wxLongLongNative
&);
331 friend WXDLLIMPEXP_BASE
332 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxLongLongNative
&);
333 friend WXDLLIMPEXP_BASE
334 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxLongLongNative
&);
342 class WXDLLIMPEXP_BASE wxULongLongNative
346 // default ctor initializes to 0
347 wxULongLongNative() : m_ll(0) { }
349 wxULongLongNative(wxULongLong_t ll
) : m_ll(ll
) { }
351 wxULongLongNative(unsigned long hi
, unsigned long lo
) : m_ll(0)
353 // assign first to avoid precision loss!
354 m_ll
= ((wxULongLong_t
) hi
) << 32;
355 m_ll
|= (wxULongLong_t
) lo
;
358 #if wxUSE_LONGLONG_WX
359 wxULongLongNative(const class wxULongLongWx
&ll
);
362 // default copy ctor is ok
366 // assignment operators
367 // from native 64 bit integer
368 #ifndef wxLongLongIsLong
369 wxULongLongNative
& operator=(wxULongLong_t ll
)
370 { m_ll
= ll
; return *this; }
371 wxULongLongNative
& operator=(wxLongLong_t ll
)
372 { m_ll
= ll
; return *this; }
373 #endif // !wxLongLongNative
374 wxULongLongNative
& operator=(int l
)
375 { m_ll
= l
; return *this; }
376 wxULongLongNative
& operator=(long l
)
377 { m_ll
= l
; return *this; }
378 wxULongLongNative
& operator=(unsigned long l
)
379 { m_ll
= l
; return *this; }
380 wxULongLongNative
& operator=(const wxLongLongNative
&ll
)
381 { m_ll
= ll
.GetValue(); return *this; }
382 #if wxUSE_LONGLONG_WX
383 wxULongLongNative
& operator=(wxLongLongWx ll
);
384 wxULongLongNative
& operator=(const class wxULongLongWx
&ll
);
387 // assignment operators from wxULongLongNative is ok
391 unsigned long GetHi() const
392 { return wx_truncate_cast(unsigned long, m_ll
>> 32); }
394 unsigned long GetLo() const
395 { return wx_truncate_cast(unsigned long, m_ll
); }
397 // convert to native ulong long
398 wxULongLong_t
GetValue() const { return m_ll
; }
400 // convert to ulong with range checking in debug mode (only!)
401 unsigned long ToULong() const
403 wxASSERT_MSG( m_ll
<= LONG_MAX
,
404 _T("wxULongLong to long conversion loss of precision") );
406 return wx_truncate_cast(unsigned long, m_ll
);
411 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
412 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
413 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
414 { m_ll
+= ll
.m_ll
; return *this; }
416 wxULongLongNative
operator+(const wxULongLong_t ll
) const
417 { return wxULongLongNative(m_ll
+ ll
); }
418 wxULongLongNative
& operator+=(const wxULongLong_t ll
)
419 { m_ll
+= ll
; return *this; }
422 wxULongLongNative
& operator++()
423 { m_ll
++; return *this; }
426 wxULongLongNative
operator++(int)
427 { wxULongLongNative
value(*this); m_ll
++; return value
; }
430 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
431 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
432 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
433 { m_ll
-= ll
.m_ll
; return *this; }
435 wxULongLongNative
operator-(const wxULongLong_t ll
) const
436 { return wxULongLongNative(m_ll
- ll
); }
437 wxULongLongNative
& operator-=(const wxULongLong_t ll
)
438 { m_ll
-= ll
; return *this; }
441 wxULongLongNative
& operator--()
442 { m_ll
--; return *this; }
445 wxULongLongNative
operator--(int)
446 { wxULongLongNative
value(*this); m_ll
--; return value
; }
450 wxULongLongNative
operator<<(int shift
) const
451 { return wxULongLongNative(m_ll
<< shift
); }
452 wxULongLongNative
& operator<<=(int shift
)
453 { m_ll
<<= shift
; return *this; }
456 wxULongLongNative
operator>>(int shift
) const
457 { return wxULongLongNative(m_ll
>> shift
); }
458 wxULongLongNative
& operator>>=(int shift
)
459 { m_ll
>>= shift
; 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 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
468 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
469 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
470 { m_ll
|= ll
.m_ll
; return *this; }
472 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
473 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
474 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
475 { m_ll
^= ll
.m_ll
; return *this; }
477 // multiplication/division
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
); }
491 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
492 { m_ll
/= ll
.m_ll
; return *this; }
493 wxULongLongNative
& operator/=(unsigned long l
)
494 { m_ll
/= l
; return *this; }
496 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
497 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
498 wxULongLongNative
operator%(unsigned long l
) const
499 { return wxULongLongNative(m_ll
% l
); }
502 bool operator==(const wxULongLongNative
& ll
) const
503 { return m_ll
== ll
.m_ll
; }
504 bool operator==(unsigned long l
) const
505 { return m_ll
== l
; }
506 bool operator!=(const wxULongLongNative
& ll
) const
507 { return m_ll
!= ll
.m_ll
; }
508 bool operator!=(unsigned long l
) const
509 { return m_ll
!= l
; }
510 bool operator<(const wxULongLongNative
& ll
) const
511 { return m_ll
< ll
.m_ll
; }
512 bool operator<(unsigned long l
) const
514 bool operator>(const wxULongLongNative
& ll
) const
515 { return m_ll
> ll
.m_ll
; }
516 bool operator>(unsigned long l
) const
518 bool operator<=(const wxULongLongNative
& ll
) const
519 { return m_ll
<= ll
.m_ll
; }
520 bool operator<=(unsigned long l
) const
521 { return m_ll
<= l
; }
522 bool operator>=(const wxULongLongNative
& ll
) const
523 { return m_ll
>= ll
.m_ll
; }
524 bool operator>=(unsigned long l
) const
525 { return m_ll
>= l
; }
529 // return the string representation of this number
530 wxString
ToString() const;
532 // conversion to byte array: returns a pointer to static buffer!
533 void *asArray() const;
535 #if wxUSE_STD_IOSTREAM
537 friend WXDLLIMPEXP_BASE
538 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
541 friend WXDLLIMPEXP_BASE
542 wxString
& operator<<(wxString
&, const wxULongLongNative
&);
545 friend WXDLLIMPEXP_BASE
546 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxULongLongNative
&);
547 friend WXDLLIMPEXP_BASE
548 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxULongLongNative
&);
556 wxLongLongNative
& wxLongLongNative::operator=(const wxULongLongNative
&ll
)
558 m_ll
= ll
.GetValue();
562 #endif // wxUSE_LONGLONG_NATIVE
564 #if wxUSE_LONGLONG_WX
566 class WXDLLIMPEXP_BASE wxLongLongWx
570 // default ctor initializes to 0
575 #ifdef wxLONGLONG_TEST_MODE
579 #endif // wxLONGLONG_TEST_MODE
582 wxLongLongWx(long l
) { *this = l
; }
584 wxLongLongWx(long hi
, unsigned long lo
)
589 #ifdef wxLONGLONG_TEST_MODE
595 #endif // wxLONGLONG_TEST_MODE
598 // default copy ctor is ok in both cases
602 // assignment operators
604 wxLongLongWx
& operator=(long l
)
607 m_hi
= (l
< 0 ? -1l : 0l);
609 #ifdef wxLONGLONG_TEST_MODE
613 #endif // wxLONGLONG_TEST_MODE
618 wxLongLongWx
& operator=(int l
)
620 return operator=((long)l
);
623 wxLongLongWx
& operator=(unsigned long l
)
628 #ifdef wxLONGLONG_TEST_MODE
632 #endif // wxLONGLONG_TEST_MODE
636 wxLongLongWx
& operator=(const class wxULongLongWx
&ll
);
639 wxLongLongWx
& Assign(double d
);
640 // can't have assignment operator from 2 longs
644 long GetHi() const { return m_hi
; }
646 unsigned long GetLo() const { return m_lo
; }
648 // get absolute value
649 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
655 #ifdef wxLONGLONG_TEST_MODE
660 #endif // wxLONGLONG_TEST_MODE
665 // convert to long with range checking in debug mode (only!)
668 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
669 _T("wxLongLong to long conversion loss of precision") );
675 double ToDouble() const;
679 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
680 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
681 wxLongLongWx
operator+(long l
) const;
682 wxLongLongWx
& operator+=(long l
);
684 // pre increment operator
685 wxLongLongWx
& operator++();
687 // post increment operator
688 wxLongLongWx
& operator++(int) { return ++(*this); }
691 wxLongLongWx
operator-() const;
692 wxLongLongWx
& Negate();
695 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
696 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
698 // pre decrement operator
699 wxLongLongWx
& operator--();
701 // post decrement operator
702 wxLongLongWx
& operator--(int) { return --(*this); }
706 wxLongLongWx
operator<<(int shift
) const;
707 wxLongLongWx
& operator<<=(int shift
);
710 wxLongLongWx
operator>>(int shift
) const;
711 wxLongLongWx
& operator>>=(int shift
);
714 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
715 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
716 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
717 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
718 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
719 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
720 wxLongLongWx
operator~() const;
723 bool operator==(const wxLongLongWx
& ll
) const
724 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
725 #if wxUSE_LONGLONG_NATIVE
726 bool operator==(const wxLongLongNative
& ll
) const
727 { return m_lo
== ll
.GetLo() && m_hi
== ll
.GetHi(); }
729 bool operator!=(const wxLongLongWx
& ll
) const
730 { return !(*this == ll
); }
731 bool operator<(const wxLongLongWx
& ll
) const;
732 bool operator>(const wxLongLongWx
& ll
) const;
733 bool operator<=(const wxLongLongWx
& ll
) const
734 { return *this < ll
|| *this == ll
; }
735 bool operator>=(const wxLongLongWx
& ll
) const
736 { return *this > ll
|| *this == ll
; }
738 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
739 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
740 bool operator==(long l
) const
742 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
743 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
746 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
747 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
750 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
751 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
754 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
755 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
757 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
759 void Divide(const wxLongLongWx
& divisor
,
760 wxLongLongWx
& quotient
,
761 wxLongLongWx
& remainder
) const;
765 // return the string representation of this number
766 wxString
ToString() const;
768 void *asArray() const;
770 #if wxUSE_STD_IOSTREAM
771 friend WXDLLIMPEXP_BASE
772 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
773 #endif // wxUSE_STD_IOSTREAM
775 friend WXDLLIMPEXP_BASE
776 wxString
& operator<<(wxString
&, const wxLongLongWx
&);
779 friend WXDLLIMPEXP_BASE
780 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxLongLongWx
&);
781 friend WXDLLIMPEXP_BASE
782 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxLongLongWx
&);
786 // long is at least 32 bits, so represent our 64bit number as 2 longs
788 long m_hi
; // signed bit is in the high part
791 #ifdef wxLONGLONG_TEST_MODE
794 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
798 #endif // wxLONGLONG_TEST_MODE
802 class WXDLLIMPEXP_BASE wxULongLongWx
806 // default ctor initializes to 0
811 #ifdef wxLONGLONG_TEST_MODE
815 #endif // wxLONGLONG_TEST_MODE
818 wxULongLongWx(unsigned long l
) { *this = l
; }
820 wxULongLongWx(unsigned long hi
, unsigned long lo
)
825 #ifdef wxLONGLONG_TEST_MODE
831 #endif // wxLONGLONG_TEST_MODE
834 // from signed to unsigned
835 wxULongLongWx(wxLongLongWx ll
)
837 wxASSERT(ll
.GetHi() >= 0);
838 m_hi
= (unsigned long)ll
.GetHi();
842 // default copy ctor is ok in both cases
846 // assignment operators
848 wxULongLongWx
& operator=(unsigned long l
)
853 #ifdef wxLONGLONG_TEST_MODE
857 #endif // wxLONGLONG_TEST_MODE
861 wxULongLongWx
& operator=(long l
)
864 m_hi
= (unsigned long) ((l
<0) ? -1l : 0);
866 #ifdef wxLONGLONG_TEST_MODE
867 m_ll
= (wxULongLong_t
) (wxLongLong_t
) l
;
870 #endif // wxLONGLONG_TEST_MODE
874 wxULongLongWx
& operator=(const class wxLongLongWx
&ll
) {
875 // Should we use an assert like it was before in the constructor?
876 // wxASSERT(ll.GetHi() >= 0);
877 m_hi
= (unsigned long)ll
.GetHi();
882 // can't have assignment operator from 2 longs
886 unsigned long GetHi() const { return m_hi
; }
888 unsigned long GetLo() const { return m_lo
; }
890 // convert to long with range checking in debug mode (only!)
891 unsigned long ToULong() const
893 wxASSERT_MSG( m_hi
== 0ul,
894 _T("wxULongLong to long conversion loss of precision") );
896 return (unsigned long)m_lo
;
901 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
902 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
903 wxULongLongWx
operator+(unsigned long l
) const;
904 wxULongLongWx
& operator+=(unsigned long l
);
906 // pre increment operator
907 wxULongLongWx
& operator++();
909 // post increment operator
910 wxULongLongWx
& operator++(int) { return ++(*this); }
913 wxLongLongWx
operator-(const wxULongLongWx
& ll
) const;
914 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
916 // pre decrement operator
917 wxULongLongWx
& operator--();
919 // post decrement operator
920 wxULongLongWx
& operator--(int) { return --(*this); }
924 wxULongLongWx
operator<<(int shift
) const;
925 wxULongLongWx
& operator<<=(int shift
);
928 wxULongLongWx
operator>>(int shift
) const;
929 wxULongLongWx
& operator>>=(int shift
);
932 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
933 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
934 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
935 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
936 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
937 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
938 wxULongLongWx
operator~() const;
941 bool operator==(const wxULongLongWx
& ll
) const
942 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
943 bool operator!=(const wxULongLongWx
& ll
) const
944 { return !(*this == ll
); }
945 bool operator<(const wxULongLongWx
& ll
) const;
946 bool operator>(const wxULongLongWx
& ll
) const;
947 bool operator<=(const wxULongLongWx
& ll
) const
948 { return *this < ll
|| *this == ll
; }
949 bool operator>=(const wxULongLongWx
& ll
) const
950 { return *this > ll
|| *this == ll
; }
952 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
953 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
954 bool operator==(unsigned long l
) const
956 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
959 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
960 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
963 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
964 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
967 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
968 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
970 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
972 void Divide(const wxULongLongWx
& divisor
,
973 wxULongLongWx
& quotient
,
974 wxULongLongWx
& remainder
) const;
978 // return the string representation of this number
979 wxString
ToString() const;
981 void *asArray() const;
983 #if wxUSE_STD_IOSTREAM
984 friend WXDLLIMPEXP_BASE
985 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
986 #endif // wxUSE_STD_IOSTREAM
988 friend WXDLLIMPEXP_BASE
989 wxString
& operator<<(wxString
&, const wxULongLongWx
&);
992 friend WXDLLIMPEXP_BASE
993 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxULongLongWx
&);
994 friend WXDLLIMPEXP_BASE
995 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxULongLongWx
&);
999 // long is at least 32 bits, so represent our 64bit number as 2 longs
1004 #ifdef wxLONGLONG_TEST_MODE
1007 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
1011 #endif // wxLONGLONG_TEST_MODE
1014 #endif // wxUSE_LONGLONG_WX
1016 // ----------------------------------------------------------------------------
1018 // ----------------------------------------------------------------------------
1020 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
1021 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
< l
; }
1022 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
>= l
; }
1023 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
<= l
; }
1024 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
1025 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
1027 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
1028 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
1030 return wxLongLong(l
) - ll
;
1033 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
1034 inline bool operator>(unsigned long l
, const wxULongLong
& ull
) { return ull
< l
; }
1035 inline bool operator<=(unsigned long l
, const wxULongLong
& ull
) { return ull
>= l
; }
1036 inline bool operator>=(unsigned long l
, const wxULongLong
& ull
) { return ull
<= l
; }
1037 inline bool operator==(unsigned long l
, const wxULongLong
& ull
) { return ull
== l
; }
1038 inline bool operator!=(unsigned long l
, const wxULongLong
& ull
) { return ull
!= l
; }
1040 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
1042 inline wxLongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
1044 wxULongLong ret
= wxULongLong(l
) - ull
;
1045 return wxLongLong((long)ret
.GetHi(),ret
.GetLo());
1048 #if wxUSE_LONGLONG_NATIVE && wxUSE_STREAMS
1050 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&stream
, wxULongLong_t value
);
1051 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&stream
, wxLongLong_t value
);
1053 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&stream
, wxULongLong_t
&value
);
1054 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&stream
, wxLongLong_t
&value
);
1058 #endif // wxUSE_LONGLONG
1060 #endif // _WX_LONGLONG_H