1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/longlong.cpp
3 // Purpose: implementation of wxLongLongNative
4 // Author: Jeffrey C. Ollie <jeff@ollie.clive.ia.us>, Vadim Zeitlin
5 // Remarks: this class is not public in wxWidgets 2.0! It is intentionally
6 // not documented and is for private use only.
10 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 // ============================================================================
16 // ============================================================================
18 #include "wx/wxprec.h"
26 #include "wx/longlong.h"
29 #include "wx/math.h" // for fabs()
33 #include "wx/txtstrm.h"
36 #if defined(__MWERKS__) && defined(__WXMSW__)
37 #include <string.h> // for memset()
39 #include <memory.h> // for memset()
42 #include "wx/ioswrap.h"
44 // ============================================================================
46 // ============================================================================
48 #if wxUSE_LONGLONG_NATIVE
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 void *wxLongLongNative::asArray() const
56 static unsigned char temp
[8];
58 temp
[0] = wx_truncate_cast(unsigned char, ((m_ll
>> 56) & 0xFF));
59 temp
[1] = wx_truncate_cast(unsigned char, ((m_ll
>> 48) & 0xFF));
60 temp
[2] = wx_truncate_cast(unsigned char, ((m_ll
>> 40) & 0xFF));
61 temp
[3] = wx_truncate_cast(unsigned char, ((m_ll
>> 32) & 0xFF));
62 temp
[4] = wx_truncate_cast(unsigned char, ((m_ll
>> 24) & 0xFF));
63 temp
[5] = wx_truncate_cast(unsigned char, ((m_ll
>> 16) & 0xFF));
64 temp
[6] = wx_truncate_cast(unsigned char, ((m_ll
>> 8) & 0xFF));
65 temp
[7] = wx_truncate_cast(unsigned char, ((m_ll
>> 0) & 0xFF));
70 void *wxULongLongNative::asArray() const
72 static unsigned char temp
[8];
74 temp
[0] = wx_truncate_cast(unsigned char, ((m_ll
>> 56) & 0xFF));
75 temp
[1] = wx_truncate_cast(unsigned char, ((m_ll
>> 48) & 0xFF));
76 temp
[2] = wx_truncate_cast(unsigned char, ((m_ll
>> 40) & 0xFF));
77 temp
[3] = wx_truncate_cast(unsigned char, ((m_ll
>> 32) & 0xFF));
78 temp
[4] = wx_truncate_cast(unsigned char, ((m_ll
>> 24) & 0xFF));
79 temp
[5] = wx_truncate_cast(unsigned char, ((m_ll
>> 16) & 0xFF));
80 temp
[6] = wx_truncate_cast(unsigned char, ((m_ll
>> 8) & 0xFF));
81 temp
[7] = wx_truncate_cast(unsigned char, ((m_ll
>> 0) & 0xFF));
87 wxLongLongNative::wxLongLongNative(wxLongLongWx ll
)
89 // assign first to avoid precision loss!
95 wxLongLongNative
& wxLongLongNative::operator=(wxLongLongWx ll
)
97 // assign first to avoid precision loss!
104 wxLongLongNative
& wxLongLongNative::operator=(const class wxULongLongWx
&ll
)
106 // assign first to avoid precision loss!
113 wxULongLongNative::wxULongLongNative(const class wxULongLongWx
&ll
)
115 // assign first to avoid precision loss!
118 m_ll
|= ((unsigned long) ll
.GetLo());
121 wxULongLongNative
& wxULongLongNative::operator=(wxLongLongWx ll
)
123 // assign first to avoid precision loss!
126 m_ll
|= ((unsigned long) ll
.GetLo());
130 wxULongLongNative
& wxULongLongNative::operator=(const class wxULongLongWx
&ll
)
132 // assign first to avoid precision loss!
135 m_ll
|= ((unsigned long) ll
.GetLo());
140 #endif // wxUSE_LONGLONG_NATIVE
142 // ============================================================================
143 // wxLongLongWx: emulation of 'long long' using 2 longs
144 // ============================================================================
146 #if wxUSE_LONGLONG_WX
148 // Set value from unsigned wxULongLongWx
149 wxLongLongWx
&wxLongLongWx::operator=(const class wxULongLongWx
&ll
)
151 m_hi
= (unsigned long) ll
.GetHi();
157 wxLongLongWx
& wxLongLongWx::Assign(double d
)
159 bool positive
= d
>= 0;
161 if ( d
<= ULONG_MAX
)
168 m_hi
= (unsigned long)(d
/ (1.0 + (double)ULONG_MAX
));
169 m_lo
= (unsigned long)(d
- ((double)m_hi
* (1.0 + (double)ULONG_MAX
)));
172 #ifdef wxLONGLONG_TEST_MODE
173 m_ll
= (wxLongLong_t
)d
;
176 #endif // wxLONGLONG_TEST_MODE
184 double wxLongLongWx::ToDouble() const
187 d
*= 1.0 + (double)ULONG_MAX
;
190 #ifdef wxLONGLONG_TEST_MODE
191 wxASSERT( d
== m_ll
);
192 #endif // wxLONGLONG_TEST_MODE
197 double wxULongLongWx::ToDouble() const
199 unsigned double d
= m_hi
;
200 d
*= 1.0 + (double)ULONG_MAX
;
203 #ifdef wxLONGLONG_TEST_MODE
204 wxASSERT( d
== m_ll
);
205 #endif // wxLONGLONG_TEST_MODE
210 wxLongLongWx
wxLongLongWx::operator<<(int shift
) const
212 wxLongLongWx
ll(*this);
218 wxULongLongWx
wxULongLongWx::operator<<(int shift
) const
220 wxULongLongWx
ll(*this);
226 wxLongLongWx
& wxLongLongWx::operator<<=(int shift
)
233 m_hi
|= m_lo
>> (32 - shift
);
238 m_hi
= m_lo
<< (shift
- 32);
243 #ifdef wxLONGLONG_TEST_MODE
247 #endif // wxLONGLONG_TEST_MODE
252 wxULongLongWx
& wxULongLongWx::operator<<=(int shift
)
259 m_hi
|= m_lo
>> (32 - shift
);
264 m_hi
= m_lo
<< (shift
- 32);
269 #ifdef wxLONGLONG_TEST_MODE
273 #endif // wxLONGLONG_TEST_MODE
278 wxLongLongWx
wxLongLongWx::operator>>(int shift
) const
280 wxLongLongWx
ll(*this);
286 wxULongLongWx
wxULongLongWx::operator>>(int shift
) const
288 wxULongLongWx
ll(*this);
294 wxLongLongWx
& wxLongLongWx::operator>>=(int shift
)
301 m_lo
|= m_hi
<< (32 - shift
);
306 m_lo
= m_hi
>> (shift
- 32);
307 m_hi
= (m_hi
< 0 ? -1L : 0);
311 #ifdef wxLONGLONG_TEST_MODE
315 #endif // wxLONGLONG_TEST_MODE
320 wxULongLongWx
& wxULongLongWx::operator>>=(int shift
)
327 m_lo
|= m_hi
<< (32 - shift
);
332 m_lo
= m_hi
>> (shift
- 32);
337 #ifdef wxLONGLONG_TEST_MODE
341 #endif // wxLONGLONG_TEST_MODE
346 wxLongLongWx
wxLongLongWx::operator+(const wxLongLongWx
& ll
) const
348 wxLongLongWx
res(*this);
354 wxULongLongWx
wxULongLongWx::operator+(const wxULongLongWx
& ll
) const
356 wxULongLongWx
res(*this);
362 wxLongLongWx
wxLongLongWx::operator+(long l
) const
364 wxLongLongWx
res(*this);
370 wxULongLongWx
wxULongLongWx::operator+(unsigned long l
) const
372 wxULongLongWx
res(*this);
378 wxLongLongWx
& wxLongLongWx::operator+=(const wxLongLongWx
& ll
)
380 unsigned long previous
= m_lo
;
385 if ((m_lo
< previous
) || (m_lo
< ll
.m_lo
))
388 #ifdef wxLONGLONG_TEST_MODE
392 #endif // wxLONGLONG_TEST_MODE
397 wxULongLongWx
& wxULongLongWx::operator+=(const wxULongLongWx
& ll
)
399 unsigned long previous
= m_lo
;
404 if ((m_lo
< previous
) || (m_lo
< ll
.m_lo
))
407 #ifdef wxLONGLONG_TEST_MODE
411 #endif // wxLONGLONG_TEST_MODE
416 wxLongLongWx
& wxLongLongWx::operator+=(long l
)
418 unsigned long previous
= m_lo
;
424 if ((m_lo
< previous
) || (m_lo
< (unsigned long)l
))
427 #ifdef wxLONGLONG_TEST_MODE
431 #endif // wxLONGLONG_TEST_MODE
436 wxULongLongWx
& wxULongLongWx::operator+=(unsigned long l
)
438 unsigned long previous
= m_lo
;
442 if ((m_lo
< previous
) || (m_lo
< l
))
445 #ifdef wxLONGLONG_TEST_MODE
449 #endif // wxLONGLONG_TEST_MODE
455 wxLongLongWx
& wxLongLongWx::operator++()
461 #ifdef wxLONGLONG_TEST_MODE
465 #endif // wxLONGLONG_TEST_MODE
470 wxULongLongWx
& wxULongLongWx::operator++()
476 #ifdef wxLONGLONG_TEST_MODE
480 #endif // wxLONGLONG_TEST_MODE
486 wxLongLongWx
wxLongLongWx::operator-() const
488 wxLongLongWx
res(*this);
494 wxLongLongWx
& wxLongLongWx::Negate()
503 #ifdef wxLONGLONG_TEST_MODE
507 #endif // wxLONGLONG_TEST_MODE
514 wxLongLongWx
wxLongLongWx::operator-(const wxLongLongWx
& ll
) const
516 wxLongLongWx
res(*this);
522 wxLongLongWx
wxULongLongWx::operator-(const wxULongLongWx
& ll
) const
524 wxASSERT(m_hi
<= LONG_MAX
);
525 wxASSERT(ll
.m_hi
<= LONG_MAX
);
527 wxLongLongWx
res( (long)m_hi
, m_lo
);
528 wxLongLongWx
op( (long)ll
.m_hi
, ll
.m_lo
);
534 wxLongLongWx
& wxLongLongWx::operator-=(const wxLongLongWx
& ll
)
536 unsigned long previous
= m_lo
;
541 if (previous
< ll
.m_lo
)
544 #ifdef wxLONGLONG_TEST_MODE
548 #endif // wxLONGLONG_TEST_MODE
553 wxULongLongWx
& wxULongLongWx::operator-=(const wxULongLongWx
& ll
)
555 unsigned long previous
= m_lo
;
560 if (previous
< ll
.m_lo
)
563 #ifdef wxLONGLONG_TEST_MODE
567 #endif // wxLONGLONG_TEST_MODE
573 wxLongLongWx
& wxLongLongWx::operator--()
576 if (m_lo
== 0xFFFFFFFF)
579 #ifdef wxLONGLONG_TEST_MODE
583 #endif // wxLONGLONG_TEST_MODE
588 wxULongLongWx
& wxULongLongWx::operator--()
591 if (m_lo
== 0xFFFFFFFF)
594 #ifdef wxLONGLONG_TEST_MODE
598 #endif // wxLONGLONG_TEST_MODE
603 // comparison operators
605 bool wxLongLongWx::operator<(const wxLongLongWx
& ll
) const
607 if ( m_hi
< ll
.m_hi
)
609 else if ( m_hi
== ll
.m_hi
)
610 return m_lo
< ll
.m_lo
;
615 bool wxULongLongWx::operator<(const wxULongLongWx
& ll
) const
617 if ( m_hi
< ll
.m_hi
)
619 else if ( m_hi
== ll
.m_hi
)
620 return m_lo
< ll
.m_lo
;
625 bool wxLongLongWx::operator>(const wxLongLongWx
& ll
) const
627 if ( m_hi
> ll
.m_hi
)
629 else if ( m_hi
== ll
.m_hi
)
630 return m_lo
> ll
.m_lo
;
635 bool wxULongLongWx::operator>(const wxULongLongWx
& ll
) const
637 if ( m_hi
> ll
.m_hi
)
639 else if ( m_hi
== ll
.m_hi
)
640 return m_lo
> ll
.m_lo
;
647 wxLongLongWx
wxLongLongWx::operator&(const wxLongLongWx
& ll
) const
649 return wxLongLongWx(m_hi
& ll
.m_hi
, m_lo
& ll
.m_lo
);
652 wxULongLongWx
wxULongLongWx::operator&(const wxULongLongWx
& ll
) const
654 return wxULongLongWx(m_hi
& ll
.m_hi
, m_lo
& ll
.m_lo
);
657 wxLongLongWx
wxLongLongWx::operator|(const wxLongLongWx
& ll
) const
659 return wxLongLongWx(m_hi
| ll
.m_hi
, m_lo
| ll
.m_lo
);
662 wxULongLongWx
wxULongLongWx::operator|(const wxULongLongWx
& ll
) const
664 return wxULongLongWx(m_hi
| ll
.m_hi
, m_lo
| ll
.m_lo
);
667 wxLongLongWx
wxLongLongWx::operator^(const wxLongLongWx
& ll
) const
669 return wxLongLongWx(m_hi
^ ll
.m_hi
, m_lo
^ ll
.m_lo
);
672 wxULongLongWx
wxULongLongWx::operator^(const wxULongLongWx
& ll
) const
674 return wxULongLongWx(m_hi
^ ll
.m_hi
, m_lo
^ ll
.m_lo
);
677 wxLongLongWx
& wxLongLongWx::operator&=(const wxLongLongWx
& ll
)
682 #ifdef wxLONGLONG_TEST_MODE
686 #endif // wxLONGLONG_TEST_MODE
691 wxULongLongWx
& wxULongLongWx::operator&=(const wxULongLongWx
& ll
)
696 #ifdef wxLONGLONG_TEST_MODE
700 #endif // wxLONGLONG_TEST_MODE
705 wxLongLongWx
& wxLongLongWx::operator|=(const wxLongLongWx
& ll
)
710 #ifdef wxLONGLONG_TEST_MODE
714 #endif // wxLONGLONG_TEST_MODE
719 wxULongLongWx
& wxULongLongWx::operator|=(const wxULongLongWx
& ll
)
724 #ifdef wxLONGLONG_TEST_MODE
728 #endif // wxLONGLONG_TEST_MODE
733 wxLongLongWx
& wxLongLongWx::operator^=(const wxLongLongWx
& ll
)
738 #ifdef wxLONGLONG_TEST_MODE
742 #endif // wxLONGLONG_TEST_MODE
747 wxULongLongWx
& wxULongLongWx::operator^=(const wxULongLongWx
& ll
)
752 #ifdef wxLONGLONG_TEST_MODE
756 #endif // wxLONGLONG_TEST_MODE
761 wxLongLongWx
wxLongLongWx::operator~() const
763 return wxLongLongWx(~m_hi
, ~m_lo
);
766 wxULongLongWx
wxULongLongWx::operator~() const
768 return wxULongLongWx(~m_hi
, ~m_lo
);
773 wxLongLongWx
wxLongLongWx::operator*(const wxLongLongWx
& ll
) const
775 wxLongLongWx
res(*this);
781 wxULongLongWx
wxULongLongWx::operator*(const wxULongLongWx
& ll
) const
783 wxULongLongWx
res(*this);
789 wxLongLongWx
& wxLongLongWx::operator*=(const wxLongLongWx
& ll
)
791 wxLongLongWx
t(m_hi
, m_lo
);
792 wxLongLongWx
q(ll
.m_hi
, ll
.m_lo
);
796 #ifdef wxLONGLONG_TEST_MODE
797 wxLongLong_t llOld
= m_ll
;
799 #endif // wxLONGLONG_TEST_MODE
804 if ((q
.m_lo
& 1) != 0)
810 while ((counter
< 64) && ((q
.m_hi
!= 0) || (q
.m_lo
!= 0)));
812 #ifdef wxLONGLONG_TEST_MODE
813 m_ll
= llOld
* ll
.m_ll
;
816 #endif // wxLONGLONG_TEST_MODE
821 wxULongLongWx
& wxULongLongWx::operator*=(const wxULongLongWx
& ll
)
823 wxULongLongWx
t(m_hi
, m_lo
);
824 wxULongLongWx
q(ll
.m_hi
, ll
.m_lo
);
828 #ifdef wxLONGLONG_TEST_MODE
829 wxULongLong_t llOld
= m_ll
;
831 #endif // wxLONGLONG_TEST_MODE
836 if ((q
.m_lo
& 1) != 0)
842 while ((counter
< 64) && ((q
.m_hi
!= 0) || (q
.m_lo
!= 0)));
844 #ifdef wxLONGLONG_TEST_MODE
845 m_ll
= llOld
* ll
.m_ll
;
848 #endif // wxLONGLONG_TEST_MODE
855 #define IS_MSB_SET(ll) ((ll.GetHi()) & (1 << (8*sizeof(long) - 1)))
857 void wxLongLongWx::Divide(const wxLongLongWx
& divisorIn
,
858 wxLongLongWx
& quotient
,
859 wxLongLongWx
& remainderIO
) const
861 if ((divisorIn
.m_lo
== 0) && (divisorIn
.m_hi
== 0))
863 // provoke division by zero error and silence the compilers warnings
864 // about an expression without effect and unused variable
865 long dummy
= divisorIn
.m_lo
/divisorIn
.m_hi
;
869 // VZ: I'm writing this in a hurry and it's surely not the fastest way to
870 // do this - any improvements are more than welcome
872 // code inspired by the snippet at
873 // http://www.bearcave.com/software/divide.htm
877 // Use of this program, for any purpose, is granted the author, Ian
878 // Kaplan, as long as this copyright notice is included in the source
879 // code or any source code derived from this program. The user assumes
880 // all responsibility for using this code.
883 wxULongLongWx dividend
, divisor
, remainder
;
888 // always do unsigned division and adjust the signs later: in C integer
889 // division, the sign of the remainder is the same as the sign of the
890 // dividend, while the sign of the quotient is the product of the signs of
891 // the dividend and divisor. Of course, we also always have
893 // dividend = quotient*divisor + remainder
895 // with 0 <= abs(remainder) < abs(divisor)
896 bool negRemainder
= GetHi() < 0;
897 bool negQuotient
= false; // assume positive
900 negQuotient
= !negQuotient
;
905 if ( divisorIn
.GetHi() < 0 )
907 negQuotient
= !negQuotient
;
908 divisor
= -divisorIn
;
913 // check for some particular cases
914 if ( divisor
> dividend
)
916 remainder
= dividend
;
918 else if ( divisor
== dividend
)
924 // here: dividend > divisor and both are positive: do unsigned division
928 while ( remainder
< divisor
)
931 if ( IS_MSB_SET(dividend
) )
942 // undo the last loop iteration
947 for ( size_t i
= 0; i
< nBits
; i
++ )
950 if ( IS_MSB_SET(dividend
) )
955 wxLongLongWx t
= remainder
- divisor
;
958 if ( !IS_MSB_SET(t
) )
967 remainderIO
= remainder
;
972 remainderIO
= -remainderIO
;
977 quotient
= -quotient
;
981 void wxULongLongWx::Divide(const wxULongLongWx
& divisorIn
,
982 wxULongLongWx
& quotient
,
983 wxULongLongWx
& remainder
) const
985 if ((divisorIn
.m_lo
== 0) && (divisorIn
.m_hi
== 0))
987 // provoke division by zero error and silence the compilers warnings
988 // about an expression without effect and unused variable
989 unsigned long dummy
= divisorIn
.m_lo
/divisorIn
.m_hi
;
993 // VZ: I'm writing this in a hurry and it's surely not the fastest way to
994 // do this - any improvements are more than welcome
996 // code inspired by the snippet at
997 // http://www.bearcave.com/software/divide.htm
1001 // Use of this program, for any purpose, is granted the author, Ian
1002 // Kaplan, as long as this copyright notice is included in the source
1003 // code or any source code derived from this program. The user assumes
1004 // all responsibility for using this code.
1007 wxULongLongWx dividend
= *this,
1008 divisor
= divisorIn
;
1013 // check for some particular cases
1014 if ( divisor
> dividend
)
1016 remainder
= dividend
;
1018 else if ( divisor
== dividend
)
1024 // here: dividend > divisor
1028 while ( remainder
< divisor
)
1031 if ( IS_MSB_SET(dividend
) )
1042 // undo the last loop iteration
1047 for ( size_t i
= 0; i
< nBits
; i
++ )
1050 if ( IS_MSB_SET(dividend
) )
1055 wxULongLongWx t
= remainder
- divisor
;
1058 if ( !IS_MSB_SET(t
) )
1068 wxLongLongWx
wxLongLongWx::operator/(const wxLongLongWx
& ll
) const
1070 wxLongLongWx quotient
, remainder
;
1072 Divide(ll
, quotient
, remainder
);
1077 wxULongLongWx
wxULongLongWx::operator/(const wxULongLongWx
& ll
) const
1079 wxULongLongWx quotient
, remainder
;
1081 Divide(ll
, quotient
, remainder
);
1086 wxLongLongWx
& wxLongLongWx::operator/=(const wxLongLongWx
& ll
)
1088 wxLongLongWx quotient
, remainder
;
1090 Divide(ll
, quotient
, remainder
);
1097 wxULongLongWx
& wxULongLongWx::operator/=(const wxULongLongWx
& ll
)
1099 wxULongLongWx quotient
, remainder
;
1101 Divide(ll
, quotient
, remainder
);
1108 wxLongLongWx
wxLongLongWx::operator%(const wxLongLongWx
& ll
) const
1110 wxLongLongWx quotient
, remainder
;
1112 Divide(ll
, quotient
, remainder
);
1117 wxULongLongWx
wxULongLongWx::operator%(const wxULongLongWx
& ll
) const
1119 wxULongLongWx quotient
, remainder
;
1121 Divide(ll
, quotient
, remainder
);
1126 // ----------------------------------------------------------------------------
1128 // ----------------------------------------------------------------------------
1130 // temporary - just for testing
1131 void *wxLongLongWx::asArray(void) const
1133 static unsigned char temp
[8];
1135 temp
[0] = (char)((m_hi
>> 24) & 0xFF);
1136 temp
[1] = (char)((m_hi
>> 16) & 0xFF);
1137 temp
[2] = (char)((m_hi
>> 8) & 0xFF);
1138 temp
[3] = (char)((m_hi
>> 0) & 0xFF);
1139 temp
[4] = (char)((m_lo
>> 24) & 0xFF);
1140 temp
[5] = (char)((m_lo
>> 16) & 0xFF);
1141 temp
[6] = (char)((m_lo
>> 8) & 0xFF);
1142 temp
[7] = (char)((m_lo
>> 0) & 0xFF);
1147 void *wxULongLongWx::asArray(void) const
1149 static unsigned char temp
[8];
1151 temp
[0] = (char)((m_hi
>> 24) & 0xFF);
1152 temp
[1] = (char)((m_hi
>> 16) & 0xFF);
1153 temp
[2] = (char)((m_hi
>> 8) & 0xFF);
1154 temp
[3] = (char)((m_hi
>> 0) & 0xFF);
1155 temp
[4] = (char)((m_lo
>> 24) & 0xFF);
1156 temp
[5] = (char)((m_lo
>> 16) & 0xFF);
1157 temp
[6] = (char)((m_lo
>> 8) & 0xFF);
1158 temp
[7] = (char)((m_lo
>> 0) & 0xFF);
1163 #endif // wxUSE_LONGLONG_WX
1165 #define LL_TO_STRING(name) \
1166 wxString name::ToString() const \
1168 /* TODO: this is awfully inefficient, anything better? */ \
1173 bool neg = ll < 0; \
1178 long digit = (ll % 10).ToLong(); \
1179 result.Prepend((wxChar)(_T('0') - digit)); \
1187 long digit = (ll % 10).ToLong(); \
1188 result.Prepend((wxChar)(_T('0') + digit)); \
1193 if ( result.empty() ) \
1196 result.Prepend(_T('-')); \
1201 #define ULL_TO_STRING(name) \
1202 wxString name::ToString() const \
1204 /* TODO: this is awfully inefficient, anything better? */ \
1211 result.Prepend((wxChar)(_T('0') + (ll % 10).ToULong())); \
1215 if ( result.empty() ) \
1221 #if wxUSE_LONGLONG_NATIVE
1222 LL_TO_STRING(wxLongLongNative
)
1223 ULL_TO_STRING(wxULongLongNative
)
1226 #if wxUSE_LONGLONG_WX
1227 LL_TO_STRING(wxLongLongWx
)
1228 ULL_TO_STRING(wxULongLongWx
)
1231 #if wxUSE_STD_IOSTREAM
1235 wxSTD ostream
& operator<< (wxSTD ostream
& o
, const wxLongLong
& ll
)
1237 return o
<< ll
.ToString();
1241 wxSTD ostream
& operator<< (wxSTD ostream
& o
, const wxULongLong
& ll
)
1243 return o
<< ll
.ToString();
1246 #endif // wxUSE_STD_IOSTREAM
1248 WXDLLIMPEXP_BASE wxString
& operator<< (wxString
& s
, const wxLongLong
& ll
)
1250 return s
<< ll
.ToString();
1253 WXDLLIMPEXP_BASE wxString
& operator<< (wxString
& s
, const wxULongLong
& ll
)
1255 return s
<< ll
.ToString();
1260 WXDLLIMPEXP_BASE wxTextOutputStream
& operator<< (wxTextOutputStream
& o
, const wxULongLong
& ll
)
1262 return o
<< ll
.ToString();
1265 WXDLLIMPEXP_BASE wxTextOutputStream
& operator<< (wxTextOutputStream
& o
, const wxLongLong
& ll
)
1267 return o
<< ll
.ToString();
1270 #define READ_STRING_CHAR(s, idx, len) ((wxChar) ((idx!=len) ? s[idx++] : 0))
1272 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&o
, wxULongLong
&ll
)
1274 wxString s
= o
.ReadWord();
1276 ll
= wxULongLong(0l, 0l);
1277 size_t length
= s
.length();
1280 wxChar ch
= READ_STRING_CHAR(s
, idx
, length
);
1283 while (ch
==wxT(' ') || ch
==wxT('\t'))
1284 ch
= READ_STRING_CHAR(s
, idx
, length
);
1287 wxULongLong
multiplier(0l, 10l);
1288 while (ch
>=wxT('0') && ch
<=wxT('9')) {
1289 long lValue
= (unsigned) (ch
- wxT('0'));
1290 ll
= ll
* multiplier
+ wxULongLong(0l, lValue
);
1291 ch
= READ_STRING_CHAR(s
, idx
, length
);
1297 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&o
, wxLongLong
&ll
)
1299 wxString s
= o
.ReadWord();
1301 ll
= wxLongLong(0l, 0l);
1302 size_t length
= s
.length();
1305 wxChar ch
= READ_STRING_CHAR(s
, idx
, length
);
1308 while (ch
==wxT(' ') || ch
==wxT('\t'))
1309 ch
= READ_STRING_CHAR(s
, idx
, length
);
1313 if (ch
==wxT('-') || ch
==wxT('+')) {
1314 iSign
= ((ch
==wxT('-')) ? -1 : 1);
1315 ch
= READ_STRING_CHAR(s
, idx
, length
);
1319 wxLongLong
multiplier(0l, 10l);
1320 while (ch
>=wxT('0') && ch
<=wxT('9')) {
1321 long lValue
= (unsigned) (ch
- wxT('0'));
1322 ll
= ll
* multiplier
+ wxLongLong(0l, lValue
);
1323 ch
= READ_STRING_CHAR(s
, idx
, length
);
1326 #if wxUSE_LONGLONG_NATIVE
1327 ll
= ll
* wxLongLong((wxLongLong_t
) iSign
);
1329 ll
= ll
* wxLongLong((long) iSign
);
1335 #if wxUSE_LONGLONG_NATIVE
1337 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&o
, wxULongLong_t value
)
1339 return o
<< wxULongLong(value
).ToString();
1342 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&o
, wxLongLong_t value
)
1344 return o
<< wxLongLong(value
).ToString();
1347 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&o
, wxULongLong_t
&value
)
1351 value
= ll
.GetValue();
1355 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&o
, wxLongLong_t
&value
)
1359 value
= ll
.GetValue();
1363 #endif // wxUSE_LONGLONG_NATIVE
1365 #endif // wxUSE_STREAMS
1367 #endif // wxUSE_LONGLONG