1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/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"
25 #include "wx/longlong.h"
26 #include "wx/math.h" // for fabs()
29 #include "wx/txtstrm.h"
32 #if defined(__MWERKS__) && defined(__WXMSW__)
33 #include <string.h> // for memset()
35 #include <memory.h> // for memset()
38 #include "wx/ioswrap.h"
40 // ============================================================================
42 // ============================================================================
44 #if wxUSE_LONGLONG_NATIVE
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 void *wxLongLongNative::asArray() const
52 static unsigned char temp
[8];
54 temp
[0] = wx_truncate_cast(unsigned char, ((m_ll
>> 56) & 0xFF));
55 temp
[1] = wx_truncate_cast(unsigned char, ((m_ll
>> 48) & 0xFF));
56 temp
[2] = wx_truncate_cast(unsigned char, ((m_ll
>> 40) & 0xFF));
57 temp
[3] = wx_truncate_cast(unsigned char, ((m_ll
>> 32) & 0xFF));
58 temp
[4] = wx_truncate_cast(unsigned char, ((m_ll
>> 24) & 0xFF));
59 temp
[5] = wx_truncate_cast(unsigned char, ((m_ll
>> 16) & 0xFF));
60 temp
[6] = wx_truncate_cast(unsigned char, ((m_ll
>> 8) & 0xFF));
61 temp
[7] = wx_truncate_cast(unsigned char, ((m_ll
>> 0) & 0xFF));
66 void *wxULongLongNative::asArray() const
68 static unsigned char temp
[8];
70 temp
[0] = wx_truncate_cast(unsigned char, ((m_ll
>> 56) & 0xFF));
71 temp
[1] = wx_truncate_cast(unsigned char, ((m_ll
>> 48) & 0xFF));
72 temp
[2] = wx_truncate_cast(unsigned char, ((m_ll
>> 40) & 0xFF));
73 temp
[3] = wx_truncate_cast(unsigned char, ((m_ll
>> 32) & 0xFF));
74 temp
[4] = wx_truncate_cast(unsigned char, ((m_ll
>> 24) & 0xFF));
75 temp
[5] = wx_truncate_cast(unsigned char, ((m_ll
>> 16) & 0xFF));
76 temp
[6] = wx_truncate_cast(unsigned char, ((m_ll
>> 8) & 0xFF));
77 temp
[7] = wx_truncate_cast(unsigned char, ((m_ll
>> 0) & 0xFF));
83 wxLongLongNative::wxLongLongNative(wxLongLongWx ll
)
85 // assign first to avoid precision loss!
91 wxLongLongNative
& wxLongLongNative::operator=(wxLongLongWx ll
)
93 // assign first to avoid precision loss!
100 wxLongLongNative
& wxLongLongNative::operator=(const class wxULongLongWx
&ll
)
102 // assign first to avoid precision loss!
109 wxULongLongNative::wxULongLongNative(const class wxULongLongWx
&ll
)
111 // assign first to avoid precision loss!
114 m_ll
|= ((unsigned long) ll
.GetLo());
117 wxULongLongNative
& wxULongLongNative::operator=(wxLongLongWx ll
)
119 // assign first to avoid precision loss!
122 m_ll
|= ((unsigned long) ll
.GetLo());
126 wxULongLongNative
& wxULongLongNative::operator=(const class wxULongLongWx
&ll
)
128 // assign first to avoid precision loss!
131 m_ll
|= ((unsigned long) ll
.GetLo());
136 #endif // wxUSE_LONGLONG_NATIVE
138 // ============================================================================
139 // wxLongLongWx: emulation of 'long long' using 2 longs
140 // ============================================================================
142 #if wxUSE_LONGLONG_WX
144 // Set value from unsigned wxULongLongWx
145 wxLongLongWx
&wxLongLongWx::operator=(const class wxULongLongWx
&ll
)
147 m_hi
= (unsigned long) ll
.GetHi();
153 wxLongLongWx
& wxLongLongWx::Assign(double d
)
155 bool positive
= d
>= 0;
157 if ( d
<= ULONG_MAX
)
164 m_hi
= (unsigned long)(d
/ (1.0 + (double)ULONG_MAX
));
165 m_lo
= (unsigned long)(d
- ((double)m_hi
* (1.0 + (double)ULONG_MAX
)));
168 #ifdef wxLONGLONG_TEST_MODE
169 m_ll
= (wxLongLong_t
)d
;
172 #endif // wxLONGLONG_TEST_MODE
180 double wxLongLongWx::ToDouble() const
183 d
*= 1.0 + (double)ULONG_MAX
;
186 #ifdef wxLONGLONG_TEST_MODE
187 wxASSERT( d
== m_ll
);
188 #endif // wxLONGLONG_TEST_MODE
193 wxLongLongWx
wxLongLongWx::operator<<(int shift
) const
195 wxLongLongWx
ll(*this);
201 wxULongLongWx
wxULongLongWx::operator<<(int shift
) const
203 wxULongLongWx
ll(*this);
209 wxLongLongWx
& wxLongLongWx::operator<<=(int shift
)
216 m_hi
|= m_lo
>> (32 - shift
);
221 m_hi
= m_lo
<< (shift
- 32);
226 #ifdef wxLONGLONG_TEST_MODE
230 #endif // wxLONGLONG_TEST_MODE
235 wxULongLongWx
& wxULongLongWx::operator<<=(int shift
)
242 m_hi
|= m_lo
>> (32 - shift
);
247 m_hi
= m_lo
<< (shift
- 32);
252 #ifdef wxLONGLONG_TEST_MODE
256 #endif // wxLONGLONG_TEST_MODE
261 wxLongLongWx
wxLongLongWx::operator>>(int shift
) const
263 wxLongLongWx
ll(*this);
269 wxULongLongWx
wxULongLongWx::operator>>(int shift
) const
271 wxULongLongWx
ll(*this);
277 wxLongLongWx
& wxLongLongWx::operator>>=(int shift
)
284 m_lo
|= m_hi
<< (32 - shift
);
289 m_lo
= m_hi
>> (shift
- 32);
290 m_hi
= (m_hi
< 0 ? -1L : 0);
294 #ifdef wxLONGLONG_TEST_MODE
298 #endif // wxLONGLONG_TEST_MODE
303 wxULongLongWx
& wxULongLongWx::operator>>=(int shift
)
310 m_lo
|= m_hi
<< (32 - shift
);
315 m_lo
= m_hi
>> (shift
- 32);
320 #ifdef wxLONGLONG_TEST_MODE
324 #endif // wxLONGLONG_TEST_MODE
329 wxLongLongWx
wxLongLongWx::operator+(const wxLongLongWx
& ll
) const
331 wxLongLongWx
res(*this);
337 wxULongLongWx
wxULongLongWx::operator+(const wxULongLongWx
& ll
) const
339 wxULongLongWx
res(*this);
345 wxLongLongWx
wxLongLongWx::operator+(long l
) const
347 wxLongLongWx
res(*this);
353 wxULongLongWx
wxULongLongWx::operator+(unsigned long l
) const
355 wxULongLongWx
res(*this);
361 wxLongLongWx
& wxLongLongWx::operator+=(const wxLongLongWx
& ll
)
363 unsigned long previous
= m_lo
;
368 if ((m_lo
< previous
) || (m_lo
< ll
.m_lo
))
371 #ifdef wxLONGLONG_TEST_MODE
375 #endif // wxLONGLONG_TEST_MODE
380 wxULongLongWx
& wxULongLongWx::operator+=(const wxULongLongWx
& ll
)
382 unsigned long previous
= m_lo
;
387 if ((m_lo
< previous
) || (m_lo
< ll
.m_lo
))
390 #ifdef wxLONGLONG_TEST_MODE
394 #endif // wxLONGLONG_TEST_MODE
399 wxLongLongWx
& wxLongLongWx::operator+=(long l
)
401 unsigned long previous
= m_lo
;
407 if ((m_lo
< previous
) || (m_lo
< (unsigned long)l
))
410 #ifdef wxLONGLONG_TEST_MODE
414 #endif // wxLONGLONG_TEST_MODE
419 wxULongLongWx
& wxULongLongWx::operator+=(unsigned long l
)
421 unsigned long previous
= m_lo
;
425 if ((m_lo
< previous
) || (m_lo
< l
))
428 #ifdef wxLONGLONG_TEST_MODE
432 #endif // wxLONGLONG_TEST_MODE
438 wxLongLongWx
& wxLongLongWx::operator++()
444 #ifdef wxLONGLONG_TEST_MODE
448 #endif // wxLONGLONG_TEST_MODE
453 wxULongLongWx
& wxULongLongWx::operator++()
459 #ifdef wxLONGLONG_TEST_MODE
463 #endif // wxLONGLONG_TEST_MODE
469 wxLongLongWx
wxLongLongWx::operator-() const
471 wxLongLongWx
res(*this);
477 wxLongLongWx
& wxLongLongWx::Negate()
486 #ifdef wxLONGLONG_TEST_MODE
490 #endif // wxLONGLONG_TEST_MODE
497 wxLongLongWx
wxLongLongWx::operator-(const wxLongLongWx
& ll
) const
499 wxLongLongWx
res(*this);
505 wxLongLongWx
wxULongLongWx::operator-(const wxULongLongWx
& ll
) const
507 wxASSERT(m_hi
<= LONG_MAX
);
508 wxASSERT(ll
.m_hi
<= LONG_MAX
);
510 wxLongLongWx
res( (long)m_hi
, m_lo
);
511 wxLongLongWx
op( (long)ll
.m_hi
, ll
.m_lo
);
517 wxLongLongWx
& wxLongLongWx::operator-=(const wxLongLongWx
& ll
)
519 unsigned long previous
= m_lo
;
524 if (previous
< ll
.m_lo
)
527 #ifdef wxLONGLONG_TEST_MODE
531 #endif // wxLONGLONG_TEST_MODE
536 wxULongLongWx
& wxULongLongWx::operator-=(const wxULongLongWx
& ll
)
538 unsigned long previous
= m_lo
;
543 if (previous
< ll
.m_lo
)
546 #ifdef wxLONGLONG_TEST_MODE
550 #endif // wxLONGLONG_TEST_MODE
556 wxLongLongWx
& wxLongLongWx::operator--()
559 if (m_lo
== 0xFFFFFFFF)
562 #ifdef wxLONGLONG_TEST_MODE
566 #endif // wxLONGLONG_TEST_MODE
571 wxULongLongWx
& wxULongLongWx::operator--()
574 if (m_lo
== 0xFFFFFFFF)
577 #ifdef wxLONGLONG_TEST_MODE
581 #endif // wxLONGLONG_TEST_MODE
586 // comparison operators
588 bool wxLongLongWx::operator<(const wxLongLongWx
& ll
) const
590 if ( m_hi
< ll
.m_hi
)
592 else if ( m_hi
== ll
.m_hi
)
593 return m_lo
< ll
.m_lo
;
598 bool wxULongLongWx::operator<(const wxULongLongWx
& ll
) const
600 if ( m_hi
< ll
.m_hi
)
602 else if ( m_hi
== ll
.m_hi
)
603 return m_lo
< ll
.m_lo
;
608 bool wxLongLongWx::operator>(const wxLongLongWx
& ll
) const
610 if ( m_hi
> ll
.m_hi
)
612 else if ( m_hi
== ll
.m_hi
)
613 return m_lo
> ll
.m_lo
;
618 bool wxULongLongWx::operator>(const wxULongLongWx
& ll
) const
620 if ( m_hi
> ll
.m_hi
)
622 else if ( m_hi
== ll
.m_hi
)
623 return m_lo
> ll
.m_lo
;
630 wxLongLongWx
wxLongLongWx::operator&(const wxLongLongWx
& ll
) const
632 return wxLongLongWx(m_hi
& ll
.m_hi
, m_lo
& ll
.m_lo
);
635 wxULongLongWx
wxULongLongWx::operator&(const wxULongLongWx
& ll
) const
637 return wxULongLongWx(m_hi
& ll
.m_hi
, m_lo
& ll
.m_lo
);
640 wxLongLongWx
wxLongLongWx::operator|(const wxLongLongWx
& ll
) const
642 return wxLongLongWx(m_hi
| ll
.m_hi
, m_lo
| ll
.m_lo
);
645 wxULongLongWx
wxULongLongWx::operator|(const wxULongLongWx
& ll
) const
647 return wxULongLongWx(m_hi
| ll
.m_hi
, m_lo
| ll
.m_lo
);
650 wxLongLongWx
wxLongLongWx::operator^(const wxLongLongWx
& ll
) const
652 return wxLongLongWx(m_hi
^ ll
.m_hi
, m_lo
^ ll
.m_lo
);
655 wxULongLongWx
wxULongLongWx::operator^(const wxULongLongWx
& ll
) const
657 return wxULongLongWx(m_hi
^ ll
.m_hi
, m_lo
^ ll
.m_lo
);
660 wxLongLongWx
& wxLongLongWx::operator&=(const wxLongLongWx
& ll
)
665 #ifdef wxLONGLONG_TEST_MODE
669 #endif // wxLONGLONG_TEST_MODE
674 wxULongLongWx
& wxULongLongWx::operator&=(const wxULongLongWx
& ll
)
679 #ifdef wxLONGLONG_TEST_MODE
683 #endif // wxLONGLONG_TEST_MODE
688 wxLongLongWx
& wxLongLongWx::operator|=(const wxLongLongWx
& ll
)
693 #ifdef wxLONGLONG_TEST_MODE
697 #endif // wxLONGLONG_TEST_MODE
702 wxULongLongWx
& wxULongLongWx::operator|=(const wxULongLongWx
& ll
)
707 #ifdef wxLONGLONG_TEST_MODE
711 #endif // wxLONGLONG_TEST_MODE
716 wxLongLongWx
& wxLongLongWx::operator^=(const wxLongLongWx
& ll
)
721 #ifdef wxLONGLONG_TEST_MODE
725 #endif // wxLONGLONG_TEST_MODE
730 wxULongLongWx
& wxULongLongWx::operator^=(const wxULongLongWx
& ll
)
735 #ifdef wxLONGLONG_TEST_MODE
739 #endif // wxLONGLONG_TEST_MODE
744 wxLongLongWx
wxLongLongWx::operator~() const
746 return wxLongLongWx(~m_hi
, ~m_lo
);
749 wxULongLongWx
wxULongLongWx::operator~() const
751 return wxULongLongWx(~m_hi
, ~m_lo
);
756 wxLongLongWx
wxLongLongWx::operator*(const wxLongLongWx
& ll
) const
758 wxLongLongWx
res(*this);
764 wxULongLongWx
wxULongLongWx::operator*(const wxULongLongWx
& ll
) const
766 wxULongLongWx
res(*this);
772 wxLongLongWx
& wxLongLongWx::operator*=(const wxLongLongWx
& ll
)
774 wxLongLongWx
t(m_hi
, m_lo
);
775 wxLongLongWx
q(ll
.m_hi
, ll
.m_lo
);
779 #ifdef wxLONGLONG_TEST_MODE
780 wxLongLong_t llOld
= m_ll
;
782 #endif // wxLONGLONG_TEST_MODE
787 if ((q
.m_lo
& 1) != 0)
793 while ((counter
< 64) && ((q
.m_hi
!= 0) || (q
.m_lo
!= 0)));
795 #ifdef wxLONGLONG_TEST_MODE
796 m_ll
= llOld
* ll
.m_ll
;
799 #endif // wxLONGLONG_TEST_MODE
804 wxULongLongWx
& wxULongLongWx::operator*=(const wxULongLongWx
& ll
)
806 wxULongLongWx
t(m_hi
, m_lo
);
807 wxULongLongWx
q(ll
.m_hi
, ll
.m_lo
);
811 #ifdef wxLONGLONG_TEST_MODE
812 wxULongLong_t llOld
= m_ll
;
814 #endif // wxLONGLONG_TEST_MODE
819 if ((q
.m_lo
& 1) != 0)
825 while ((counter
< 64) && ((q
.m_hi
!= 0) || (q
.m_lo
!= 0)));
827 #ifdef wxLONGLONG_TEST_MODE
828 m_ll
= llOld
* ll
.m_ll
;
831 #endif // wxLONGLONG_TEST_MODE
838 #define IS_MSB_SET(ll) ((ll.GetHi()) & (1 << (8*sizeof(long) - 1)))
840 void wxLongLongWx::Divide(const wxLongLongWx
& divisorIn
,
841 wxLongLongWx
& quotient
,
842 wxLongLongWx
& remainderIO
) const
844 if ((divisorIn
.m_lo
== 0) && (divisorIn
.m_hi
== 0))
846 // provoke division by zero error and silence the compilers warnings
847 // about an expression without effect and unused variable
848 long dummy
= divisorIn
.m_lo
/divisorIn
.m_hi
;
852 // VZ: I'm writing this in a hurry and it's surely not the fastest way to
853 // do this - any improvements are more than welcome
855 // code inspired by the snippet at
856 // http://www.bearcave.com/software/divide.htm
860 // Use of this program, for any purpose, is granted the author, Ian
861 // Kaplan, as long as this copyright notice is included in the source
862 // code or any source code derived from this program. The user assumes
863 // all responsibility for using this code.
866 wxULongLongWx dividend
, divisor
, remainder
;
871 // always do unsigned division and adjust the signs later: in C integer
872 // division, the sign of the remainder is the same as the sign of the
873 // dividend, while the sign of the quotient is the product of the signs of
874 // the dividend and divisor. Of course, we also always have
876 // dividend = quotient*divisor + remainder
878 // with 0 <= abs(remainder) < abs(divisor)
879 bool negRemainder
= GetHi() < 0;
880 bool negQuotient
= false; // assume positive
883 negQuotient
= !negQuotient
;
888 if ( divisorIn
.GetHi() < 0 )
890 negQuotient
= !negQuotient
;
891 divisor
= -divisorIn
;
896 // check for some particular cases
897 if ( divisor
> dividend
)
899 remainder
= dividend
;
901 else if ( divisor
== dividend
)
907 // here: dividend > divisor and both are positive: do unsigned division
911 while ( remainder
< divisor
)
914 if ( IS_MSB_SET(dividend
) )
925 // undo the last loop iteration
930 for ( size_t i
= 0; i
< nBits
; i
++ )
933 if ( IS_MSB_SET(dividend
) )
938 wxLongLongWx t
= remainder
- divisor
;
941 if ( !IS_MSB_SET(t
) )
950 remainderIO
= remainder
;
955 remainderIO
= -remainderIO
;
960 quotient
= -quotient
;
964 void wxULongLongWx::Divide(const wxULongLongWx
& divisorIn
,
965 wxULongLongWx
& quotient
,
966 wxULongLongWx
& remainder
) const
968 if ((divisorIn
.m_lo
== 0) && (divisorIn
.m_hi
== 0))
970 // provoke division by zero error and silence the compilers warnings
971 // about an expression without effect and unused variable
972 unsigned long dummy
= divisorIn
.m_lo
/divisorIn
.m_hi
;
976 // VZ: I'm writing this in a hurry and it's surely not the fastest way to
977 // do this - any improvements are more than welcome
979 // code inspired by the snippet at
980 // http://www.bearcave.com/software/divide.htm
984 // Use of this program, for any purpose, is granted the author, Ian
985 // Kaplan, as long as this copyright notice is included in the source
986 // code or any source code derived from this program. The user assumes
987 // all responsibility for using this code.
990 wxULongLongWx dividend
= *this,
996 // check for some particular cases
997 if ( divisor
> dividend
)
999 remainder
= dividend
;
1001 else if ( divisor
== dividend
)
1007 // here: dividend > divisor
1011 while ( remainder
< divisor
)
1014 if ( IS_MSB_SET(dividend
) )
1025 // undo the last loop iteration
1030 for ( size_t i
= 0; i
< nBits
; i
++ )
1033 if ( IS_MSB_SET(dividend
) )
1038 wxULongLongWx t
= remainder
- divisor
;
1041 if ( !IS_MSB_SET(t
) )
1051 wxLongLongWx
wxLongLongWx::operator/(const wxLongLongWx
& ll
) const
1053 wxLongLongWx quotient
, remainder
;
1055 Divide(ll
, quotient
, remainder
);
1060 wxULongLongWx
wxULongLongWx::operator/(const wxULongLongWx
& ll
) const
1062 wxULongLongWx quotient
, remainder
;
1064 Divide(ll
, quotient
, remainder
);
1069 wxLongLongWx
& wxLongLongWx::operator/=(const wxLongLongWx
& ll
)
1071 wxLongLongWx quotient
, remainder
;
1073 Divide(ll
, quotient
, remainder
);
1080 wxULongLongWx
& wxULongLongWx::operator/=(const wxULongLongWx
& ll
)
1082 wxULongLongWx quotient
, remainder
;
1084 Divide(ll
, quotient
, remainder
);
1091 wxLongLongWx
wxLongLongWx::operator%(const wxLongLongWx
& ll
) const
1093 wxLongLongWx quotient
, remainder
;
1095 Divide(ll
, quotient
, remainder
);
1100 wxULongLongWx
wxULongLongWx::operator%(const wxULongLongWx
& ll
) const
1102 wxULongLongWx quotient
, remainder
;
1104 Divide(ll
, quotient
, remainder
);
1109 // ----------------------------------------------------------------------------
1111 // ----------------------------------------------------------------------------
1113 // temporary - just for testing
1114 void *wxLongLongWx::asArray(void) const
1116 static unsigned char temp
[8];
1118 temp
[0] = (char)((m_hi
>> 24) & 0xFF);
1119 temp
[1] = (char)((m_hi
>> 16) & 0xFF);
1120 temp
[2] = (char)((m_hi
>> 8) & 0xFF);
1121 temp
[3] = (char)((m_hi
>> 0) & 0xFF);
1122 temp
[4] = (char)((m_lo
>> 24) & 0xFF);
1123 temp
[5] = (char)((m_lo
>> 16) & 0xFF);
1124 temp
[6] = (char)((m_lo
>> 8) & 0xFF);
1125 temp
[7] = (char)((m_lo
>> 0) & 0xFF);
1130 void *wxULongLongWx::asArray(void) const
1132 static unsigned char temp
[8];
1134 temp
[0] = (char)((m_hi
>> 24) & 0xFF);
1135 temp
[1] = (char)((m_hi
>> 16) & 0xFF);
1136 temp
[2] = (char)((m_hi
>> 8) & 0xFF);
1137 temp
[3] = (char)((m_hi
>> 0) & 0xFF);
1138 temp
[4] = (char)((m_lo
>> 24) & 0xFF);
1139 temp
[5] = (char)((m_lo
>> 16) & 0xFF);
1140 temp
[6] = (char)((m_lo
>> 8) & 0xFF);
1141 temp
[7] = (char)((m_lo
>> 0) & 0xFF);
1146 #endif // wxUSE_LONGLONG_WX
1148 #define LL_TO_STRING(name) \
1149 wxString name::ToString() const \
1151 /* TODO: this is awfully inefficient, anything better? */ \
1156 bool neg = ll < 0; \
1161 long digit = (ll % 10).ToLong(); \
1162 result.Prepend((wxChar)(_T('0') - digit)); \
1170 long digit = (ll % 10).ToLong(); \
1171 result.Prepend((wxChar)(_T('0') + digit)); \
1176 if ( result.empty() ) \
1179 result.Prepend(_T('-')); \
1184 #define ULL_TO_STRING(name) \
1185 wxString name::ToString() const \
1187 /* TODO: this is awfully inefficient, anything better? */ \
1194 result.Prepend((wxChar)(_T('0') + (ll % 10).ToULong())); \
1198 if ( result.empty() ) \
1204 #if wxUSE_LONGLONG_NATIVE
1205 LL_TO_STRING(wxLongLongNative
)
1206 ULL_TO_STRING(wxULongLongNative
)
1209 #if wxUSE_LONGLONG_WX
1210 LL_TO_STRING(wxLongLongWx
)
1211 ULL_TO_STRING(wxULongLongWx
)
1214 #if wxUSE_STD_IOSTREAM
1218 wxSTD ostream
& operator<< (wxSTD ostream
& o
, const wxLongLong
& ll
)
1220 return o
<< ll
.ToString();
1224 wxSTD ostream
& operator<< (wxSTD ostream
& o
, const wxULongLong
& ll
)
1226 return o
<< ll
.ToString();
1229 #endif // wxUSE_STD_IOSTREAM
1231 WXDLLIMPEXP_BASE wxString
& operator<< (wxString
& s
, const wxLongLong
& ll
)
1233 return s
<< ll
.ToString();
1236 WXDLLIMPEXP_BASE wxString
& operator<< (wxString
& s
, const wxULongLong
& ll
)
1238 return s
<< ll
.ToString();
1243 WXDLLIMPEXP_BASE wxTextOutputStream
& operator<< (wxTextOutputStream
& o
, const wxULongLong
& ll
)
1245 return o
<< ll
.ToString();
1248 WXDLLIMPEXP_BASE wxTextOutputStream
& operator<< (wxTextOutputStream
& o
, const wxLongLong
& ll
)
1250 return o
<< ll
.ToString();
1253 #define READ_STRING_CHAR(s, idx, len) ((wxChar) ((idx!=len) ? s[idx++] : 0))
1255 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&o
, wxULongLong
&ll
)
1257 wxString s
= o
.ReadWord();
1259 ll
= wxULongLong(0l, 0l);
1260 size_t length
= s
.Length();
1263 wxChar ch
= READ_STRING_CHAR(s
, idx
, length
);
1266 while (ch
==wxT(' ') || ch
==wxT('\t'))
1267 ch
= READ_STRING_CHAR(s
, idx
, length
);
1270 wxULongLong
multiplier(0l, 10l);
1271 while (ch
>=wxT('0') && ch
<=wxT('9')) {
1272 long lValue
= (unsigned) (ch
- wxT('0'));
1273 ll
= ll
* multiplier
+ wxULongLong(0l, lValue
);
1274 ch
= READ_STRING_CHAR(s
, idx
, length
);
1280 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&o
, wxLongLong
&ll
)
1282 wxString s
= o
.ReadWord();
1284 ll
= wxLongLong(0l, 0l);
1285 size_t length
= s
.Length();
1288 wxChar ch
= READ_STRING_CHAR(s
, idx
, length
);
1291 while (ch
==wxT(' ') || ch
==wxT('\t'))
1292 ch
= READ_STRING_CHAR(s
, idx
, length
);
1296 if (ch
==wxT('-') || ch
==wxT('+')) {
1297 iSign
= ((ch
==wxT('-')) ? -1 : 1);
1298 ch
= READ_STRING_CHAR(s
, idx
, length
);
1302 wxLongLong
multiplier(0l, 10l);
1303 while (ch
>=wxT('0') && ch
<=wxT('9')) {
1304 long lValue
= (unsigned) (ch
- wxT('0'));
1305 ll
= ll
* multiplier
+ wxLongLong(0l, lValue
);
1306 ch
= READ_STRING_CHAR(s
, idx
, length
);
1309 #if wxUSE_LONGLONG_NATIVE
1310 ll
= ll
* wxLongLong((wxLongLong_t
) iSign
);
1312 ll
= ll
* wxLongLong((long) iSign
);
1318 #if wxUSE_LONGLONG_NATIVE
1320 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&o
, wxULongLong_t value
)
1322 return o
<< wxULongLong(value
).ToString();
1325 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&o
, wxLongLong_t value
)
1327 return o
<< wxLongLong(value
).ToString();
1330 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&o
, wxULongLong_t
&value
)
1334 value
= ll
.GetValue();
1338 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&o
, wxLongLong_t
&value
)
1342 value
= ll
.GetValue();
1346 #endif // wxUSE_LONGLONG_NATIVE
1348 #endif // wxUSE_STREAMS
1350 #endif // wxUSE_LONGLONG