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
6 // Remarks: this class is not public in wxWindows 2.0! It is intentionally
7 // not documented and is for private use only.
11 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
12 // Licence: wxWindows license
13 /////////////////////////////////////////////////////////////////////////////
15 #ifndef _WX_LONGLONG_H
16 #define _WX_LONGLONG_H
19 #pragma interface "longlong.h"
22 // ----------------------------------------------------------------------------
23 // decide upon which class we will use
24 // ----------------------------------------------------------------------------
26 // to avoid compilation problems on 64bit machines with ambiguous method calls
28 #undef wxLongLongIsLong
30 // NB: we #define and not typedef wxLongLong_t because we want to be able to
31 // use 'unsigned wxLongLong_t' as well
32 #if defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
33 #define wxLongLong_t long
34 #define wxLongLongIsLong
35 #elif defined(__VISUALC__)
36 #define wxLongLong_t __int64
37 #elif defined(__GNUG__)
38 #define wxLongLong_t long long
39 #elif defined(__MWERKS__)
40 #if __option(longlong)
41 #define wxLongLong_t long long
43 #error "The 64 bit integer support in CodeWarrior has been disabled."
44 #error "See the documentation on the 'longlong' pragma."
47 #warning "Your compiler does not appear to support 64 bit integers, "\
48 "using emulation class instead."
49 #define wxUSE_LONGLONG_WX 1
52 // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
53 // to disable automatic testing (useful for the test program which defines
54 // both classes) but by default we only use one class
56 #undef wxUSE_LONGLONG_NATIVE
57 #define wxUSE_LONGLONG_NATIVE 0
58 class WXDLLEXPORT wxLongLongWx
;
59 typedef wxLongLongWx wxLongLong
;
62 #ifndef wxUSE_LONGLONG_WX
63 #define wxUSE_LONGLONG_WX 0
64 class WXDLLEXPORT wxLongLongNative
;
65 typedef wxLongLongNative wxLongLong
;
68 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
69 // typedef wxLongLong as it wants, we don't do it
71 // ----------------------------------------------------------------------------
72 // choose the appropriate class
73 // ----------------------------------------------------------------------------
75 // we use iostream for wxLongLong output
76 #include "wx/ioswrap.h"
78 #if wxUSE_LONGLONG_NATIVE
80 class WXDLLEXPORT wxLongLongNative
84 // default ctor initializes to 0
85 wxLongLongNative() { m_ll
= 0; }
87 wxLongLongNative(wxLongLong_t ll
) { m_ll
= ll
; }
89 wxLongLongNative(long hi
, unsigned long lo
)
91 // assign first to avoid precision loss!
92 m_ll
= ((wxLongLong_t
) hi
) << 32;
93 m_ll
|= (wxLongLong_t
) lo
;
96 // default copy ctor is ok in both cases
100 // assignment operators
101 // from native 64 bit integer
102 wxLongLongNative
& operator=(wxLongLong_t ll
)
103 { m_ll
= ll
; return *this; }
105 // assignment operators from wxLongLongNative is ok
110 { return (long)((m_ll
& 0xFFFFFFFF00000000l
) >> 32); }
112 unsigned long GetLo() const
113 { return (unsigned long) (m_ll
& 0x00000000FFFFFFFFl
); }
115 // convert to native long long
116 wxLongLong_t
GetValue() const { return m_ll
; }
118 operator wxLongLong_t() const { return m_ll
; }
122 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
123 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
124 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
125 { m_ll
+= ll
.m_ll
; return *this; }
127 wxLongLongNative
operator+(const wxLongLong_t ll
) const
128 { return wxLongLongNative(m_ll
+ ll
); }
129 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
130 { m_ll
+= ll
; return *this; }
133 wxLongLongNative
& operator++()
134 { m_ll
++; return *this; }
137 wxLongLongNative
& operator++(int)
138 { m_ll
++; return *this; }
141 wxLongLongNative
operator-() const
142 { return wxLongLongNative(-m_ll
); }
145 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
146 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
147 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
148 { m_ll
-= ll
.m_ll
; return *this; }
150 wxLongLongNative
operator-(const wxLongLong_t ll
) const
151 { return wxLongLongNative(m_ll
- ll
); }
152 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
153 { m_ll
-= ll
; return *this; }
156 wxLongLongNative
& operator--()
157 { m_ll
--; return *this; }
160 wxLongLongNative
& operator--(int)
161 { m_ll
--; return *this; }
165 wxLongLongNative
operator<<(int shift
) const
166 { return wxLongLongNative(m_ll
<< shift
);; }
167 wxLongLongNative
& operator<<=(int shift
)
168 { m_ll
<<= shift
; return *this; }
171 wxLongLongNative
operator>>(int shift
) const
172 { return wxLongLongNative(m_ll
>> shift
);; }
173 wxLongLongNative
& operator>>=(int shift
)
174 { m_ll
>>= shift
; return *this; }
177 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
178 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
179 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
180 { m_ll
&= ll
.m_ll
; return *this; }
182 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
183 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
184 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
185 { m_ll
|= ll
.m_ll
; return *this; }
187 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
188 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
189 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
190 { m_ll
^= ll
.m_ll
; return *this; }
192 // multiplication/division TODO
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 wxLongLongNative
& ll
) const
199 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
200 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
201 { m_ll
/= ll
.m_ll
; return *this; }
203 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
204 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
207 bool operator==(const wxLongLongNative
& ll
) const
208 { return m_ll
== ll
.m_ll
; }
209 bool operator!=(const wxLongLongNative
& ll
) const
210 { return m_ll
!= ll
.m_ll
; }
211 bool operator<(const wxLongLongNative
& ll
) const
212 { return m_ll
< ll
.m_ll
; }
213 bool operator>(const wxLongLongNative
& ll
) const
214 { return m_ll
> ll
.m_ll
; }
215 bool operator<=(const wxLongLongNative
& ll
) const
216 { return m_ll
<= ll
.m_ll
; }
217 bool operator>=(const wxLongLongNative
& ll
) const
218 { return m_ll
>= ll
.m_ll
; }
221 // conversion to byte array: returns a pointer to static buffer!
222 void *asArray() const;
225 friend ostream
& operator<<(ostream
&, const wxLongLongNative
&);
231 #endif // wxUSE_LONGLONG_NATIVE
233 #if wxUSE_LONGLONG_WX
235 class WXDLLEXPORT wxLongLongWx
239 // default ctor initializes to 0
240 wxLongLongWx() { m_lo
= m_hi
= 0; }
243 { m_lo
= l
; m_hi
= (l
< 0 ? -1l : 0l); }
245 wxLongLongWx(long hi
, unsigned long lo
)
246 { m_hi
= hi
; m_lo
= lo
; }
248 // default copy ctor is ok in both cases
252 // assignment operators
254 wxLongLongWx
& operator=(long l
)
255 { m_lo
= l
; m_hi
= (l
< 0 ? -1l : 0l); return *this; }
256 // can't have assignment operator from 2 longs
260 long GetHi() const { return m_hi
; }
262 unsigned long GetLo() const { return m_lo
; }
266 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
267 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
268 wxLongLongWx
operator+(long l
) const;
269 wxLongLongWx
& operator+=(long l
);
271 // pre increment operator
272 wxLongLongWx
& operator++();
274 // post increment operator
275 wxLongLongWx
& operator++(int);
278 wxLongLongWx
operator-() const;
281 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
282 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
284 // pre decrement operator
285 wxLongLongWx
& operator--();
287 // post decrement operator
288 wxLongLongWx
& operator--(int);
292 wxLongLongWx
operator<<(int shift
) const;
293 wxLongLongWx
& operator<<=(int shift
);
296 wxLongLongWx
operator>>(int shift
) const;
297 wxLongLongWx
& operator>>=(int shift
);
300 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
301 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
302 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
303 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
304 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
305 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
306 wxLongLongWx
operator~() const;
309 bool operator==(const wxLongLongWx
& ll
) const;
310 bool operator!=(const wxLongLongWx
& ll
) const;
311 bool operator<(const wxLongLongWx
& ll
) const;
312 bool operator>(const wxLongLongWx
& ll
) const;
313 bool operator<=(const wxLongLongWx
& ll
) const;
314 bool operator>=(const wxLongLongWx
& ll
) const;
317 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
318 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
319 void *asArray(void) const;
322 void Divide(const wxLongLongWx
& divisor
,
323 wxLongLongWx
& quotient
,
324 wxLongLongWx
& remainder
) const;
327 friend ostream
& operator<<(ostream
&, const wxLongLongWx
&);
330 // long is at least 32 bits, so represent our 64bit number as 2 longs
332 long m_hi
; // signed bit is in the high part
336 #endif // wxUSE_LONGLONG_WX
338 #endif // _WX_LONGLONG_H