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 int l
)
144 { m_ll
= l
; return *this; }
145 wxLongLongNative
& operator=(unsigned long l
)
146 { m_ll
= l
; return *this; }
147 #if wxUSE_LONGLONG_WX
148 wxLongLongNative
& operator=(wxLongLongWx ll
);
149 wxLongLongNative
& operator=(const class wxULongLongWx
&ll
);
153 // from double: this one has an explicit name because otherwise we
154 // would have ambiguity with "ll = int" and also because we don't want
155 // to have implicit conversions between doubles and wxLongLongs
156 wxLongLongNative
& Assign(double d
)
157 { m_ll
= (wxLongLong_t
)d
; return *this; }
159 // assignment operators from wxLongLongNative is ok
164 { return wx_truncate_cast(long, m_ll
>> 32); }
166 unsigned long GetLo() const
167 { return wx_truncate_cast(unsigned long, m_ll
); }
169 // get absolute value
170 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
171 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
173 // convert to native long long
174 wxLongLong_t
GetValue() const { return m_ll
; }
176 // convert to long with range checking in debug mode (only!)
179 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
180 _T("wxLongLong to long conversion loss of precision") );
182 return wx_truncate_cast(long, m_ll
);
186 double ToDouble() const { return wx_truncate_cast(double, m_ll
); }
188 // don't provide implicit conversion to wxLongLong_t or we will have an
189 // ambiguity for all arithmetic operations
190 //operator wxLongLong_t() const { return m_ll; }
194 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
195 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
196 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
197 { m_ll
+= ll
.m_ll
; return *this; }
199 wxLongLongNative
operator+(const wxLongLong_t ll
) const
200 { return wxLongLongNative(m_ll
+ ll
); }
201 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
202 { m_ll
+= ll
; return *this; }
205 wxLongLongNative
& operator++()
206 { m_ll
++; return *this; }
209 wxLongLongNative
operator++(int)
210 { wxLongLongNative
value(*this); m_ll
++; return value
; }
213 wxLongLongNative
operator-() const
214 { return wxLongLongNative(-m_ll
); }
215 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
218 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
219 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
220 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
221 { m_ll
-= ll
.m_ll
; return *this; }
223 wxLongLongNative
operator-(const wxLongLong_t ll
) const
224 { return wxLongLongNative(m_ll
- ll
); }
225 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
226 { m_ll
-= ll
; return *this; }
229 wxLongLongNative
& operator--()
230 { m_ll
--; return *this; }
233 wxLongLongNative
operator--(int)
234 { wxLongLongNative
value(*this); m_ll
--; return value
; }
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>>(int shift
) const
245 { return wxLongLongNative(m_ll
>> shift
); }
246 wxLongLongNative
& operator>>=(int shift
)
247 { m_ll
>>= shift
; return *this; }
250 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
251 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
252 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
253 { m_ll
&= ll
.m_ll
; return *this; }
255 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
256 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
257 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
258 { m_ll
|= ll
.m_ll
; return *this; }
260 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
261 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
262 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
263 { m_ll
^= ll
.m_ll
; return *this; }
265 // multiplication/division
266 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
267 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
268 wxLongLongNative
operator*(long l
) const
269 { return wxLongLongNative(m_ll
* l
); }
270 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
271 { m_ll
*= ll
.m_ll
; return *this; }
272 wxLongLongNative
& operator*=(long l
)
273 { m_ll
*= l
; return *this; }
275 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
276 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
277 wxLongLongNative
operator/(long l
) const
278 { return wxLongLongNative(m_ll
/ l
); }
279 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
280 { m_ll
/= ll
.m_ll
; return *this; }
281 wxLongLongNative
& operator/=(long l
)
282 { m_ll
/= l
; return *this; }
284 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
285 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
286 wxLongLongNative
operator%(long l
) const
287 { return wxLongLongNative(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
297 { return m_ll
!= l
; }
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
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
; }
310 bool operator>=(const wxLongLongNative
& ll
) const
311 { return m_ll
>= ll
.m_ll
; }
312 bool operator>=(long l
) const
313 { return m_ll
>= l
; }
317 // return the string representation of this number
318 wxString
ToString() const;
320 // conversion to byte array: returns a pointer to static buffer!
321 void *asArray() const;
323 #if wxUSE_STD_IOSTREAM
325 friend WXDLLIMPEXP_BASE
326 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
329 friend WXDLLIMPEXP_BASE
330 wxString
& operator<<(wxString
&, const wxLongLongNative
&);
333 friend WXDLLIMPEXP_BASE
334 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxLongLongNative
&);
335 friend WXDLLIMPEXP_BASE
336 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxLongLongNative
&);
344 class WXDLLIMPEXP_BASE wxULongLongNative
348 // default ctor initializes to 0
349 wxULongLongNative() : m_ll(0) { }
351 wxULongLongNative(wxULongLong_t ll
) : m_ll(ll
) { }
353 wxULongLongNative(unsigned long hi
, unsigned long lo
) : m_ll(0)
355 // assign first to avoid precision loss!
356 m_ll
= ((wxULongLong_t
) hi
) << 32;
357 m_ll
|= (wxULongLong_t
) lo
;
360 #if wxUSE_LONGLONG_WX
361 wxULongLongNative(const class wxULongLongWx
&ll
);
364 // default copy ctor is ok
368 // assignment operators
369 // from native 64 bit integer
370 #ifndef wxLongLongIsLong
371 wxULongLongNative
& operator=(wxULongLong_t ll
)
372 { m_ll
= ll
; return *this; }
373 wxULongLongNative
& operator=(wxLongLong_t ll
)
374 { m_ll
= ll
; return *this; }
375 #endif // !wxLongLongNative
376 wxULongLongNative
& operator=(int l
)
377 { m_ll
= l
; return *this; }
378 wxULongLongNative
& operator=(long l
)
379 { m_ll
= l
; return *this; }
380 wxULongLongNative
& operator=(unsigned int l
)
381 { m_ll
= l
; return *this; }
382 wxULongLongNative
& operator=(unsigned long l
)
383 { m_ll
= l
; return *this; }
384 wxULongLongNative
& operator=(const wxLongLongNative
&ll
)
385 { m_ll
= ll
.GetValue(); return *this; }
386 #if wxUSE_LONGLONG_WX
387 wxULongLongNative
& operator=(wxLongLongWx ll
);
388 wxULongLongNative
& operator=(const class wxULongLongWx
&ll
);
391 // assignment operators from wxULongLongNative is ok
395 unsigned long GetHi() const
396 { return wx_truncate_cast(unsigned long, m_ll
>> 32); }
398 unsigned long GetLo() const
399 { return wx_truncate_cast(unsigned long, m_ll
); }
401 // convert to native ulong long
402 wxULongLong_t
GetValue() const { return m_ll
; }
404 // convert to ulong with range checking in debug mode (only!)
405 unsigned long ToULong() const
407 wxASSERT_MSG( m_ll
<= LONG_MAX
,
408 _T("wxULongLong to long conversion loss of precision") );
410 return wx_truncate_cast(unsigned long, m_ll
);
415 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
416 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
417 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
418 { m_ll
+= ll
.m_ll
; return *this; }
420 wxULongLongNative
operator+(const wxULongLong_t ll
) const
421 { return wxULongLongNative(m_ll
+ ll
); }
422 wxULongLongNative
& operator+=(const wxULongLong_t ll
)
423 { m_ll
+= ll
; return *this; }
426 wxULongLongNative
& operator++()
427 { m_ll
++; return *this; }
430 wxULongLongNative
operator++(int)
431 { wxULongLongNative
value(*this); m_ll
++; return value
; }
434 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
435 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
436 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
437 { m_ll
-= ll
.m_ll
; return *this; }
439 wxULongLongNative
operator-(const wxULongLong_t ll
) const
440 { return wxULongLongNative(m_ll
- ll
); }
441 wxULongLongNative
& operator-=(const wxULongLong_t ll
)
442 { m_ll
-= ll
; return *this; }
445 wxULongLongNative
& operator--()
446 { m_ll
--; return *this; }
449 wxULongLongNative
operator--(int)
450 { wxULongLongNative
value(*this); m_ll
--; return value
; }
454 wxULongLongNative
operator<<(int shift
) const
455 { return wxULongLongNative(m_ll
<< shift
); }
456 wxULongLongNative
& operator<<=(int shift
)
457 { m_ll
<<= shift
; return *this; }
460 wxULongLongNative
operator>>(int shift
) const
461 { return wxULongLongNative(m_ll
>> shift
); }
462 wxULongLongNative
& operator>>=(int shift
)
463 { m_ll
>>= shift
; return *this; }
466 wxULongLongNative
operator&(const wxULongLongNative
& ll
) const
467 { return wxULongLongNative(m_ll
& ll
.m_ll
); }
468 wxULongLongNative
& operator&=(const wxULongLongNative
& ll
)
469 { m_ll
&= ll
.m_ll
; return *this; }
471 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
472 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
473 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
474 { m_ll
|= ll
.m_ll
; return *this; }
476 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
477 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
478 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
479 { m_ll
^= ll
.m_ll
; return *this; }
481 // multiplication/division
482 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
483 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
484 wxULongLongNative
operator*(unsigned long l
) const
485 { return wxULongLongNative(m_ll
* l
); }
486 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
487 { m_ll
*= ll
.m_ll
; return *this; }
488 wxULongLongNative
& operator*=(unsigned long l
)
489 { m_ll
*= l
; return *this; }
491 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
492 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
493 wxULongLongNative
operator/(unsigned long l
) const
494 { return wxULongLongNative(m_ll
/ l
); }
495 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
496 { m_ll
/= ll
.m_ll
; return *this; }
497 wxULongLongNative
& operator/=(unsigned long l
)
498 { m_ll
/= l
; return *this; }
500 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
501 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
502 wxULongLongNative
operator%(unsigned long l
) const
503 { return wxULongLongNative(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
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
518 bool operator>(const wxULongLongNative
& ll
) const
519 { return m_ll
> ll
.m_ll
; }
520 bool operator>(unsigned long l
) const
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
; }
526 bool operator>=(const wxULongLongNative
& ll
) const
527 { return m_ll
>= ll
.m_ll
; }
528 bool operator>=(unsigned long l
) const
529 { return m_ll
>= l
; }
533 // return the string representation of this number
534 wxString
ToString() const;
536 // conversion to byte array: returns a pointer to static buffer!
537 void *asArray() const;
539 #if wxUSE_STD_IOSTREAM
541 friend WXDLLIMPEXP_BASE
542 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
545 friend WXDLLIMPEXP_BASE
546 wxString
& operator<<(wxString
&, const wxULongLongNative
&);
549 friend WXDLLIMPEXP_BASE
550 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxULongLongNative
&);
551 friend WXDLLIMPEXP_BASE
552 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxULongLongNative
&);
560 wxLongLongNative
& wxLongLongNative::operator=(const wxULongLongNative
&ll
)
562 m_ll
= ll
.GetValue();
566 #endif // wxUSE_LONGLONG_NATIVE
568 #if wxUSE_LONGLONG_WX
570 class WXDLLIMPEXP_BASE wxLongLongWx
574 // default ctor initializes to 0
579 #ifdef wxLONGLONG_TEST_MODE
583 #endif // wxLONGLONG_TEST_MODE
586 wxLongLongWx(long l
) { *this = l
; }
588 wxLongLongWx(long hi
, unsigned long lo
)
593 #ifdef wxLONGLONG_TEST_MODE
599 #endif // wxLONGLONG_TEST_MODE
602 // default copy ctor is ok in both cases
606 // assignment operators
608 wxLongLongWx
& operator=(long l
)
611 m_hi
= (l
< 0 ? -1l : 0l);
613 #ifdef wxLONGLONG_TEST_MODE
617 #endif // wxLONGLONG_TEST_MODE
622 wxLongLongWx
& operator=(int l
)
624 return operator=((long)l
);
627 wxLongLongWx
& operator=(unsigned long l
)
632 #ifdef wxLONGLONG_TEST_MODE
636 #endif // wxLONGLONG_TEST_MODE
641 wxLongLongWx
& operator=(unsigned int l
)
643 return operator=((unsigned long)l
);
646 wxLongLongWx
& operator=(const class wxULongLongWx
&ll
);
649 wxLongLongWx
& Assign(double d
);
650 // can't have assignment operator from 2 longs
654 long GetHi() const { return m_hi
; }
656 unsigned long GetLo() const { return m_lo
; }
658 // get absolute value
659 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
665 #ifdef wxLONGLONG_TEST_MODE
670 #endif // wxLONGLONG_TEST_MODE
675 // convert to long with range checking in debug mode (only!)
678 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
679 _T("wxLongLong to long conversion loss of precision") );
685 double ToDouble() const;
689 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
690 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
691 wxLongLongWx
operator+(long l
) const;
692 wxLongLongWx
& operator+=(long l
);
694 // pre increment operator
695 wxLongLongWx
& operator++();
697 // post increment operator
698 wxLongLongWx
& operator++(int) { return ++(*this); }
701 wxLongLongWx
operator-() const;
702 wxLongLongWx
& Negate();
705 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
706 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
708 // pre decrement operator
709 wxLongLongWx
& operator--();
711 // post decrement operator
712 wxLongLongWx
& operator--(int) { return --(*this); }
716 wxLongLongWx
operator<<(int shift
) const;
717 wxLongLongWx
& operator<<=(int shift
);
720 wxLongLongWx
operator>>(int shift
) const;
721 wxLongLongWx
& operator>>=(int shift
);
724 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
725 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
726 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
727 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
728 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
729 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
730 wxLongLongWx
operator~() const;
733 bool operator==(const wxLongLongWx
& ll
) const
734 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
735 #if wxUSE_LONGLONG_NATIVE
736 bool operator==(const wxLongLongNative
& ll
) const
737 { return m_lo
== ll
.GetLo() && m_hi
== ll
.GetHi(); }
739 bool operator!=(const wxLongLongWx
& ll
) const
740 { return !(*this == ll
); }
741 bool operator<(const wxLongLongWx
& ll
) const;
742 bool operator>(const wxLongLongWx
& ll
) const;
743 bool operator<=(const wxLongLongWx
& ll
) const
744 { return *this < ll
|| *this == ll
; }
745 bool operator>=(const wxLongLongWx
& ll
) const
746 { return *this > ll
|| *this == ll
; }
748 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
749 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
750 bool operator==(long l
) const
752 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
753 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
756 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
757 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
760 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
761 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
764 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
765 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
767 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
769 void Divide(const wxLongLongWx
& divisor
,
770 wxLongLongWx
& quotient
,
771 wxLongLongWx
& remainder
) const;
775 // return the string representation of this number
776 wxString
ToString() const;
778 void *asArray() const;
780 #if wxUSE_STD_IOSTREAM
781 friend WXDLLIMPEXP_BASE
782 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
783 #endif // wxUSE_STD_IOSTREAM
785 friend WXDLLIMPEXP_BASE
786 wxString
& operator<<(wxString
&, const wxLongLongWx
&);
789 friend WXDLLIMPEXP_BASE
790 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxLongLongWx
&);
791 friend WXDLLIMPEXP_BASE
792 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxLongLongWx
&);
796 // long is at least 32 bits, so represent our 64bit number as 2 longs
798 long m_hi
; // signed bit is in the high part
801 #ifdef wxLONGLONG_TEST_MODE
804 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
808 #endif // wxLONGLONG_TEST_MODE
812 class WXDLLIMPEXP_BASE wxULongLongWx
816 // default ctor initializes to 0
821 #ifdef wxLONGLONG_TEST_MODE
825 #endif // wxLONGLONG_TEST_MODE
828 wxULongLongWx(unsigned long l
) { *this = l
; }
830 wxULongLongWx(unsigned long hi
, unsigned long lo
)
835 #ifdef wxLONGLONG_TEST_MODE
841 #endif // wxLONGLONG_TEST_MODE
844 // from signed to unsigned
845 wxULongLongWx(wxLongLongWx ll
)
847 wxASSERT(ll
.GetHi() >= 0);
848 m_hi
= (unsigned long)ll
.GetHi();
852 // default copy ctor is ok in both cases
856 // assignment operators
858 wxULongLongWx
& operator=(unsigned long l
)
863 #ifdef wxLONGLONG_TEST_MODE
867 #endif // wxLONGLONG_TEST_MODE
871 wxULongLongWx
& operator=(long l
)
874 m_hi
= (unsigned long) ((l
<0) ? -1l : 0);
876 #ifdef wxLONGLONG_TEST_MODE
877 m_ll
= (wxULongLong_t
) (wxLongLong_t
) l
;
880 #endif // wxLONGLONG_TEST_MODE
884 wxULongLongWx
& operator=(const class wxLongLongWx
&ll
) {
885 // Should we use an assert like it was before in the constructor?
886 // wxASSERT(ll.GetHi() >= 0);
887 m_hi
= (unsigned long)ll
.GetHi();
892 // can't have assignment operator from 2 longs
896 unsigned long GetHi() const { return m_hi
; }
898 unsigned long GetLo() const { return m_lo
; }
900 // convert to long with range checking in debug mode (only!)
901 unsigned long ToULong() const
903 wxASSERT_MSG( m_hi
== 0ul,
904 _T("wxULongLong to long conversion loss of precision") );
906 return (unsigned long)m_lo
;
911 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
912 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
913 wxULongLongWx
operator+(unsigned long l
) const;
914 wxULongLongWx
& operator+=(unsigned long l
);
916 // pre increment operator
917 wxULongLongWx
& operator++();
919 // post increment operator
920 wxULongLongWx
& operator++(int) { return ++(*this); }
923 wxLongLongWx
operator-(const wxULongLongWx
& ll
) const;
924 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
926 // pre decrement operator
927 wxULongLongWx
& operator--();
929 // post decrement operator
930 wxULongLongWx
& operator--(int) { return --(*this); }
934 wxULongLongWx
operator<<(int shift
) const;
935 wxULongLongWx
& operator<<=(int shift
);
938 wxULongLongWx
operator>>(int shift
) const;
939 wxULongLongWx
& operator>>=(int shift
);
942 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
943 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
944 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
945 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
946 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
947 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
948 wxULongLongWx
operator~() const;
951 bool operator==(const wxULongLongWx
& ll
) const
952 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
953 bool operator!=(const wxULongLongWx
& ll
) const
954 { return !(*this == ll
); }
955 bool operator<(const wxULongLongWx
& ll
) const;
956 bool operator>(const wxULongLongWx
& ll
) const;
957 bool operator<=(const wxULongLongWx
& ll
) const
958 { return *this < ll
|| *this == ll
; }
959 bool operator>=(const wxULongLongWx
& ll
) const
960 { return *this > ll
|| *this == ll
; }
962 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
963 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
964 bool operator==(unsigned long l
) const
966 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
969 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
970 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
973 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
974 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
977 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
978 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
980 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
982 void Divide(const wxULongLongWx
& divisor
,
983 wxULongLongWx
& quotient
,
984 wxULongLongWx
& remainder
) const;
988 // return the string representation of this number
989 wxString
ToString() const;
991 void *asArray() const;
993 #if wxUSE_STD_IOSTREAM
994 friend WXDLLIMPEXP_BASE
995 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
996 #endif // wxUSE_STD_IOSTREAM
998 friend WXDLLIMPEXP_BASE
999 wxString
& operator<<(wxString
&, const wxULongLongWx
&);
1002 friend WXDLLIMPEXP_BASE
1003 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxULongLongWx
&);
1004 friend WXDLLIMPEXP_BASE
1005 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxULongLongWx
&);
1009 // long is at least 32 bits, so represent our 64bit number as 2 longs
1014 #ifdef wxLONGLONG_TEST_MODE
1017 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
1021 #endif // wxLONGLONG_TEST_MODE
1024 #endif // wxUSE_LONGLONG_WX
1026 // ----------------------------------------------------------------------------
1028 // ----------------------------------------------------------------------------
1030 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
1031 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
< l
; }
1032 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
>= l
; }
1033 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
<= l
; }
1034 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
1035 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
1037 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
1038 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
1040 return wxLongLong(l
) - ll
;
1043 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
1044 inline bool operator>(unsigned long l
, const wxULongLong
& ull
) { return ull
< l
; }
1045 inline bool operator<=(unsigned long l
, const wxULongLong
& ull
) { return ull
>= l
; }
1046 inline bool operator>=(unsigned long l
, const wxULongLong
& ull
) { return ull
<= l
; }
1047 inline bool operator==(unsigned long l
, const wxULongLong
& ull
) { return ull
== l
; }
1048 inline bool operator!=(unsigned long l
, const wxULongLong
& ull
) { return ull
!= l
; }
1050 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
1052 inline wxLongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
1054 wxULongLong ret
= wxULongLong(l
) - ull
;
1055 return wxLongLong((long)ret
.GetHi(),ret
.GetLo());
1058 #if wxUSE_LONGLONG_NATIVE && wxUSE_STREAMS
1060 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&stream
, wxULongLong_t value
);
1061 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&stream
, wxLongLong_t value
);
1063 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&stream
, wxULongLong_t
&value
);
1064 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&stream
, wxLongLong_t
&value
);
1068 #endif // wxUSE_LONGLONG
1070 #endif // _WX_LONGLONG_H