]> git.saurik.com Git - wxWidgets.git/blob - include/wx/longlong.h
added and documented SetEscapeId()
[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 #if wxABI_VERSION >= 20602
164 // convert to double
165 double ToDouble() const { return wx_truncate_cast(double, m_ll); }
166 #endif // ABI >= 2.6.2
167
168 // don't provide implicit conversion to wxLongLong_t or we will have an
169 // ambiguity for all arithmetic operations
170 //operator wxLongLong_t() const { return m_ll; }
171
172 // operations
173 // addition
174 wxLongLongNative operator+(const wxLongLongNative& ll) const
175 { return wxLongLongNative(m_ll + ll.m_ll); }
176 wxLongLongNative& operator+=(const wxLongLongNative& ll)
177 { m_ll += ll.m_ll; return *this; }
178
179 wxLongLongNative operator+(const wxLongLong_t ll) const
180 { return wxLongLongNative(m_ll + ll); }
181 wxLongLongNative& operator+=(const wxLongLong_t ll)
182 { m_ll += ll; return *this; }
183
184 // pre increment
185 wxLongLongNative& operator++()
186 { m_ll++; return *this; }
187
188 // post increment
189 wxLongLongNative operator++(int)
190 { wxLongLongNative value(*this); m_ll++; return value; }
191
192 // negation operator
193 wxLongLongNative operator-() const
194 { return wxLongLongNative(-m_ll); }
195 wxLongLongNative& Negate() { m_ll = -m_ll; return *this; }
196
197 // subtraction
198 wxLongLongNative operator-(const wxLongLongNative& ll) const
199 { return wxLongLongNative(m_ll - ll.m_ll); }
200 wxLongLongNative& operator-=(const wxLongLongNative& ll)
201 { m_ll -= ll.m_ll; return *this; }
202
203 wxLongLongNative operator-(const wxLongLong_t ll) const
204 { return wxLongLongNative(m_ll - ll); }
205 wxLongLongNative& operator-=(const wxLongLong_t ll)
206 { m_ll -= ll; return *this; }
207
208 // pre decrement
209 wxLongLongNative& operator--()
210 { m_ll--; return *this; }
211
212 // post decrement
213 wxLongLongNative operator--(int)
214 { wxLongLongNative value(*this); m_ll--; return value; }
215
216 // shifts
217 // left shift
218 wxLongLongNative operator<<(int shift) const
219 { return wxLongLongNative(m_ll << shift); }
220 wxLongLongNative& operator<<=(int shift)
221 { m_ll <<= shift; return *this; }
222
223 // right shift
224 wxLongLongNative operator>>(int shift) const
225 { return wxLongLongNative(m_ll >> shift); }
226 wxLongLongNative& operator>>=(int shift)
227 { m_ll >>= shift; return *this; }
228
229 // bitwise operators
230 wxLongLongNative operator&(const wxLongLongNative& ll) const
231 { return wxLongLongNative(m_ll & ll.m_ll); }
232 wxLongLongNative& operator&=(const wxLongLongNative& ll)
233 { m_ll &= ll.m_ll; return *this; }
234
235 wxLongLongNative operator|(const wxLongLongNative& ll) const
236 { return wxLongLongNative(m_ll | ll.m_ll); }
237 wxLongLongNative& operator|=(const wxLongLongNative& ll)
238 { m_ll |= ll.m_ll; return *this; }
239
240 wxLongLongNative operator^(const wxLongLongNative& ll) const
241 { return wxLongLongNative(m_ll ^ ll.m_ll); }
242 wxLongLongNative& operator^=(const wxLongLongNative& ll)
243 { m_ll ^= ll.m_ll; return *this; }
244
245 // multiplication/division
246 wxLongLongNative operator*(const wxLongLongNative& ll) const
247 { return wxLongLongNative(m_ll * ll.m_ll); }
248 wxLongLongNative operator*(long l) const
249 { return wxLongLongNative(m_ll * l); }
250 wxLongLongNative& operator*=(const wxLongLongNative& ll)
251 { m_ll *= ll.m_ll; return *this; }
252 wxLongLongNative& operator*=(long l)
253 { m_ll *= l; return *this; }
254
255 wxLongLongNative operator/(const wxLongLongNative& ll) const
256 { return wxLongLongNative(m_ll / ll.m_ll); }
257 wxLongLongNative operator/(long l) const
258 { return wxLongLongNative(m_ll / l); }
259 wxLongLongNative& operator/=(const wxLongLongNative& ll)
260 { m_ll /= ll.m_ll; return *this; }
261 wxLongLongNative& operator/=(long l)
262 { m_ll /= l; return *this; }
263
264 wxLongLongNative operator%(const wxLongLongNative& ll) const
265 { return wxLongLongNative(m_ll % ll.m_ll); }
266 wxLongLongNative operator%(long l) const
267 { return wxLongLongNative(m_ll % l); }
268
269 // comparison
270 bool operator==(const wxLongLongNative& ll) const
271 { return m_ll == ll.m_ll; }
272 bool operator==(long l) const
273 { return m_ll == l; }
274 bool operator!=(const wxLongLongNative& ll) const
275 { return m_ll != ll.m_ll; }
276 bool operator!=(long l) const
277 { return m_ll != l; }
278 bool operator<(const wxLongLongNative& ll) const
279 { return m_ll < ll.m_ll; }
280 bool operator<(long l) const
281 { return m_ll < l; }
282 bool operator>(const wxLongLongNative& ll) const
283 { return m_ll > ll.m_ll; }
284 bool operator>(long l) const
285 { return m_ll > l; }
286 bool operator<=(const wxLongLongNative& ll) const
287 { return m_ll <= ll.m_ll; }
288 bool operator<=(long l) const
289 { return m_ll <= l; }
290 bool operator>=(const wxLongLongNative& ll) const
291 { return m_ll >= ll.m_ll; }
292 bool operator>=(long l) const
293 { return m_ll >= l; }
294
295 // miscellaneous
296
297 // return the string representation of this number
298 wxString ToString() const;
299
300 // conversion to byte array: returns a pointer to static buffer!
301 void *asArray() const;
302
303 #if wxUSE_STD_IOSTREAM
304 // input/output
305 friend WXDLLIMPEXP_BASE
306 wxSTD ostream& operator<<(wxSTD ostream&, const wxLongLongNative&);
307 #endif
308
309 friend WXDLLIMPEXP_BASE
310 wxString& operator<<(wxString&, const wxLongLongNative&);
311
312 private:
313 wxLongLong_t m_ll;
314 };
315
316
317 class WXDLLIMPEXP_BASE wxULongLongNative
318 {
319 public:
320 // ctors
321 // default ctor initializes to 0
322 wxULongLongNative() : m_ll(0) { }
323 // from long long
324 wxULongLongNative(wxULongLong_t ll) : m_ll(ll) { }
325 // from 2 longs
326 wxULongLongNative(unsigned long hi, unsigned long lo) : m_ll(0)
327 {
328 // assign first to avoid precision loss!
329 m_ll = ((wxULongLong_t) hi) << 32;
330 m_ll |= (wxULongLong_t) lo;
331 }
332
333 // default copy ctor is ok
334
335 // no dtor
336
337 // assignment operators
338 // from native 64 bit integer
339 wxULongLongNative& operator=(wxULongLong_t ll)
340 { m_ll = ll; return *this; }
341
342 // assignment operators from wxULongLongNative is ok
343
344 // accessors
345 // get high part
346 unsigned long GetHi() const
347 { return wx_truncate_cast(unsigned long, m_ll >> 32); }
348 // get low part
349 unsigned long GetLo() const
350 { return wx_truncate_cast(unsigned long, m_ll); }
351
352 // convert to native ulong long
353 wxULongLong_t GetValue() const { return m_ll; }
354
355 // convert to ulong with range checking in the debug mode (only!)
356 unsigned long ToULong() const
357 {
358 wxASSERT_MSG( m_ll <= LONG_MAX,
359 _T("wxULongLong to long conversion loss of precision") );
360
361 return wx_truncate_cast(unsigned long, m_ll);
362 }
363
364 // operations
365 // addition
366 wxULongLongNative operator+(const wxULongLongNative& ll) const
367 { return wxULongLongNative(m_ll + ll.m_ll); }
368 wxULongLongNative& operator+=(const wxULongLongNative& ll)
369 { m_ll += ll.m_ll; return *this; }
370
371 wxULongLongNative operator+(const wxULongLong_t ll) const
372 { return wxULongLongNative(m_ll + ll); }
373 wxULongLongNative& operator+=(const wxULongLong_t ll)
374 { m_ll += ll; return *this; }
375
376 // pre increment
377 wxULongLongNative& operator++()
378 { m_ll++; return *this; }
379
380 // post increment
381 wxULongLongNative operator++(int)
382 { wxULongLongNative value(*this); m_ll++; return value; }
383
384 // subtraction
385 wxULongLongNative operator-(const wxULongLongNative& ll) const
386 { return wxULongLongNative(m_ll - ll.m_ll); }
387 wxULongLongNative& operator-=(const wxULongLongNative& ll)
388 { m_ll -= ll.m_ll; return *this; }
389
390 wxULongLongNative operator-(const wxULongLong_t ll) const
391 { return wxULongLongNative(m_ll - ll); }
392 wxULongLongNative& operator-=(const wxULongLong_t ll)
393 { m_ll -= ll; return *this; }
394
395 // pre decrement
396 wxULongLongNative& operator--()
397 { m_ll--; return *this; }
398
399 // post decrement
400 wxULongLongNative operator--(int)
401 { wxULongLongNative value(*this); m_ll--; return value; }
402
403 // shifts
404 // left shift
405 wxULongLongNative operator<<(int shift) const
406 { return wxULongLongNative(m_ll << shift); }
407 wxULongLongNative& operator<<=(int shift)
408 { m_ll <<= shift; return *this; }
409
410 // right shift
411 wxULongLongNative operator>>(int shift) const
412 { return wxULongLongNative(m_ll >> shift); }
413 wxULongLongNative& operator>>=(int shift)
414 { m_ll >>= shift; return *this; }
415
416 // bitwise operators
417 wxULongLongNative operator&(const wxULongLongNative& ll) const
418 { return wxULongLongNative(m_ll & ll.m_ll); }
419 wxULongLongNative& operator&=(const wxULongLongNative& ll)
420 { m_ll &= ll.m_ll; return *this; }
421
422 wxULongLongNative operator|(const wxULongLongNative& ll) const
423 { return wxULongLongNative(m_ll | ll.m_ll); }
424 wxULongLongNative& operator|=(const wxULongLongNative& ll)
425 { m_ll |= ll.m_ll; return *this; }
426
427 wxULongLongNative operator^(const wxULongLongNative& ll) const
428 { return wxULongLongNative(m_ll ^ ll.m_ll); }
429 wxULongLongNative& operator^=(const wxULongLongNative& ll)
430 { m_ll ^= ll.m_ll; return *this; }
431
432 // multiplication/division
433 wxULongLongNative operator*(const wxULongLongNative& ll) const
434 { return wxULongLongNative(m_ll * ll.m_ll); }
435 wxULongLongNative operator*(unsigned long l) const
436 { return wxULongLongNative(m_ll * l); }
437 wxULongLongNative& operator*=(const wxULongLongNative& ll)
438 { m_ll *= ll.m_ll; return *this; }
439 wxULongLongNative& operator*=(unsigned long l)
440 { m_ll *= l; return *this; }
441
442 wxULongLongNative operator/(const wxULongLongNative& ll) const
443 { return wxULongLongNative(m_ll / ll.m_ll); }
444 wxULongLongNative operator/(unsigned long l) const
445 { return wxULongLongNative(m_ll / l); }
446 wxULongLongNative& operator/=(const wxULongLongNative& ll)
447 { m_ll /= ll.m_ll; return *this; }
448 wxULongLongNative& operator/=(unsigned long l)
449 { m_ll /= l; return *this; }
450
451 wxULongLongNative operator%(const wxULongLongNative& ll) const
452 { return wxULongLongNative(m_ll % ll.m_ll); }
453 wxULongLongNative operator%(unsigned long l) const
454 { return wxULongLongNative(m_ll % l); }
455
456 // comparison
457 bool operator==(const wxULongLongNative& ll) const
458 { return m_ll == ll.m_ll; }
459 bool operator==(unsigned long l) const
460 { return m_ll == l; }
461 bool operator!=(const wxULongLongNative& ll) const
462 { return m_ll != ll.m_ll; }
463 bool operator!=(unsigned long l) const
464 { return m_ll != l; }
465 bool operator<(const wxULongLongNative& ll) const
466 { return m_ll < ll.m_ll; }
467 bool operator<(unsigned long l) const
468 { return m_ll < l; }
469 bool operator>(const wxULongLongNative& ll) const
470 { return m_ll > ll.m_ll; }
471 bool operator>(unsigned long l) const
472 { return m_ll > l; }
473 bool operator<=(const wxULongLongNative& ll) const
474 { return m_ll <= ll.m_ll; }
475 bool operator<=(unsigned long l) const
476 { return m_ll <= l; }
477 bool operator>=(const wxULongLongNative& ll) const
478 { return m_ll >= ll.m_ll; }
479 bool operator>=(unsigned long l) const
480 { return m_ll >= l; }
481
482 // miscellaneous
483
484 // return the string representation of this number
485 wxString ToString() const;
486
487 // conversion to byte array: returns a pointer to static buffer!
488 void *asArray() const;
489
490 #if wxUSE_STD_IOSTREAM
491 // input/output
492 friend WXDLLIMPEXP_BASE
493 wxSTD ostream& operator<<(wxSTD ostream&, const wxULongLongNative&);
494 #endif
495
496 friend WXDLLIMPEXP_BASE
497 wxString& operator<<(wxString&, const wxULongLongNative&);
498
499 private:
500 wxULongLong_t m_ll;
501 };
502
503 #endif // wxUSE_LONGLONG_NATIVE
504
505 #if wxUSE_LONGLONG_WX
506
507 class WXDLLIMPEXP_BASE wxLongLongWx
508 {
509 public:
510 // ctors
511 // default ctor initializes to 0
512 wxLongLongWx()
513 {
514 m_lo = m_hi = 0;
515
516 #ifdef wxLONGLONG_TEST_MODE
517 m_ll = 0;
518
519 Check();
520 #endif // wxLONGLONG_TEST_MODE
521 }
522 // from long
523 wxLongLongWx(long l) { *this = l; }
524 // from 2 longs
525 wxLongLongWx(long hi, unsigned long lo)
526 {
527 m_hi = hi;
528 m_lo = lo;
529
530 #ifdef wxLONGLONG_TEST_MODE
531 m_ll = hi;
532 m_ll <<= 32;
533 m_ll |= lo;
534
535 Check();
536 #endif // wxLONGLONG_TEST_MODE
537 }
538
539 // default copy ctor is ok in both cases
540
541 // no dtor
542
543 // assignment operators
544 // from long
545 wxLongLongWx& operator=(long l)
546 {
547 m_lo = l;
548 m_hi = (l < 0 ? -1l : 0l);
549
550 #ifdef wxLONGLONG_TEST_MODE
551 m_ll = l;
552
553 Check();
554 #endif // wxLONGLONG_TEST_MODE
555
556 return *this;
557 }
558 // from double
559 wxLongLongWx& Assign(double d);
560 // can't have assignment operator from 2 longs
561
562 // accessors
563 // get high part
564 long GetHi() const { return m_hi; }
565 // get low part
566 unsigned long GetLo() const { return m_lo; }
567
568 // get absolute value
569 wxLongLongWx Abs() const { return wxLongLongWx(*this).Abs(); }
570 wxLongLongWx& Abs()
571 {
572 if ( m_hi < 0 )
573 m_hi = -m_hi;
574
575 #ifdef wxLONGLONG_TEST_MODE
576 if ( m_ll < 0 )
577 m_ll = -m_ll;
578
579 Check();
580 #endif // wxLONGLONG_TEST_MODE
581
582 return *this;
583 }
584
585 // convert to long with range checking in the debug mode (only!)
586 long ToLong() const
587 {
588 wxASSERT_MSG( (m_hi == 0l) || (m_hi == -1l),
589 _T("wxLongLong to long conversion loss of precision") );
590
591 return (long)m_lo;
592 }
593
594 #if wxABI_VERSION >= 20602
595 // convert to double
596 double ToDouble() const;
597 #endif // ABI >= 2.6.2
598
599 // operations
600 // addition
601 wxLongLongWx operator+(const wxLongLongWx& ll) const;
602 wxLongLongWx& operator+=(const wxLongLongWx& ll);
603 wxLongLongWx operator+(long l) const;
604 wxLongLongWx& operator+=(long l);
605
606 // pre increment operator
607 wxLongLongWx& operator++();
608
609 // post increment operator
610 wxLongLongWx& operator++(int) { return ++(*this); }
611
612 // negation operator
613 wxLongLongWx operator-() const;
614 wxLongLongWx& Negate();
615
616 // subraction
617 wxLongLongWx operator-(const wxLongLongWx& ll) const;
618 wxLongLongWx& operator-=(const wxLongLongWx& ll);
619
620 // pre decrement operator
621 wxLongLongWx& operator--();
622
623 // post decrement operator
624 wxLongLongWx& operator--(int) { return --(*this); }
625
626 // shifts
627 // left shift
628 wxLongLongWx operator<<(int shift) const;
629 wxLongLongWx& operator<<=(int shift);
630
631 // right shift
632 wxLongLongWx operator>>(int shift) const;
633 wxLongLongWx& operator>>=(int shift);
634
635 // bitwise operators
636 wxLongLongWx operator&(const wxLongLongWx& ll) const;
637 wxLongLongWx& operator&=(const wxLongLongWx& ll);
638 wxLongLongWx operator|(const wxLongLongWx& ll) const;
639 wxLongLongWx& operator|=(const wxLongLongWx& ll);
640 wxLongLongWx operator^(const wxLongLongWx& ll) const;
641 wxLongLongWx& operator^=(const wxLongLongWx& ll);
642 wxLongLongWx operator~() const;
643
644 // comparison
645 bool operator==(const wxLongLongWx& ll) const
646 { return m_lo == ll.m_lo && m_hi == ll.m_hi; }
647 #if wxUSE_LONGLONG_NATIVE
648 bool operator==(const wxLongLongNative& ll) const
649 { return m_lo == ll.GetLo() && m_hi == ll.GetHi(); }
650 #endif
651 bool operator!=(const wxLongLongWx& ll) const
652 { return !(*this == ll); }
653 bool operator<(const wxLongLongWx& ll) const;
654 bool operator>(const wxLongLongWx& ll) const;
655 bool operator<=(const wxLongLongWx& ll) const
656 { return *this < ll || *this == ll; }
657 bool operator>=(const wxLongLongWx& ll) const
658 { return *this > ll || *this == ll; }
659
660 bool operator<(long l) const { return *this < wxLongLongWx(l); }
661 bool operator>(long l) const { return *this > wxLongLongWx(l); }
662 bool operator==(long l) const
663 {
664 return l >= 0 ? (m_hi == 0 && m_lo == (unsigned long)l)
665 : (m_hi == -1 && m_lo == (unsigned long)l);
666 }
667
668 bool operator<=(long l) const { return *this < l || *this == l; }
669 bool operator>=(long l) const { return *this > l || *this == l; }
670
671 // multiplication
672 wxLongLongWx operator*(const wxLongLongWx& ll) const;
673 wxLongLongWx& operator*=(const wxLongLongWx& ll);
674
675 // division
676 wxLongLongWx operator/(const wxLongLongWx& ll) const;
677 wxLongLongWx& operator/=(const wxLongLongWx& ll);
678
679 wxLongLongWx operator%(const wxLongLongWx& ll) const;
680
681 void Divide(const wxLongLongWx& divisor,
682 wxLongLongWx& quotient,
683 wxLongLongWx& remainder) const;
684
685 // input/output
686
687 // return the string representation of this number
688 wxString ToString() const;
689
690 void *asArray() const;
691
692 #if wxUSE_STD_IOSTREAM
693 friend WXDLLIMPEXP_BASE
694 wxSTD ostream& operator<<(wxSTD ostream&, const wxLongLongWx&);
695 #endif // wxUSE_STD_IOSTREAM
696
697 friend WXDLLIMPEXP_BASE
698 wxString& operator<<(wxString&, const wxLongLongWx&);
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 WXDLLIMPEXP_BASE 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 // from signed to unsigned
750 wxULongLongWx(wxLongLongWx ll)
751 {
752 wxASSERT(ll.GetHi() >= 0);
753 m_hi = (unsigned long)ll.GetHi();
754 m_lo = ll.GetLo();
755 }
756
757 // default copy ctor is ok in both cases
758
759 // no dtor
760
761 // assignment operators
762 // from long
763 wxULongLongWx& operator=(unsigned long l)
764 {
765 m_lo = l;
766 m_hi = 0;
767
768 #ifdef wxLONGLONG_TEST_MODE
769 m_ll = l;
770
771 Check();
772 #endif // wxLONGLONG_TEST_MODE
773
774 return *this;
775 }
776
777 // can't have assignment operator from 2 longs
778
779 // accessors
780 // get high part
781 unsigned long GetHi() const { return m_hi; }
782 // get low part
783 unsigned long GetLo() const { return m_lo; }
784
785 // convert to long with range checking in the debug mode (only!)
786 unsigned long ToULong() const
787 {
788 wxASSERT_MSG( m_hi == 0ul,
789 _T("wxULongLong to long conversion loss of precision") );
790
791 return (unsigned long)m_lo;
792 }
793
794 // operations
795 // addition
796 wxULongLongWx operator+(const wxULongLongWx& ll) const;
797 wxULongLongWx& operator+=(const wxULongLongWx& ll);
798 wxULongLongWx operator+(unsigned long l) const;
799 wxULongLongWx& operator+=(unsigned long l);
800
801 // pre increment operator
802 wxULongLongWx& operator++();
803
804 // post increment operator
805 wxULongLongWx& operator++(int) { return ++(*this); }
806
807 // subtraction
808 wxLongLongWx operator-(const wxULongLongWx& ll) const;
809 wxULongLongWx& operator-=(const wxULongLongWx& ll);
810
811 // pre decrement operator
812 wxULongLongWx& operator--();
813
814 // post decrement operator
815 wxULongLongWx& operator--(int) { return --(*this); }
816
817 // shifts
818 // left shift
819 wxULongLongWx operator<<(int shift) const;
820 wxULongLongWx& operator<<=(int shift);
821
822 // right shift
823 wxULongLongWx operator>>(int shift) const;
824 wxULongLongWx& operator>>=(int shift);
825
826 // bitwise operators
827 wxULongLongWx operator&(const wxULongLongWx& ll) const;
828 wxULongLongWx& operator&=(const wxULongLongWx& ll);
829 wxULongLongWx operator|(const wxULongLongWx& ll) const;
830 wxULongLongWx& operator|=(const wxULongLongWx& ll);
831 wxULongLongWx operator^(const wxULongLongWx& ll) const;
832 wxULongLongWx& operator^=(const wxULongLongWx& ll);
833 wxULongLongWx operator~() const;
834
835 // comparison
836 bool operator==(const wxULongLongWx& ll) const
837 { return m_lo == ll.m_lo && m_hi == ll.m_hi; }
838 bool operator!=(const wxULongLongWx& ll) const
839 { return !(*this == ll); }
840 bool operator<(const wxULongLongWx& ll) const;
841 bool operator>(const wxULongLongWx& ll) const;
842 bool operator<=(const wxULongLongWx& ll) const
843 { return *this < ll || *this == ll; }
844 bool operator>=(const wxULongLongWx& ll) const
845 { return *this > ll || *this == ll; }
846
847 bool operator<(unsigned long l) const { return *this < wxULongLongWx(l); }
848 bool operator>(unsigned long l) const { return *this > wxULongLongWx(l); }
849 bool operator==(unsigned long l) const
850 {
851 return (m_hi == 0 && m_lo == (unsigned long)l);
852 }
853
854 bool operator<=(unsigned long l) const { return *this < l || *this == l; }
855 bool operator>=(unsigned long l) const { return *this > l || *this == l; }
856
857 // multiplication
858 wxULongLongWx operator*(const wxULongLongWx& ll) const;
859 wxULongLongWx& operator*=(const wxULongLongWx& ll);
860
861 // division
862 wxULongLongWx operator/(const wxULongLongWx& ll) const;
863 wxULongLongWx& operator/=(const wxULongLongWx& ll);
864
865 wxULongLongWx operator%(const wxULongLongWx& ll) const;
866
867 void Divide(const wxULongLongWx& divisor,
868 wxULongLongWx& quotient,
869 wxULongLongWx& remainder) const;
870
871 // input/output
872
873 // return the string representation of this number
874 wxString ToString() const;
875
876 void *asArray() const;
877
878 #if wxUSE_STD_IOSTREAM
879 friend WXDLLIMPEXP_BASE
880 wxSTD ostream& operator<<(wxSTD ostream&, const wxULongLongWx&);
881 #endif // wxUSE_STD_IOSTREAM
882
883 friend WXDLLIMPEXP_BASE
884 wxString& operator<<(wxString&, const wxULongLongWx&);
885
886 private:
887 // long is at least 32 bits, so represent our 64bit number as 2 longs
888
889 unsigned long m_hi;
890 unsigned long m_lo;
891
892 #ifdef wxLONGLONG_TEST_MODE
893 void Check()
894 {
895 wxASSERT( (m_ll >> 32) == m_hi && (unsigned long)m_ll == m_lo );
896 }
897
898 wxULongLong_t m_ll;
899 #endif // wxLONGLONG_TEST_MODE
900 };
901
902 #endif // wxUSE_LONGLONG_WX
903
904 // ----------------------------------------------------------------------------
905 // binary operators
906 // ----------------------------------------------------------------------------
907
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 inline bool operator<=(long l, const wxLongLong& ll) { return ll >= l; }
911 inline bool operator>=(long l, const wxLongLong& ll) { return ll <= l; }
912 inline bool operator==(long l, const wxLongLong& ll) { return ll == l; }
913 inline bool operator!=(long l, const wxLongLong& ll) { return ll != l; }
914
915 inline wxLongLong operator+(long l, const wxLongLong& ll) { return ll + l; }
916 inline wxLongLong operator-(long l, const wxLongLong& ll)
917 {
918 return wxLongLong(l) - ll;
919 }
920
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 inline bool operator<=(unsigned long l, const wxULongLong& ull) { return ull >= l; }
924 inline bool operator>=(unsigned long l, const wxULongLong& ull) { return ull <= l; }
925 inline bool operator==(unsigned long l, const wxULongLong& ull) { return ull == l; }
926 inline bool operator!=(unsigned long l, const wxULongLong& ull) { return ull != l; }
927
928 inline wxULongLong operator+(unsigned long l, const wxULongLong& ull) { return ull + l; }
929
930 inline wxLongLong operator-(unsigned long l, const wxULongLong& ull)
931 {
932 wxULongLong ret = wxULongLong(l) - ull;
933 return wxLongLong((long)ret.GetHi(),ret.GetLo());
934 }
935
936 #endif // _WX_LONGLONG_H