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