]>
Commit | Line | Data |
---|---|---|
8b81872f VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/longlong.h | |
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 | |
8b81872f VZ |
6 | // Modified by: |
7 | // Created: 10.02.99 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
65571936 | 10 | // Licence: wxWindows licence |
8b81872f VZ |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
13 | #ifndef _WX_LONGLONG_H | |
14 | #define _WX_LONGLONG_H | |
15 | ||
1ef54dcf | 16 | #include "wx/defs.h" |
216a72f3 VZ |
17 | |
18 | #if wxUSE_LONGLONG | |
19 | ||
3a994742 | 20 | #include "wx/string.h" |
1ef54dcf VZ |
21 | |
22 | #include <limits.h> // for LONG_MAX | |
23 | ||
2a310492 VZ |
24 | // define this to compile wxLongLongWx in "test" mode: the results of all |
25 | // calculations will be compared with the real results taken from | |
617ec456 VZ |
26 | // wxLongLongNative -- this is extremely useful to find the bugs in |
27 | // wxLongLongWx class! | |
28 | ||
f6bcfd97 | 29 | // #define wxLONGLONG_TEST_MODE |
2a310492 VZ |
30 | |
31 | #ifdef wxLONGLONG_TEST_MODE | |
32 | #define wxUSE_LONGLONG_WX 1 | |
33 | #define wxUSE_LONGLONG_NATIVE 1 | |
34 | #endif // wxLONGLONG_TEST_MODE | |
2ea24d9f | 35 | |
8b81872f VZ |
36 | // ---------------------------------------------------------------------------- |
37 | // decide upon which class we will use | |
38 | // ---------------------------------------------------------------------------- | |
39 | ||
8fb37472 | 40 | #ifndef wxLongLong_t |
9c2882d9 | 41 | // both warning and pragma warning are not portable, but at least an |
2b5f62a0 | 42 | // unknown pragma should never be an error -- except that, actually, some |
58ef67ab VZ |
43 | // broken compilers don't like it, so we have to disable it in this case |
44 | // <sigh> | |
216a72f3 VZ |
45 | #ifdef __GNUC__ |
46 | #warning "Your compiler does not appear to support 64 bit "\ | |
47 | "integers, using emulation class instead.\n" \ | |
48 | "Please report your compiler version to " \ | |
49 | "wx-dev@lists.wxwidgets.org!" | |
50 | #elif !(defined(__WATCOMC__) || defined(__VISAGECPP__)) | |
8fb37472 VZ |
51 | #pragma warning "Your compiler does not appear to support 64 bit "\ |
52 | "integers, using emulation class instead.\n" \ | |
53 | "Please report your compiler version to " \ | |
77ffb593 | 54 | "wx-dev@lists.wxwidgets.org!" |
8fb37472 | 55 | #endif |
8db6ac55 | 56 | |
8b81872f VZ |
57 | #define wxUSE_LONGLONG_WX 1 |
58 | #endif // compiler | |
59 | ||
60 | // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE | |
61 | // to disable automatic testing (useful for the test program which defines | |
62 | // both classes) but by default we only use one class | |
2ea24d9f | 63 | #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t) |
2a310492 | 64 | // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set: |
384223b3 | 65 | // this is useful in test programs and only there |
2a310492 VZ |
66 | #ifndef wxUSE_LONGLONG_NATIVE |
67 | #define wxUSE_LONGLONG_NATIVE 0 | |
68 | #endif | |
69 | ||
bddd7a8d VZ |
70 | class WXDLLIMPEXP_BASE wxLongLongWx; |
71 | class WXDLLIMPEXP_BASE wxULongLongWx; | |
92f5ff59 JS |
72 | #if defined(__VISUALC__) && !defined(__WIN32__) |
73 | #define wxLongLong wxLongLongWx | |
8e38fd1f | 74 | #define wxULongLong wxULongLongWx |
92f5ff59 | 75 | #else |
8b81872f | 76 | typedef wxLongLongWx wxLongLong; |
8e38fd1f | 77 | typedef wxULongLongWx wxULongLong; |
92f5ff59 JS |
78 | #endif |
79 | ||
b76b015e VZ |
80 | #else |
81 | // if nothing is defined, use native implementation by default, of course | |
82 | #ifndef wxUSE_LONGLONG_NATIVE | |
83 | #define wxUSE_LONGLONG_NATIVE 1 | |
84 | #endif | |
8b81872f VZ |
85 | #endif |
86 | ||
87 | #ifndef wxUSE_LONGLONG_WX | |
88 | #define wxUSE_LONGLONG_WX 0 | |
bddd7a8d VZ |
89 | class WXDLLIMPEXP_BASE wxLongLongNative; |
90 | class WXDLLIMPEXP_BASE wxULongLongNative; | |
8b81872f | 91 | typedef wxLongLongNative wxLongLong; |
8e38fd1f | 92 | typedef wxULongLongNative wxULongLong; |
8b81872f VZ |
93 | #endif |
94 | ||
95 | // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should | |
96 | // typedef wxLongLong as it wants, we don't do it | |
97 | ||
98 | // ---------------------------------------------------------------------------- | |
99 | // choose the appropriate class | |
100 | // ---------------------------------------------------------------------------- | |
101 | ||
102 | // we use iostream for wxLongLong output | |
65f19af1 | 103 | #include "wx/iosfwrap.h" |
8b81872f VZ |
104 | |
105 | #if wxUSE_LONGLONG_NATIVE | |
106 | ||
bddd7a8d | 107 | class WXDLLIMPEXP_BASE wxLongLongNative |
8b81872f VZ |
108 | { |
109 | public: | |
110 | // ctors | |
111 | // default ctor initializes to 0 | |
2e403d6d | 112 | wxLongLongNative() : m_ll(0) { } |
8b81872f | 113 | // from long long |
2e403d6d | 114 | wxLongLongNative(wxLongLong_t ll) : m_ll(ll) { } |
8b81872f | 115 | // from 2 longs |
2e403d6d | 116 | wxLongLongNative(long hi, unsigned long lo) : m_ll(0) |
8b81872f VZ |
117 | { |
118 | // assign first to avoid precision loss! | |
119 | m_ll = ((wxLongLong_t) hi) << 32; | |
120 | m_ll |= (wxLongLong_t) lo; | |
121 | } | |
842215bb WS |
122 | #if wxUSE_LONGLONG_WX |
123 | wxLongLongNative(wxLongLongWx ll); | |
124 | #endif | |
8b81872f | 125 | |
2f02cb89 | 126 | // default copy ctor is ok |
8b81872f VZ |
127 | |
128 | // no dtor | |
129 | ||
130 | // assignment operators | |
131 | // from native 64 bit integer | |
132 | wxLongLongNative& operator=(wxLongLong_t ll) | |
133 | { m_ll = ll; return *this; } | |
216a72f3 VZ |
134 | wxLongLongNative& operator=(wxULongLong_t ll) |
135 | { m_ll = ll; return *this; } | |
136 | wxLongLongNative& operator=(const wxULongLongNative &ll); | |
a4d2944e VZ |
137 | wxLongLongNative& operator=(int l) |
138 | { m_ll = l; return *this; } | |
216a72f3 VZ |
139 | wxLongLongNative& operator=(long l) |
140 | { m_ll = l; return *this; } | |
141 | wxLongLongNative& operator=(unsigned long l) | |
142 | { m_ll = l; return *this; } | |
842215bb WS |
143 | #if wxUSE_LONGLONG_WX |
144 | wxLongLongNative& operator=(wxLongLongWx ll); | |
216a72f3 | 145 | wxLongLongNative& operator=(const class wxULongLongWx &ll); |
842215bb WS |
146 | #endif |
147 | ||
8b81872f | 148 | |
cd0b1709 VZ |
149 | // from double: this one has an explicit name because otherwise we |
150 | // would have ambiguity with "ll = int" and also because we don't want | |
151 | // to have implicit conversions between doubles and wxLongLongs | |
152 | wxLongLongNative& Assign(double d) | |
153 | { m_ll = (wxLongLong_t)d; return *this; } | |
154 | ||
8b81872f VZ |
155 | // assignment operators from wxLongLongNative is ok |
156 | ||
157 | // accessors | |
158 | // get high part | |
159 | long GetHi() const | |
17a1ebd1 | 160 | { return wx_truncate_cast(long, m_ll >> 32); } |
8b81872f VZ |
161 | // get low part |
162 | unsigned long GetLo() const | |
17a1ebd1 | 163 | { return wx_truncate_cast(unsigned long, m_ll); } |
8b81872f | 164 | |
b76b015e | 165 | // get absolute value |
2ea24d9f | 166 | wxLongLongNative Abs() const { return wxLongLongNative(*this).Abs(); } |
b76b015e VZ |
167 | wxLongLongNative& Abs() { if ( m_ll < 0 ) m_ll = -m_ll; return *this; } |
168 | ||
8b81872f VZ |
169 | // convert to native long long |
170 | wxLongLong_t GetValue() const { return m_ll; } | |
171 | ||
90e572f1 | 172 | // convert to long with range checking in debug mode (only!) |
1ef54dcf VZ |
173 | long ToLong() const |
174 | { | |
175 | wxASSERT_MSG( (m_ll >= LONG_MIN) && (m_ll <= LONG_MAX), | |
176 | _T("wxLongLong to long conversion loss of precision") ); | |
177 | ||
17a1ebd1 | 178 | return wx_truncate_cast(long, m_ll); |
1ef54dcf VZ |
179 | } |
180 | ||
e7aaf2de | 181 | // convert to double |
17a1ebd1 | 182 | double ToDouble() const { return wx_truncate_cast(double, m_ll); } |
e7aaf2de | 183 | |
2f02cb89 VZ |
184 | // don't provide implicit conversion to wxLongLong_t or we will have an |
185 | // ambiguity for all arithmetic operations | |
b76b015e | 186 | //operator wxLongLong_t() const { return m_ll; } |
8b81872f VZ |
187 | |
188 | // operations | |
189 | // addition | |
190 | wxLongLongNative operator+(const wxLongLongNative& ll) const | |
191 | { return wxLongLongNative(m_ll + ll.m_ll); } | |
192 | wxLongLongNative& operator+=(const wxLongLongNative& ll) | |
193 | { m_ll += ll.m_ll; return *this; } | |
194 | ||
195 | wxLongLongNative operator+(const wxLongLong_t ll) const | |
196 | { return wxLongLongNative(m_ll + ll); } | |
197 | wxLongLongNative& operator+=(const wxLongLong_t ll) | |
198 | { m_ll += ll; return *this; } | |
199 | ||
200 | // pre increment | |
201 | wxLongLongNative& operator++() | |
202 | { m_ll++; return *this; } | |
203 | ||
204 | // post increment | |
2e403d6d GD |
205 | wxLongLongNative operator++(int) |
206 | { wxLongLongNative value(*this); m_ll++; return value; } | |
8b81872f VZ |
207 | |
208 | // negation operator | |
209 | wxLongLongNative operator-() const | |
210 | { return wxLongLongNative(-m_ll); } | |
3a994742 | 211 | wxLongLongNative& Negate() { m_ll = -m_ll; return *this; } |
8b81872f VZ |
212 | |
213 | // subtraction | |
214 | wxLongLongNative operator-(const wxLongLongNative& ll) const | |
215 | { return wxLongLongNative(m_ll - ll.m_ll); } | |
216 | wxLongLongNative& operator-=(const wxLongLongNative& ll) | |
217 | { m_ll -= ll.m_ll; return *this; } | |
218 | ||
219 | wxLongLongNative operator-(const wxLongLong_t ll) const | |
220 | { return wxLongLongNative(m_ll - ll); } | |
221 | wxLongLongNative& operator-=(const wxLongLong_t ll) | |
222 | { m_ll -= ll; return *this; } | |
223 | ||
224 | // pre decrement | |
225 | wxLongLongNative& operator--() | |
226 | { m_ll--; return *this; } | |
227 | ||
228 | // post decrement | |
2e403d6d GD |
229 | wxLongLongNative operator--(int) |
230 | { wxLongLongNative value(*this); m_ll--; return value; } | |
8b81872f VZ |
231 | |
232 | // shifts | |
233 | // left shift | |
234 | wxLongLongNative operator<<(int shift) const | |
d0ee33f5 | 235 | { return wxLongLongNative(m_ll << shift); } |
8b81872f VZ |
236 | wxLongLongNative& operator<<=(int shift) |
237 | { m_ll <<= shift; return *this; } | |
238 | ||
239 | // right shift | |
240 | wxLongLongNative operator>>(int shift) const | |
d0ee33f5 | 241 | { return wxLongLongNative(m_ll >> shift); } |
8b81872f VZ |
242 | wxLongLongNative& operator>>=(int shift) |
243 | { m_ll >>= shift; return *this; } | |
244 | ||
245 | // bitwise operators | |
246 | wxLongLongNative operator&(const wxLongLongNative& ll) const | |
247 | { return wxLongLongNative(m_ll & ll.m_ll); } | |
248 | wxLongLongNative& operator&=(const wxLongLongNative& ll) | |
249 | { m_ll &= ll.m_ll; return *this; } | |
250 | ||
251 | wxLongLongNative operator|(const wxLongLongNative& ll) const | |
252 | { return wxLongLongNative(m_ll | ll.m_ll); } | |
253 | wxLongLongNative& operator|=(const wxLongLongNative& ll) | |
254 | { m_ll |= ll.m_ll; return *this; } | |
255 | ||
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; } | |
260 | ||
b76b015e | 261 | // multiplication/division |
8b81872f VZ |
262 | wxLongLongNative operator*(const wxLongLongNative& ll) const |
263 | { return wxLongLongNative(m_ll * ll.m_ll); } | |
2f02cb89 VZ |
264 | wxLongLongNative operator*(long l) const |
265 | { return wxLongLongNative(m_ll * l); } | |
8b81872f VZ |
266 | wxLongLongNative& operator*=(const wxLongLongNative& ll) |
267 | { m_ll *= ll.m_ll; return *this; } | |
2f02cb89 VZ |
268 | wxLongLongNative& operator*=(long l) |
269 | { m_ll *= l; return *this; } | |
8b81872f VZ |
270 | |
271 | wxLongLongNative operator/(const wxLongLongNative& ll) const | |
272 | { return wxLongLongNative(m_ll / ll.m_ll); } | |
b76b015e VZ |
273 | wxLongLongNative operator/(long l) const |
274 | { return wxLongLongNative(m_ll / l); } | |
8b81872f VZ |
275 | wxLongLongNative& operator/=(const wxLongLongNative& ll) |
276 | { m_ll /= ll.m_ll; return *this; } | |
2f02cb89 VZ |
277 | wxLongLongNative& operator/=(long l) |
278 | { m_ll /= l; return *this; } | |
8b81872f VZ |
279 | |
280 | wxLongLongNative operator%(const wxLongLongNative& ll) const | |
281 | { return wxLongLongNative(m_ll % ll.m_ll); } | |
b76b015e VZ |
282 | wxLongLongNative operator%(long l) const |
283 | { return wxLongLongNative(m_ll % l); } | |
8b81872f VZ |
284 | |
285 | // comparison | |
286 | bool operator==(const wxLongLongNative& ll) const | |
287 | { return m_ll == ll.m_ll; } | |
b76b015e VZ |
288 | bool operator==(long l) const |
289 | { return m_ll == l; } | |
8b81872f VZ |
290 | bool operator!=(const wxLongLongNative& ll) const |
291 | { return m_ll != ll.m_ll; } | |
b76b015e VZ |
292 | bool operator!=(long l) const |
293 | { return m_ll != l; } | |
8b81872f VZ |
294 | bool operator<(const wxLongLongNative& ll) const |
295 | { return m_ll < ll.m_ll; } | |
b76b015e VZ |
296 | bool operator<(long l) const |
297 | { return m_ll < l; } | |
8b81872f VZ |
298 | bool operator>(const wxLongLongNative& ll) const |
299 | { return m_ll > ll.m_ll; } | |
b76b015e VZ |
300 | bool operator>(long l) const |
301 | { return m_ll > l; } | |
8b81872f VZ |
302 | bool operator<=(const wxLongLongNative& ll) const |
303 | { return m_ll <= ll.m_ll; } | |
b76b015e VZ |
304 | bool operator<=(long l) const |
305 | { return m_ll <= l; } | |
8b81872f VZ |
306 | bool operator>=(const wxLongLongNative& ll) const |
307 | { return m_ll >= ll.m_ll; } | |
b76b015e VZ |
308 | bool operator>=(long l) const |
309 | { return m_ll >= l; } | |
8b81872f VZ |
310 | |
311 | // miscellaneous | |
3a994742 VZ |
312 | |
313 | // return the string representation of this number | |
314 | wxString ToString() const; | |
315 | ||
8b81872f VZ |
316 | // conversion to byte array: returns a pointer to static buffer! |
317 | void *asArray() const; | |
318 | ||
fcc3d7cb | 319 | #if wxUSE_STD_IOSTREAM |
8b81872f | 320 | // input/output |
a353dc98 VZ |
321 | friend WXDLLIMPEXP_BASE |
322 | wxSTD ostream& operator<<(wxSTD ostream&, const wxLongLongNative&); | |
fcc3d7cb | 323 | #endif |
8b81872f | 324 | |
a353dc98 VZ |
325 | friend WXDLLIMPEXP_BASE |
326 | wxString& operator<<(wxString&, const wxLongLongNative&); | |
51496782 | 327 | |
216a72f3 VZ |
328 | #if wxUSE_STREAMS |
329 | friend WXDLLIMPEXP_BASE | |
330 | class wxTextOutputStream& operator<<(class wxTextOutputStream&, const wxLongLongNative&); | |
331 | friend WXDLLIMPEXP_BASE | |
332 | class wxTextInputStream& operator>>(class wxTextInputStream&, wxLongLongNative&); | |
333 | #endif | |
334 | ||
8b81872f VZ |
335 | private: |
336 | wxLongLong_t m_ll; | |
337 | }; | |
338 | ||
8e38fd1f | 339 | |
bddd7a8d | 340 | class WXDLLIMPEXP_BASE wxULongLongNative |
8e38fd1f RL |
341 | { |
342 | public: | |
343 | // ctors | |
344 | // default ctor initializes to 0 | |
2e403d6d | 345 | wxULongLongNative() : m_ll(0) { } |
8e38fd1f | 346 | // from long long |
60582201 | 347 | wxULongLongNative(wxULongLong_t ll) : m_ll(ll) { } |
8e38fd1f | 348 | // from 2 longs |
2e403d6d | 349 | wxULongLongNative(unsigned long hi, unsigned long lo) : m_ll(0) |
8e38fd1f RL |
350 | { |
351 | // assign first to avoid precision loss! | |
60582201 WS |
352 | m_ll = ((wxULongLong_t) hi) << 32; |
353 | m_ll |= (wxULongLong_t) lo; | |
8e38fd1f RL |
354 | } |
355 | ||
216a72f3 VZ |
356 | #if wxUSE_LONGLONG_WX |
357 | wxULongLongNative(const class wxULongLongWx &ll); | |
358 | #endif | |
359 | ||
8e38fd1f RL |
360 | // default copy ctor is ok |
361 | ||
362 | // no dtor | |
363 | ||
364 | // assignment operators | |
365 | // from native 64 bit integer | |
60582201 | 366 | wxULongLongNative& operator=(wxULongLong_t ll) |
8e38fd1f | 367 | { m_ll = ll; return *this; } |
216a72f3 VZ |
368 | wxULongLongNative& operator=(wxLongLong_t ll) |
369 | { m_ll = ll; return *this; } | |
a4d2944e VZ |
370 | wxULongLongNative& operator=(int l) |
371 | { m_ll = l; return *this; } | |
216a72f3 VZ |
372 | wxULongLongNative& operator=(long l) |
373 | { m_ll = l; return *this; } | |
374 | wxULongLongNative& operator=(unsigned long l) | |
375 | { m_ll = l; return *this; } | |
376 | wxULongLongNative& operator=(const wxLongLongNative &ll) | |
377 | { m_ll = ll.GetValue(); return *this; } | |
378 | #if wxUSE_LONGLONG_WX | |
379 | wxULongLongNative& operator=(wxLongLongWx ll); | |
380 | wxULongLongNative& operator=(const class wxULongLongWx &ll); | |
381 | #endif | |
8e38fd1f RL |
382 | |
383 | // assignment operators from wxULongLongNative is ok | |
384 | ||
385 | // accessors | |
386 | // get high part | |
387 | unsigned long GetHi() const | |
17a1ebd1 | 388 | { return wx_truncate_cast(unsigned long, m_ll >> 32); } |
8e38fd1f RL |
389 | // get low part |
390 | unsigned long GetLo() const | |
17a1ebd1 | 391 | { return wx_truncate_cast(unsigned long, m_ll); } |
8e38fd1f RL |
392 | |
393 | // convert to native ulong long | |
60582201 | 394 | wxULongLong_t GetValue() const { return m_ll; } |
8e38fd1f | 395 | |
90e572f1 | 396 | // convert to ulong with range checking in debug mode (only!) |
8e38fd1f RL |
397 | unsigned long ToULong() const |
398 | { | |
0ba9f867 | 399 | wxASSERT_MSG( m_ll <= LONG_MAX, |
8e38fd1f RL |
400 | _T("wxULongLong to long conversion loss of precision") ); |
401 | ||
17a1ebd1 | 402 | return wx_truncate_cast(unsigned long, m_ll); |
8e38fd1f RL |
403 | } |
404 | ||
8e38fd1f RL |
405 | // operations |
406 | // addition | |
407 | wxULongLongNative operator+(const wxULongLongNative& ll) const | |
408 | { return wxULongLongNative(m_ll + ll.m_ll); } | |
409 | wxULongLongNative& operator+=(const wxULongLongNative& ll) | |
410 | { m_ll += ll.m_ll; return *this; } | |
411 | ||
60582201 | 412 | wxULongLongNative operator+(const wxULongLong_t ll) const |
8e38fd1f | 413 | { return wxULongLongNative(m_ll + ll); } |
60582201 | 414 | wxULongLongNative& operator+=(const wxULongLong_t ll) |
8e38fd1f RL |
415 | { m_ll += ll; return *this; } |
416 | ||
417 | // pre increment | |
418 | wxULongLongNative& operator++() | |
419 | { m_ll++; return *this; } | |
420 | ||
421 | // post increment | |
2e403d6d GD |
422 | wxULongLongNative operator++(int) |
423 | { wxULongLongNative value(*this); m_ll++; return value; } | |
8e38fd1f RL |
424 | |
425 | // subtraction | |
426 | wxULongLongNative operator-(const wxULongLongNative& ll) const | |
427 | { return wxULongLongNative(m_ll - ll.m_ll); } | |
428 | wxULongLongNative& operator-=(const wxULongLongNative& ll) | |
429 | { m_ll -= ll.m_ll; return *this; } | |
430 | ||
60582201 | 431 | wxULongLongNative operator-(const wxULongLong_t ll) const |
8e38fd1f | 432 | { return wxULongLongNative(m_ll - ll); } |
60582201 | 433 | wxULongLongNative& operator-=(const wxULongLong_t ll) |
8e38fd1f RL |
434 | { m_ll -= ll; return *this; } |
435 | ||
436 | // pre decrement | |
437 | wxULongLongNative& operator--() | |
438 | { m_ll--; return *this; } | |
439 | ||
440 | // post decrement | |
2e403d6d GD |
441 | wxULongLongNative operator--(int) |
442 | { wxULongLongNative value(*this); m_ll--; return value; } | |
8e38fd1f RL |
443 | |
444 | // shifts | |
445 | // left shift | |
446 | wxULongLongNative operator<<(int shift) const | |
d0ee33f5 | 447 | { return wxULongLongNative(m_ll << shift); } |
8e38fd1f RL |
448 | wxULongLongNative& operator<<=(int shift) |
449 | { m_ll <<= shift; return *this; } | |
450 | ||
451 | // right shift | |
452 | wxULongLongNative operator>>(int shift) const | |
d0ee33f5 | 453 | { return wxULongLongNative(m_ll >> shift); } |
8e38fd1f RL |
454 | wxULongLongNative& operator>>=(int shift) |
455 | { m_ll >>= shift; return *this; } | |
456 | ||
457 | // bitwise operators | |
458 | wxULongLongNative operator&(const wxULongLongNative& ll) const | |
459 | { return wxULongLongNative(m_ll & ll.m_ll); } | |
460 | wxULongLongNative& operator&=(const wxULongLongNative& ll) | |
461 | { m_ll &= ll.m_ll; return *this; } | |
462 | ||
463 | wxULongLongNative operator|(const wxULongLongNative& ll) const | |
464 | { return wxULongLongNative(m_ll | ll.m_ll); } | |
465 | wxULongLongNative& operator|=(const wxULongLongNative& ll) | |
466 | { m_ll |= ll.m_ll; return *this; } | |
467 | ||
468 | wxULongLongNative operator^(const wxULongLongNative& ll) const | |
469 | { return wxULongLongNative(m_ll ^ ll.m_ll); } | |
470 | wxULongLongNative& operator^=(const wxULongLongNative& ll) | |
471 | { m_ll ^= ll.m_ll; return *this; } | |
472 | ||
473 | // multiplication/division | |
474 | wxULongLongNative operator*(const wxULongLongNative& ll) const | |
475 | { return wxULongLongNative(m_ll * ll.m_ll); } | |
476 | wxULongLongNative operator*(unsigned long l) const | |
477 | { return wxULongLongNative(m_ll * l); } | |
478 | wxULongLongNative& operator*=(const wxULongLongNative& ll) | |
479 | { m_ll *= ll.m_ll; return *this; } | |
480 | wxULongLongNative& operator*=(unsigned long l) | |
481 | { m_ll *= l; return *this; } | |
482 | ||
483 | wxULongLongNative operator/(const wxULongLongNative& ll) const | |
484 | { return wxULongLongNative(m_ll / ll.m_ll); } | |
485 | wxULongLongNative operator/(unsigned long l) const | |
486 | { return wxULongLongNative(m_ll / l); } | |
487 | wxULongLongNative& operator/=(const wxULongLongNative& ll) | |
488 | { m_ll /= ll.m_ll; return *this; } | |
489 | wxULongLongNative& operator/=(unsigned long l) | |
490 | { m_ll /= l; return *this; } | |
491 | ||
492 | wxULongLongNative operator%(const wxULongLongNative& ll) const | |
493 | { return wxULongLongNative(m_ll % ll.m_ll); } | |
494 | wxULongLongNative operator%(unsigned long l) const | |
495 | { return wxULongLongNative(m_ll % l); } | |
496 | ||
497 | // comparison | |
498 | bool operator==(const wxULongLongNative& ll) const | |
499 | { return m_ll == ll.m_ll; } | |
500 | bool operator==(unsigned long l) const | |
501 | { return m_ll == l; } | |
502 | bool operator!=(const wxULongLongNative& ll) const | |
503 | { return m_ll != ll.m_ll; } | |
504 | bool operator!=(unsigned long l) const | |
505 | { return m_ll != l; } | |
506 | bool operator<(const wxULongLongNative& ll) const | |
507 | { return m_ll < ll.m_ll; } | |
508 | bool operator<(unsigned long l) const | |
509 | { return m_ll < l; } | |
510 | bool operator>(const wxULongLongNative& ll) const | |
511 | { return m_ll > ll.m_ll; } | |
512 | bool operator>(unsigned long l) const | |
513 | { return m_ll > l; } | |
514 | bool operator<=(const wxULongLongNative& ll) const | |
515 | { return m_ll <= ll.m_ll; } | |
516 | bool operator<=(unsigned long l) const | |
517 | { return m_ll <= l; } | |
518 | bool operator>=(const wxULongLongNative& ll) const | |
519 | { return m_ll >= ll.m_ll; } | |
520 | bool operator>=(unsigned long l) const | |
521 | { return m_ll >= l; } | |
522 | ||
523 | // miscellaneous | |
524 | ||
525 | // return the string representation of this number | |
526 | wxString ToString() const; | |
527 | ||
528 | // conversion to byte array: returns a pointer to static buffer! | |
529 | void *asArray() const; | |
530 | ||
531 | #if wxUSE_STD_IOSTREAM | |
532 | // input/output | |
7fcdf88f VZ |
533 | friend WXDLLIMPEXP_BASE |
534 | wxSTD ostream& operator<<(wxSTD ostream&, const wxULongLongNative&); | |
8e38fd1f RL |
535 | #endif |
536 | ||
7fcdf88f VZ |
537 | friend WXDLLIMPEXP_BASE |
538 | wxString& operator<<(wxString&, const wxULongLongNative&); | |
51496782 | 539 | |
216a72f3 VZ |
540 | #if wxUSE_STREAMS |
541 | friend WXDLLIMPEXP_BASE | |
542 | class wxTextOutputStream& operator<<(class wxTextOutputStream&, const wxULongLongNative&); | |
543 | friend WXDLLIMPEXP_BASE | |
544 | class wxTextInputStream& operator>>(class wxTextInputStream&, wxULongLongNative&); | |
545 | #endif | |
546 | ||
8e38fd1f | 547 | private: |
60582201 | 548 | wxULongLong_t m_ll; |
8e38fd1f RL |
549 | }; |
550 | ||
216a72f3 VZ |
551 | inline |
552 | wxLongLongNative& wxLongLongNative::operator=(const wxULongLongNative &ll) | |
553 | { | |
554 | m_ll = ll.GetValue(); | |
555 | return *this; | |
556 | } | |
557 | ||
8b81872f VZ |
558 | #endif // wxUSE_LONGLONG_NATIVE |
559 | ||
560 | #if wxUSE_LONGLONG_WX | |
561 | ||
bddd7a8d | 562 | class WXDLLIMPEXP_BASE wxLongLongWx |
8b81872f VZ |
563 | { |
564 | public: | |
565 | // ctors | |
566 | // default ctor initializes to 0 | |
2a310492 VZ |
567 | wxLongLongWx() |
568 | { | |
569 | m_lo = m_hi = 0; | |
570 | ||
571 | #ifdef wxLONGLONG_TEST_MODE | |
572 | m_ll = 0; | |
573 | ||
574 | Check(); | |
575 | #endif // wxLONGLONG_TEST_MODE | |
576 | } | |
8b81872f | 577 | // from long |
2a310492 | 578 | wxLongLongWx(long l) { *this = l; } |
8b81872f VZ |
579 | // from 2 longs |
580 | wxLongLongWx(long hi, unsigned long lo) | |
2a310492 VZ |
581 | { |
582 | m_hi = hi; | |
583 | m_lo = lo; | |
584 | ||
585 | #ifdef wxLONGLONG_TEST_MODE | |
586 | m_ll = hi; | |
587 | m_ll <<= 32; | |
588 | m_ll |= lo; | |
589 | ||
590 | Check(); | |
591 | #endif // wxLONGLONG_TEST_MODE | |
592 | } | |
8b81872f VZ |
593 | |
594 | // default copy ctor is ok in both cases | |
595 | ||
596 | // no dtor | |
597 | ||
598 | // assignment operators | |
599 | // from long | |
600 | wxLongLongWx& operator=(long l) | |
2a310492 VZ |
601 | { |
602 | m_lo = l; | |
603 | m_hi = (l < 0 ? -1l : 0l); | |
604 | ||
605 | #ifdef wxLONGLONG_TEST_MODE | |
606 | m_ll = l; | |
607 | ||
608 | Check(); | |
609 | #endif // wxLONGLONG_TEST_MODE | |
610 | ||
611 | return *this; | |
612 | } | |
a4d2944e VZ |
613 | // from int |
614 | wxLongLongWx& operator=(int l) | |
615 | { | |
616 | return operator=((long)l); | |
617 | } | |
618 | ||
216a72f3 VZ |
619 | wxLongLongWx& operator=(unsigned long l) |
620 | { | |
621 | m_lo = l; | |
622 | m_hi = 0; | |
623 | ||
624 | #ifdef wxLONGLONG_TEST_MODE | |
625 | m_ll = l; | |
626 | ||
627 | Check(); | |
628 | #endif // wxLONGLONG_TEST_MODE | |
629 | ||
630 | return *this; | |
631 | } | |
632 | wxLongLongWx& operator=(const class wxULongLongWx &ll); | |
633 | ||
634 | // from double | |
cd0b1709 | 635 | wxLongLongWx& Assign(double d); |
8b81872f VZ |
636 | // can't have assignment operator from 2 longs |
637 | ||
638 | // accessors | |
639 | // get high part | |
640 | long GetHi() const { return m_hi; } | |
641 | // get low part | |
642 | unsigned long GetLo() const { return m_lo; } | |
643 | ||
cd0b1709 | 644 | // get absolute value |
2ea24d9f | 645 | wxLongLongWx Abs() const { return wxLongLongWx(*this).Abs(); } |
2a310492 VZ |
646 | wxLongLongWx& Abs() |
647 | { | |
648 | if ( m_hi < 0 ) | |
649 | m_hi = -m_hi; | |
650 | ||
651 | #ifdef wxLONGLONG_TEST_MODE | |
652 | if ( m_ll < 0 ) | |
653 | m_ll = -m_ll; | |
654 | ||
655 | Check(); | |
656 | #endif // wxLONGLONG_TEST_MODE | |
657 | ||
658 | return *this; | |
659 | } | |
cd0b1709 | 660 | |
90e572f1 | 661 | // convert to long with range checking in debug mode (only!) |
cd0b1709 VZ |
662 | long ToLong() const |
663 | { | |
2a310492 | 664 | wxASSERT_MSG( (m_hi == 0l) || (m_hi == -1l), |
cd0b1709 VZ |
665 | _T("wxLongLong to long conversion loss of precision") ); |
666 | ||
667 | return (long)m_lo; | |
668 | } | |
669 | ||
e7aaf2de VZ |
670 | // convert to double |
671 | double ToDouble() const; | |
672 | ||
8b81872f VZ |
673 | // operations |
674 | // addition | |
675 | wxLongLongWx operator+(const wxLongLongWx& ll) const; | |
676 | wxLongLongWx& operator+=(const wxLongLongWx& ll); | |
677 | wxLongLongWx operator+(long l) const; | |
678 | wxLongLongWx& operator+=(long l); | |
679 | ||
680 | // pre increment operator | |
681 | wxLongLongWx& operator++(); | |
682 | ||
683 | // post increment operator | |
2a310492 | 684 | wxLongLongWx& operator++(int) { return ++(*this); } |
8b81872f VZ |
685 | |
686 | // negation operator | |
687 | wxLongLongWx operator-() const; | |
2a310492 | 688 | wxLongLongWx& Negate(); |
8b81872f VZ |
689 | |
690 | // subraction | |
691 | wxLongLongWx operator-(const wxLongLongWx& ll) const; | |
692 | wxLongLongWx& operator-=(const wxLongLongWx& ll); | |
693 | ||
694 | // pre decrement operator | |
695 | wxLongLongWx& operator--(); | |
696 | ||
697 | // post decrement operator | |
2a310492 | 698 | wxLongLongWx& operator--(int) { return --(*this); } |
8b81872f VZ |
699 | |
700 | // shifts | |
701 | // left shift | |
702 | wxLongLongWx operator<<(int shift) const; | |
703 | wxLongLongWx& operator<<=(int shift); | |
704 | ||
705 | // right shift | |
706 | wxLongLongWx operator>>(int shift) const; | |
707 | wxLongLongWx& operator>>=(int shift); | |
708 | ||
709 | // bitwise operators | |
710 | wxLongLongWx operator&(const wxLongLongWx& ll) const; | |
711 | wxLongLongWx& operator&=(const wxLongLongWx& ll); | |
712 | wxLongLongWx operator|(const wxLongLongWx& ll) const; | |
713 | wxLongLongWx& operator|=(const wxLongLongWx& ll); | |
714 | wxLongLongWx operator^(const wxLongLongWx& ll) const; | |
715 | wxLongLongWx& operator^=(const wxLongLongWx& ll); | |
716 | wxLongLongWx operator~() const; | |
717 | ||
718 | // comparison | |
2ea24d9f VZ |
719 | bool operator==(const wxLongLongWx& ll) const |
720 | { return m_lo == ll.m_lo && m_hi == ll.m_hi; } | |
842215bb WS |
721 | #if wxUSE_LONGLONG_NATIVE |
722 | bool operator==(const wxLongLongNative& ll) const | |
723 | { return m_lo == ll.GetLo() && m_hi == ll.GetHi(); } | |
724 | #endif | |
2ea24d9f VZ |
725 | bool operator!=(const wxLongLongWx& ll) const |
726 | { return !(*this == ll); } | |
8b81872f VZ |
727 | bool operator<(const wxLongLongWx& ll) const; |
728 | bool operator>(const wxLongLongWx& ll) const; | |
2ea24d9f VZ |
729 | bool operator<=(const wxLongLongWx& ll) const |
730 | { return *this < ll || *this == ll; } | |
731 | bool operator>=(const wxLongLongWx& ll) const | |
732 | { return *this > ll || *this == ll; } | |
8b81872f | 733 | |
f6bcfd97 BP |
734 | bool operator<(long l) const { return *this < wxLongLongWx(l); } |
735 | bool operator>(long l) const { return *this > wxLongLongWx(l); } | |
736 | bool operator==(long l) const | |
737 | { | |
738 | return l >= 0 ? (m_hi == 0 && m_lo == (unsigned long)l) | |
739 | : (m_hi == -1 && m_lo == (unsigned long)l); | |
740 | } | |
741 | ||
742 | bool operator<=(long l) const { return *this < l || *this == l; } | |
743 | bool operator>=(long l) const { return *this > l || *this == l; } | |
744 | ||
8b81872f VZ |
745 | // multiplication |
746 | wxLongLongWx operator*(const wxLongLongWx& ll) const; | |
747 | wxLongLongWx& operator*=(const wxLongLongWx& ll); | |
8b81872f VZ |
748 | |
749 | // division | |
cd0b1709 VZ |
750 | wxLongLongWx operator/(const wxLongLongWx& ll) const; |
751 | wxLongLongWx& operator/=(const wxLongLongWx& ll); | |
752 | ||
753 | wxLongLongWx operator%(const wxLongLongWx& ll) const; | |
754 | ||
8b81872f VZ |
755 | void Divide(const wxLongLongWx& divisor, |
756 | wxLongLongWx& quotient, | |
757 | wxLongLongWx& remainder) const; | |
758 | ||
759 | // input/output | |
3a994742 VZ |
760 | |
761 | // return the string representation of this number | |
762 | wxString ToString() const; | |
763 | ||
764 | void *asArray() const; | |
765 | ||
cd0b1709 | 766 | #if wxUSE_STD_IOSTREAM |
a353dc98 VZ |
767 | friend WXDLLIMPEXP_BASE |
768 | wxSTD ostream& operator<<(wxSTD ostream&, const wxLongLongWx&); | |
fcc3d7cb | 769 | #endif // wxUSE_STD_IOSTREAM |
8b81872f | 770 | |
a353dc98 VZ |
771 | friend WXDLLIMPEXP_BASE |
772 | wxString& operator<<(wxString&, const wxLongLongWx&); | |
51496782 | 773 | |
216a72f3 VZ |
774 | #if wxUSE_STREAMS |
775 | friend WXDLLIMPEXP_BASE | |
776 | class wxTextOutputStream& operator<<(class wxTextOutputStream&, const wxLongLongWx&); | |
777 | friend WXDLLIMPEXP_BASE | |
778 | class wxTextInputStream& operator>>(class wxTextInputStream&, wxLongLongWx&); | |
779 | #endif | |
780 | ||
8b81872f VZ |
781 | private: |
782 | // long is at least 32 bits, so represent our 64bit number as 2 longs | |
783 | ||
784 | long m_hi; // signed bit is in the high part | |
785 | unsigned long m_lo; | |
2a310492 VZ |
786 | |
787 | #ifdef wxLONGLONG_TEST_MODE | |
788 | void Check() | |
789 | { | |
790 | wxASSERT( (m_ll >> 32) == m_hi && (unsigned long)m_ll == m_lo ); | |
791 | } | |
792 | ||
793 | wxLongLong_t m_ll; | |
794 | #endif // wxLONGLONG_TEST_MODE | |
8b81872f VZ |
795 | }; |
796 | ||
8e38fd1f | 797 | |
bddd7a8d | 798 | class WXDLLIMPEXP_BASE wxULongLongWx |
8e38fd1f RL |
799 | { |
800 | public: | |
801 | // ctors | |
802 | // default ctor initializes to 0 | |
803 | wxULongLongWx() | |
804 | { | |
805 | m_lo = m_hi = 0; | |
806 | ||
807 | #ifdef wxLONGLONG_TEST_MODE | |
808 | m_ll = 0; | |
809 | ||
810 | Check(); | |
811 | #endif // wxLONGLONG_TEST_MODE | |
812 | } | |
813 | // from ulong | |
814 | wxULongLongWx(unsigned long l) { *this = l; } | |
815 | // from 2 ulongs | |
816 | wxULongLongWx(unsigned long hi, unsigned long lo) | |
817 | { | |
818 | m_hi = hi; | |
819 | m_lo = lo; | |
820 | ||
821 | #ifdef wxLONGLONG_TEST_MODE | |
822 | m_ll = hi; | |
823 | m_ll <<= 32; | |
824 | m_ll |= lo; | |
825 | ||
826 | Check(); | |
827 | #endif // wxLONGLONG_TEST_MODE | |
828 | } | |
829 | ||
842215bb WS |
830 | // from signed to unsigned |
831 | wxULongLongWx(wxLongLongWx ll) | |
832 | { | |
833 | wxASSERT(ll.GetHi() >= 0); | |
834 | m_hi = (unsigned long)ll.GetHi(); | |
835 | m_lo = ll.GetLo(); | |
836 | } | |
837 | ||
8e38fd1f RL |
838 | // default copy ctor is ok in both cases |
839 | ||
840 | // no dtor | |
841 | ||
842 | // assignment operators | |
843 | // from long | |
844 | wxULongLongWx& operator=(unsigned long l) | |
845 | { | |
846 | m_lo = l; | |
847 | m_hi = 0; | |
848 | ||
849 | #ifdef wxLONGLONG_TEST_MODE | |
850 | m_ll = l; | |
851 | ||
852 | Check(); | |
853 | #endif // wxLONGLONG_TEST_MODE | |
854 | ||
855 | return *this; | |
856 | } | |
216a72f3 VZ |
857 | wxULongLongWx& operator=(long l) |
858 | { | |
859 | m_lo = l; | |
860 | m_hi = (unsigned long) ((l<0) ? -1l : 0); | |
861 | ||
862 | #ifdef wxLONGLONG_TEST_MODE | |
863 | m_ll = (wxULongLong_t) (wxLongLong_t) l; | |
864 | ||
865 | Check(); | |
866 | #endif // wxLONGLONG_TEST_MODE | |
867 | ||
868 | return *this; | |
869 | } | |
870 | wxULongLongWx& operator=(const class wxLongLongWx &ll) { | |
871 | // Should we use an assert like it was before in the constructor? | |
872 | // wxASSERT(ll.GetHi() >= 0); | |
873 | m_hi = (unsigned long)ll.GetHi(); | |
874 | m_lo = ll.GetLo(); | |
875 | return *this; | |
876 | } | |
8e38fd1f RL |
877 | |
878 | // can't have assignment operator from 2 longs | |
879 | ||
880 | // accessors | |
881 | // get high part | |
882 | unsigned long GetHi() const { return m_hi; } | |
883 | // get low part | |
884 | unsigned long GetLo() const { return m_lo; } | |
885 | ||
90e572f1 | 886 | // convert to long with range checking in debug mode (only!) |
8e38fd1f RL |
887 | unsigned long ToULong() const |
888 | { | |
d7997e1a | 889 | wxASSERT_MSG( m_hi == 0ul, |
8e38fd1f RL |
890 | _T("wxULongLong to long conversion loss of precision") ); |
891 | ||
892 | return (unsigned long)m_lo; | |
893 | } | |
894 | ||
895 | // operations | |
896 | // addition | |
897 | wxULongLongWx operator+(const wxULongLongWx& ll) const; | |
898 | wxULongLongWx& operator+=(const wxULongLongWx& ll); | |
899 | wxULongLongWx operator+(unsigned long l) const; | |
900 | wxULongLongWx& operator+=(unsigned long l); | |
901 | ||
902 | // pre increment operator | |
903 | wxULongLongWx& operator++(); | |
904 | ||
905 | // post increment operator | |
906 | wxULongLongWx& operator++(int) { return ++(*this); } | |
907 | ||
43e8916f | 908 | // subtraction |
842215bb | 909 | wxLongLongWx operator-(const wxULongLongWx& ll) const; |
8e38fd1f RL |
910 | wxULongLongWx& operator-=(const wxULongLongWx& ll); |
911 | ||
912 | // pre decrement operator | |
913 | wxULongLongWx& operator--(); | |
914 | ||
915 | // post decrement operator | |
916 | wxULongLongWx& operator--(int) { return --(*this); } | |
917 | ||
918 | // shifts | |
919 | // left shift | |
920 | wxULongLongWx operator<<(int shift) const; | |
921 | wxULongLongWx& operator<<=(int shift); | |
922 | ||
923 | // right shift | |
924 | wxULongLongWx operator>>(int shift) const; | |
925 | wxULongLongWx& operator>>=(int shift); | |
926 | ||
927 | // bitwise operators | |
928 | wxULongLongWx operator&(const wxULongLongWx& ll) const; | |
929 | wxULongLongWx& operator&=(const wxULongLongWx& ll); | |
930 | wxULongLongWx operator|(const wxULongLongWx& ll) const; | |
931 | wxULongLongWx& operator|=(const wxULongLongWx& ll); | |
932 | wxULongLongWx operator^(const wxULongLongWx& ll) const; | |
933 | wxULongLongWx& operator^=(const wxULongLongWx& ll); | |
934 | wxULongLongWx operator~() const; | |
935 | ||
936 | // comparison | |
937 | bool operator==(const wxULongLongWx& ll) const | |
938 | { return m_lo == ll.m_lo && m_hi == ll.m_hi; } | |
939 | bool operator!=(const wxULongLongWx& ll) const | |
940 | { return !(*this == ll); } | |
941 | bool operator<(const wxULongLongWx& ll) const; | |
942 | bool operator>(const wxULongLongWx& ll) const; | |
943 | bool operator<=(const wxULongLongWx& ll) const | |
944 | { return *this < ll || *this == ll; } | |
945 | bool operator>=(const wxULongLongWx& ll) const | |
946 | { return *this > ll || *this == ll; } | |
947 | ||
948 | bool operator<(unsigned long l) const { return *this < wxULongLongWx(l); } | |
949 | bool operator>(unsigned long l) const { return *this > wxULongLongWx(l); } | |
950 | bool operator==(unsigned long l) const | |
951 | { | |
952 | return (m_hi == 0 && m_lo == (unsigned long)l); | |
953 | } | |
954 | ||
955 | bool operator<=(unsigned long l) const { return *this < l || *this == l; } | |
956 | bool operator>=(unsigned long l) const { return *this > l || *this == l; } | |
957 | ||
958 | // multiplication | |
959 | wxULongLongWx operator*(const wxULongLongWx& ll) const; | |
960 | wxULongLongWx& operator*=(const wxULongLongWx& ll); | |
961 | ||
962 | // division | |
963 | wxULongLongWx operator/(const wxULongLongWx& ll) const; | |
964 | wxULongLongWx& operator/=(const wxULongLongWx& ll); | |
965 | ||
966 | wxULongLongWx operator%(const wxULongLongWx& ll) const; | |
967 | ||
968 | void Divide(const wxULongLongWx& divisor, | |
969 | wxULongLongWx& quotient, | |
970 | wxULongLongWx& remainder) const; | |
971 | ||
972 | // input/output | |
973 | ||
974 | // return the string representation of this number | |
975 | wxString ToString() const; | |
976 | ||
977 | void *asArray() const; | |
978 | ||
979 | #if wxUSE_STD_IOSTREAM | |
a353dc98 VZ |
980 | friend WXDLLIMPEXP_BASE |
981 | wxSTD ostream& operator<<(wxSTD ostream&, const wxULongLongWx&); | |
8e38fd1f RL |
982 | #endif // wxUSE_STD_IOSTREAM |
983 | ||
a353dc98 VZ |
984 | friend WXDLLIMPEXP_BASE |
985 | wxString& operator<<(wxString&, const wxULongLongWx&); | |
51496782 | 986 | |
216a72f3 VZ |
987 | #if wxUSE_STREAMS |
988 | friend WXDLLIMPEXP_BASE | |
989 | class wxTextOutputStream& operator<<(class wxTextOutputStream&, const wxULongLongWx&); | |
990 | friend WXDLLIMPEXP_BASE | |
991 | class wxTextInputStream& operator>>(class wxTextInputStream&, wxULongLongWx&); | |
992 | #endif | |
993 | ||
8e38fd1f RL |
994 | private: |
995 | // long is at least 32 bits, so represent our 64bit number as 2 longs | |
996 | ||
d2ce649b | 997 | unsigned long m_hi; |
8e38fd1f RL |
998 | unsigned long m_lo; |
999 | ||
1000 | #ifdef wxLONGLONG_TEST_MODE | |
1001 | void Check() | |
1002 | { | |
1003 | wxASSERT( (m_ll >> 32) == m_hi && (unsigned long)m_ll == m_lo ); | |
1004 | } | |
1005 | ||
60582201 | 1006 | wxULongLong_t m_ll; |
8e38fd1f RL |
1007 | #endif // wxLONGLONG_TEST_MODE |
1008 | }; | |
1009 | ||
8b81872f VZ |
1010 | #endif // wxUSE_LONGLONG_WX |
1011 | ||
2ea24d9f VZ |
1012 | // ---------------------------------------------------------------------------- |
1013 | // binary operators | |
1014 | // ---------------------------------------------------------------------------- | |
1015 | ||
6d56eb5c | 1016 | inline bool operator<(long l, const wxLongLong& ll) { return ll > l; } |
d7997e1a VZ |
1017 | inline bool operator>(long l, const wxLongLong& ll) { return ll < l; } |
1018 | inline bool operator<=(long l, const wxLongLong& ll) { return ll >= l; } | |
1019 | inline bool operator>=(long l, const wxLongLong& ll) { return ll <= l; } | |
1020 | inline bool operator==(long l, const wxLongLong& ll) { return ll == l; } | |
1021 | inline bool operator!=(long l, const wxLongLong& ll) { return ll != l; } | |
b01fb5c3 | 1022 | |
d7997e1a | 1023 | inline wxLongLong operator+(long l, const wxLongLong& ll) { return ll + l; } |
b01fb5c3 VZ |
1024 | inline wxLongLong operator-(long l, const wxLongLong& ll) |
1025 | { | |
d7997e1a | 1026 | return wxLongLong(l) - ll; |
b01fb5c3 | 1027 | } |
2ea24d9f | 1028 | |
d7997e1a VZ |
1029 | inline bool operator<(unsigned long l, const wxULongLong& ull) { return ull > l; } |
1030 | inline bool operator>(unsigned long l, const wxULongLong& ull) { return ull < l; } | |
1031 | inline bool operator<=(unsigned long l, const wxULongLong& ull) { return ull >= l; } | |
1032 | inline bool operator>=(unsigned long l, const wxULongLong& ull) { return ull <= l; } | |
1033 | inline bool operator==(unsigned long l, const wxULongLong& ull) { return ull == l; } | |
1034 | inline bool operator!=(unsigned long l, const wxULongLong& ull) { return ull != l; } | |
1035 | ||
1036 | inline wxULongLong operator+(unsigned long l, const wxULongLong& ull) { return ull + l; } | |
8e38fd1f | 1037 | |
842215bb | 1038 | inline wxLongLong operator-(unsigned long l, const wxULongLong& ull) |
d7997e1a | 1039 | { |
842215bb WS |
1040 | wxULongLong ret = wxULongLong(l) - ull; |
1041 | return wxLongLong((long)ret.GetHi(),ret.GetLo()); | |
d7997e1a | 1042 | } |
8e38fd1f | 1043 | |
216a72f3 VZ |
1044 | #if wxUSE_LONGLONG_NATIVE && wxUSE_STREAMS |
1045 | ||
1046 | WXDLLIMPEXP_BASE class wxTextOutputStream &operator<<(class wxTextOutputStream &stream, wxULongLong_t value); | |
1047 | WXDLLIMPEXP_BASE class wxTextOutputStream &operator<<(class wxTextOutputStream &stream, wxLongLong_t value); | |
1048 | ||
1049 | WXDLLIMPEXP_BASE class wxTextInputStream &operator>>(class wxTextInputStream &stream, wxULongLong_t &value); | |
1050 | WXDLLIMPEXP_BASE class wxTextInputStream &operator>>(class wxTextInputStream &stream, wxLongLong_t &value); | |
1051 | ||
1052 | #endif | |
1053 | ||
1054 | #endif // wxUSE_LONGLONG | |
1055 | ||
8b81872f | 1056 | #endif // _WX_LONGLONG_H |