]> git.saurik.com Git - wxWidgets.git/blame - include/wx/longlong.h
test for timegm() added
[wxWidgets.git] / include / wx / longlong.h
CommitLineData
8b81872f
VZ
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
2f02cb89 27// we will need to define this
8b81872f
VZ
28#undef wxLongLongIsLong
29
30// NB: we #define and not typedef wxLongLong_t because we want to be able to
2f02cb89
VZ
31// use 'unsigned wxLongLong_t' as well and because we use "#ifdef
32// wxLongLong_t" below
8b81872f
VZ
33#if defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
34 #define wxLongLong_t long
35 #define wxLongLongIsLong
36#elif defined(__VISUALC__)
37 #define wxLongLong_t __int64
38#elif defined(__GNUG__)
39 #define wxLongLong_t long long
40#elif defined(__MWERKS__)
41 #if __option(longlong)
42 #define wxLongLong_t long long
43 #else
44 #error "The 64 bit integer support in CodeWarrior has been disabled."
45 #error "See the documentation on the 'longlong' pragma."
46 #endif
47#else
48 #warning "Your compiler does not appear to support 64 bit integers, "\
49 "using emulation class instead."
50 #define wxUSE_LONGLONG_WX 1
51#endif // compiler
52
53// the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
54// to disable automatic testing (useful for the test program which defines
55// both classes) but by default we only use one class
56#ifndef wxLongLong_t
57 #undef wxUSE_LONGLONG_NATIVE
58 #define wxUSE_LONGLONG_NATIVE 0
59 class WXDLLEXPORT wxLongLongWx;
60 typedef wxLongLongWx wxLongLong;
b76b015e
VZ
61#else
62 // if nothing is defined, use native implementation by default, of course
63 #ifndef wxUSE_LONGLONG_NATIVE
64 #define wxUSE_LONGLONG_NATIVE 1
65 #endif
8b81872f
VZ
66#endif
67
68#ifndef wxUSE_LONGLONG_WX
69 #define wxUSE_LONGLONG_WX 0
70 class WXDLLEXPORT wxLongLongNative;
71 typedef wxLongLongNative wxLongLong;
72#endif
73
74// NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
75// typedef wxLongLong as it wants, we don't do it
76
77// ----------------------------------------------------------------------------
78// choose the appropriate class
79// ----------------------------------------------------------------------------
80
81// we use iostream for wxLongLong output
82#include "wx/ioswrap.h"
83
84#if wxUSE_LONGLONG_NATIVE
85
86class WXDLLEXPORT wxLongLongNative
87{
88public:
89 // ctors
90 // default ctor initializes to 0
91 wxLongLongNative() { m_ll = 0; }
92 // from long long
93 wxLongLongNative(wxLongLong_t ll) { m_ll = ll; }
94 // from 2 longs
95 wxLongLongNative(long hi, unsigned long lo)
96 {
97 // assign first to avoid precision loss!
98 m_ll = ((wxLongLong_t) hi) << 32;
99 m_ll |= (wxLongLong_t) lo;
100 }
101
2f02cb89 102 // default copy ctor is ok
8b81872f
VZ
103
104 // no dtor
105
106 // assignment operators
107 // from native 64 bit integer
108 wxLongLongNative& operator=(wxLongLong_t ll)
109 { m_ll = ll; return *this; }
110
111 // assignment operators from wxLongLongNative is ok
112
113 // accessors
114 // get high part
115 long GetHi() const
2f02cb89 116 { return (long)(m_ll >> 32); }
8b81872f
VZ
117 // get low part
118 unsigned long GetLo() const
2f02cb89 119 { return (unsigned long)m_ll; }
8b81872f 120
b76b015e
VZ
121 // get absolute value
122 wxLongLongNative& Abs() { if ( m_ll < 0 ) m_ll = -m_ll; return *this; }
123
8b81872f
VZ
124 // convert to native long long
125 wxLongLong_t GetValue() const { return m_ll; }
126
2f02cb89
VZ
127 // don't provide implicit conversion to wxLongLong_t or we will have an
128 // ambiguity for all arithmetic operations
b76b015e 129 //operator wxLongLong_t() const { return m_ll; }
8b81872f
VZ
130
131 // operations
132 // addition
133 wxLongLongNative operator+(const wxLongLongNative& ll) const
134 { return wxLongLongNative(m_ll + ll.m_ll); }
135 wxLongLongNative& operator+=(const wxLongLongNative& ll)
136 { m_ll += ll.m_ll; return *this; }
137
138 wxLongLongNative operator+(const wxLongLong_t ll) const
139 { return wxLongLongNative(m_ll + ll); }
140 wxLongLongNative& operator+=(const wxLongLong_t ll)
141 { m_ll += ll; return *this; }
142
143 // pre increment
144 wxLongLongNative& operator++()
145 { m_ll++; return *this; }
146
147 // post increment
148 wxLongLongNative& operator++(int)
149 { m_ll++; return *this; }
150
151 // negation operator
152 wxLongLongNative operator-() const
153 { return wxLongLongNative(-m_ll); }
154
155 // subtraction
156 wxLongLongNative operator-(const wxLongLongNative& ll) const
157 { return wxLongLongNative(m_ll - ll.m_ll); }
158 wxLongLongNative& operator-=(const wxLongLongNative& ll)
159 { m_ll -= ll.m_ll; return *this; }
160
161 wxLongLongNative operator-(const wxLongLong_t ll) const
162 { return wxLongLongNative(m_ll - ll); }
163 wxLongLongNative& operator-=(const wxLongLong_t ll)
164 { m_ll -= ll; return *this; }
165
166 // pre decrement
167 wxLongLongNative& operator--()
168 { m_ll--; return *this; }
169
170 // post decrement
171 wxLongLongNative& operator--(int)
172 { m_ll--; return *this; }
173
174 // shifts
175 // left shift
176 wxLongLongNative operator<<(int shift) const
177 { return wxLongLongNative(m_ll << shift);; }
178 wxLongLongNative& operator<<=(int shift)
179 { m_ll <<= shift; return *this; }
180
181 // right shift
182 wxLongLongNative operator>>(int shift) const
183 { return wxLongLongNative(m_ll >> shift);; }
184 wxLongLongNative& operator>>=(int shift)
185 { m_ll >>= shift; return *this; }
186
187 // bitwise operators
188 wxLongLongNative operator&(const wxLongLongNative& ll) const
189 { return wxLongLongNative(m_ll & ll.m_ll); }
190 wxLongLongNative& operator&=(const wxLongLongNative& ll)
191 { m_ll &= ll.m_ll; return *this; }
192
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
b76b015e 203 // multiplication/division
8b81872f
VZ
204 wxLongLongNative operator*(const wxLongLongNative& ll) const
205 { return wxLongLongNative(m_ll * ll.m_ll); }
2f02cb89
VZ
206 wxLongLongNative operator*(long l) const
207 { return wxLongLongNative(m_ll * l); }
8b81872f
VZ
208 wxLongLongNative& operator*=(const wxLongLongNative& ll)
209 { m_ll *= ll.m_ll; return *this; }
2f02cb89
VZ
210 wxLongLongNative& operator*=(long l)
211 { m_ll *= l; return *this; }
8b81872f
VZ
212
213 wxLongLongNative operator/(const wxLongLongNative& ll) const
214 { return wxLongLongNative(m_ll / ll.m_ll); }
b76b015e
VZ
215 wxLongLongNative operator/(long l) const
216 { return wxLongLongNative(m_ll / l); }
8b81872f
VZ
217 wxLongLongNative& operator/=(const wxLongLongNative& ll)
218 { m_ll /= ll.m_ll; return *this; }
2f02cb89
VZ
219 wxLongLongNative& operator/=(long l)
220 { m_ll /= l; return *this; }
8b81872f
VZ
221
222 wxLongLongNative operator%(const wxLongLongNative& ll) const
223 { return wxLongLongNative(m_ll % ll.m_ll); }
b76b015e
VZ
224 wxLongLongNative operator%(long l) const
225 { return wxLongLongNative(m_ll % l); }
8b81872f
VZ
226
227 // comparison
228 bool operator==(const wxLongLongNative& ll) const
229 { return m_ll == ll.m_ll; }
b76b015e
VZ
230 bool operator==(long l) const
231 { return m_ll == l; }
8b81872f
VZ
232 bool operator!=(const wxLongLongNative& ll) const
233 { return m_ll != ll.m_ll; }
b76b015e
VZ
234 bool operator!=(long l) const
235 { return m_ll != l; }
8b81872f
VZ
236 bool operator<(const wxLongLongNative& ll) const
237 { return m_ll < ll.m_ll; }
b76b015e
VZ
238 bool operator<(long l) const
239 { return m_ll < l; }
8b81872f
VZ
240 bool operator>(const wxLongLongNative& ll) const
241 { return m_ll > ll.m_ll; }
b76b015e
VZ
242 bool operator>(long l) const
243 { return m_ll > l; }
8b81872f
VZ
244 bool operator<=(const wxLongLongNative& ll) const
245 { return m_ll <= ll.m_ll; }
b76b015e
VZ
246 bool operator<=(long l) const
247 { return m_ll <= l; }
8b81872f
VZ
248 bool operator>=(const wxLongLongNative& ll) const
249 { return m_ll >= ll.m_ll; }
b76b015e
VZ
250 bool operator>=(long l) const
251 { return m_ll >= l; }
8b81872f
VZ
252
253 // miscellaneous
254 // conversion to byte array: returns a pointer to static buffer!
255 void *asArray() const;
256
fcc3d7cb 257#if wxUSE_STD_IOSTREAM
8b81872f 258 // input/output
162b0c3b 259 friend ostream& operator<<(ostream&, const wxLongLongNative&);
fcc3d7cb 260#endif
8b81872f
VZ
261
262private:
263 wxLongLong_t m_ll;
264};
265
266#endif // wxUSE_LONGLONG_NATIVE
267
268#if wxUSE_LONGLONG_WX
269
270class WXDLLEXPORT wxLongLongWx
271{
272public:
273 // ctors
274 // default ctor initializes to 0
275 wxLongLongWx() { m_lo = m_hi = 0; }
276 // from long
277 wxLongLongWx(long l)
278 { m_lo = l; m_hi = (l < 0 ? -1l : 0l); }
279 // from 2 longs
280 wxLongLongWx(long hi, unsigned long lo)
281 { m_hi = hi; m_lo = lo; }
282
283 // default copy ctor is ok in both cases
284
285 // no dtor
286
287 // assignment operators
288 // from long
289 wxLongLongWx& operator=(long l)
290 { m_lo = l; m_hi = (l < 0 ? -1l : 0l); return *this; }
291 // can't have assignment operator from 2 longs
292
293 // accessors
294 // get high part
295 long GetHi() const { return m_hi; }
296 // get low part
297 unsigned long GetLo() const { return m_lo; }
298
299 // operations
300 // addition
301 wxLongLongWx operator+(const wxLongLongWx& ll) const;
302 wxLongLongWx& operator+=(const wxLongLongWx& ll);
303 wxLongLongWx operator+(long l) const;
304 wxLongLongWx& operator+=(long l);
305
306 // pre increment operator
307 wxLongLongWx& operator++();
308
309 // post increment operator
310 wxLongLongWx& operator++(int);
311
312 // negation operator
313 wxLongLongWx operator-() const;
314
315 // subraction
316 wxLongLongWx operator-(const wxLongLongWx& ll) const;
317 wxLongLongWx& operator-=(const wxLongLongWx& ll);
318
319 // pre decrement operator
320 wxLongLongWx& operator--();
321
322 // post decrement operator
323 wxLongLongWx& operator--(int);
324
325 // shifts
326 // left shift
327 wxLongLongWx operator<<(int shift) const;
328 wxLongLongWx& operator<<=(int shift);
329
330 // right shift
331 wxLongLongWx operator>>(int shift) const;
332 wxLongLongWx& operator>>=(int shift);
333
334 // bitwise operators
335 wxLongLongWx operator&(const wxLongLongWx& ll) const;
336 wxLongLongWx& operator&=(const wxLongLongWx& ll);
337 wxLongLongWx operator|(const wxLongLongWx& ll) const;
338 wxLongLongWx& operator|=(const wxLongLongWx& ll);
339 wxLongLongWx operator^(const wxLongLongWx& ll) const;
340 wxLongLongWx& operator^=(const wxLongLongWx& ll);
341 wxLongLongWx operator~() const;
342
343 // comparison
344 bool operator==(const wxLongLongWx& ll) const;
345 bool operator!=(const wxLongLongWx& ll) const;
346 bool operator<(const wxLongLongWx& ll) const;
347 bool operator>(const wxLongLongWx& ll) const;
348 bool operator<=(const wxLongLongWx& ll) const;
349 bool operator>=(const wxLongLongWx& ll) const;
350
351 // multiplication
352 wxLongLongWx operator*(const wxLongLongWx& ll) const;
353 wxLongLongWx& operator*=(const wxLongLongWx& ll);
354 void *asArray(void) const;
355
356 // division
357 void Divide(const wxLongLongWx& divisor,
358 wxLongLongWx& quotient,
359 wxLongLongWx& remainder) const;
360
fcc3d7cb 361#if wxUSE_STD_IOSTREAM
8b81872f 362 // input/output
162b0c3b 363 friend ostream& operator<<(ostream&, const wxLongLongWx&);
fcc3d7cb 364#endif // wxUSE_STD_IOSTREAM
8b81872f
VZ
365
366private:
367 // long is at least 32 bits, so represent our 64bit number as 2 longs
368
369 long m_hi; // signed bit is in the high part
370 unsigned long m_lo;
371};
372
373#endif // wxUSE_LONGLONG_WX
374
375#endif // _WX_LONGLONG_H