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