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