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