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 #include <string.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 double wxULongLongWx::ToDouble() const
195 unsigned double d
= m_hi
;
196 d
*= 1.0 + (double)ULONG_MAX
;
199 #ifdef wxLONGLONG_TEST_MODE
200 wxASSERT( d
== m_ll
);
201 #endif // wxLONGLONG_TEST_MODE
206 wxLongLongWx
wxLongLongWx::operator<<(int shift
) const
208 wxLongLongWx
ll(*this);
214 wxULongLongWx
wxULongLongWx::operator<<(int shift
) const
216 wxULongLongWx
ll(*this);
222 wxLongLongWx
& wxLongLongWx::operator<<=(int shift
)
229 m_hi
|= m_lo
>> (32 - shift
);
234 m_hi
= m_lo
<< (shift
- 32);
239 #ifdef wxLONGLONG_TEST_MODE
243 #endif // wxLONGLONG_TEST_MODE
248 wxULongLongWx
& wxULongLongWx::operator<<=(int shift
)
255 m_hi
|= m_lo
>> (32 - shift
);
260 m_hi
= m_lo
<< (shift
- 32);
265 #ifdef wxLONGLONG_TEST_MODE
269 #endif // wxLONGLONG_TEST_MODE
274 wxLongLongWx
wxLongLongWx::operator>>(int shift
) const
276 wxLongLongWx
ll(*this);
282 wxULongLongWx
wxULongLongWx::operator>>(int shift
) const
284 wxULongLongWx
ll(*this);
290 wxLongLongWx
& wxLongLongWx::operator>>=(int shift
)
297 m_lo
|= m_hi
<< (32 - shift
);
302 m_lo
= m_hi
>> (shift
- 32);
303 m_hi
= (m_hi
< 0 ? -1L : 0);
307 #ifdef wxLONGLONG_TEST_MODE
311 #endif // wxLONGLONG_TEST_MODE
316 wxULongLongWx
& wxULongLongWx::operator>>=(int shift
)
323 m_lo
|= m_hi
<< (32 - shift
);
328 m_lo
= m_hi
>> (shift
- 32);
333 #ifdef wxLONGLONG_TEST_MODE
337 #endif // wxLONGLONG_TEST_MODE
342 wxLongLongWx
wxLongLongWx::operator+(const wxLongLongWx
& ll
) const
344 wxLongLongWx
res(*this);
350 wxULongLongWx
wxULongLongWx::operator+(const wxULongLongWx
& ll
) const
352 wxULongLongWx
res(*this);
358 wxLongLongWx
wxLongLongWx::operator+(long l
) const
360 wxLongLongWx
res(*this);
366 wxULongLongWx
wxULongLongWx::operator+(unsigned long l
) const
368 wxULongLongWx
res(*this);
374 wxLongLongWx
& wxLongLongWx::operator+=(const wxLongLongWx
& ll
)
376 unsigned long previous
= m_lo
;
381 if ((m_lo
< previous
) || (m_lo
< ll
.m_lo
))
384 #ifdef wxLONGLONG_TEST_MODE
388 #endif // wxLONGLONG_TEST_MODE
393 wxULongLongWx
& wxULongLongWx::operator+=(const wxULongLongWx
& ll
)
395 unsigned long previous
= m_lo
;
400 if ((m_lo
< previous
) || (m_lo
< ll
.m_lo
))
403 #ifdef wxLONGLONG_TEST_MODE
407 #endif // wxLONGLONG_TEST_MODE
412 wxLongLongWx
& wxLongLongWx::operator+=(long l
)
414 unsigned long previous
= m_lo
;
420 if ((m_lo
< previous
) || (m_lo
< (unsigned long)l
))
423 #ifdef wxLONGLONG_TEST_MODE
427 #endif // wxLONGLONG_TEST_MODE
432 wxULongLongWx
& wxULongLongWx::operator+=(unsigned long l
)
434 unsigned long previous
= m_lo
;
438 if ((m_lo
< previous
) || (m_lo
< l
))
441 #ifdef wxLONGLONG_TEST_MODE
445 #endif // wxLONGLONG_TEST_MODE
451 wxLongLongWx
& wxLongLongWx::operator++()
457 #ifdef wxLONGLONG_TEST_MODE
461 #endif // wxLONGLONG_TEST_MODE
466 wxULongLongWx
& wxULongLongWx::operator++()
472 #ifdef wxLONGLONG_TEST_MODE
476 #endif // wxLONGLONG_TEST_MODE
482 wxLongLongWx
wxLongLongWx::operator-() const
484 wxLongLongWx
res(*this);
490 wxLongLongWx
& wxLongLongWx::Negate()
499 #ifdef wxLONGLONG_TEST_MODE
503 #endif // wxLONGLONG_TEST_MODE
510 wxLongLongWx
wxLongLongWx::operator-(const wxLongLongWx
& ll
) const
512 wxLongLongWx
res(*this);
518 wxLongLongWx
wxULongLongWx::operator-(const wxULongLongWx
& ll
) const
520 wxASSERT(m_hi
<= LONG_MAX
);
521 wxASSERT(ll
.m_hi
<= LONG_MAX
);
523 wxLongLongWx
res( (long)m_hi
, m_lo
);
524 wxLongLongWx
op( (long)ll
.m_hi
, ll
.m_lo
);
530 wxLongLongWx
& wxLongLongWx::operator-=(const wxLongLongWx
& ll
)
532 unsigned long previous
= m_lo
;
537 if (previous
< ll
.m_lo
)
540 #ifdef wxLONGLONG_TEST_MODE
544 #endif // wxLONGLONG_TEST_MODE
549 wxULongLongWx
& wxULongLongWx::operator-=(const wxULongLongWx
& ll
)
551 unsigned long previous
= m_lo
;
556 if (previous
< ll
.m_lo
)
559 #ifdef wxLONGLONG_TEST_MODE
563 #endif // wxLONGLONG_TEST_MODE
569 wxLongLongWx
& wxLongLongWx::operator--()
572 if (m_lo
== 0xFFFFFFFF)
575 #ifdef wxLONGLONG_TEST_MODE
579 #endif // wxLONGLONG_TEST_MODE
584 wxULongLongWx
& wxULongLongWx::operator--()
587 if (m_lo
== 0xFFFFFFFF)
590 #ifdef wxLONGLONG_TEST_MODE
594 #endif // wxLONGLONG_TEST_MODE
599 // comparison operators
601 bool wxLongLongWx::operator<(const wxLongLongWx
& ll
) const
603 if ( m_hi
< ll
.m_hi
)
605 else if ( m_hi
== ll
.m_hi
)
606 return m_lo
< ll
.m_lo
;
611 bool wxULongLongWx::operator<(const wxULongLongWx
& ll
) const
613 if ( m_hi
< ll
.m_hi
)
615 else if ( m_hi
== ll
.m_hi
)
616 return m_lo
< ll
.m_lo
;
621 bool wxLongLongWx::operator>(const wxLongLongWx
& ll
) const
623 if ( m_hi
> ll
.m_hi
)
625 else if ( m_hi
== ll
.m_hi
)
626 return m_lo
> ll
.m_lo
;
631 bool wxULongLongWx::operator>(const wxULongLongWx
& ll
) const
633 if ( m_hi
> ll
.m_hi
)
635 else if ( m_hi
== ll
.m_hi
)
636 return m_lo
> ll
.m_lo
;
643 wxLongLongWx
wxLongLongWx::operator&(const wxLongLongWx
& ll
) const
645 return wxLongLongWx(m_hi
& ll
.m_hi
, m_lo
& ll
.m_lo
);
648 wxULongLongWx
wxULongLongWx::operator&(const wxULongLongWx
& ll
) const
650 return wxULongLongWx(m_hi
& ll
.m_hi
, m_lo
& ll
.m_lo
);
653 wxLongLongWx
wxLongLongWx::operator|(const wxLongLongWx
& ll
) const
655 return wxLongLongWx(m_hi
| ll
.m_hi
, m_lo
| ll
.m_lo
);
658 wxULongLongWx
wxULongLongWx::operator|(const wxULongLongWx
& ll
) const
660 return wxULongLongWx(m_hi
| ll
.m_hi
, m_lo
| ll
.m_lo
);
663 wxLongLongWx
wxLongLongWx::operator^(const wxLongLongWx
& ll
) const
665 return wxLongLongWx(m_hi
^ ll
.m_hi
, m_lo
^ ll
.m_lo
);
668 wxULongLongWx
wxULongLongWx::operator^(const wxULongLongWx
& ll
) const
670 return wxULongLongWx(m_hi
^ ll
.m_hi
, m_lo
^ ll
.m_lo
);
673 wxLongLongWx
& wxLongLongWx::operator&=(const wxLongLongWx
& ll
)
678 #ifdef wxLONGLONG_TEST_MODE
682 #endif // wxLONGLONG_TEST_MODE
687 wxULongLongWx
& wxULongLongWx::operator&=(const wxULongLongWx
& ll
)
692 #ifdef wxLONGLONG_TEST_MODE
696 #endif // wxLONGLONG_TEST_MODE
701 wxLongLongWx
& wxLongLongWx::operator|=(const wxLongLongWx
& ll
)
706 #ifdef wxLONGLONG_TEST_MODE
710 #endif // wxLONGLONG_TEST_MODE
715 wxULongLongWx
& wxULongLongWx::operator|=(const wxULongLongWx
& ll
)
720 #ifdef wxLONGLONG_TEST_MODE
724 #endif // wxLONGLONG_TEST_MODE
729 wxLongLongWx
& wxLongLongWx::operator^=(const wxLongLongWx
& ll
)
734 #ifdef wxLONGLONG_TEST_MODE
738 #endif // wxLONGLONG_TEST_MODE
743 wxULongLongWx
& wxULongLongWx::operator^=(const wxULongLongWx
& ll
)
748 #ifdef wxLONGLONG_TEST_MODE
752 #endif // wxLONGLONG_TEST_MODE
757 wxLongLongWx
wxLongLongWx::operator~() const
759 return wxLongLongWx(~m_hi
, ~m_lo
);
762 wxULongLongWx
wxULongLongWx::operator~() const
764 return wxULongLongWx(~m_hi
, ~m_lo
);
769 wxLongLongWx
wxLongLongWx::operator*(const wxLongLongWx
& ll
) const
771 wxLongLongWx
res(*this);
777 wxULongLongWx
wxULongLongWx::operator*(const wxULongLongWx
& ll
) const
779 wxULongLongWx
res(*this);
785 wxLongLongWx
& wxLongLongWx::operator*=(const wxLongLongWx
& ll
)
787 wxLongLongWx
t(m_hi
, m_lo
);
788 wxLongLongWx
q(ll
.m_hi
, ll
.m_lo
);
792 #ifdef wxLONGLONG_TEST_MODE
793 wxLongLong_t llOld
= m_ll
;
795 #endif // wxLONGLONG_TEST_MODE
800 if ((q
.m_lo
& 1) != 0)
806 while ((counter
< 64) && ((q
.m_hi
!= 0) || (q
.m_lo
!= 0)));
808 #ifdef wxLONGLONG_TEST_MODE
809 m_ll
= llOld
* ll
.m_ll
;
812 #endif // wxLONGLONG_TEST_MODE
817 wxULongLongWx
& wxULongLongWx::operator*=(const wxULongLongWx
& ll
)
819 wxULongLongWx
t(m_hi
, m_lo
);
820 wxULongLongWx
q(ll
.m_hi
, ll
.m_lo
);
824 #ifdef wxLONGLONG_TEST_MODE
825 wxULongLong_t llOld
= m_ll
;
827 #endif // wxLONGLONG_TEST_MODE
832 if ((q
.m_lo
& 1) != 0)
838 while ((counter
< 64) && ((q
.m_hi
!= 0) || (q
.m_lo
!= 0)));
840 #ifdef wxLONGLONG_TEST_MODE
841 m_ll
= llOld
* ll
.m_ll
;
844 #endif // wxLONGLONG_TEST_MODE
851 #define IS_MSB_SET(ll) ((ll.GetHi()) & (1 << (8*sizeof(long) - 1)))
853 void wxLongLongWx::Divide(const wxLongLongWx
& divisorIn
,
854 wxLongLongWx
& quotient
,
855 wxLongLongWx
& remainderIO
) const
857 if ((divisorIn
.m_lo
== 0) && (divisorIn
.m_hi
== 0))
859 // provoke division by zero error and silence the compilers warnings
860 // about an expression without effect and unused variable
861 long dummy
= divisorIn
.m_lo
/divisorIn
.m_hi
;
865 // VZ: I'm writing this in a hurry and it's surely not the fastest way to
866 // do this - any improvements are more than welcome
868 // code inspired by the snippet at
869 // http://www.bearcave.com/software/divide.htm
873 // Use of this program, for any purpose, is granted the author, Ian
874 // Kaplan, as long as this copyright notice is included in the source
875 // code or any source code derived from this program. The user assumes
876 // all responsibility for using this code.
879 wxULongLongWx dividend
, divisor
, remainder
;
884 // always do unsigned division and adjust the signs later: in C integer
885 // division, the sign of the remainder is the same as the sign of the
886 // dividend, while the sign of the quotient is the product of the signs of
887 // the dividend and divisor. Of course, we also always have
889 // dividend = quotient*divisor + remainder
891 // with 0 <= abs(remainder) < abs(divisor)
892 bool negRemainder
= GetHi() < 0;
893 bool negQuotient
= false; // assume positive
896 negQuotient
= !negQuotient
;
901 if ( divisorIn
.GetHi() < 0 )
903 negQuotient
= !negQuotient
;
904 divisor
= -divisorIn
;
909 // check for some particular cases
910 if ( divisor
> dividend
)
912 remainder
= dividend
;
914 else if ( divisor
== dividend
)
920 // here: dividend > divisor and both are positive: do unsigned division
924 while ( remainder
< divisor
)
927 if ( IS_MSB_SET(dividend
) )
938 // undo the last loop iteration
943 for ( size_t i
= 0; i
< nBits
; i
++ )
946 if ( IS_MSB_SET(dividend
) )
951 wxLongLongWx t
= remainder
- divisor
;
954 if ( !IS_MSB_SET(t
) )
963 remainderIO
= remainder
;
968 remainderIO
= -remainderIO
;
973 quotient
= -quotient
;
977 void wxULongLongWx::Divide(const wxULongLongWx
& divisorIn
,
978 wxULongLongWx
& quotient
,
979 wxULongLongWx
& remainder
) const
981 if ((divisorIn
.m_lo
== 0) && (divisorIn
.m_hi
== 0))
983 // provoke division by zero error and silence the compilers warnings
984 // about an expression without effect and unused variable
985 unsigned long dummy
= divisorIn
.m_lo
/divisorIn
.m_hi
;
989 // VZ: I'm writing this in a hurry and it's surely not the fastest way to
990 // do this - any improvements are more than welcome
992 // code inspired by the snippet at
993 // http://www.bearcave.com/software/divide.htm
997 // Use of this program, for any purpose, is granted the author, Ian
998 // Kaplan, as long as this copyright notice is included in the source
999 // code or any source code derived from this program. The user assumes
1000 // all responsibility for using this code.
1003 wxULongLongWx dividend
= *this,
1004 divisor
= divisorIn
;
1009 // check for some particular cases
1010 if ( divisor
> dividend
)
1012 remainder
= dividend
;
1014 else if ( divisor
== dividend
)
1020 // here: dividend > divisor
1024 while ( remainder
< divisor
)
1027 if ( IS_MSB_SET(dividend
) )
1038 // undo the last loop iteration
1043 for ( size_t i
= 0; i
< nBits
; i
++ )
1046 if ( IS_MSB_SET(dividend
) )
1051 wxULongLongWx t
= remainder
- divisor
;
1054 if ( !IS_MSB_SET(t
) )
1064 wxLongLongWx
wxLongLongWx::operator/(const wxLongLongWx
& ll
) const
1066 wxLongLongWx quotient
, remainder
;
1068 Divide(ll
, quotient
, remainder
);
1073 wxULongLongWx
wxULongLongWx::operator/(const wxULongLongWx
& ll
) const
1075 wxULongLongWx quotient
, remainder
;
1077 Divide(ll
, quotient
, remainder
);
1082 wxLongLongWx
& wxLongLongWx::operator/=(const wxLongLongWx
& ll
)
1084 wxLongLongWx quotient
, remainder
;
1086 Divide(ll
, quotient
, remainder
);
1093 wxULongLongWx
& wxULongLongWx::operator/=(const wxULongLongWx
& ll
)
1095 wxULongLongWx quotient
, remainder
;
1097 Divide(ll
, quotient
, remainder
);
1104 wxLongLongWx
wxLongLongWx::operator%(const wxLongLongWx
& ll
) const
1106 wxLongLongWx quotient
, remainder
;
1108 Divide(ll
, quotient
, remainder
);
1113 wxULongLongWx
wxULongLongWx::operator%(const wxULongLongWx
& ll
) const
1115 wxULongLongWx quotient
, remainder
;
1117 Divide(ll
, quotient
, remainder
);
1122 // ----------------------------------------------------------------------------
1124 // ----------------------------------------------------------------------------
1126 // temporary - just for testing
1127 void *wxLongLongWx::asArray(void) const
1129 static unsigned char temp
[8];
1131 temp
[0] = (char)((m_hi
>> 24) & 0xFF);
1132 temp
[1] = (char)((m_hi
>> 16) & 0xFF);
1133 temp
[2] = (char)((m_hi
>> 8) & 0xFF);
1134 temp
[3] = (char)((m_hi
>> 0) & 0xFF);
1135 temp
[4] = (char)((m_lo
>> 24) & 0xFF);
1136 temp
[5] = (char)((m_lo
>> 16) & 0xFF);
1137 temp
[6] = (char)((m_lo
>> 8) & 0xFF);
1138 temp
[7] = (char)((m_lo
>> 0) & 0xFF);
1143 void *wxULongLongWx::asArray(void) const
1145 static unsigned char temp
[8];
1147 temp
[0] = (char)((m_hi
>> 24) & 0xFF);
1148 temp
[1] = (char)((m_hi
>> 16) & 0xFF);
1149 temp
[2] = (char)((m_hi
>> 8) & 0xFF);
1150 temp
[3] = (char)((m_hi
>> 0) & 0xFF);
1151 temp
[4] = (char)((m_lo
>> 24) & 0xFF);
1152 temp
[5] = (char)((m_lo
>> 16) & 0xFF);
1153 temp
[6] = (char)((m_lo
>> 8) & 0xFF);
1154 temp
[7] = (char)((m_lo
>> 0) & 0xFF);
1159 #endif // wxUSE_LONGLONG_WX
1161 #define LL_TO_STRING(name) \
1162 wxString name::ToString() const \
1164 /* TODO: this is awfully inefficient, anything better? */ \
1169 bool neg = ll < 0; \
1174 long digit = (ll % 10).ToLong(); \
1175 result.Prepend((wxChar)(_T('0') - digit)); \
1183 long digit = (ll % 10).ToLong(); \
1184 result.Prepend((wxChar)(_T('0') + digit)); \
1189 if ( result.empty() ) \
1192 result.Prepend(_T('-')); \
1197 #define ULL_TO_STRING(name) \
1198 wxString name::ToString() const \
1200 /* TODO: this is awfully inefficient, anything better? */ \
1207 result.Prepend((wxChar)(_T('0') + (ll % 10).ToULong())); \
1211 if ( result.empty() ) \
1217 #if wxUSE_LONGLONG_NATIVE
1218 LL_TO_STRING(wxLongLongNative
)
1219 ULL_TO_STRING(wxULongLongNative
)
1222 #if wxUSE_LONGLONG_WX
1223 LL_TO_STRING(wxLongLongWx
)
1224 ULL_TO_STRING(wxULongLongWx
)
1227 #if wxUSE_STD_IOSTREAM
1231 wxSTD ostream
& operator<< (wxSTD ostream
& o
, const wxLongLong
& ll
)
1233 return o
<< ll
.ToString();
1237 wxSTD ostream
& operator<< (wxSTD ostream
& o
, const wxULongLong
& ll
)
1239 return o
<< ll
.ToString();
1242 #endif // wxUSE_STD_IOSTREAM
1244 WXDLLIMPEXP_BASE wxString
& operator<< (wxString
& s
, const wxLongLong
& ll
)
1246 return s
<< ll
.ToString();
1249 WXDLLIMPEXP_BASE wxString
& operator<< (wxString
& s
, const wxULongLong
& ll
)
1251 return s
<< ll
.ToString();
1256 WXDLLIMPEXP_BASE wxTextOutputStream
& operator<< (wxTextOutputStream
& o
, const wxULongLong
& ll
)
1258 return o
<< ll
.ToString();
1261 WXDLLIMPEXP_BASE wxTextOutputStream
& operator<< (wxTextOutputStream
& o
, const wxLongLong
& ll
)
1263 return o
<< ll
.ToString();
1266 #define READ_STRING_CHAR(s, idx, len) ((wxChar) ((idx!=len) ? s[idx++] : 0))
1268 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&o
, wxULongLong
&ll
)
1270 wxString s
= o
.ReadWord();
1272 ll
= wxULongLong(0l, 0l);
1273 size_t length
= s
.length();
1276 wxChar ch
= READ_STRING_CHAR(s
, idx
, length
);
1279 while (ch
==wxT(' ') || ch
==wxT('\t'))
1280 ch
= READ_STRING_CHAR(s
, idx
, length
);
1283 wxULongLong
multiplier(0l, 10l);
1284 while (ch
>=wxT('0') && ch
<=wxT('9')) {
1285 long lValue
= (unsigned) (ch
- wxT('0'));
1286 ll
= ll
* multiplier
+ wxULongLong(0l, lValue
);
1287 ch
= READ_STRING_CHAR(s
, idx
, length
);
1293 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&o
, wxLongLong
&ll
)
1295 wxString s
= o
.ReadWord();
1297 ll
= wxLongLong(0l, 0l);
1298 size_t length
= s
.length();
1301 wxChar ch
= READ_STRING_CHAR(s
, idx
, length
);
1304 while (ch
==wxT(' ') || ch
==wxT('\t'))
1305 ch
= READ_STRING_CHAR(s
, idx
, length
);
1309 if (ch
==wxT('-') || ch
==wxT('+')) {
1310 iSign
= ((ch
==wxT('-')) ? -1 : 1);
1311 ch
= READ_STRING_CHAR(s
, idx
, length
);
1315 wxLongLong
multiplier(0l, 10l);
1316 while (ch
>=wxT('0') && ch
<=wxT('9')) {
1317 long lValue
= (unsigned) (ch
- wxT('0'));
1318 ll
= ll
* multiplier
+ wxLongLong(0l, lValue
);
1319 ch
= READ_STRING_CHAR(s
, idx
, length
);
1322 #if wxUSE_LONGLONG_NATIVE
1323 ll
= ll
* wxLongLong((wxLongLong_t
) iSign
);
1325 ll
= ll
* wxLongLong((long) iSign
);
1331 #if wxUSE_LONGLONG_NATIVE
1333 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&o
, wxULongLong_t value
)
1335 return o
<< wxULongLong(value
).ToString();
1338 WXDLLIMPEXP_BASE
class wxTextOutputStream
&operator<<(class wxTextOutputStream
&o
, wxLongLong_t value
)
1340 return o
<< wxLongLong(value
).ToString();
1343 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&o
, wxULongLong_t
&value
)
1347 value
= ll
.GetValue();
1351 WXDLLIMPEXP_BASE
class wxTextInputStream
&operator>>(class wxTextInputStream
&o
, wxLongLong_t
&value
)
1355 value
= ll
.GetValue();
1359 #endif // wxUSE_LONGLONG_NATIVE
1361 #endif // wxUSE_STREAMS
1363 #endif // wxUSE_LONGLONG