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=(int l
)
138 { m_ll
= l
; return *this; }
139 wxLongLongNative
& operator=(long l
)
140 { m_ll
= l
; return *this; }
141 wxLongLongNative
& operator=(unsigned long l
)
142 { m_ll
= l
; return *this; }
143 #if wxUSE_LONGLONG_WX
144 wxLongLongNative
& operator=(wxLongLongWx ll
);
145 wxLongLongNative
& operator=(const class wxULongLongWx
&ll
);
149 // from double: this one has an explicit name because otherwise we
150 // would have ambiguity with "ll = int" and also because we don't want
151 // to have implicit conversions between doubles and wxLongLongs
152 wxLongLongNative
& Assign(double d
)
153 { m_ll
= (wxLongLong_t
)d
; return *this; }
155 // assignment operators from wxLongLongNative is ok
160 { return wx_truncate_cast(long, m_ll
>> 32); }
162 unsigned long GetLo() const
163 { return wx_truncate_cast(unsigned long, m_ll
); }
165 // get absolute value
166 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
167 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
169 // convert to native long long
170 wxLongLong_t
GetValue() const { return m_ll
; }
172 // convert to long with range checking in debug mode (only!)
175 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
176 _T("wxLongLong to long conversion loss of precision") );
178 return wx_truncate_cast(long, m_ll
);
182 double ToDouble() const { return wx_truncate_cast(double, m_ll
); }
184 // don't provide implicit conversion to wxLongLong_t or we will have an
185 // ambiguity for all arithmetic operations
186 //operator wxLongLong_t() const { return m_ll; }
190 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
191 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
192 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
193 { m_ll
+= ll
.m_ll
; return *this; }
195 wxLongLongNative
operator+(const wxLongLong_t ll
) const
196 { return wxLongLongNative(m_ll
+ ll
); }
197 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
198 { m_ll
+= ll
; return *this; }
201 wxLongLongNative
& operator++()
202 { m_ll
++; return *this; }
205 wxLongLongNative
operator++(int)
206 { wxLongLongNative
value(*this); m_ll
++; return value
; }
209 wxLongLongNative
operator-() const
210 { return wxLongLongNative(-m_ll
); }
211 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
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
; }
234 wxLongLongNative
operator<<(int shift
) const
235 { return wxLongLongNative(m_ll
<< shift
); }
236 wxLongLongNative
& operator<<=(int shift
)
237 { m_ll
<<= shift
; return *this; }
240 wxLongLongNative
operator>>(int shift
) const
241 { return wxLongLongNative(m_ll
>> shift
); }
242 wxLongLongNative
& operator>>=(int shift
)
243 { m_ll
>>= shift
; return *this; }
246 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
247 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
248 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
249 { m_ll
&= ll
.m_ll
; return *this; }
251 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
252 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
253 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
254 { m_ll
|= ll
.m_ll
; return *this; }
256 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
257 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
258 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
259 { m_ll
^= ll
.m_ll
; return *this; }
261 // multiplication/division
262 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
263 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
264 wxLongLongNative
operator*(long l
) const
265 { return wxLongLongNative(m_ll
* l
); }
266 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
267 { m_ll
*= ll
.m_ll
; return *this; }
268 wxLongLongNative
& operator*=(long l
)
269 { m_ll
*= l
; return *this; }
271 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
272 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
273 wxLongLongNative
operator/(long l
) const
274 { return wxLongLongNative(m_ll
/ l
); }
275 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
276 { m_ll
/= ll
.m_ll
; return *this; }
277 wxLongLongNative
& operator/=(long l
)
278 { m_ll
/= l
; return *this; }
280 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
281 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
282 wxLongLongNative
operator%(long l
) const
283 { return wxLongLongNative(m_ll
% l
); }
286 bool operator==(const wxLongLongNative
& ll
) const
287 { return m_ll
== ll
.m_ll
; }
288 bool operator==(long l
) const
289 { return m_ll
== l
; }
290 bool operator!=(const wxLongLongNative
& ll
) const
291 { return m_ll
!= ll
.m_ll
; }
292 bool operator!=(long l
) const
293 { return m_ll
!= l
; }
294 bool operator<(const wxLongLongNative
& ll
) const
295 { return m_ll
< ll
.m_ll
; }
296 bool operator<(long l
) const
298 bool operator>(const wxLongLongNative
& ll
) const
299 { return m_ll
> ll
.m_ll
; }
300 bool operator>(long l
) const
302 bool operator<=(const wxLongLongNative
& ll
) const
303 { return m_ll
<= ll
.m_ll
; }
304 bool operator<=(long l
) const
305 { return m_ll
<= l
; }
306 bool operator>=(const wxLongLongNative
& ll
) const
307 { return m_ll
>= ll
.m_ll
; }
308 bool operator>=(long l
) const
309 { return m_ll
>= l
; }
313 // return the string representation of this number
314 wxString
ToString() const;
316 // conversion to byte array: returns a pointer to static buffer!
317 void *asArray() const;
319 #if wxUSE_STD_IOSTREAM
321 friend WXDLLIMPEXP_BASE
322 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
325 friend WXDLLIMPEXP_BASE
326 wxString
& operator<<(wxString
&, const wxLongLongNative
&);
329 friend WXDLLIMPEXP_BASE
330 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxLongLongNative
&);
331 friend WXDLLIMPEXP_BASE
332 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxLongLongNative
&);
340 class WXDLLIMPEXP_BASE wxULongLongNative
344 // default ctor initializes to 0
345 wxULongLongNative() : m_ll(0) { }
347 wxULongLongNative(wxULongLong_t ll
) : m_ll(ll
) { }
349 wxULongLongNative(unsigned long hi
, unsigned long lo
) : m_ll(0)
351 // assign first to avoid precision loss!
352 m_ll
= ((wxULongLong_t
) hi
) << 32;
353 m_ll
|= (wxULongLong_t
) lo
;
356 #if wxUSE_LONGLONG_WX
357 wxULongLongNative(const class wxULongLongWx
&ll
);
360 // default copy ctor is ok
364 // assignment operators
365 // from native 64 bit integer
366 wxULongLongNative
& operator=(wxULongLong_t ll
)
367 { m_ll
= ll
; return *this; }
368 wxULongLongNative
& operator=(wxLongLong_t ll
)
369 { m_ll
= ll
; return *this; }
370 wxULongLongNative
& operator=(int l
)
371 { m_ll
= l
; return *this; }
372 wxULongLongNative
& operator=(long l
)
373 { m_ll
= l
; return *this; }
374 wxULongLongNative
& operator=(unsigned long l
)
375 { m_ll
= l
; return *this; }
376 wxULongLongNative
& operator=(const wxLongLongNative
&ll
)
377 { m_ll
= ll
.GetValue(); return *this; }
378 #if wxUSE_LONGLONG_WX
379 wxULongLongNative
& operator=(wxLongLongWx ll
);
380 wxULongLongNative
& operator=(const class wxULongLongWx
&ll
);
383 // assignment operators from wxULongLongNative is ok
387 unsigned long GetHi() const
388 { return wx_truncate_cast(unsigned long, m_ll
>> 32); }
390 unsigned long GetLo() const
391 { return wx_truncate_cast(unsigned long, m_ll
); }
393 // convert to native ulong long
394 wxULongLong_t
GetValue() const { return m_ll
; }
396 // convert to ulong with range checking in debug mode (only!)
397 unsigned long ToULong() const
399 wxASSERT_MSG( m_ll
<= LONG_MAX
,
400 _T("wxULongLong to long conversion loss of precision") );
402 return wx_truncate_cast(unsigned long, m_ll
);
407 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
408 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
409 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
410 { m_ll
+= ll
.m_ll
; return *this; }
412 wxULongLongNative
operator+(const wxULongLong_t ll
) const
413 { return wxULongLongNative(m_ll
+ ll
); }
414 wxULongLongNative
& operator+=(const wxULongLong_t ll
)
415 { m_ll
+= ll
; return *this; }
418 wxULongLongNative
& operator++()
419 { m_ll
++; return *this; }
422 wxULongLongNative
operator++(int)
423 { wxULongLongNative
value(*this); m_ll
++; return value
; }
426 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
427 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
428 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
429 { m_ll
-= ll
.m_ll
; return *this; }
431 wxULongLongNative
operator-(const wxULongLong_t ll
) const
432 { return wxULongLongNative(m_ll
- ll
); }
433 wxULongLongNative
& operator-=(const wxULongLong_t ll
)
434 { m_ll
-= ll
; return *this; }
437 wxULongLongNative
& operator--()
438 { m_ll
--; return *this; }
441 wxULongLongNative
operator--(int)
442 { wxULongLongNative
value(*this); m_ll
--; return value
; }
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>>(int shift
) const
453 { return wxULongLongNative(m_ll
>> shift
); }
454 wxULongLongNative
& operator>>=(int shift
)
455 { m_ll
>>= shift
; 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 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
469 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
470 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
471 { m_ll
^= ll
.m_ll
; return *this; }
473 // multiplication/division
474 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
475 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
476 wxULongLongNative
operator*(unsigned long l
) const
477 { return wxULongLongNative(m_ll
* l
); }
478 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
479 { m_ll
*= ll
.m_ll
; return *this; }
480 wxULongLongNative
& operator*=(unsigned long l
)
481 { m_ll
*= l
; return *this; }
483 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
484 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
485 wxULongLongNative
operator/(unsigned long l
) const
486 { return wxULongLongNative(m_ll
/ l
); }
487 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
488 { m_ll
/= ll
.m_ll
; return *this; }
489 wxULongLongNative
& operator/=(unsigned long l
)
490 { m_ll
/= l
; return *this; }
492 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
493 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
494 wxULongLongNative
operator%(unsigned long l
) const
495 { return wxULongLongNative(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
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
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
517 { return m_ll
<= l
; }
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
; }
525 // return the string representation of this number
526 wxString
ToString() const;
528 // conversion to byte array: returns a pointer to static buffer!
529 void *asArray() const;
531 #if wxUSE_STD_IOSTREAM
533 friend WXDLLIMPEXP_BASE
534 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
537 friend WXDLLIMPEXP_BASE
538 wxString
& operator<<(wxString
&, const wxULongLongNative
&);
541 friend WXDLLIMPEXP_BASE
542 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxULongLongNative
&);
543 friend WXDLLIMPEXP_BASE
544 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxULongLongNative
&);
552 wxLongLongNative
& wxLongLongNative::operator=(const wxULongLongNative
&ll
)
554 m_ll
= ll
.GetValue();
558 #endif // wxUSE_LONGLONG_NATIVE
560 #if wxUSE_LONGLONG_WX
562 class WXDLLIMPEXP_BASE wxLongLongWx
566 // default ctor initializes to 0
571 #ifdef wxLONGLONG_TEST_MODE
575 #endif // wxLONGLONG_TEST_MODE
578 wxLongLongWx(long l
) { *this = l
; }
580 wxLongLongWx(long hi
, unsigned long lo
)
585 #ifdef wxLONGLONG_TEST_MODE
591 #endif // wxLONGLONG_TEST_MODE
594 // default copy ctor is ok in both cases
598 // assignment operators
600 wxLongLongWx
& operator=(long l
)
603 m_hi
= (l
< 0 ? -1l : 0l);
605 #ifdef wxLONGLONG_TEST_MODE
609 #endif // wxLONGLONG_TEST_MODE
614 wxLongLongWx
& operator=(int l
)
616 return operator=((long)l
);
619 wxLongLongWx
& operator=(unsigned long l
)
624 #ifdef wxLONGLONG_TEST_MODE
628 #endif // wxLONGLONG_TEST_MODE
632 wxLongLongWx
& operator=(const class wxULongLongWx
&ll
);
635 wxLongLongWx
& Assign(double d
);
636 // can't have assignment operator from 2 longs
640 long GetHi() const { return m_hi
; }
642 unsigned long GetLo() const { return m_lo
; }
644 // get absolute value
645 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
651 #ifdef wxLONGLONG_TEST_MODE
656 #endif // wxLONGLONG_TEST_MODE
661 // convert to long with range checking in debug mode (only!)
664 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
665 _T("wxLongLong to long conversion loss of precision") );
671 double ToDouble() const;
675 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
676 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
677 wxLongLongWx
operator+(long l
) const;
678 wxLongLongWx
& operator+=(long l
);
680 // pre increment operator
681 wxLongLongWx
& operator++();
683 // post increment operator
684 wxLongLongWx
& operator++(int) { return ++(*this); }
687 wxLongLongWx
operator-() const;
688 wxLongLongWx
& Negate();
691 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
692 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
694 // pre decrement operator
695 wxLongLongWx
& operator--();
697 // post decrement operator
698 wxLongLongWx
& operator--(int) { return --(*this); }
702 wxLongLongWx
operator<<(int shift
) const;
703 wxLongLongWx
& operator<<=(int shift
);
706 wxLongLongWx
operator>>(int shift
) const;
707 wxLongLongWx
& operator>>=(int shift
);
710 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
711 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
712 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
713 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
714 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
715 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
716 wxLongLongWx
operator~() const;
719 bool operator==(const wxLongLongWx
& ll
) const
720 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
721 #if wxUSE_LONGLONG_NATIVE
722 bool operator==(const wxLongLongNative
& ll
) const
723 { return m_lo
== ll
.GetLo() && m_hi
== ll
.GetHi(); }
725 bool operator!=(const wxLongLongWx
& ll
) const
726 { return !(*this == ll
); }
727 bool operator<(const wxLongLongWx
& ll
) const;
728 bool operator>(const wxLongLongWx
& ll
) const;
729 bool operator<=(const wxLongLongWx
& ll
) const
730 { return *this < ll
|| *this == ll
; }
731 bool operator>=(const wxLongLongWx
& ll
) const
732 { return *this > ll
|| *this == ll
; }
734 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
735 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
736 bool operator==(long l
) const
738 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
739 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
742 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
743 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
746 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
747 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
750 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
751 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
753 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
755 void Divide(const wxLongLongWx
& divisor
,
756 wxLongLongWx
& quotient
,
757 wxLongLongWx
& remainder
) const;
761 // return the string representation of this number
762 wxString
ToString() const;
764 void *asArray() const;
766 #if wxUSE_STD_IOSTREAM
767 friend WXDLLIMPEXP_BASE
768 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
769 #endif // wxUSE_STD_IOSTREAM
771 friend WXDLLIMPEXP_BASE
772 wxString
& operator<<(wxString
&, const wxLongLongWx
&);
775 friend WXDLLIMPEXP_BASE
776 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxLongLongWx
&);
777 friend WXDLLIMPEXP_BASE
778 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxLongLongWx
&);
782 // long is at least 32 bits, so represent our 64bit number as 2 longs
784 long m_hi
; // signed bit is in the high part
787 #ifdef wxLONGLONG_TEST_MODE
790 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
794 #endif // wxLONGLONG_TEST_MODE
798 class WXDLLIMPEXP_BASE wxULongLongWx
802 // default ctor initializes to 0
807 #ifdef wxLONGLONG_TEST_MODE
811 #endif // wxLONGLONG_TEST_MODE
814 wxULongLongWx(unsigned long l
) { *this = l
; }
816 wxULongLongWx(unsigned long hi
, unsigned long lo
)
821 #ifdef wxLONGLONG_TEST_MODE
827 #endif // wxLONGLONG_TEST_MODE
830 // from signed to unsigned
831 wxULongLongWx(wxLongLongWx ll
)
833 wxASSERT(ll
.GetHi() >= 0);
834 m_hi
= (unsigned long)ll
.GetHi();
838 // default copy ctor is ok in both cases
842 // assignment operators
844 wxULongLongWx
& operator=(unsigned long l
)
849 #ifdef wxLONGLONG_TEST_MODE
853 #endif // wxLONGLONG_TEST_MODE
857 wxULongLongWx
& operator=(long l
)
860 m_hi
= (unsigned long) ((l
<0) ? -1l : 0);
862 #ifdef wxLONGLONG_TEST_MODE
863 m_ll
= (wxULongLong_t
) (wxLongLong_t
) l
;
866 #endif // wxLONGLONG_TEST_MODE
870 wxULongLongWx
& operator=(const class wxLongLongWx
&ll
) {
871 // Should we use an assert like it was before in the constructor?
872 // wxASSERT(ll.GetHi() >= 0);
873 m_hi
= (unsigned long)ll
.GetHi();
878 // can't have assignment operator from 2 longs
882 unsigned long GetHi() const { return m_hi
; }
884 unsigned long GetLo() const { return m_lo
; }
886 // convert to long with range checking in debug mode (only!)
887 unsigned long ToULong() const
889 wxASSERT_MSG( m_hi
== 0ul,
890 _T("wxULongLong to long conversion loss of precision") );
892 return (unsigned long)m_lo
;
897 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
898 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
899 wxULongLongWx
operator+(unsigned long l
) const;
900 wxULongLongWx
& operator+=(unsigned long l
);
902 // pre increment operator
903 wxULongLongWx
& operator++();
905 // post increment operator
906 wxULongLongWx
& operator++(int) { return ++(*this); }
909 wxLongLongWx
operator-(const wxULongLongWx
& ll
) const;
910 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
912 // pre decrement operator
913 wxULongLongWx
& operator--();
915 // post decrement operator
916 wxULongLongWx
& operator--(int) { return --(*this); }
920 wxULongLongWx
operator<<(int shift
) const;
921 wxULongLongWx
& operator<<=(int shift
);
924 wxULongLongWx
operator>>(int shift
) const;
925 wxULongLongWx
& operator>>=(int shift
);
928 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
929 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
930 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
931 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
932 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
933 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
934 wxULongLongWx
operator~() const;
937 bool operator==(const wxULongLongWx
& ll
) const
938 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
939 bool operator!=(const wxULongLongWx
& ll
) const
940 { return !(*this == ll
); }
941 bool operator<(const wxULongLongWx
& ll
) const;
942 bool operator>(const wxULongLongWx
& ll
) const;
943 bool operator<=(const wxULongLongWx
& ll
) const
944 { return *this < ll
|| *this == ll
; }
945 bool operator>=(const wxULongLongWx
& ll
) const
946 { return *this > ll
|| *this == ll
; }
948 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
949 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
950 bool operator==(unsigned long l
) const
952 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
955 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
956 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
959 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
960 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
963 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
964 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
966 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
968 void Divide(const wxULongLongWx
& divisor
,
969 wxULongLongWx
& quotient
,
970 wxULongLongWx
& remainder
) const;
974 // return the string representation of this number
975 wxString
ToString() const;
977 void *asArray() const;
979 #if wxUSE_STD_IOSTREAM
980 friend WXDLLIMPEXP_BASE
981 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
982 #endif // wxUSE_STD_IOSTREAM
984 friend WXDLLIMPEXP_BASE
985 wxString
& operator<<(wxString
&, const wxULongLongWx
&);
988 friend WXDLLIMPEXP_BASE
989 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxULongLongWx
&);
990 friend WXDLLIMPEXP_BASE
991 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxULongLongWx
&);
995 // long is at least 32 bits, so represent our 64bit number as 2 longs
1000 #ifdef wxLONGLONG_TEST_MODE
1003 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
1007 #endif // wxLONGLONG_TEST_MODE
1010 #endif // wxUSE_LONGLONG_WX
1012 // ----------------------------------------------------------------------------
1014 // ----------------------------------------------------------------------------
1016 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
1017 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
< l
; }
1018 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
>= l
; }
1019 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
<= l
; }
1020 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
1021 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
1023 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
1024 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
1026 return wxLongLong(l
) - ll
;
1029 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
1030 inline bool operator>(unsigned long l
, const wxULongLong
& ull
) { return ull
< l
; }
1031 inline bool operator<=(unsigned long l
, const wxULongLong
& ull
) { return ull
>= l
; }
1032 inline bool operator>=(unsigned long l
, const wxULongLong
& ull
) { return ull
<= l
; }
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
; }
1036 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
1038 inline wxLongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
1040 wxULongLong ret
= wxULongLong(l
) - ull
;
1041 return wxLongLong((long)ret
.GetHi(),ret
.GetLo());
1044 #if wxUSE_LONGLONG_NATIVE && wxUSE_STREAMS
1046 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&stream
, wxULongLong_t value
);
1047 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&stream
, wxLongLong_t value
);
1049 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&stream
, wxULongLong_t
&value
);
1050 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&stream
, wxLongLong_t
&value
);
1054 #endif // wxUSE_LONGLONG
1056 #endif // _WX_LONGLONG_H