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