|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 // uint64.h |
|
18 // minimal double precision unsigned int arithmetics for numeric_facets support. |
|
19 // Written by Tsutomu Yoshida, Minokamo, Japan. 03/25/2000 |
|
20 #ifndef _UINT64_H |
|
21 #define _UINT64_H |
|
22 |
|
23 template <class _Tp> |
|
24 class _compound_int : public _Tp { |
|
25 public: |
|
26 typedef _compound_int<_Tp> _Self; |
|
27 |
|
28 // Constructors, destructor, assignment operator. |
|
29 _compound_int(); // platform specific |
|
30 _compound_int(unsigned long); // platform specific |
|
31 _compound_int(unsigned long hi, unsigned long lo); // platform specific |
|
32 _compound_int(const _Tp& rhs) : _Tp(rhs) {} |
|
33 |
|
34 // Arithmetic op= operations involving two _compound_int. |
|
35 _Self& operator+= (const _Self&); // platform specific |
|
36 _Self& operator-= (const _Self&); // platform specific |
|
37 _Self& operator*= (const _Self&); // platform specific |
|
38 _Self& operator/= (const _Self&); // platform specific |
|
39 _Self& operator%= (const _Self&); // platform specific |
|
40 _Self& operator&= (const _Self&); // platform specific |
|
41 _Self& operator|= (const _Self&); // platform specific |
|
42 _Self& operator^= (const _Self&); // platform specific |
|
43 |
|
44 // Arithmetic op= operations involving built-in integer. |
|
45 _Self& operator<<= (unsigned int); // platform specific |
|
46 _Self& operator>>= (unsigned int); // platform specific |
|
47 |
|
48 _Self& operator= (unsigned long rhs) { return *this = _Self(rhs); } |
|
49 _Self& operator+= (unsigned long rhs) { return *this += _Self(rhs); } |
|
50 _Self& operator-= (unsigned long rhs) { return *this -= _Self(rhs); } |
|
51 _Self& operator*= (unsigned long rhs) { return *this *= _Self(rhs); } |
|
52 _Self& operator/= (unsigned long rhs) { return *this /= _Self(rhs); } |
|
53 _Self& operator%= (unsigned long rhs) { return *this %= _Self(rhs); } |
|
54 _Self& operator&= (unsigned long rhs) { return *this &= _Self(rhs); } |
|
55 _Self& operator|= (unsigned long rhs) { return *this |= _Self(rhs); } |
|
56 _Self& operator^= (unsigned long rhs) { return *this ^= _Self(rhs); } |
|
57 |
|
58 // Increment and decrement |
|
59 _Self& operator++() { return (*this) += 1; } |
|
60 _Self& operator--() { return (*this) -= 1; } |
|
61 _Self operator++(int) { _Self temp(*this); ++(*this); return temp; } |
|
62 _Self operator--(int) { _Self temp(*this); --(*this); return temp; } |
|
63 }; |
|
64 |
|
65 // Comparison operators. |
|
66 template <class _Tp> bool operator==(const _compound_int<_Tp>&, const _compound_int<_Tp>&); // platform specific |
|
67 template <class _Tp> bool operator<(const _compound_int<_Tp>&, const _compound_int<_Tp>&); // platform specific |
|
68 |
|
69 template <class _Tp> inline bool operator==(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs == _compound_int<_Tp>(rhs); } |
|
70 template <class _Tp> inline bool operator==(unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs == lhs; } |
|
71 |
|
72 template <class _Tp> inline bool operator< (const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs < _compound_int<_Tp>(rhs); } |
|
73 template <class _Tp> inline bool operator< (unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) < rhs; } |
|
74 |
|
75 template <class _Tp> inline bool operator!=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs == rhs); } |
|
76 template <class _Tp> inline bool operator!=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs == rhs); } |
|
77 |
|
78 template <class _Tp> inline bool operator> (const _compound_int<_Tp>& lhs, unsigned long rhs) { return rhs < lhs; } |
|
79 template <class _Tp> inline bool operator> (unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs < lhs; } |
|
80 |
|
81 template <class _Tp> inline bool operator<=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs > rhs); } |
|
82 template <class _Tp> inline bool operator<=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs > rhs); } |
|
83 |
|
84 template <class _Tp> inline bool operator>=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs < rhs); } |
|
85 template <class _Tp> inline bool operator>=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs < rhs); } |
|
86 |
|
87 // Unary non-member arithmetic operators. |
|
88 template <class _Tp> unsigned long to_ulong(const _compound_int<_Tp>&); // platform specific |
|
89 template <class _Tp> _compound_int<_Tp> operator~(const _compound_int<_Tp>&); // platform specific |
|
90 |
|
91 template <class _Tp> inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& val) {return val;} |
|
92 template <class _Tp> inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& val) {return 0 - val;} |
|
93 template <class _Tp> inline bool operator!(const _compound_int<_Tp>& val) {return val==0;} |
|
94 |
|
95 // Non-member arithmetic operations involving two _compound_int arguments |
|
96 template <class _Tp> |
|
97 inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) |
|
98 { _compound_int<_Tp> temp(lhs); return temp += rhs; } |
|
99 template <class _Tp> |
|
100 inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) |
|
101 { _compound_int<_Tp> temp(lhs); return temp -= rhs; } |
|
102 template <class _Tp> |
|
103 inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) |
|
104 { _compound_int<_Tp> temp(lhs); return temp *= rhs; } |
|
105 template <class _Tp> |
|
106 inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) |
|
107 { _compound_int<_Tp> temp(lhs); return temp /= rhs; } |
|
108 template <class _Tp> |
|
109 inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) |
|
110 { _compound_int<_Tp> temp(lhs); return temp %= rhs; } |
|
111 template <class _Tp> |
|
112 inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) |
|
113 { _compound_int<_Tp> temp(lhs); return temp &= rhs; } |
|
114 template <class _Tp> |
|
115 inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) |
|
116 { _compound_int<_Tp> temp(lhs); return temp |= rhs; } |
|
117 template <class _Tp> |
|
118 inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) |
|
119 { _compound_int<_Tp> temp(lhs); return temp ^= rhs; } |
|
120 |
|
121 // Non-member arithmetic operations involving one built-in integer argument. |
|
122 template <class _Tp> |
|
123 inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs + _compound_int<_Tp>(rhs); } |
|
124 template <class _Tp> |
|
125 inline _compound_int<_Tp> operator+(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) + rhs; } |
|
126 |
|
127 template <class _Tp> |
|
128 inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs - _compound_int<_Tp>(rhs); } |
|
129 template <class _Tp> |
|
130 inline _compound_int<_Tp> operator-(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) - rhs; } |
|
131 |
|
132 template <class _Tp> |
|
133 inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs * _compound_int<_Tp>(rhs); } |
|
134 template <class _Tp> |
|
135 inline _compound_int<_Tp> operator*(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) * rhs; } |
|
136 |
|
137 template <class _Tp> |
|
138 inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs / _compound_int<_Tp>(rhs); } |
|
139 template <class _Tp> |
|
140 inline _compound_int<_Tp> operator/(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) / rhs; } |
|
141 |
|
142 template <class _Tp> |
|
143 inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs % _compound_int<_Tp>(rhs); } |
|
144 template <class _Tp> |
|
145 inline _compound_int<_Tp> operator%(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) % rhs; } |
|
146 |
|
147 template <class _Tp> |
|
148 inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs & _compound_int<_Tp>(rhs); } |
|
149 template <class _Tp> |
|
150 inline _compound_int<_Tp> operator&(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) & rhs; } |
|
151 |
|
152 template <class _Tp> |
|
153 inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs | _compound_int<_Tp>(rhs); } |
|
154 template <class _Tp> |
|
155 inline _compound_int<_Tp> operator|(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) | rhs; } |
|
156 |
|
157 template <class _Tp> |
|
158 inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs ^ _compound_int<_Tp>(rhs); } |
|
159 template <class _Tp> |
|
160 inline _compound_int<_Tp> operator^(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) ^ rhs; } |
|
161 |
|
162 template <class _Tp> |
|
163 inline _compound_int<_Tp> operator<<(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp <<= rhs; } |
|
164 template <class _Tp> |
|
165 inline _compound_int<_Tp> operator>>(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp >>= rhs; } |
|
166 |
|
167 // platform specific specializations |
|
168 #if defined (__MRC__) || defined (__SC__) |
|
169 |
|
170 _STLP_END_NAMESPACE |
|
171 # include <Math64.h> |
|
172 # include <utility> |
|
173 # undef modff //*TY 04/06/2000 - defined in <math.h> which conflicts with <fp.h> definition |
|
174 # include <fp.h> |
|
175 |
|
176 _STLP_BEGIN_NAMESPACE |
|
177 |
|
178 # if TYPE_LONGLONG |
|
179 typedef UInt64 uint64; |
|
180 # define ULL(x) (U64SetU(x)) |
|
181 |
|
182 # else |
|
183 // Apple's mpw sc compiler for 68k macintosh does not support native 64bit integer type. |
|
184 // Instead, it comes with external support library and struct data type representing 64bit int: |
|
185 // |
|
186 // struct UnsignedWide { |
|
187 // UInt32 hi; |
|
188 // UInt32 lo; |
|
189 // }; |
|
190 |
|
191 typedef _compound_int<UnsignedWide> uint64; |
|
192 # define ULL(x) uint64(x) |
|
193 # define ULL2(hi,lo) {hi,lo} |
|
194 |
|
195 // Constructors, destructor, assignment operator. |
|
196 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int() { hi = 0; lo = 0; } |
|
197 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long val) { hi = 0; lo = val; } |
|
198 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long h, unsigned long l) { hi = h; lo = l; } |
|
199 |
|
200 // Arithmetic op= operations involving two _compound_int. |
|
201 _STLP_TEMPLATE_NULL |
|
202 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator+= (const _compound_int<UnsignedWide>& rhs) |
|
203 { *this = U64Add( *this, rhs ); return *this; } |
|
204 _STLP_TEMPLATE_NULL |
|
205 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator-= (const _compound_int<UnsignedWide>& rhs) |
|
206 { *this = U64Subtract( *this, rhs ); return *this; } |
|
207 _STLP_TEMPLATE_NULL |
|
208 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator*= (const _compound_int<UnsignedWide>& rhs) |
|
209 { *this = U64Multiply( *this, rhs ); return *this; } |
|
210 _STLP_TEMPLATE_NULL |
|
211 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator/= (const _compound_int<UnsignedWide>& rhs) |
|
212 { *this = U64Divide( *this, rhs, NULL ); return *this; } |
|
213 _STLP_TEMPLATE_NULL |
|
214 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator%= (const _compound_int<UnsignedWide>& rhs) |
|
215 { U64Divide( *this, rhs, this ); return *this; } |
|
216 _STLP_TEMPLATE_NULL |
|
217 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator&= (const _compound_int<UnsignedWide>& rhs) |
|
218 { *this = U64BitwiseAnd( *this, rhs ); return *this; } |
|
219 _STLP_TEMPLATE_NULL |
|
220 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator|= (const _compound_int<UnsignedWide>& rhs) |
|
221 { *this = U64BitwiseOr( *this, rhs ); return *this; } |
|
222 _STLP_TEMPLATE_NULL |
|
223 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator^= (const _compound_int<UnsignedWide>& rhs) |
|
224 { *this = U64BitwiseEor( *this, rhs ); return *this; } |
|
225 |
|
226 // Arithmetic op= operations involving built-in integer. |
|
227 _STLP_TEMPLATE_NULL |
|
228 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator<<= (unsigned int rhs) |
|
229 { *this = U64ShiftLeft( *this, rhs ); return *this; } |
|
230 _STLP_TEMPLATE_NULL |
|
231 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator>>= (unsigned int rhs) |
|
232 { *this = U64ShiftRight( *this, rhs ); return *this; } |
|
233 |
|
234 // Comparison operators. |
|
235 _STLP_TEMPLATE_NULL |
|
236 inline bool operator==(const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs) |
|
237 { return (lhs.hi == rhs.hi) && (lhs.lo == rhs.lo); } |
|
238 _STLP_TEMPLATE_NULL |
|
239 inline bool operator< (const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs) |
|
240 { return U64Compare( lhs, rhs ) < 0; } |
|
241 _STLP_TEMPLATE_NULL |
|
242 inline bool operator==(const _compound_int<UnsignedWide>& lhs, unsigned long rhs) |
|
243 { return (lhs.hi == 0) && (lhs.lo == rhs); } |
|
244 |
|
245 // Unary non-member arithmetic operators. |
|
246 _STLP_TEMPLATE_NULL |
|
247 inline unsigned long to_ulong(const _compound_int<UnsignedWide>& val) { return val.lo; } |
|
248 _STLP_TEMPLATE_NULL |
|
249 inline _compound_int<UnsignedWide> operator~(const _compound_int<UnsignedWide>& val) { return U64BitwiseNot( val ); } |
|
250 _STLP_TEMPLATE_NULL |
|
251 inline bool operator!(const _compound_int<UnsignedWide>& val) { return !((val.hi == 0) && (val.lo == 0)); } |
|
252 |
|
253 # endif // TYPE_LONGLONG |
|
254 #endif // __MRC__ |
|
255 |
|
256 #endif // _UINT64_H |