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