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
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_LONGLONG_H
13 #define _WX_LONGLONG_H
19 #include "wx/string.h"
21 #include <limits.h> // for LONG_MAX
23 // define this to compile wxLongLongWx in "test" mode: the results of all
24 // calculations will be compared with the real results taken from
25 // wxLongLongNative -- this is extremely useful to find the bugs in
26 // wxLongLongWx class!
28 // #define wxLONGLONG_TEST_MODE
30 #ifdef wxLONGLONG_TEST_MODE
31 #define wxUSE_LONGLONG_WX 1
32 #define wxUSE_LONGLONG_NATIVE 1
33 #endif // wxLONGLONG_TEST_MODE
35 // ----------------------------------------------------------------------------
36 // decide upon which class we will use
37 // ----------------------------------------------------------------------------
40 // both warning and pragma warning are not portable, but at least an
41 // unknown pragma should never be an error -- except that, actually, some
42 // broken compilers don't like it, so we have to disable it in this case
45 #warning "Your compiler does not appear to support 64 bit "\
46 "integers, using emulation class instead.\n" \
47 "Please report your compiler version to " \
48 "wx-dev@lists.wxwidgets.org!"
49 #elif !(defined(__WATCOMC__) || defined(__VISAGECPP__))
50 #pragma warning "Your compiler does not appear to support 64 bit "\
51 "integers, using emulation class instead.\n" \
52 "Please report your compiler version to " \
53 "wx-dev@lists.wxwidgets.org!"
56 #define wxUSE_LONGLONG_WX 1
59 // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
60 // to disable automatic testing (useful for the test program which defines
61 // both classes) but by default we only use one class
62 #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
63 // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
64 // this is useful in test programs and only there
65 #ifndef wxUSE_LONGLONG_NATIVE
66 #define wxUSE_LONGLONG_NATIVE 0
69 class WXDLLIMPEXP_FWD_BASE wxLongLongWx
;
70 class WXDLLIMPEXP_FWD_BASE wxULongLongWx
;
71 #if defined(__VISUALC__) && !defined(__WIN32__)
72 #define wxLongLong wxLongLongWx
73 #define wxULongLong wxULongLongWx
75 typedef wxLongLongWx wxLongLong
;
76 typedef wxULongLongWx wxULongLong
;
80 // if nothing is defined, use native implementation by default, of course
81 #ifndef wxUSE_LONGLONG_NATIVE
82 #define wxUSE_LONGLONG_NATIVE 1
86 #ifndef wxUSE_LONGLONG_WX
87 #define wxUSE_LONGLONG_WX 0
88 class WXDLLIMPEXP_FWD_BASE wxLongLongNative
;
89 class WXDLLIMPEXP_FWD_BASE wxULongLongNative
;
90 typedef wxLongLongNative wxLongLong
;
91 typedef wxULongLongNative wxULongLong
;
94 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
95 // typedef wxLongLong as it wants, we don't do it
97 // ----------------------------------------------------------------------------
98 // choose the appropriate class
99 // ----------------------------------------------------------------------------
101 // we use iostream for wxLongLong output
102 #include "wx/iosfwrap.h"
104 #if wxUSE_LONGLONG_NATIVE
106 class WXDLLIMPEXP_BASE wxLongLongNative
110 // default ctor initializes to 0
111 wxLongLongNative() : m_ll(0) { }
113 wxLongLongNative(wxLongLong_t ll
) : m_ll(ll
) { }
115 wxLongLongNative(wxInt32 hi
, wxUint32 lo
)
117 // cast to wxLongLong_t first to avoid precision loss!
118 m_ll
= ((wxLongLong_t
) hi
) << 32;
119 m_ll
|= (wxLongLong_t
) lo
;
121 #if wxUSE_LONGLONG_WX
122 wxLongLongNative(wxLongLongWx ll
);
125 // default copy ctor is ok
129 // assignment operators
130 // from native 64 bit integer
131 #ifndef wxLongLongIsLong
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 #endif // !wxLongLongNative
137 wxLongLongNative
& operator=(const wxULongLongNative
&ll
);
138 wxLongLongNative
& operator=(int l
)
139 { m_ll
= l
; return *this; }
140 wxLongLongNative
& operator=(long l
)
141 { m_ll
= l
; return *this; }
142 wxLongLongNative
& operator=(unsigned int l
)
143 { m_ll
= l
; return *this; }
144 wxLongLongNative
& operator=(unsigned long l
)
145 { m_ll
= l
; return *this; }
146 #if wxUSE_LONGLONG_WX
147 wxLongLongNative
& operator=(wxLongLongWx ll
);
148 wxLongLongNative
& operator=(const class wxULongLongWx
&ll
);
152 // from double: this one has an explicit name because otherwise we
153 // would have ambiguity with "ll = int" and also because we don't want
154 // to have implicit conversions between doubles and wxLongLongs
155 wxLongLongNative
& Assign(double d
)
156 { m_ll
= (wxLongLong_t
)d
; return *this; }
158 // assignment operators from wxLongLongNative is ok
162 wxInt32
GetHi() const
163 { return wx_truncate_cast(wxInt32
, m_ll
>> 32); }
165 wxUint32
GetLo() const
166 { return wx_truncate_cast(wxUint32
, m_ll
); }
168 // get absolute value
169 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
170 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
172 // convert to native long long
173 wxLongLong_t
GetValue() const { return m_ll
; }
175 // convert to long with range checking in debug mode (only!)
178 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
179 wxT("wxLongLong to long conversion loss of precision") );
181 return wx_truncate_cast(long, m_ll
);
185 double ToDouble() const { return wx_truncate_cast(double, m_ll
); }
187 // don't provide implicit conversion to wxLongLong_t or we will have an
188 // ambiguity for all arithmetic operations
189 //operator wxLongLong_t() const { return m_ll; }
193 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
194 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
195 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
196 { m_ll
+= ll
.m_ll
; return *this; }
198 wxLongLongNative
operator+(const wxLongLong_t ll
) const
199 { return wxLongLongNative(m_ll
+ ll
); }
200 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
201 { m_ll
+= ll
; return *this; }
204 wxLongLongNative
& operator++()
205 { m_ll
++; return *this; }
208 wxLongLongNative
operator++(int)
209 { wxLongLongNative
value(*this); m_ll
++; return value
; }
212 wxLongLongNative
operator-() const
213 { return wxLongLongNative(-m_ll
); }
214 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
217 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
218 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
219 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
220 { m_ll
-= ll
.m_ll
; return *this; }
222 wxLongLongNative
operator-(const wxLongLong_t ll
) const
223 { return wxLongLongNative(m_ll
- ll
); }
224 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
225 { m_ll
-= ll
; return *this; }
228 wxLongLongNative
& operator--()
229 { m_ll
--; return *this; }
232 wxLongLongNative
operator--(int)
233 { wxLongLongNative
value(*this); m_ll
--; return value
; }
237 wxLongLongNative
operator<<(int shift
) const
238 { return wxLongLongNative(m_ll
<< shift
); }
239 wxLongLongNative
& operator<<=(int shift
)
240 { m_ll
<<= shift
; return *this; }
243 wxLongLongNative
operator>>(int shift
) const
244 { return wxLongLongNative(m_ll
>> shift
); }
245 wxLongLongNative
& operator>>=(int shift
)
246 { m_ll
>>= shift
; 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 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
260 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
261 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
262 { m_ll
^= ll
.m_ll
; return *this; }
264 // multiplication/division
265 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
266 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
267 wxLongLongNative
operator*(long l
) const
268 { return wxLongLongNative(m_ll
* l
); }
269 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
270 { m_ll
*= ll
.m_ll
; return *this; }
271 wxLongLongNative
& operator*=(long l
)
272 { m_ll
*= l
; return *this; }
274 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
275 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
276 wxLongLongNative
operator/(long l
) const
277 { return wxLongLongNative(m_ll
/ l
); }
278 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
279 { m_ll
/= ll
.m_ll
; return *this; }
280 wxLongLongNative
& operator/=(long l
)
281 { m_ll
/= l
; return *this; }
283 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
284 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
285 wxLongLongNative
operator%(long l
) const
286 { return wxLongLongNative(m_ll
% l
); }
289 bool operator==(const wxLongLongNative
& ll
) const
290 { return m_ll
== ll
.m_ll
; }
291 bool operator==(long l
) const
292 { return m_ll
== l
; }
293 bool operator!=(const wxLongLongNative
& ll
) const
294 { return m_ll
!= ll
.m_ll
; }
295 bool operator!=(long l
) const
296 { return m_ll
!= l
; }
297 bool operator<(const wxLongLongNative
& ll
) const
298 { return m_ll
< ll
.m_ll
; }
299 bool operator<(long l
) const
301 bool operator>(const wxLongLongNative
& ll
) const
302 { return m_ll
> ll
.m_ll
; }
303 bool operator>(long l
) const
305 bool operator<=(const wxLongLongNative
& ll
) const
306 { return m_ll
<= ll
.m_ll
; }
307 bool operator<=(long l
) const
308 { return m_ll
<= l
; }
309 bool operator>=(const wxLongLongNative
& ll
) const
310 { return m_ll
>= ll
.m_ll
; }
311 bool operator>=(long l
) const
312 { return m_ll
>= l
; }
316 // return the string representation of this number
317 wxString
ToString() const;
319 // conversion to byte array: returns a pointer to static buffer!
320 void *asArray() const;
322 #if wxUSE_STD_IOSTREAM
324 friend WXDLLIMPEXP_BASE
325 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
328 friend WXDLLIMPEXP_BASE
329 wxString
& operator<<(wxString
&, const wxLongLongNative
&);
332 friend WXDLLIMPEXP_BASE
333 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxLongLongNative
&);
334 friend WXDLLIMPEXP_BASE
335 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxLongLongNative
&);
343 class WXDLLIMPEXP_BASE wxULongLongNative
347 // default ctor initializes to 0
348 wxULongLongNative() : m_ll(0) { }
350 wxULongLongNative(wxULongLong_t ll
) : m_ll(ll
) { }
352 wxULongLongNative(wxUint32 hi
, wxUint32 lo
) : m_ll(0)
354 // cast to wxLongLong_t first to avoid precision loss!
355 m_ll
= ((wxULongLong_t
) hi
) << 32;
356 m_ll
|= (wxULongLong_t
) lo
;
359 #if wxUSE_LONGLONG_WX
360 wxULongLongNative(const class wxULongLongWx
&ll
);
363 // default copy ctor is ok
367 // assignment operators
368 // from native 64 bit integer
369 #ifndef wxLongLongIsLong
370 wxULongLongNative
& operator=(wxULongLong_t ll
)
371 { m_ll
= ll
; return *this; }
372 wxULongLongNative
& operator=(wxLongLong_t ll
)
373 { m_ll
= ll
; return *this; }
374 #endif // !wxLongLongNative
375 wxULongLongNative
& operator=(int l
)
376 { m_ll
= l
; return *this; }
377 wxULongLongNative
& operator=(long l
)
378 { m_ll
= l
; return *this; }
379 wxULongLongNative
& operator=(unsigned int l
)
380 { m_ll
= l
; return *this; }
381 wxULongLongNative
& operator=(unsigned long l
)
382 { m_ll
= l
; return *this; }
383 wxULongLongNative
& operator=(const wxLongLongNative
&ll
)
384 { m_ll
= ll
.GetValue(); return *this; }
385 #if wxUSE_LONGLONG_WX
386 wxULongLongNative
& operator=(wxLongLongWx ll
);
387 wxULongLongNative
& operator=(const class wxULongLongWx
&ll
);
390 // assignment operators from wxULongLongNative is ok
394 wxUint32
GetHi() const
395 { return wx_truncate_cast(wxUint32
, m_ll
>> 32); }
397 wxUint32
GetLo() const
398 { return wx_truncate_cast(wxUint32
, m_ll
); }
400 // convert to native ulong long
401 wxULongLong_t
GetValue() const { return m_ll
; }
403 // convert to ulong with range checking in debug mode (only!)
404 unsigned long ToULong() const
406 wxASSERT_MSG( m_ll
<= ULONG_MAX
,
407 wxT("wxULongLong to long conversion loss of precision") );
409 return wx_truncate_cast(unsigned long, m_ll
);
414 // For some completely obscure reasons compiling the cast below with
415 // VC6 in DLL builds only (!) results in "error C2520: conversion from
416 // unsigned __int64 to double not implemented, use signed __int64" so
417 // we must use a different version for that compiler.
419 double ToDouble() const;
421 double ToDouble() const { return wx_truncate_cast(double, m_ll
); }
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
; }
445 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
446 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
447 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
448 { m_ll
-= ll
.m_ll
; return *this; }
450 wxULongLongNative
operator-(const wxULongLong_t ll
) const
451 { return wxULongLongNative(m_ll
- ll
); }
452 wxULongLongNative
& operator-=(const wxULongLong_t ll
)
453 { m_ll
-= ll
; return *this; }
456 wxULongLongNative
& operator--()
457 { m_ll
--; return *this; }
460 wxULongLongNative
operator--(int)
461 { wxULongLongNative
value(*this); m_ll
--; return value
; }
465 wxULongLongNative
operator<<(int shift
) const
466 { return wxULongLongNative(m_ll
<< shift
); }
467 wxULongLongNative
& operator<<=(int shift
)
468 { m_ll
<<= shift
; return *this; }
471 wxULongLongNative
operator>>(int shift
) const
472 { return wxULongLongNative(m_ll
>> shift
); }
473 wxULongLongNative
& operator>>=(int shift
)
474 { m_ll
>>= shift
; return *this; }
477 wxULongLongNative
operator&(const wxULongLongNative
& ll
) const
478 { return wxULongLongNative(m_ll
& ll
.m_ll
); }
479 wxULongLongNative
& operator&=(const wxULongLongNative
& ll
)
480 { m_ll
&= ll
.m_ll
; return *this; }
482 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
483 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
484 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
485 { m_ll
|= ll
.m_ll
; return *this; }
487 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
488 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
489 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
490 { m_ll
^= ll
.m_ll
; return *this; }
492 // multiplication/division
493 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
494 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
495 wxULongLongNative
operator*(unsigned long l
) const
496 { return wxULongLongNative(m_ll
* l
); }
497 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
498 { m_ll
*= ll
.m_ll
; return *this; }
499 wxULongLongNative
& operator*=(unsigned long l
)
500 { m_ll
*= l
; return *this; }
502 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
503 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
504 wxULongLongNative
operator/(unsigned long l
) const
505 { return wxULongLongNative(m_ll
/ l
); }
506 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
507 { m_ll
/= ll
.m_ll
; return *this; }
508 wxULongLongNative
& operator/=(unsigned long l
)
509 { m_ll
/= l
; return *this; }
511 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
512 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
513 wxULongLongNative
operator%(unsigned long l
) const
514 { return wxULongLongNative(m_ll
% l
); }
517 bool operator==(const wxULongLongNative
& ll
) const
518 { return m_ll
== ll
.m_ll
; }
519 bool operator==(unsigned long l
) const
520 { return m_ll
== l
; }
521 bool operator!=(const wxULongLongNative
& ll
) const
522 { return m_ll
!= ll
.m_ll
; }
523 bool operator!=(unsigned long l
) const
524 { return m_ll
!= l
; }
525 bool operator<(const wxULongLongNative
& ll
) const
526 { return m_ll
< ll
.m_ll
; }
527 bool operator<(unsigned long l
) const
529 bool operator>(const wxULongLongNative
& ll
) const
530 { return m_ll
> ll
.m_ll
; }
531 bool operator>(unsigned long l
) const
533 bool operator<=(const wxULongLongNative
& ll
) const
534 { return m_ll
<= ll
.m_ll
; }
535 bool operator<=(unsigned long l
) const
536 { return m_ll
<= l
; }
537 bool operator>=(const wxULongLongNative
& ll
) const
538 { return m_ll
>= ll
.m_ll
; }
539 bool operator>=(unsigned long l
) const
540 { return m_ll
>= l
; }
544 // return the string representation of this number
545 wxString
ToString() const;
547 // conversion to byte array: returns a pointer to static buffer!
548 void *asArray() const;
550 #if wxUSE_STD_IOSTREAM
552 friend WXDLLIMPEXP_BASE
553 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
556 friend WXDLLIMPEXP_BASE
557 wxString
& operator<<(wxString
&, const wxULongLongNative
&);
560 friend WXDLLIMPEXP_BASE
561 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxULongLongNative
&);
562 friend WXDLLIMPEXP_BASE
563 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxULongLongNative
&);
571 wxLongLongNative
& wxLongLongNative::operator=(const wxULongLongNative
&ll
)
573 m_ll
= ll
.GetValue();
577 #endif // wxUSE_LONGLONG_NATIVE
579 #if wxUSE_LONGLONG_WX
581 class WXDLLIMPEXP_BASE wxLongLongWx
585 // default ctor initializes to 0
590 #ifdef wxLONGLONG_TEST_MODE
594 #endif // wxLONGLONG_TEST_MODE
597 wxLongLongWx(long l
) { *this = l
; }
599 wxLongLongWx(long hi
, unsigned long lo
)
604 #ifdef wxLONGLONG_TEST_MODE
610 #endif // wxLONGLONG_TEST_MODE
613 // default copy ctor is ok in both cases
617 // assignment operators
619 wxLongLongWx
& operator=(long l
)
622 m_hi
= (l
< 0 ? -1l : 0l);
624 #ifdef wxLONGLONG_TEST_MODE
628 #endif // wxLONGLONG_TEST_MODE
633 wxLongLongWx
& operator=(int l
)
635 return operator=((long)l
);
638 wxLongLongWx
& operator=(unsigned long l
)
643 #ifdef wxLONGLONG_TEST_MODE
647 #endif // wxLONGLONG_TEST_MODE
652 wxLongLongWx
& operator=(unsigned int l
)
654 return operator=((unsigned long)l
);
657 wxLongLongWx
& operator=(const class wxULongLongWx
&ll
);
660 wxLongLongWx
& Assign(double d
);
661 // can't have assignment operator from 2 longs
665 long GetHi() const { return m_hi
; }
667 unsigned long GetLo() const { return m_lo
; }
669 // get absolute value
670 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
676 #ifdef wxLONGLONG_TEST_MODE
681 #endif // wxLONGLONG_TEST_MODE
686 // convert to long with range checking in debug mode (only!)
689 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
690 wxT("wxLongLong to long conversion loss of precision") );
696 double ToDouble() const;
700 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
701 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
702 wxLongLongWx
operator+(long l
) const;
703 wxLongLongWx
& operator+=(long l
);
705 // pre increment operator
706 wxLongLongWx
& operator++();
708 // post increment operator
709 wxLongLongWx
& operator++(int) { return ++(*this); }
712 wxLongLongWx
operator-() const;
713 wxLongLongWx
& Negate();
716 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
717 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
719 // pre decrement operator
720 wxLongLongWx
& operator--();
722 // post decrement operator
723 wxLongLongWx
& operator--(int) { return --(*this); }
727 wxLongLongWx
operator<<(int shift
) const;
728 wxLongLongWx
& operator<<=(int shift
);
731 wxLongLongWx
operator>>(int shift
) const;
732 wxLongLongWx
& operator>>=(int shift
);
735 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
736 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
737 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
738 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
739 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
740 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
741 wxLongLongWx
operator~() const;
744 bool operator==(const wxLongLongWx
& ll
) const
745 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
746 #if wxUSE_LONGLONG_NATIVE
747 bool operator==(const wxLongLongNative
& ll
) const
748 { return m_lo
== ll
.GetLo() && m_hi
== ll
.GetHi(); }
750 bool operator!=(const wxLongLongWx
& ll
) const
751 { return !(*this == ll
); }
752 bool operator<(const wxLongLongWx
& ll
) const;
753 bool operator>(const wxLongLongWx
& ll
) const;
754 bool operator<=(const wxLongLongWx
& ll
) const
755 { return *this < ll
|| *this == ll
; }
756 bool operator>=(const wxLongLongWx
& ll
) const
757 { return *this > ll
|| *this == ll
; }
759 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
760 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
761 bool operator==(long l
) const
763 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
764 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
767 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
768 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
771 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
772 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
775 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
776 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
778 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
780 void Divide(const wxLongLongWx
& divisor
,
781 wxLongLongWx
& quotient
,
782 wxLongLongWx
& remainder
) const;
786 // return the string representation of this number
787 wxString
ToString() const;
789 void *asArray() const;
791 #if wxUSE_STD_IOSTREAM
792 friend WXDLLIMPEXP_BASE
793 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
794 #endif // wxUSE_STD_IOSTREAM
796 friend WXDLLIMPEXP_BASE
797 wxString
& operator<<(wxString
&, const wxLongLongWx
&);
800 friend WXDLLIMPEXP_BASE
801 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxLongLongWx
&);
802 friend WXDLLIMPEXP_BASE
803 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxLongLongWx
&);
807 // long is at least 32 bits, so represent our 64bit number as 2 longs
809 long m_hi
; // signed bit is in the high part
812 #ifdef wxLONGLONG_TEST_MODE
815 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
819 #endif // wxLONGLONG_TEST_MODE
823 class WXDLLIMPEXP_BASE wxULongLongWx
827 // default ctor initializes to 0
832 #ifdef wxLONGLONG_TEST_MODE
836 #endif // wxLONGLONG_TEST_MODE
839 wxULongLongWx(unsigned long l
) { *this = l
; }
841 wxULongLongWx(unsigned long hi
, unsigned long lo
)
846 #ifdef wxLONGLONG_TEST_MODE
852 #endif // wxLONGLONG_TEST_MODE
855 // from signed to unsigned
856 wxULongLongWx(wxLongLongWx ll
)
858 wxASSERT(ll
.GetHi() >= 0);
859 m_hi
= (unsigned long)ll
.GetHi();
863 // default copy ctor is ok in both cases
867 // assignment operators
869 wxULongLongWx
& operator=(unsigned long l
)
874 #ifdef wxLONGLONG_TEST_MODE
878 #endif // wxLONGLONG_TEST_MODE
882 wxULongLongWx
& operator=(long l
)
885 m_hi
= (unsigned long) ((l
<0) ? -1l : 0);
887 #ifdef wxLONGLONG_TEST_MODE
888 m_ll
= (wxULongLong_t
) (wxLongLong_t
) l
;
891 #endif // wxLONGLONG_TEST_MODE
895 wxULongLongWx
& operator=(const class wxLongLongWx
&ll
) {
896 // Should we use an assert like it was before in the constructor?
897 // wxASSERT(ll.GetHi() >= 0);
898 m_hi
= (unsigned long)ll
.GetHi();
903 // can't have assignment operator from 2 longs
907 unsigned long GetHi() const { return m_hi
; }
909 unsigned long GetLo() const { return m_lo
; }
911 // convert to long with range checking in debug mode (only!)
912 unsigned long ToULong() const
914 wxASSERT_MSG( m_hi
== 0ul,
915 wxT("wxULongLong to long conversion loss of precision") );
917 return (unsigned long)m_lo
;
921 double ToDouble() const;
925 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
926 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
927 wxULongLongWx
operator+(unsigned long l
) const;
928 wxULongLongWx
& operator+=(unsigned long l
);
930 // pre increment operator
931 wxULongLongWx
& operator++();
933 // post increment operator
934 wxULongLongWx
& operator++(int) { return ++(*this); }
937 wxLongLongWx
operator-(const wxULongLongWx
& ll
) const;
938 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
940 // pre decrement operator
941 wxULongLongWx
& operator--();
943 // post decrement operator
944 wxULongLongWx
& operator--(int) { return --(*this); }
948 wxULongLongWx
operator<<(int shift
) const;
949 wxULongLongWx
& operator<<=(int shift
);
952 wxULongLongWx
operator>>(int shift
) const;
953 wxULongLongWx
& operator>>=(int shift
);
956 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
957 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
958 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
959 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
960 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
961 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
962 wxULongLongWx
operator~() const;
965 bool operator==(const wxULongLongWx
& ll
) const
966 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
967 bool operator!=(const wxULongLongWx
& ll
) const
968 { return !(*this == ll
); }
969 bool operator<(const wxULongLongWx
& ll
) const;
970 bool operator>(const wxULongLongWx
& ll
) const;
971 bool operator<=(const wxULongLongWx
& ll
) const
972 { return *this < ll
|| *this == ll
; }
973 bool operator>=(const wxULongLongWx
& ll
) const
974 { return *this > ll
|| *this == ll
; }
976 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
977 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
978 bool operator==(unsigned long l
) const
980 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
983 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
984 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
987 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
988 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
991 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
992 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
994 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
996 void Divide(const wxULongLongWx
& divisor
,
997 wxULongLongWx
& quotient
,
998 wxULongLongWx
& remainder
) const;
1002 // return the string representation of this number
1003 wxString
ToString() const;
1005 void *asArray() const;
1007 #if wxUSE_STD_IOSTREAM
1008 friend WXDLLIMPEXP_BASE
1009 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
1010 #endif // wxUSE_STD_IOSTREAM
1012 friend WXDLLIMPEXP_BASE
1013 wxString
& operator<<(wxString
&, const wxULongLongWx
&);
1016 friend WXDLLIMPEXP_BASE
1017 class wxTextOutputStream
& operator<<(class wxTextOutputStream
&, const wxULongLongWx
&);
1018 friend WXDLLIMPEXP_BASE
1019 class wxTextInputStream
& operator>>(class wxTextInputStream
&, wxULongLongWx
&);
1023 // long is at least 32 bits, so represent our 64bit number as 2 longs
1028 #ifdef wxLONGLONG_TEST_MODE
1031 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
1035 #endif // wxLONGLONG_TEST_MODE
1038 #endif // wxUSE_LONGLONG_WX
1040 // ----------------------------------------------------------------------------
1042 // ----------------------------------------------------------------------------
1044 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
1045 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
< l
; }
1046 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
>= l
; }
1047 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
<= l
; }
1048 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
1049 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
1051 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
1052 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
1054 return wxLongLong(l
) - ll
;
1057 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
1058 inline bool operator>(unsigned long l
, const wxULongLong
& ull
) { return ull
< l
; }
1059 inline bool operator<=(unsigned long l
, const wxULongLong
& ull
) { return ull
>= l
; }
1060 inline bool operator>=(unsigned long l
, const wxULongLong
& ull
) { return ull
<= l
; }
1061 inline bool operator==(unsigned long l
, const wxULongLong
& ull
) { return ull
== l
; }
1062 inline bool operator!=(unsigned long l
, const wxULongLong
& ull
) { return ull
!= l
; }
1064 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
1066 inline wxLongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
1068 wxULongLong ret
= wxULongLong(l
) - ull
;
1069 return wxLongLong((wxInt32
)ret
.GetHi(),ret
.GetLo());
1072 #if wxUSE_LONGLONG_NATIVE && wxUSE_STREAMS
1074 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&stream
, wxULongLong_t value
);
1075 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&stream
, wxLongLong_t value
);
1077 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&stream
, wxULongLong_t
&value
);
1078 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&stream
, wxLongLong_t
&value
);
1082 // ----------------------------------------------------------------------------
1083 // Specialize numeric_limits<> for our long long wrapper classes.
1084 // ----------------------------------------------------------------------------
1086 #if wxUSE_LONGLONG_NATIVE
1088 // VC6 is known to not have __int64 specializations of numeric_limits<> in its
1089 // <limits> anyhow so don't bother including it, especially as it results in
1090 // tons of warnings because the standard header itself uses obsolete template
1091 // specialization syntax.
1092 #ifndef __VISUALC6__
1100 // libstdc++ (used by Clang) uses struct for numeric_limits; unlike gcc, clang
1102 template<> struct numeric_limits
<wxLongLong
> : public numeric_limits
<wxLongLong_t
> {};
1103 template<> struct numeric_limits
<wxULongLong
> : public numeric_limits
<wxULongLong_t
> {};
1105 template<> class numeric_limits
<wxLongLong
> : public numeric_limits
<wxLongLong_t
> {};
1106 template<> class numeric_limits
<wxULongLong
> : public numeric_limits
<wxULongLong_t
> {};
1113 #endif // wxUSE_LONGLONG_NATIVE
1115 // ----------------------------------------------------------------------------
1116 // Specialize wxArgNormalizer to allow using wxLongLong directly with wx pseudo
1117 // vararg functions.
1118 // ----------------------------------------------------------------------------
1120 // Notice that this must be done here and not in wx/strvararg.h itself because
1121 // we can't include wx/longlong.h from there as this header itself includes
1122 // wx/string.h which includes wx/strvararg.h too, so to avoid the circular
1123 // dependencies we can only do it here (or add another header just for this but
1124 // it doesn't seem necessary).
1125 #include "wx/strvararg.h"
1128 struct WXDLLIMPEXP_BASE wxArgNormalizer
<wxLongLong
>
1130 wxArgNormalizer(wxLongLong value
,
1131 const wxFormatString
*fmt
, unsigned index
)
1134 wxASSERT_ARG_TYPE( fmt
, index
, wxFormatString::Arg_LongLongInt
);
1137 wxLongLong_t
get() const { return m_value
.GetValue(); }
1142 #endif // wxUSE_LONGLONG
1144 #endif // _WX_LONGLONG_H