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 license
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_LONGLONG_H
14 #define _WX_LONGLONG_H
17 #pragma interface "longlong.h"
21 #include "wx/string.h"
23 #include <limits.h> // for LONG_MAX
25 // define this to compile wxLongLongWx in "test" mode: the results of all
26 // calculations will be compared with the real results taken from
27 // wxLongLongNative -- this is extremely useful to find the bugs in
28 // wxLongLongWx class!
30 // #define wxLONGLONG_TEST_MODE
32 #ifdef wxLONGLONG_TEST_MODE
33 #define wxUSE_LONGLONG_WX 1
34 #define wxUSE_LONGLONG_NATIVE 1
35 #endif // wxLONGLONG_TEST_MODE
37 // ----------------------------------------------------------------------------
38 // decide upon which class we will use
39 // ----------------------------------------------------------------------------
41 // to avoid compilation problems on 64bit machines with ambiguous method calls
42 // we will need to define this
43 #undef wxLongLongIsLong
45 // NB: we #define and not typedef wxLongLong_t because we want to be able to
46 // use 'unsigned wxLongLong_t' as well and because we use "#ifdef
47 // wxLongLong_t" below
49 // first check for generic cases which are long on 64bit machine and "long
50 // long", then check for specific compilers
51 #if defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
52 #define wxLongLong_t long
53 #define wxLongLongIsLong
54 #elif (defined(__VISUALC__) && defined(__WIN32__)) || defined( __VMS__ )
55 #define wxLongLong_t __int64
56 #elif defined(__BORLANDC__) && defined(__WIN32__) && (__BORLANDC__ >= 0x520)
57 #define wxLongLong_t __int64
58 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG >= 8
59 #define wxLongLong_t long long
60 #elif defined(__MINGW32__) || defined(__CYGWIN__) || defined(__WXMICROWIN__)
61 #define wxLongLong_t long long
62 #elif defined(__MWERKS__)
63 #if __option(longlong)
64 #define wxLongLong_t long long
66 #error "The 64 bit integer support in CodeWarrior has been disabled."
67 #error "See the documentation on the 'longlong' pragma."
69 #elif defined(__VISAGECPP__) && __IBMCPP__ >= 400
70 #define wxLongLong_t long long
71 #else // no native long long type
72 // both warning and pragma warning are not portable, but at least an
73 // unknown pragma should never be an error - except that, actually, some
74 // broken compilers don't like it, so we have to disable it in this case
76 #if !(defined(__WATCOMC__) || defined(__VISAGECPP__))
77 #pragma warning "Your compiler does not appear to support 64 bit "\
78 "integers, using emulation class instead.\n" \
79 "Please report your compiler version to " \
80 "wx-dev@lists.wxwindows.org!"
83 #define wxUSE_LONGLONG_WX 1
86 // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
87 // to disable automatic testing (useful for the test program which defines
88 // both classes) but by default we only use one class
89 #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
90 // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
91 // this is useful in test programs and only there
92 #ifndef wxUSE_LONGLONG_NATIVE
93 #define wxUSE_LONGLONG_NATIVE 0
96 class WXDLLEXPORT wxLongLongWx
;
97 #if defined(__VISUALC__) && !defined(__WIN32__)
98 #define wxLongLong wxLongLongWx
99 #define wxULongLong wxULongLongWx
101 typedef wxLongLongWx wxLongLong
;
102 typedef wxULongLongWx wxULongLong
;
106 // if nothing is defined, use native implementation by default, of course
107 #ifndef wxUSE_LONGLONG_NATIVE
108 #define wxUSE_LONGLONG_NATIVE 1
112 #ifndef wxUSE_LONGLONG_WX
113 #define wxUSE_LONGLONG_WX 0
114 class WXDLLEXPORT wxLongLongNative
;
115 class WXDLLEXPORT wxULongLongNative
;
116 typedef wxLongLongNative wxLongLong
;
117 typedef wxULongLongNative wxULongLong
;
120 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
121 // typedef wxLongLong as it wants, we don't do it
123 // ----------------------------------------------------------------------------
124 // choose the appropriate class
125 // ----------------------------------------------------------------------------
127 // we use iostream for wxLongLong output
128 #include "wx/ioswrap.h"
130 #if wxUSE_LONGLONG_NATIVE
132 class WXDLLEXPORT wxLongLongNative
136 // default ctor initializes to 0
137 wxLongLongNative() { m_ll
= 0; }
139 wxLongLongNative(wxLongLong_t ll
) { m_ll
= ll
; }
141 wxLongLongNative(long hi
, unsigned long lo
)
143 // assign first to avoid precision loss!
144 m_ll
= ((wxLongLong_t
) hi
) << 32;
145 m_ll
|= (wxLongLong_t
) lo
;
148 // default copy ctor is ok
152 // assignment operators
153 // from native 64 bit integer
154 wxLongLongNative
& operator=(wxLongLong_t ll
)
155 { m_ll
= ll
; return *this; }
157 // from double: this one has an explicit name because otherwise we
158 // would have ambiguity with "ll = int" and also because we don't want
159 // to have implicit conversions between doubles and wxLongLongs
160 wxLongLongNative
& Assign(double d
)
161 { m_ll
= (wxLongLong_t
)d
; return *this; }
163 // assignment operators from wxLongLongNative is ok
168 { return (long)(m_ll
>> 32); }
170 unsigned long GetLo() const
171 { return (unsigned long)m_ll
; }
173 // get absolute value
174 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
175 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
177 // convert to native long long
178 wxLongLong_t
GetValue() const { return m_ll
; }
180 // implicit conversion for times when we want a native type
181 // or wxLongLong, NOT wxLongLongNative and without having
182 // to ifdef user code for each use.
183 operator wxLongLong_t() const { return m_ll
; }
185 // convert to long with range checking in the debug mode (only!)
188 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
189 _T("wxLongLong to long conversion loss of precision") );
194 // don't provide implicit conversion to wxLongLong_t or we will have an
195 // ambiguity for all arithmetic operations
196 //operator wxLongLong_t() const { return m_ll; }
200 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
201 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
202 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
203 { m_ll
+= ll
.m_ll
; return *this; }
205 wxLongLongNative
operator+(const wxLongLong_t ll
) const
206 { return wxLongLongNative(m_ll
+ ll
); }
207 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
208 { m_ll
+= ll
; return *this; }
211 wxLongLongNative
& operator++()
212 { m_ll
++; return *this; }
215 wxLongLongNative
& operator++(int)
216 { m_ll
++; return *this; }
219 wxLongLongNative
operator-() const
220 { return wxLongLongNative(-m_ll
); }
221 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
224 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
225 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
226 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
227 { m_ll
-= ll
.m_ll
; return *this; }
229 wxLongLongNative
operator-(const wxLongLong_t ll
) const
230 { return wxLongLongNative(m_ll
- ll
); }
231 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
232 { m_ll
-= ll
; return *this; }
235 wxLongLongNative
& operator--()
236 { m_ll
--; return *this; }
239 wxLongLongNative
& operator--(int)
240 { m_ll
--; 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>>(int shift
) const
251 { return wxLongLongNative(m_ll
>> shift
);; }
252 wxLongLongNative
& operator>>=(int shift
)
253 { m_ll
>>= shift
; 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 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
262 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
263 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
264 { m_ll
|= ll
.m_ll
; return *this; }
266 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
267 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
268 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
269 { m_ll
^= ll
.m_ll
; return *this; }
271 // multiplication/division
272 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
273 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
274 wxLongLongNative
operator*(long l
) const
275 { return wxLongLongNative(m_ll
* l
); }
276 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
277 { m_ll
*= ll
.m_ll
; return *this; }
278 wxLongLongNative
& operator*=(long l
)
279 { m_ll
*= l
; return *this; }
281 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
282 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
283 wxLongLongNative
operator/(long l
) const
284 { return wxLongLongNative(m_ll
/ l
); }
285 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
286 { m_ll
/= ll
.m_ll
; return *this; }
287 wxLongLongNative
& operator/=(long l
)
288 { m_ll
/= l
; return *this; }
290 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
291 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
292 wxLongLongNative
operator%(long l
) const
293 { return wxLongLongNative(m_ll
% l
); }
296 bool operator==(const wxLongLongNative
& ll
) const
297 { return m_ll
== ll
.m_ll
; }
298 bool operator==(long l
) const
299 { return m_ll
== l
; }
300 bool operator!=(const wxLongLongNative
& ll
) const
301 { return m_ll
!= ll
.m_ll
; }
302 bool operator!=(long l
) const
303 { return m_ll
!= l
; }
304 bool operator<(const wxLongLongNative
& ll
) const
305 { return m_ll
< ll
.m_ll
; }
306 bool operator<(long l
) const
308 bool operator>(const wxLongLongNative
& ll
) const
309 { return m_ll
> ll
.m_ll
; }
310 bool operator>(long l
) const
312 bool operator<=(const wxLongLongNative
& ll
) const
313 { return m_ll
<= ll
.m_ll
; }
314 bool operator<=(long l
) const
315 { return m_ll
<= l
; }
316 bool operator>=(const wxLongLongNative
& ll
) const
317 { return m_ll
>= ll
.m_ll
; }
318 bool operator>=(long l
) const
319 { return m_ll
>= l
; }
323 // return the string representation of this number
324 wxString
ToString() const;
326 // conversion to byte array: returns a pointer to static buffer!
327 void *asArray() const;
329 #if wxUSE_STD_IOSTREAM
331 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
339 class WXDLLEXPORT wxULongLongNative
343 // default ctor initializes to 0
344 wxULongLongNative() { m_ll
= 0; }
346 wxULongLongNative(unsigned wxLongLong_t ll
) { m_ll
= ll
; }
348 wxULongLongNative(unsigned long hi
, unsigned long lo
)
350 // assign first to avoid precision loss!
351 m_ll
= ((unsigned wxLongLong_t
) hi
) << 32;
352 m_ll
|= (unsigned wxLongLong_t
) lo
;
355 // default copy ctor is ok
359 // assignment operators
360 // from native 64 bit integer
361 wxULongLongNative
& operator=(unsigned wxLongLong_t ll
)
362 { m_ll
= ll
; return *this; }
364 // assignment operators from wxULongLongNative is ok
368 unsigned long GetHi() const
369 { return (unsigned long)(m_ll
>> 32); }
371 unsigned long GetLo() const
372 { return (unsigned long)m_ll
; }
374 // convert to native ulong long
375 unsigned wxLongLong_t
GetValue() const { return m_ll
; }
377 // convert to ulong with range checking in the debug mode (only!)
378 unsigned long ToULong() const
380 wxASSERT_MSG( m_ll
<= LONG_MAX
,
381 _T("wxULongLong to long conversion loss of precision") );
383 return (unsigned long)m_ll
;
386 // don't provide implicit conversion to unsigned wxLongLong_t or we
387 // will have an ambiguity for all arithmetic operations
388 //operator wxULongLong_t() const { return m_ll; }
392 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
393 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
394 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
395 { m_ll
+= ll
.m_ll
; return *this; }
397 wxULongLongNative
operator+(const unsigned wxLongLong_t ll
) const
398 { return wxULongLongNative(m_ll
+ ll
); }
399 wxULongLongNative
& operator+=(const unsigned wxLongLong_t ll
)
400 { m_ll
+= ll
; return *this; }
403 wxULongLongNative
& operator++()
404 { m_ll
++; return *this; }
407 wxULongLongNative
& operator++(int)
408 { m_ll
++; return *this; }
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 unsigned wxLongLong_t ll
) const
417 { return wxULongLongNative(m_ll
- ll
); }
418 wxULongLongNative
& operator-=(const unsigned wxLongLong_t ll
)
419 { m_ll
-= ll
; return *this; }
422 wxULongLongNative
& operator--()
423 { m_ll
--; return *this; }
426 wxULongLongNative
& operator--(int)
427 { m_ll
--; return *this; }
431 wxULongLongNative
operator<<(int shift
) const
432 { return wxULongLongNative(m_ll
<< shift
);; }
433 wxULongLongNative
& operator<<=(int shift
)
434 { m_ll
<<= shift
; return *this; }
437 wxULongLongNative
operator>>(int shift
) const
438 { return wxULongLongNative(m_ll
>> shift
);; }
439 wxULongLongNative
& operator>>=(int shift
)
440 { m_ll
>>= shift
; return *this; }
443 wxULongLongNative
operator&(const wxULongLongNative
& ll
) const
444 { return wxULongLongNative(m_ll
& ll
.m_ll
); }
445 wxULongLongNative
& operator&=(const wxULongLongNative
& ll
)
446 { m_ll
&= ll
.m_ll
; return *this; }
448 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
449 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
450 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
451 { m_ll
|= ll
.m_ll
; return *this; }
453 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
454 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
455 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
456 { m_ll
^= ll
.m_ll
; return *this; }
458 // multiplication/division
459 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
460 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
461 wxULongLongNative
operator*(unsigned long l
) const
462 { return wxULongLongNative(m_ll
* l
); }
463 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
464 { m_ll
*= ll
.m_ll
; return *this; }
465 wxULongLongNative
& operator*=(unsigned long l
)
466 { m_ll
*= l
; return *this; }
468 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
469 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
470 wxULongLongNative
operator/(unsigned long l
) const
471 { return wxULongLongNative(m_ll
/ l
); }
472 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
473 { m_ll
/= ll
.m_ll
; return *this; }
474 wxULongLongNative
& operator/=(unsigned long l
)
475 { m_ll
/= l
; return *this; }
477 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
478 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
479 wxULongLongNative
operator%(unsigned long l
) const
480 { return wxULongLongNative(m_ll
% l
); }
483 bool operator==(const wxULongLongNative
& ll
) const
484 { return m_ll
== ll
.m_ll
; }
485 bool operator==(unsigned long l
) const
486 { return m_ll
== l
; }
487 bool operator!=(const wxULongLongNative
& ll
) const
488 { return m_ll
!= ll
.m_ll
; }
489 bool operator!=(unsigned long l
) const
490 { return m_ll
!= l
; }
491 bool operator<(const wxULongLongNative
& ll
) const
492 { return m_ll
< ll
.m_ll
; }
493 bool operator<(unsigned long l
) const
495 bool operator>(const wxULongLongNative
& ll
) const
496 { return m_ll
> ll
.m_ll
; }
497 bool operator>(unsigned long l
) const
499 bool operator<=(const wxULongLongNative
& ll
) const
500 { return m_ll
<= ll
.m_ll
; }
501 bool operator<=(unsigned long l
) const
502 { return m_ll
<= l
; }
503 bool operator>=(const wxULongLongNative
& ll
) const
504 { return m_ll
>= ll
.m_ll
; }
505 bool operator>=(unsigned long l
) const
506 { return m_ll
>= l
; }
510 // return the string representation of this number
511 wxString
ToString() const;
513 // conversion to byte array: returns a pointer to static buffer!
514 void *asArray() const;
516 #if wxUSE_STD_IOSTREAM
518 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
522 unsigned wxLongLong_t m_ll
;
525 #endif // wxUSE_LONGLONG_NATIVE
527 #if wxUSE_LONGLONG_WX
529 class WXDLLEXPORT wxLongLongWx
533 // default ctor initializes to 0
538 #ifdef wxLONGLONG_TEST_MODE
542 #endif // wxLONGLONG_TEST_MODE
545 wxLongLongWx(long l
) { *this = l
; }
547 wxLongLongWx(long hi
, unsigned long lo
)
552 #ifdef wxLONGLONG_TEST_MODE
558 #endif // wxLONGLONG_TEST_MODE
561 // default copy ctor is ok in both cases
565 // assignment operators
567 wxLongLongWx
& operator=(long l
)
570 m_hi
= (l
< 0 ? -1l : 0l);
572 #ifdef wxLONGLONG_TEST_MODE
576 #endif // wxLONGLONG_TEST_MODE
581 wxLongLongWx
& Assign(double d
);
582 // can't have assignment operator from 2 longs
586 long GetHi() const { return m_hi
; }
588 unsigned long GetLo() const { return m_lo
; }
590 // get absolute value
591 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
597 #ifdef wxLONGLONG_TEST_MODE
602 #endif // wxLONGLONG_TEST_MODE
607 // convert to long with range checking in the debug mode (only!)
610 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
611 _T("wxLongLong to long conversion loss of precision") );
618 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
619 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
620 wxLongLongWx
operator+(long l
) const;
621 wxLongLongWx
& operator+=(long l
);
623 // pre increment operator
624 wxLongLongWx
& operator++();
626 // post increment operator
627 wxLongLongWx
& operator++(int) { return ++(*this); }
630 wxLongLongWx
operator-() const;
631 wxLongLongWx
& Negate();
634 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
635 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
637 // pre decrement operator
638 wxLongLongWx
& operator--();
640 // post decrement operator
641 wxLongLongWx
& operator--(int) { return --(*this); }
645 wxLongLongWx
operator<<(int shift
) const;
646 wxLongLongWx
& operator<<=(int shift
);
649 wxLongLongWx
operator>>(int shift
) const;
650 wxLongLongWx
& operator>>=(int shift
);
653 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
654 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
655 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
656 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
657 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
658 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
659 wxLongLongWx
operator~() const;
662 bool operator==(const wxLongLongWx
& ll
) const
663 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
664 bool operator!=(const wxLongLongWx
& ll
) const
665 { return !(*this == ll
); }
666 bool operator<(const wxLongLongWx
& ll
) const;
667 bool operator>(const wxLongLongWx
& ll
) const;
668 bool operator<=(const wxLongLongWx
& ll
) const
669 { return *this < ll
|| *this == ll
; }
670 bool operator>=(const wxLongLongWx
& ll
) const
671 { return *this > ll
|| *this == ll
; }
673 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
674 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
675 bool operator==(long l
) const
677 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
678 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
681 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
682 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
685 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
686 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
689 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
690 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
692 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
694 void Divide(const wxLongLongWx
& divisor
,
695 wxLongLongWx
& quotient
,
696 wxLongLongWx
& remainder
) const;
700 // return the string representation of this number
701 wxString
ToString() const;
703 void *asArray() const;
705 #if wxUSE_STD_IOSTREAM
706 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
707 #endif // wxUSE_STD_IOSTREAM
710 // long is at least 32 bits, so represent our 64bit number as 2 longs
712 long m_hi
; // signed bit is in the high part
715 #ifdef wxLONGLONG_TEST_MODE
718 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
722 #endif // wxLONGLONG_TEST_MODE
726 class WXDLLEXPORT wxULongLongWx
730 // default ctor initializes to 0
735 #ifdef wxLONGLONG_TEST_MODE
739 #endif // wxLONGLONG_TEST_MODE
742 wxULongLongWx(unsigned long l
) { *this = l
; }
744 wxULongLongWx(unsigned long hi
, unsigned long lo
)
749 #ifdef wxLONGLONG_TEST_MODE
755 #endif // wxLONGLONG_TEST_MODE
758 // default copy ctor is ok in both cases
762 // assignment operators
764 wxULongLongWx
& operator=(unsigned long l
)
769 #ifdef wxLONGLONG_TEST_MODE
773 #endif // wxLONGLONG_TEST_MODE
778 // can't have assignment operator from 2 longs
782 unsigned long GetHi() const { return m_hi
; }
784 unsigned long GetLo() const { return m_lo
; }
786 // convert to long with range checking in the debug mode (only!)
787 unsigned long ToULong() const
789 wxASSERT_MSG( (m_hi
== 0l),
790 _T("wxULongLong to long conversion loss of precision") );
792 return (unsigned long)m_lo
;
797 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
798 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
799 wxULongLongWx
operator+(unsigned long l
) const;
800 wxULongLongWx
& operator+=(unsigned long l
);
802 // pre increment operator
803 wxULongLongWx
& operator++();
805 // post increment operator
806 wxULongLongWx
& operator++(int) { return ++(*this); }
809 wxULongLongWx
operator-(const wxULongLongWx
& ll
) const;
810 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
812 // pre decrement operator
813 wxULongLongWx
& operator--();
815 // post decrement operator
816 wxULongLongWx
& operator--(int) { return --(*this); }
820 wxULongLongWx
operator<<(int shift
) const;
821 wxULongLongWx
& operator<<=(int shift
);
824 wxULongLongWx
operator>>(int shift
) const;
825 wxULongLongWx
& operator>>=(int shift
);
828 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
829 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
830 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
831 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
832 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
833 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
834 wxULongLongWx
operator~() const;
837 bool operator==(const wxULongLongWx
& ll
) const
838 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
839 bool operator!=(const wxULongLongWx
& ll
) const
840 { return !(*this == ll
); }
841 bool operator<(const wxULongLongWx
& ll
) const;
842 bool operator>(const wxULongLongWx
& ll
) const;
843 bool operator<=(const wxULongLongWx
& ll
) const
844 { return *this < ll
|| *this == ll
; }
845 bool operator>=(const wxULongLongWx
& ll
) const
846 { return *this > ll
|| *this == ll
; }
848 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
849 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
850 bool operator==(unsigned long l
) const
852 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
855 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
856 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
859 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
860 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
863 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
864 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
866 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
868 void Divide(const wxULongLongWx
& divisor
,
869 wxULongLongWx
& quotient
,
870 wxULongLongWx
& remainder
) const;
874 // return the string representation of this number
875 wxString
ToString() const;
877 void *asArray() const;
879 #if wxUSE_STD_IOSTREAM
880 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
881 #endif // wxUSE_STD_IOSTREAM
884 // long is at least 32 bits, so represent our 64bit number as 2 longs
889 #ifdef wxLONGLONG_TEST_MODE
892 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
895 unsigned wxLongLong_t m_ll
;
896 #endif // wxLONGLONG_TEST_MODE
899 #endif // wxUSE_LONGLONG_WX
901 // ----------------------------------------------------------------------------
903 // ----------------------------------------------------------------------------
905 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
906 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
> l
; }
907 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
> l
; }
908 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
> l
; }
909 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
> l
; }
910 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
> l
; }
912 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
913 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
) { return ll
- l
; }
915 inline bool operator<(unsigned long l
, const wxULongLong
& ll
) { return ll
> l
; }
916 inline bool operator>(unsigned long l
, const wxULongLong
& ll
) { return ll
> l
; }
917 inline bool operator<=(unsigned long l
, const wxULongLong
& ll
) { return ll
> l
; }
918 inline bool operator>=(unsigned long l
, const wxULongLong
& ll
) { return ll
> l
; }
919 inline bool operator==(unsigned long l
, const wxULongLong
& ll
) { return ll
> l
; }
920 inline bool operator!=(unsigned long l
, const wxULongLong
& ll
) { return ll
> l
; }
922 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ll
) { return ll
+ l
; }
923 inline wxULongLong
operator-(unsigned long l
, const wxULongLong
& ll
) { return ll
- l
; }
925 #endif // _WX_LONGLONG_H