]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/longlong.h
Moved all WXDLLEXPORT's to be before the return type in order to make
[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// Remarks: this class is not public in wxWindows 2.0! It is intentionally
7// not documented and is for private use only.
8// Modified by:
9// Created: 10.02.99
10// RCS-ID: $Id$
11// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
12// Licence: wxWindows license
13/////////////////////////////////////////////////////////////////////////////
14
15#ifndef _WX_LONGLONG_H
16#define _WX_LONGLONG_H
17
18#ifdef __GNUG__
19 #pragma interface "longlong.h"
20#endif
21
22// ----------------------------------------------------------------------------
23// decide upon which class we will use
24// ----------------------------------------------------------------------------
25
26// to avoid compilation problems on 64bit machines with ambiguous method calls
27// we will need this
28#undef wxLongLongIsLong
29
30// NB: we #define and not typedef wxLongLong_t because we want to be able to
31// use 'unsigned wxLongLong_t' as well
32#if defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
33 #define wxLongLong_t long
34 #define wxLongLongIsLong
35#elif defined(__VISUALC__)
36 #define wxLongLong_t __int64
37#elif defined(__GNUG__)
38 #define wxLongLong_t long long
39#elif defined(__MWERKS__)
40 #if __option(longlong)
41 #define wxLongLong_t long long
42 #else
43 #error "The 64 bit integer support in CodeWarrior has been disabled."
44 #error "See the documentation on the 'longlong' pragma."
45 #endif
46#else
47 #warning "Your compiler does not appear to support 64 bit integers, "\
48 "using emulation class instead."
49 #define wxUSE_LONGLONG_WX 1
50#endif // compiler
51
52// the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
53// to disable automatic testing (useful for the test program which defines
54// both classes) but by default we only use one class
55#ifndef wxLongLong_t
56 #undef wxUSE_LONGLONG_NATIVE
57 #define wxUSE_LONGLONG_NATIVE 0
58 class WXDLLEXPORT wxLongLongWx;
59 typedef wxLongLongWx wxLongLong;
60#endif
61
62#ifndef wxUSE_LONGLONG_WX
63 #define wxUSE_LONGLONG_WX 0
64 class WXDLLEXPORT wxLongLongNative;
65 typedef wxLongLongNative wxLongLong;
66#endif
67
68// NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
69// typedef wxLongLong as it wants, we don't do it
70
71// ----------------------------------------------------------------------------
72// choose the appropriate class
73// ----------------------------------------------------------------------------
74
75// we use iostream for wxLongLong output
76#include "wx/ioswrap.h"
77
78#if wxUSE_LONGLONG_NATIVE
79
80class WXDLLEXPORT wxLongLongNative
81{
82public:
83 // ctors
84 // default ctor initializes to 0
85 wxLongLongNative() { m_ll = 0; }
86 // from long long
87 wxLongLongNative(wxLongLong_t ll) { m_ll = ll; }
88 // from 2 longs
89 wxLongLongNative(long hi, unsigned long lo)
90 {
91 // assign first to avoid precision loss!
92 m_ll = ((wxLongLong_t) hi) << 32;
93 m_ll |= (wxLongLong_t) lo;
94 }
95
96 // default copy ctor is ok in both cases
97
98 // no dtor
99
100 // assignment operators
101 // from native 64 bit integer
102 wxLongLongNative& operator=(wxLongLong_t ll)
103 { m_ll = ll; return *this; }
104
105 // assignment operators from wxLongLongNative is ok
106
107 // accessors
108 // get high part
109 long GetHi() const
110 { return (long)((m_ll & 0xFFFFFFFF00000000l) >> 32); }
111 // get low part
112 unsigned long GetLo() const
113 { return (unsigned long) (m_ll & 0x00000000FFFFFFFFl); }
114
115 // convert to native long long
116 wxLongLong_t GetValue() const { return m_ll; }
117
118 operator wxLongLong_t() const { return m_ll; }
119
120 // operations
121 // addition
122 wxLongLongNative operator+(const wxLongLongNative& ll) const
123 { return wxLongLongNative(m_ll + ll.m_ll); }
124 wxLongLongNative& operator+=(const wxLongLongNative& ll)
125 { m_ll += ll.m_ll; return *this; }
126
127 wxLongLongNative operator+(const wxLongLong_t ll) const
128 { return wxLongLongNative(m_ll + ll); }
129 wxLongLongNative& operator+=(const wxLongLong_t ll)
130 { m_ll += ll; return *this; }
131
132 // pre increment
133 wxLongLongNative& operator++()
134 { m_ll++; return *this; }
135
136 // post increment
137 wxLongLongNative& operator++(int)
138 { m_ll++; return *this; }
139
140 // negation operator
141 wxLongLongNative operator-() const
142 { return wxLongLongNative(-m_ll); }
143
144 // subtraction
145 wxLongLongNative operator-(const wxLongLongNative& ll) const
146 { return wxLongLongNative(m_ll - ll.m_ll); }
147 wxLongLongNative& operator-=(const wxLongLongNative& ll)
148 { m_ll -= ll.m_ll; return *this; }
149
150 wxLongLongNative operator-(const wxLongLong_t ll) const
151 { return wxLongLongNative(m_ll - ll); }
152 wxLongLongNative& operator-=(const wxLongLong_t ll)
153 { m_ll -= ll; return *this; }
154
155 // pre decrement
156 wxLongLongNative& operator--()
157 { m_ll--; return *this; }
158
159 // post decrement
160 wxLongLongNative& operator--(int)
161 { m_ll--; return *this; }
162
163 // shifts
164 // left shift
165 wxLongLongNative operator<<(int shift) const
166 { return wxLongLongNative(m_ll << shift);; }
167 wxLongLongNative& operator<<=(int shift)
168 { m_ll <<= shift; return *this; }
169
170 // right shift
171 wxLongLongNative operator>>(int shift) const
172 { return wxLongLongNative(m_ll >> shift);; }
173 wxLongLongNative& operator>>=(int shift)
174 { m_ll >>= shift; return *this; }
175
176 // bitwise operators
177 wxLongLongNative operator&(const wxLongLongNative& ll) const
178 { return wxLongLongNative(m_ll & ll.m_ll); }
179 wxLongLongNative& operator&=(const wxLongLongNative& ll)
180 { m_ll &= ll.m_ll; return *this; }
181
182 wxLongLongNative operator|(const wxLongLongNative& ll) const
183 { return wxLongLongNative(m_ll | ll.m_ll); }
184 wxLongLongNative& operator|=(const wxLongLongNative& ll)
185 { m_ll |= ll.m_ll; return *this; }
186
187 wxLongLongNative operator^(const wxLongLongNative& ll) const
188 { return wxLongLongNative(m_ll ^ ll.m_ll); }
189 wxLongLongNative& operator^=(const wxLongLongNative& ll)
190 { m_ll ^= ll.m_ll; return *this; }
191
192 // multiplication/division TODO
193 wxLongLongNative operator*(const wxLongLongNative& ll) const
194 { return wxLongLongNative(m_ll * ll.m_ll); }
195 wxLongLongNative& operator*=(const wxLongLongNative& ll)
196 { m_ll *= ll.m_ll; return *this; }
197
198 wxLongLongNative operator/(const wxLongLongNative& ll) const
199 { return wxLongLongNative(m_ll / ll.m_ll); }
200 wxLongLongNative& operator/=(const wxLongLongNative& ll)
201 { m_ll /= ll.m_ll; return *this; }
202
203 wxLongLongNative operator%(const wxLongLongNative& ll) const
204 { return wxLongLongNative(m_ll % ll.m_ll); }
205
206 // comparison
207 bool operator==(const wxLongLongNative& ll) const
208 { return m_ll == ll.m_ll; }
209 bool operator!=(const wxLongLongNative& ll) const
210 { return m_ll != ll.m_ll; }
211 bool operator<(const wxLongLongNative& ll) const
212 { return m_ll < ll.m_ll; }
213 bool operator>(const wxLongLongNative& ll) const
214 { return m_ll > ll.m_ll; }
215 bool operator<=(const wxLongLongNative& ll) const
216 { return m_ll <= ll.m_ll; }
217 bool operator>=(const wxLongLongNative& ll) const
218 { return m_ll >= ll.m_ll; }
219
220 // miscellaneous
221 // conversion to byte array: returns a pointer to static buffer!
222 void *asArray() const;
223
224 // input/output
225 friend ostream& operator<<(ostream&, const wxLongLongNative&);
226
227private:
228 wxLongLong_t m_ll;
229};
230
231#endif // wxUSE_LONGLONG_NATIVE
232
233#if wxUSE_LONGLONG_WX
234
235class WXDLLEXPORT wxLongLongWx
236{
237public:
238 // ctors
239 // default ctor initializes to 0
240 wxLongLongWx() { m_lo = m_hi = 0; }
241 // from long
242 wxLongLongWx(long l)
243 { m_lo = l; m_hi = (l < 0 ? -1l : 0l); }
244 // from 2 longs
245 wxLongLongWx(long hi, unsigned long lo)
246 { m_hi = hi; m_lo = lo; }
247
248 // default copy ctor is ok in both cases
249
250 // no dtor
251
252 // assignment operators
253 // from long
254 wxLongLongWx& operator=(long l)
255 { m_lo = l; m_hi = (l < 0 ? -1l : 0l); return *this; }
256 // can't have assignment operator from 2 longs
257
258 // accessors
259 // get high part
260 long GetHi() const { return m_hi; }
261 // get low part
262 unsigned long GetLo() const { return m_lo; }
263
264 // operations
265 // addition
266 wxLongLongWx operator+(const wxLongLongWx& ll) const;
267 wxLongLongWx& operator+=(const wxLongLongWx& ll);
268 wxLongLongWx operator+(long l) const;
269 wxLongLongWx& operator+=(long l);
270
271 // pre increment operator
272 wxLongLongWx& operator++();
273
274 // post increment operator
275 wxLongLongWx& operator++(int);
276
277 // negation operator
278 wxLongLongWx operator-() const;
279
280 // subraction
281 wxLongLongWx operator-(const wxLongLongWx& ll) const;
282 wxLongLongWx& operator-=(const wxLongLongWx& ll);
283
284 // pre decrement operator
285 wxLongLongWx& operator--();
286
287 // post decrement operator
288 wxLongLongWx& operator--(int);
289
290 // shifts
291 // left shift
292 wxLongLongWx operator<<(int shift) const;
293 wxLongLongWx& operator<<=(int shift);
294
295 // right shift
296 wxLongLongWx operator>>(int shift) const;
297 wxLongLongWx& operator>>=(int shift);
298
299 // bitwise operators
300 wxLongLongWx operator&(const wxLongLongWx& ll) const;
301 wxLongLongWx& operator&=(const wxLongLongWx& ll);
302 wxLongLongWx operator|(const wxLongLongWx& ll) const;
303 wxLongLongWx& operator|=(const wxLongLongWx& ll);
304 wxLongLongWx operator^(const wxLongLongWx& ll) const;
305 wxLongLongWx& operator^=(const wxLongLongWx& ll);
306 wxLongLongWx operator~() const;
307
308 // comparison
309 bool operator==(const wxLongLongWx& ll) const;
310 bool operator!=(const wxLongLongWx& ll) const;
311 bool operator<(const wxLongLongWx& ll) const;
312 bool operator>(const wxLongLongWx& ll) const;
313 bool operator<=(const wxLongLongWx& ll) const;
314 bool operator>=(const wxLongLongWx& ll) const;
315
316 // multiplication
317 wxLongLongWx operator*(const wxLongLongWx& ll) const;
318 wxLongLongWx& operator*=(const wxLongLongWx& ll);
319 void *asArray(void) const;
320
321 // division
322 void Divide(const wxLongLongWx& divisor,
323 wxLongLongWx& quotient,
324 wxLongLongWx& remainder) const;
325
326 // input/output
327 friend ostream& operator<<(ostream&, const wxLongLongWx&);
328
329private:
330 // long is at least 32 bits, so represent our 64bit number as 2 longs
331
332 long m_hi; // signed bit is in the high part
333 unsigned long m_lo;
334};
335
336#endif // wxUSE_LONGLONG_WX
337
338#endif // _WX_LONGLONG_H