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