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