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