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