Merge lp:~zorba-coders/zorba/bug-1178322 into lp:zorba
- bug-1178322
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Matthias Brantner |
Approved revision: | 11468 |
Merged at revision: | 11464 |
Proposed branch: | lp:~zorba-coders/zorba/bug-1178322 |
Merge into: | lp:zorba |
Diff against target: |
809 lines (+165/-149) 7 files modified
src/runtime/core/path_iterators.cpp (+1/-1) src/types/casting.cpp (+28/-18) src/zorbatypes/decimal.cpp (+12/-3) src/zorbatypes/float.cpp (+23/-18) src/zorbatypes/float.h (+1/-2) src/zorbatypes/integer.cpp (+36/-38) src/zorbatypes/integer.h (+64/-69) |
To merge this branch: | bzr merge lp:~zorba-coders/zorba/bug-1178322 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matthias Brantner | Approve | ||
Paul J. Lucas | Approve | ||
Review via email: mp+164494@code.launchpad.net |
Commit message
Undid some of my previous changes regarding which std exception is thrown by IntegerImpl. Now, invalid_argument is used when the argument is not a valid integer; range_error is used when the value is a valid integer, but out of range for the type (or a valid floating point constant like INF). Generally, invalid_argument will map to FOCA0002 and range_error will map to FORG0001.
This fixes several "wrongError" FOTS tests.
Description of the change
Undid some of my previous changes regarding which std exception is thrown by IntegerImpl. Now, invalid_argument is used when the argument is not a valid integer; range_error is used when the value is a valid integer, but out of range for the type (or a valid floating point constant like INF). Generally, invalid_argument will map to FOCA0002 and range_error will map to FORG0001.
This fixes several "wrongError" FOTS tests.
Paul J. Lucas (paul-lucas) : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~zorba-coders/zorba/bug-1178322 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-1178322-2013-05-
final status was:
14 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~zorba-coders/zorba/bug-1178322 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-1178322-2013-05-
final status was:
3 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~zorba-coders/zorba/bug-1178322 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-1178322-2013-05-
final status was:
2 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job bug-1178322-2013-05-
All tests succeeded!
Zorba Build Bot (zorba-buildbot) wrote : | # |
Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1, Needs Information < 1, Resubmit < 1. Got: 1 Approve.
Matthias Brantner (matthias-brantner) : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job bug-1178322-2013-05-
All tests succeeded!
Preview Diff
1 | === modified file 'src/runtime/core/path_iterators.cpp' | |||
2 | --- src/runtime/core/path_iterators.cpp 2013-04-09 13:08:21 +0000 | |||
3 | +++ src/runtime/core/path_iterators.cpp 2013-05-20 23:18:26 +0000 | |||
4 | @@ -1145,7 +1145,7 @@ | |||
5 | 1145 | 1145 | ||
6 | 1146 | if (!state->theContextNode->isNode()) | 1146 | if (!state->theContextNode->isNode()) |
7 | 1147 | { | 1147 | { |
9 | 1148 | assert(false); | 1148 | //assert(false); |
10 | 1149 | throw XQUERY_EXCEPTION(err::XPTY0020, ERROR_LOC(loc)); | 1149 | throw XQUERY_EXCEPTION(err::XPTY0020, ERROR_LOC(loc)); |
11 | 1150 | } | 1150 | } |
12 | 1151 | } | 1151 | } |
13 | 1152 | 1152 | ||
14 | === modified file 'src/types/casting.cpp' | |||
15 | --- src/types/casting.cpp 2013-05-16 22:26:07 +0000 | |||
16 | +++ src/types/casting.cpp 2013-05-20 23:18:26 +0000 | |||
17 | @@ -385,7 +385,11 @@ | |||
18 | 385 | xs_decimal const n(strval.c_str()); | 385 | xs_decimal const n(strval.c_str()); |
19 | 386 | aFactory->createDecimal(result, n); | 386 | aFactory->createDecimal(result, n); |
20 | 387 | } | 387 | } |
22 | 388 | catch (const std::exception& ) | 388 | catch (const std::invalid_argument& ) |
23 | 389 | { | ||
24 | 390 | throwFOCA0002Exception(strval, errInfo); | ||
25 | 391 | } | ||
26 | 392 | catch (const std::range_error& ) | ||
27 | 389 | { | 393 | { |
28 | 390 | throwFORG0001Exception(strval, errInfo); | 394 | throwFORG0001Exception(strval, errInfo); |
29 | 391 | } | 395 | } |
30 | @@ -401,12 +405,12 @@ | |||
31 | 401 | } | 405 | } |
32 | 402 | catch (const std::invalid_argument& ) | 406 | catch (const std::invalid_argument& ) |
33 | 403 | { | 407 | { |
34 | 408 | throwFOCA0002Exception(strval, errInfo); | ||
35 | 409 | } | ||
36 | 410 | catch (const std::range_error& ) | ||
37 | 411 | { | ||
38 | 404 | throwFORG0001Exception(strval, errInfo); | 412 | throwFORG0001Exception(strval, errInfo); |
39 | 405 | } | 413 | } |
40 | 406 | catch (const std::range_error& ) | ||
41 | 407 | { | ||
42 | 408 | RAISE_ERROR(err::FOAR0002, errInfo.theLoc, ERROR_PARAMS(strval)); | ||
43 | 409 | } | ||
44 | 410 | } | 414 | } |
45 | 411 | 415 | ||
46 | 412 | 416 | ||
47 | @@ -419,11 +423,11 @@ | |||
48 | 419 | } | 423 | } |
49 | 420 | catch ( std::invalid_argument const& ) | 424 | catch ( std::invalid_argument const& ) |
50 | 421 | { | 425 | { |
52 | 422 | throwFORG0001Exception(strval, errInfo); | 426 | throwFOCA0002Exception(strval, errInfo); |
53 | 423 | } | 427 | } |
54 | 424 | catch ( std::range_error const& ) | 428 | catch ( std::range_error const& ) |
55 | 425 | { | 429 | { |
57 | 426 | RAISE_ERROR(err::FOAR0002, errInfo.theLoc, ERROR_PARAMS(strval)); | 430 | throwFORG0001Exception(strval, errInfo); |
58 | 427 | } | 431 | } |
59 | 428 | } | 432 | } |
60 | 429 | 433 | ||
61 | @@ -993,15 +997,16 @@ | |||
62 | 993 | 997 | ||
63 | 994 | T1_TO_T2(flt, int) | 998 | T1_TO_T2(flt, int) |
64 | 995 | { | 999 | { |
65 | 996 | xs_float const f( aItem->getFloatValue() ); | ||
66 | 997 | if ( !f.isFinite() ) | ||
67 | 998 | throwFOCA0002Exception(aItem->getStringValue(), errInfo); | ||
68 | 999 | try | 1000 | try |
69 | 1000 | { | 1001 | { |
71 | 1001 | xs_integer const n( f ); | 1002 | xs_integer const n( aItem->getFloatValue() ); |
72 | 1002 | aFactory->createInteger(result, n); | 1003 | aFactory->createInteger(result, n); |
73 | 1003 | } | 1004 | } |
75 | 1004 | catch (const std::exception&) | 1005 | catch ( std::invalid_argument const& ) |
76 | 1006 | { | ||
77 | 1007 | throwFOCA0002Exception(aItem->getStringValue(), errInfo); | ||
78 | 1008 | } | ||
79 | 1009 | catch (const std::range_error&) | ||
80 | 1005 | { | 1010 | { |
81 | 1006 | throwFOCA0003Exception(aItem->getStringValue(), errInfo); | 1011 | throwFOCA0003Exception(aItem->getStringValue(), errInfo); |
82 | 1007 | } | 1012 | } |
83 | @@ -1050,15 +1055,16 @@ | |||
84 | 1050 | 1055 | ||
85 | 1051 | T1_TO_T2(dbl, int) | 1056 | T1_TO_T2(dbl, int) |
86 | 1052 | { | 1057 | { |
87 | 1053 | xs_double const d( aItem->getDoubleValue() ); | ||
88 | 1054 | if ( !d.isFinite() ) | ||
89 | 1055 | throwFOCA0002Exception(aItem->getStringValue(), errInfo); | ||
90 | 1056 | try | 1058 | try |
91 | 1057 | { | 1059 | { |
93 | 1058 | xs_integer const n( d ); | 1060 | xs_integer const n( aItem->getDoubleValue() ); |
94 | 1059 | aFactory->createInteger(result, n); | 1061 | aFactory->createInteger(result, n); |
95 | 1060 | } | 1062 | } |
97 | 1061 | catch (const std::exception& ) | 1063 | catch ( std::invalid_argument const& ) |
98 | 1064 | { | ||
99 | 1065 | throwFOCA0002Exception(aItem->getStringValue(), errInfo); | ||
100 | 1066 | } | ||
101 | 1067 | catch (const std::range_error&) | ||
102 | 1062 | { | 1068 | { |
103 | 1063 | throwFOCA0003Exception(aItem->getStringValue(), errInfo); | 1069 | throwFOCA0003Exception(aItem->getStringValue(), errInfo); |
104 | 1064 | } | 1070 | } |
105 | @@ -1679,10 +1685,14 @@ | |||
106 | 1679 | xs_nonNegativeInteger const n(aItem->getIntegerValue()); | 1685 | xs_nonNegativeInteger const n(aItem->getIntegerValue()); |
107 | 1680 | aFactory->createNonNegativeInteger(result, n); | 1686 | aFactory->createNonNegativeInteger(result, n); |
108 | 1681 | } | 1687 | } |
110 | 1682 | catch (const std::exception& ) | 1688 | catch ( std::invalid_argument const& ) |
111 | 1683 | { | 1689 | { |
112 | 1684 | throwFOCA0002Exception(aItem->getStringValue(), errInfo); | 1690 | throwFOCA0002Exception(aItem->getStringValue(), errInfo); |
113 | 1685 | } | 1691 | } |
114 | 1692 | catch ( std::range_error const& ) | ||
115 | 1693 | { | ||
116 | 1694 | throwFORG0001Exception(aItem->getStringValue(), errInfo); | ||
117 | 1695 | } | ||
118 | 1686 | } | 1696 | } |
119 | 1687 | 1697 | ||
120 | 1688 | 1698 | ||
121 | 1689 | 1699 | ||
122 | === modified file 'src/zorbatypes/decimal.cpp' | |||
123 | --- src/zorbatypes/decimal.cpp 2013-05-15 23:22:01 +0000 | |||
124 | +++ src/zorbatypes/decimal.cpp 2013-05-20 23:18:26 +0000 | |||
125 | @@ -36,8 +36,15 @@ | |||
126 | 36 | Decimal::value_type const Decimal::round_precision_limit( 64 ); | 36 | Decimal::value_type const Decimal::round_precision_limit( 64 ); |
127 | 37 | 37 | ||
128 | 38 | void Decimal::parse( char const *s, value_type *result, int parse_options ) { | 38 | void Decimal::parse( char const *s, value_type *result, int parse_options ) { |
131 | 39 | if ( !*s ) | 39 | if ( !*s ) { |
132 | 40 | throw invalid_argument( "empty string" ); | 40 | // |
133 | 41 | // In an ideal world, this would throw invalid_argument. The XQuery spec | ||
134 | 42 | // wants FORG0001 to be raised, but invalid_argument is being mapped to | ||
135 | 43 | // FOCA0002; instead, range_error is mapped to FORG0001, so we throw | ||
136 | 44 | // range_error. | ||
137 | 45 | // | ||
138 | 46 | throw range_error( "empty string" ); | ||
139 | 47 | } | ||
140 | 41 | 48 | ||
141 | 42 | s = ascii::trim_start_space( s ); | 49 | s = ascii::trim_start_space( s ); |
142 | 43 | char const *const first_non_ws = s; | 50 | char const *const first_non_ws = s; |
143 | @@ -60,7 +67,9 @@ | |||
144 | 60 | ++s; | 67 | ++s; |
145 | 61 | } | 68 | } |
146 | 62 | if ( *s ) | 69 | if ( *s ) |
148 | 63 | throw invalid_argument( BUILD_STRING( '"', *s, "\": invalid character" ) ); | 70 | throw range_error( |
149 | 71 | BUILD_STRING( '"', *s, "\": invalid value for integer" ) | ||
150 | 72 | ); | ||
151 | 64 | 73 | ||
152 | 65 | if ( first_trailing_ws ) { | 74 | if ( first_trailing_ws ) { |
153 | 66 | ptrdiff_t const size = first_trailing_ws - first_non_ws; | 75 | ptrdiff_t const size = first_trailing_ws - first_non_ws; |
154 | 67 | 76 | ||
155 | === modified file 'src/zorbatypes/float.cpp' | |||
156 | --- src/zorbatypes/float.cpp 2013-05-15 23:22:01 +0000 | |||
157 | +++ src/zorbatypes/float.cpp 2013-05-20 23:18:26 +0000 | |||
158 | @@ -119,19 +119,19 @@ | |||
159 | 119 | significant_digits : max_precision(); | 119 | significant_digits : max_precision(); |
160 | 120 | } | 120 | } |
161 | 121 | 121 | ||
164 | 122 | template<typename FloatType> | 122 | template<typename F> |
165 | 123 | bool FloatImpl<FloatType>::parse_etc( char const *s ) { | 123 | bool FloatImpl<F>::parse_etc( char const *s ) { |
166 | 124 | if ( strncmp( s, "INF", 3 ) == 0 ) { | 124 | if ( strncmp( s, "INF", 3 ) == 0 ) { |
168 | 125 | value_ = FloatImpl<FloatType>::pos_inf().value_; | 125 | value_ = FloatImpl<F>::pos_inf().value_; |
169 | 126 | s += 3; | 126 | s += 3; |
170 | 127 | } else if ( strncmp( s, "-INF", 4 ) == 0 ) { | 127 | } else if ( strncmp( s, "-INF", 4 ) == 0 ) { |
172 | 128 | value_ = FloatImpl<FloatType>::neg_inf().value_; | 128 | value_ = FloatImpl<F>::neg_inf().value_; |
173 | 129 | s += 4; | 129 | s += 4; |
174 | 130 | } else if ( strncmp( s, "NaN", 3 ) == 0 ) { | 130 | } else if ( strncmp( s, "NaN", 3 ) == 0 ) { |
176 | 131 | value_ = FloatImpl<FloatType>::nan().value_; | 131 | value_ = FloatImpl<F>::nan().value_; |
177 | 132 | s += 3; | 132 | s += 3; |
178 | 133 | } else if ( strncmp( s, "+INF", 4 ) == 0 ) { // allowed by XSD 1.1 | 133 | } else if ( strncmp( s, "+INF", 4 ) == 0 ) { // allowed by XSD 1.1 |
180 | 134 | value_ = FloatImpl<FloatType>::pos_inf().value_; | 134 | value_ = FloatImpl<F>::pos_inf().value_; |
181 | 135 | s += 4; | 135 | s += 4; |
182 | 136 | } else | 136 | } else |
183 | 137 | return false; | 137 | return false; |
184 | @@ -154,17 +154,22 @@ | |||
185 | 154 | parse( temp.c_str() ); | 154 | parse( temp.c_str() ); |
186 | 155 | } | 155 | } |
187 | 156 | 156 | ||
199 | 157 | template FloatImpl<float>::FloatImpl( Integer const& ); | 157 | #define ZORBA_INSTANTIATE(F,I) \ |
200 | 158 | template FloatImpl<float>::FloatImpl( NegativeInteger const& ); | 158 | template FloatImpl<F>::FloatImpl( I const& ) |
201 | 159 | template FloatImpl<float>::FloatImpl( NonNegativeInteger const& ); | 159 | |
202 | 160 | template FloatImpl<float>::FloatImpl( NonPositiveInteger const& ); | 160 | |
203 | 161 | template FloatImpl<float>::FloatImpl( PositiveInteger const& ); | 161 | ZORBA_INSTANTIATE(float,Integer); |
204 | 162 | 162 | ZORBA_INSTANTIATE(float,NegativeInteger); | |
205 | 163 | template FloatImpl<double>::FloatImpl( Integer const& ); | 163 | ZORBA_INSTANTIATE(float,NonNegativeInteger); |
206 | 164 | template FloatImpl<double>::FloatImpl( NegativeInteger const& ); | 164 | ZORBA_INSTANTIATE(float,NonPositiveInteger); |
207 | 165 | template FloatImpl<double>::FloatImpl( NonNegativeInteger const& ); | 165 | ZORBA_INSTANTIATE(float,PositiveInteger); |
208 | 166 | template FloatImpl<double>::FloatImpl( NonPositiveInteger const& ); | 166 | |
209 | 167 | template FloatImpl<double>::FloatImpl( PositiveInteger const& ); | 167 | ZORBA_INSTANTIATE(double,Integer); |
210 | 168 | ZORBA_INSTANTIATE(double,NegativeInteger); | ||
211 | 169 | ZORBA_INSTANTIATE(double,NonNegativeInteger); | ||
212 | 170 | ZORBA_INSTANTIATE(double,NonPositiveInteger); | ||
213 | 171 | ZORBA_INSTANTIATE(double,PositiveInteger); | ||
214 | 172 | #undef ZORBA_INSTANTIATE | ||
215 | 168 | 173 | ||
216 | 169 | ////////// assignment operators /////////////////////////////////////////////// | 174 | ////////// assignment operators /////////////////////////////////////////////// |
217 | 170 | 175 | ||
218 | @@ -343,7 +348,7 @@ | |||
219 | 343 | zstring FloatImpl<F>::toIntegerString() const { | 348 | zstring FloatImpl<F>::toIntegerString() const { |
220 | 344 | if ( isNaN() ) | 349 | if ( isNaN() ) |
221 | 345 | return nan_str(); | 350 | return nan_str(); |
223 | 346 | if (isPosInf() ) | 351 | if ( isPosInf() ) |
224 | 347 | return pos_inf_str(); | 352 | return pos_inf_str(); |
225 | 348 | if ( isNegInf() ) | 353 | if ( isNegInf() ) |
226 | 349 | return neg_inf_str(); | 354 | return neg_inf_str(); |
227 | 350 | 355 | ||
228 | === modified file 'src/zorbatypes/float.h' | |||
229 | --- src/zorbatypes/float.h 2013-05-15 23:22:01 +0000 | |||
230 | +++ src/zorbatypes/float.h 2013-05-20 23:18:26 +0000 | |||
231 | @@ -292,9 +292,8 @@ | |||
232 | 292 | void parse( char const* ); | 292 | void parse( char const* ); |
233 | 293 | bool parse_etc( char const* ); | 293 | bool parse_etc( char const* ); |
234 | 294 | 294 | ||
235 | 295 | friend class Decimal; | ||
236 | 295 | template<class T> friend class IntegerImpl; | 296 | template<class T> friend class IntegerImpl; |
237 | 296 | friend class Decimal; | ||
238 | 297 | |||
239 | 298 | friend class FloatImpl<float>; | 297 | friend class FloatImpl<float>; |
240 | 299 | friend class FloatImpl<double>; | 298 | friend class FloatImpl<double>; |
241 | 300 | }; | 299 | }; |
242 | 301 | 300 | ||
243 | === modified file 'src/zorbatypes/integer.cpp' | |||
244 | --- src/zorbatypes/integer.cpp 2013-05-16 00:07:00 +0000 | |||
245 | +++ src/zorbatypes/integer.cpp 2013-05-20 23:18:26 +0000 | |||
246 | @@ -37,18 +37,11 @@ | |||
247 | 37 | 37 | ||
248 | 38 | /////////////////////////////////////////////////////////////////////////////// | 38 | /////////////////////////////////////////////////////////////////////////////// |
249 | 39 | 39 | ||
258 | 40 | void integer_traits::throw_error( string const &what, bool throw_range_error ) { | 40 | void integer_traits::throw_error( MAPM const &n, char const *op ) { |
251 | 41 | if ( throw_range_error ) | ||
252 | 42 | throw range_error( what ); | ||
253 | 43 | throw invalid_argument( what ); | ||
254 | 44 | } | ||
255 | 45 | |||
256 | 46 | void integer_traits::throw_error( MAPM const &n, char const *op, | ||
257 | 47 | bool throw_range_error ) { | ||
259 | 48 | unique_ptr<char[]> const buf( new char[ n.exponent() + 3 ] ); | 41 | unique_ptr<char[]> const buf( new char[ n.exponent() + 3 ] ); |
260 | 49 | n.toIntegerString( buf.get() ); | 42 | n.toIntegerString( buf.get() ); |
261 | 50 | string const what( BUILD_STRING( buf.get(), ": not ", op, " 0" ) ); | 43 | string const what( BUILD_STRING( buf.get(), ": not ", op, " 0" ) ); |
263 | 51 | throw_error( what, throw_range_error ); | 44 | throw range_error( what ); |
264 | 52 | } | 45 | } |
265 | 53 | 46 | ||
266 | 54 | /////////////////////////////////////////////////////////////////////////////// | 47 | /////////////////////////////////////////////////////////////////////////////// |
267 | @@ -60,20 +53,25 @@ | |||
268 | 60 | value_type const i = d; | 53 | value_type const i = d; |
269 | 61 | if ( i != d ) | 54 | if ( i != d ) |
270 | 62 | throw range_error( | 55 | throw range_error( |
272 | 63 | BUILD_STRING( '"', d, "\": value too large for integer" ) | 56 | BUILD_STRING( '"', d, "\": value too large/small for integer" ) |
273 | 64 | ); | 57 | ); |
274 | 65 | return i; | 58 | return i; |
275 | 66 | } | 59 | } |
276 | 67 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 60 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
277 | 68 | 61 | ||
278 | 69 | template<class T> | 62 | template<class T> |
280 | 70 | void IntegerImpl<T>::parse( char const *s, bool throw_range_error ) { | 63 | void IntegerImpl<T>::parse( char const *s ) { |
281 | 64 | try { | ||
282 | 71 | #ifdef ZORBA_WITH_BIG_INTEGER | 65 | #ifdef ZORBA_WITH_BIG_INTEGER |
284 | 72 | Decimal::parse( s, &value_, Decimal::parse_integer ); | 66 | Decimal::parse( s, &value_, Decimal::parse_integer ); |
285 | 73 | #else | 67 | #else |
287 | 74 | value_ = ztd::aton<value_type>( s ); | 68 | value_ = ztd::aton<value_type>( s ); |
288 | 75 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 69 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
290 | 76 | T::check_value( value_, throw_range_error ); | 70 | } |
291 | 71 | catch ( invalid_argument const &e ) { | ||
292 | 72 | throw range_error( e.what() ); | ||
293 | 73 | } | ||
294 | 74 | T::check_value( value_ ); | ||
295 | 77 | } | 75 | } |
296 | 78 | 76 | ||
297 | 79 | ////////// constructors /////////////////////////////////////////////////////// | 77 | ////////// constructors /////////////////////////////////////////////////////// |
298 | @@ -83,7 +81,7 @@ | |||
299 | 83 | IntegerImpl<T>::IntegerImpl( long long n ) { | 81 | IntegerImpl<T>::IntegerImpl( long long n ) { |
300 | 84 | ascii::itoa_buf_type buf; | 82 | ascii::itoa_buf_type buf; |
301 | 85 | value_ = ascii::itoa( n, buf ); | 83 | value_ = ascii::itoa( n, buf ); |
303 | 86 | T::check_value( value_, false ); | 84 | T::check_value( value_ ); |
304 | 87 | } | 85 | } |
305 | 88 | 86 | ||
306 | 89 | #if ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG | 87 | #if ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG |
307 | @@ -91,7 +89,7 @@ | |||
308 | 91 | IntegerImpl<T>::IntegerImpl( unsigned int n ) { | 89 | IntegerImpl<T>::IntegerImpl( unsigned int n ) { |
309 | 92 | ascii::itoa_buf_type buf; | 90 | ascii::itoa_buf_type buf; |
310 | 93 | value_ = ascii::itoa( n, buf ); | 91 | value_ = ascii::itoa( n, buf ); |
312 | 94 | T::check_value( value_, false ); | 92 | T::check_value( value_ ); |
313 | 95 | } | 93 | } |
314 | 96 | #endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */ | 94 | #endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */ |
315 | 97 | 95 | ||
316 | @@ -99,34 +97,34 @@ | |||
317 | 99 | IntegerImpl<T>::IntegerImpl( unsigned long n ) { | 97 | IntegerImpl<T>::IntegerImpl( unsigned long n ) { |
318 | 100 | ascii::itoa_buf_type buf; | 98 | ascii::itoa_buf_type buf; |
319 | 101 | value_ = ascii::itoa( n, buf ); | 99 | value_ = ascii::itoa( n, buf ); |
321 | 102 | T::check_value( value_, false ); | 100 | T::check_value( value_ ); |
322 | 103 | } | 101 | } |
323 | 104 | 102 | ||
324 | 105 | template<class T> | 103 | template<class T> |
325 | 106 | IntegerImpl<T>::IntegerImpl( unsigned long long n ) { | 104 | IntegerImpl<T>::IntegerImpl( unsigned long long n ) { |
326 | 107 | ascii::itoa_buf_type buf; | 105 | ascii::itoa_buf_type buf; |
327 | 108 | value_ = ascii::itoa( n, buf ); | 106 | value_ = ascii::itoa( n, buf ); |
329 | 109 | T::check_value( value_, false ); | 107 | T::check_value( value_ ); |
330 | 110 | } | 108 | } |
331 | 111 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 109 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
332 | 112 | 110 | ||
333 | 113 | template<class T> | 111 | template<class T> |
334 | 114 | IntegerImpl<T>::IntegerImpl( Decimal const &d ) { | 112 | IntegerImpl<T>::IntegerImpl( Decimal const &d ) { |
336 | 115 | value_ = T::check_value( ftoi( d.value_ ), false ); | 113 | value_ = T::check_value( ftoi( d.value_ ) ); |
337 | 116 | } | 114 | } |
338 | 117 | 115 | ||
339 | 118 | template<class T> | 116 | template<class T> |
340 | 119 | IntegerImpl<T>::IntegerImpl( Double const &d ) { | 117 | IntegerImpl<T>::IntegerImpl( Double const &d ) { |
341 | 120 | if ( !d.isFinite() ) | 118 | if ( !d.isFinite() ) |
344 | 121 | throw std::invalid_argument( "not finite" ); | 119 | throw invalid_argument( "not finite" ); |
345 | 122 | value_ = T::check_value( ftoi( d.getNumber() ), false ); | 120 | value_ = T::check_value( ftoi( d.getNumber() ) ); |
346 | 123 | } | 121 | } |
347 | 124 | 122 | ||
348 | 125 | template<class T> | 123 | template<class T> |
349 | 126 | IntegerImpl<T>::IntegerImpl( Float const &f ) { | 124 | IntegerImpl<T>::IntegerImpl( Float const &f ) { |
350 | 127 | if ( !f.isFinite() ) | 125 | if ( !f.isFinite() ) |
353 | 128 | throw std::invalid_argument( "not finite" ); | 126 | throw invalid_argument( "not finite" ); |
354 | 129 | value_ = T::check_value( ftoi( f.getNumber() ), false ); | 127 | value_ = T::check_value( ftoi( f.getNumber() ) ); |
355 | 130 | } | 128 | } |
356 | 131 | 129 | ||
357 | 132 | ////////// assignment operators /////////////////////////////////////////////// | 130 | ////////// assignment operators /////////////////////////////////////////////// |
358 | @@ -136,7 +134,7 @@ | |||
359 | 136 | IntegerImpl<T>& IntegerImpl<T>::operator=( long long n ) { | 134 | IntegerImpl<T>& IntegerImpl<T>::operator=( long long n ) { |
360 | 137 | ascii::itoa_buf_type buf; | 135 | ascii::itoa_buf_type buf; |
361 | 138 | value_ = ascii::itoa( n, buf ); | 136 | value_ = ascii::itoa( n, buf ); |
363 | 139 | T::check_value( value_, true ); | 137 | T::check_value( value_ ); |
364 | 140 | return *this; | 138 | return *this; |
365 | 141 | } | 139 | } |
366 | 142 | 140 | ||
367 | @@ -144,7 +142,7 @@ | |||
368 | 144 | IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long n ) { | 142 | IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long n ) { |
369 | 145 | ascii::itoa_buf_type buf; | 143 | ascii::itoa_buf_type buf; |
370 | 146 | value_ = ascii::itoa( n, buf ); | 144 | value_ = ascii::itoa( n, buf ); |
372 | 147 | T::check_value( value_, true ); | 145 | T::check_value( value_ ); |
373 | 148 | return *this; | 146 | return *this; |
374 | 149 | } | 147 | } |
375 | 150 | 148 | ||
376 | @@ -152,30 +150,30 @@ | |||
377 | 152 | IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long long n ) { | 150 | IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long long n ) { |
378 | 153 | ascii::itoa_buf_type buf; | 151 | ascii::itoa_buf_type buf; |
379 | 154 | value_ = ascii::itoa( n, buf ); | 152 | value_ = ascii::itoa( n, buf ); |
381 | 155 | T::check_value( value_, true ); | 153 | T::check_value( value_ ); |
382 | 156 | return *this; | 154 | return *this; |
383 | 157 | } | 155 | } |
384 | 158 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 156 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
385 | 159 | 157 | ||
386 | 160 | template<class T> | 158 | template<class T> |
387 | 161 | IntegerImpl<T>& IntegerImpl<T>::operator=( Decimal const &d ) { | 159 | IntegerImpl<T>& IntegerImpl<T>::operator=( Decimal const &d ) { |
389 | 162 | value_ = T::check_value( ftoi( d.value_ ), true ); | 160 | value_ = T::check_value( ftoi( d.value_ ) ); |
390 | 163 | return *this; | 161 | return *this; |
391 | 164 | } | 162 | } |
392 | 165 | 163 | ||
393 | 166 | template<class T> | 164 | template<class T> |
394 | 167 | IntegerImpl<T>& IntegerImpl<T>::operator=( Double const &d ) { | 165 | IntegerImpl<T>& IntegerImpl<T>::operator=( Double const &d ) { |
395 | 168 | if ( !d.isFinite() ) | 166 | if ( !d.isFinite() ) |
398 | 169 | throw std::invalid_argument( "not finite" ); | 167 | throw invalid_argument( "not finite" ); |
399 | 170 | value_ = T::check_value( ftoi( d.getNumber() ), true ); | 168 | value_ = T::check_value( ftoi( d.getNumber() ) ); |
400 | 171 | return *this; | 169 | return *this; |
401 | 172 | } | 170 | } |
402 | 173 | 171 | ||
403 | 174 | template<class T> | 172 | template<class T> |
404 | 175 | IntegerImpl<T>& IntegerImpl<T>::operator=( Float const &f ) { | 173 | IntegerImpl<T>& IntegerImpl<T>::operator=( Float const &f ) { |
405 | 176 | if ( !f.isFinite() ) | 174 | if ( !f.isFinite() ) |
408 | 177 | throw std::invalid_argument( "not finite" ); | 175 | throw invalid_argument( "not finite" ); |
409 | 178 | value_ = T::check_value( ftoi( f.getNumber() ), true ); | 176 | value_ = T::check_value( ftoi( f.getNumber() ) ); |
410 | 179 | return *this; | 177 | return *this; |
411 | 180 | } | 178 | } |
412 | 181 | 179 | ||
413 | @@ -275,7 +273,7 @@ | |||
414 | 275 | IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \ | 273 | IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \ |
415 | 276 | ascii::itoa_buf_type buf; \ | 274 | ascii::itoa_buf_type buf; \ |
416 | 277 | value_type const temp( ascii::itoa( n, buf ) ); \ | 275 | value_type const temp( ascii::itoa( n, buf ) ); \ |
418 | 278 | T::check_value( value_ OP temp, true ); \ | 276 | T::check_value( value_ OP temp ); \ |
419 | 279 | return *this; \ | 277 | return *this; \ |
420 | 280 | } | 278 | } |
421 | 281 | 279 | ||
422 | @@ -294,12 +292,12 @@ | |||
423 | 294 | #undef ZORBA_INTEGER_OP | 292 | #undef ZORBA_INTEGER_OP |
424 | 295 | 293 | ||
425 | 296 | #define ZORBA_INTEGER_OP(N) \ | 294 | #define ZORBA_INTEGER_OP(N) \ |
432 | 297 | template<class T> \ | 295 | template<class T> \ |
433 | 298 | IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \ | 296 | IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \ |
434 | 299 | ascii::itoa_buf_type buf; \ | 297 | ascii::itoa_buf_type buf; \ |
435 | 300 | value_type const temp( ascii::itoa( n, buf ) ); \ | 298 | value_type const temp( ascii::itoa( n, buf ) ); \ |
436 | 301 | T::check_value( value_ = ftoi( value_ / temp ), true ); \ | 299 | T::check_value( value_ = ftoi( value_ / temp ) ); \ |
437 | 302 | return *this; \ | 300 | return *this; \ |
438 | 303 | } | 301 | } |
439 | 304 | 302 | ||
440 | 305 | ZORBA_INTEGER_OP(long long) | 303 | ZORBA_INTEGER_OP(long long) |
441 | 306 | 304 | ||
442 | === modified file 'src/zorbatypes/integer.h' | |||
443 | --- src/zorbatypes/integer.h 2013-05-16 19:05:52 +0000 | |||
444 | +++ src/zorbatypes/integer.h 2013-05-20 23:18:26 +0000 | |||
445 | @@ -55,38 +55,34 @@ | |||
446 | 55 | static int const default_value = 0; | 55 | static int const default_value = 0; |
447 | 56 | 56 | ||
448 | 57 | template<typename ValueType> | 57 | template<typename ValueType> |
450 | 58 | static ValueType check_value( ValueType n, bool ) { | 58 | static ValueType check_value( ValueType n ) { |
451 | 59 | return n; | 59 | return n; |
452 | 60 | } | 60 | } |
453 | 61 | 61 | ||
455 | 62 | static MAPM const& check_value( MAPM const &n, bool ) { | 62 | static MAPM const& check_value( MAPM const &n ) { |
456 | 63 | return n; | 63 | return n; |
457 | 64 | } | 64 | } |
458 | 65 | 65 | ||
459 | 66 | protected: | 66 | protected: |
460 | 67 | static void throw_error( std::string const&, bool ); | ||
461 | 68 | |||
462 | 69 | template<typename ValueType> | 67 | template<typename ValueType> |
465 | 70 | static void throw_error( ValueType n, char const *op, | 68 | static void throw_error( ValueType n, char const *op ) { |
464 | 71 | bool throw_range_error ) { | ||
466 | 72 | std::string const what( BUILD_STRING( n, ": not ", op, " 0" ) ); | 69 | std::string const what( BUILD_STRING( n, ": not ", op, " 0" ) ); |
468 | 73 | throw_error( what, throw_range_error ); | 70 | throw std::range_error( what ); |
469 | 74 | } | 71 | } |
470 | 75 | 72 | ||
473 | 76 | static void throw_error( MAPM const &n, char const *op, | 73 | static void throw_error( MAPM const &n, char const *op ); |
472 | 77 | bool throw_range_error ); | ||
474 | 78 | }; | 74 | }; |
475 | 79 | 75 | ||
476 | 80 | struct nonPositive_traits : integer_traits { | 76 | struct nonPositive_traits : integer_traits { |
477 | 81 | template<typename ValueType> | 77 | template<typename ValueType> |
479 | 82 | static ValueType check_value( ValueType n, bool throw_range_error ) { | 78 | static ValueType check_value( ValueType n ) { |
480 | 83 | if ( !ztd::le0( n ) ) | 79 | if ( !ztd::le0( n ) ) |
482 | 84 | throw_error( n, "<=", throw_range_error ); | 80 | throw_error( n, "<=" ); |
483 | 85 | return n; | 81 | return n; |
484 | 86 | } | 82 | } |
486 | 87 | static MAPM const& check_value( MAPM const &n, bool throw_range_error ) { | 83 | static MAPM const& check_value( MAPM const &n ) { |
487 | 88 | if ( !(n.sign() <= 0) ) | 84 | if ( !(n.sign() <= 0) ) |
489 | 89 | throw_error( n, "<=", throw_range_error ); | 85 | throw_error( n, "<=" ); |
490 | 90 | return n; | 86 | return n; |
491 | 91 | } | 87 | } |
492 | 92 | }; | 88 | }; |
493 | @@ -95,28 +91,28 @@ | |||
494 | 95 | static int const default_value = -1; | 91 | static int const default_value = -1; |
495 | 96 | 92 | ||
496 | 97 | template<typename ValueType> | 93 | template<typename ValueType> |
498 | 98 | static ValueType check_value( ValueType n, bool throw_range_error ) { | 94 | static ValueType check_value( ValueType n ) { |
499 | 99 | if ( !ztd::lt0( n ) ) | 95 | if ( !ztd::lt0( n ) ) |
501 | 100 | throw_error( n, "<", throw_range_error ); | 96 | throw_error( n, "<" ); |
502 | 101 | return n; | 97 | return n; |
503 | 102 | } | 98 | } |
505 | 103 | static MAPM const& check_value( MAPM const &n, bool throw_range_error ) { | 99 | static MAPM const& check_value( MAPM const &n ) { |
506 | 104 | if ( !(n.sign() < 0) ) | 100 | if ( !(n.sign() < 0) ) |
508 | 105 | throw_error( n, "<", throw_range_error ); | 101 | throw_error( n, "<" ); |
509 | 106 | return n; | 102 | return n; |
510 | 107 | } | 103 | } |
511 | 108 | }; | 104 | }; |
512 | 109 | 105 | ||
513 | 110 | struct nonNegative_traits : integer_traits { | 106 | struct nonNegative_traits : integer_traits { |
514 | 111 | template<typename ValueType> | 107 | template<typename ValueType> |
516 | 112 | static ValueType check_value( ValueType n, bool throw_range_error ) { | 108 | static ValueType check_value( ValueType n ) { |
517 | 113 | if ( !ztd::ge0( n ) ) | 109 | if ( !ztd::ge0( n ) ) |
519 | 114 | throw_error( n, ">=", throw_range_error ); | 110 | throw_error( n, ">=" ); |
520 | 115 | return n; | 111 | return n; |
521 | 116 | } | 112 | } |
523 | 117 | static MAPM const& check_value( MAPM const &n, bool throw_range_error ) { | 113 | static MAPM const& check_value( MAPM const &n ) { |
524 | 118 | if ( !(n.sign() >= 0) ) | 114 | if ( !(n.sign() >= 0) ) |
526 | 119 | throw_error( n, ">=", throw_range_error ); | 115 | throw_error( n, ">=" ); |
527 | 120 | return n; | 116 | return n; |
528 | 121 | } | 117 | } |
529 | 122 | }; | 118 | }; |
530 | @@ -125,14 +121,14 @@ | |||
531 | 125 | static int const default_value = 1; | 121 | static int const default_value = 1; |
532 | 126 | 122 | ||
533 | 127 | template<typename ValueType> | 123 | template<typename ValueType> |
535 | 128 | static ValueType check_value( ValueType n, bool throw_range_error ) { | 124 | static ValueType check_value( ValueType n ) { |
536 | 129 | if ( !ztd::gt0( n ) ) | 125 | if ( !ztd::gt0( n ) ) |
538 | 130 | throw_error( n, ">", throw_range_error ); | 126 | throw_error( n, ">" ); |
539 | 131 | return n; | 127 | return n; |
540 | 132 | } | 128 | } |
542 | 133 | static MAPM const& check_value( MAPM const &n, bool throw_range_error ) { | 129 | static MAPM const& check_value( MAPM const &n ) { |
543 | 134 | if ( !(n.sign() > 0) ) | 130 | if ( !(n.sign() > 0) ) |
545 | 135 | throw_error( n, ">", throw_range_error ); | 131 | throw_error( n, ">" ); |
546 | 136 | return n; | 132 | return n; |
547 | 137 | } | 133 | } |
548 | 138 | }; | 134 | }; |
549 | @@ -174,8 +170,7 @@ | |||
550 | 174 | * whitespace is ignored. | 170 | * whitespace is ignored. |
551 | 175 | * @throw std::invalid_argument if \a s does not contain a valid integer. | 171 | * @throw std::invalid_argument if \a s does not contain a valid integer. |
552 | 176 | * @throw std::range_error if \a s contains an integer that either underflows | 172 | * @throw std::range_error if \a s contains an integer that either underflows |
555 | 177 | * or overflows the smallest or largest representable integer (only when not | 173 | * or overflows the smallest or largest representable/legal integer. |
554 | 178 | * compiled with ZORBA_WITH_BIG_INTEGER). | ||
556 | 179 | */ | 174 | */ |
557 | 180 | explicit IntegerImpl( char const *s ); | 175 | explicit IntegerImpl( char const *s ); |
558 | 181 | 176 | ||
559 | @@ -596,7 +591,7 @@ | |||
560 | 596 | } | 591 | } |
561 | 597 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 592 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
562 | 598 | 593 | ||
564 | 599 | void parse( char const *s, bool throw_range_error ); | 594 | void parse( char const *s ); |
565 | 600 | 595 | ||
566 | 601 | friend class Decimal; | 596 | friend class Decimal; |
567 | 602 | template<typename F> friend class FloatImpl; | 597 | template<typename F> friend class FloatImpl; |
568 | @@ -623,51 +618,51 @@ | |||
569 | 623 | 618 | ||
570 | 624 | template<class T> | 619 | template<class T> |
571 | 625 | inline IntegerImpl<T>::IntegerImpl( char c ) : | 620 | inline IntegerImpl<T>::IntegerImpl( char c ) : |
573 | 626 | value_( static_cast<long>( T::check_value( c, false ) ) ) | 621 | value_( static_cast<long>( T::check_value( c ) ) ) |
574 | 627 | { | 622 | { |
575 | 628 | } | 623 | } |
576 | 629 | 624 | ||
577 | 630 | template<class T> | 625 | template<class T> |
578 | 631 | inline IntegerImpl<T>::IntegerImpl( signed char c ) : | 626 | inline IntegerImpl<T>::IntegerImpl( signed char c ) : |
580 | 632 | value_( static_cast<long>( T::check_value( c, false ) ) ) | 627 | value_( static_cast<long>( T::check_value( c ) ) ) |
581 | 633 | { | 628 | { |
582 | 634 | } | 629 | } |
583 | 635 | 630 | ||
584 | 636 | template<class T> | 631 | template<class T> |
585 | 637 | inline IntegerImpl<T>::IntegerImpl( short n ) : | 632 | inline IntegerImpl<T>::IntegerImpl( short n ) : |
587 | 638 | value_( static_cast<long>( T::check_value( n, false ) ) ) | 633 | value_( static_cast<long>( T::check_value( n ) ) ) |
588 | 639 | { | 634 | { |
589 | 640 | } | 635 | } |
590 | 641 | 636 | ||
591 | 642 | template<class T> | 637 | template<class T> |
592 | 643 | inline IntegerImpl<T>::IntegerImpl( int n ) : | 638 | inline IntegerImpl<T>::IntegerImpl( int n ) : |
594 | 644 | value_( static_cast<long>( T::check_value( n, false ) ) ) | 639 | value_( static_cast<long>( T::check_value( n ) ) ) |
595 | 645 | { | 640 | { |
596 | 646 | } | 641 | } |
597 | 647 | 642 | ||
598 | 648 | template<class T> | 643 | template<class T> |
599 | 649 | inline IntegerImpl<T>::IntegerImpl( long n ) : | 644 | inline IntegerImpl<T>::IntegerImpl( long n ) : |
601 | 650 | value_( T::check_value( n, false ) ) | 645 | value_( T::check_value( n ) ) |
602 | 651 | { | 646 | { |
603 | 652 | } | 647 | } |
604 | 653 | 648 | ||
605 | 654 | #ifndef ZORBA_WITH_BIG_INTEGER | 649 | #ifndef ZORBA_WITH_BIG_INTEGER |
606 | 655 | template<class T> | 650 | template<class T> |
607 | 656 | inline IntegerImpl<T>::IntegerImpl( long long n ) : | 651 | inline IntegerImpl<T>::IntegerImpl( long long n ) : |
609 | 657 | value_( T::check_value( n, false ) ) | 652 | value_( T::check_value( n ) ) |
610 | 658 | { | 653 | { |
611 | 659 | } | 654 | } |
612 | 660 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 655 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
613 | 661 | 656 | ||
614 | 662 | template<class T> | 657 | template<class T> |
615 | 663 | inline IntegerImpl<T>::IntegerImpl( unsigned char c ) : | 658 | inline IntegerImpl<T>::IntegerImpl( unsigned char c ) : |
617 | 664 | value_( static_cast<long>( (unsigned long)T::check_value( c, false ) ) ) | 659 | value_( static_cast<long>( (unsigned long)T::check_value( c ) ) ) |
618 | 665 | { | 660 | { |
619 | 666 | } | 661 | } |
620 | 667 | 662 | ||
621 | 668 | template<class T> | 663 | template<class T> |
622 | 669 | inline IntegerImpl<T>::IntegerImpl( unsigned short n ) : | 664 | inline IntegerImpl<T>::IntegerImpl( unsigned short n ) : |
624 | 670 | value_( static_cast<long>( (unsigned long)T::check_value( n, false ) ) ) | 665 | value_( static_cast<long>( (unsigned long)T::check_value( n ) ) ) |
625 | 671 | { | 666 | { |
626 | 672 | } | 667 | } |
627 | 673 | 668 | ||
628 | @@ -675,7 +670,7 @@ | |||
629 | 675 | #if ZORBA_SIZEOF_INT != ZORBA_SIZEOF_LONG | 670 | #if ZORBA_SIZEOF_INT != ZORBA_SIZEOF_LONG |
630 | 676 | template<class T> | 671 | template<class T> |
631 | 677 | inline IntegerImpl<T>::IntegerImpl( unsigned int n ) : | 672 | inline IntegerImpl<T>::IntegerImpl( unsigned int n ) : |
633 | 678 | value_( static_cast<long>( (unsigned long)T::check_value( n, false ) ) ) | 673 | value_( static_cast<long>( (unsigned long)T::check_value( n ) ) ) |
634 | 679 | { | 674 | { |
635 | 680 | } | 675 | } |
636 | 681 | #endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */ | 676 | #endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */ |
637 | @@ -683,19 +678,19 @@ | |||
638 | 683 | 678 | ||
639 | 684 | template<class T> | 679 | template<class T> |
640 | 685 | inline IntegerImpl<T>::IntegerImpl( unsigned int n ) : | 680 | inline IntegerImpl<T>::IntegerImpl( unsigned int n ) : |
642 | 686 | value_( static_cast<value_type>( T::check_value( n, false ) ) ) | 681 | value_( static_cast<value_type>( T::check_value( n ) ) ) |
643 | 687 | { | 682 | { |
644 | 688 | } | 683 | } |
645 | 689 | 684 | ||
646 | 690 | template<class T> | 685 | template<class T> |
647 | 691 | inline IntegerImpl<T>::IntegerImpl( unsigned long n ) : | 686 | inline IntegerImpl<T>::IntegerImpl( unsigned long n ) : |
649 | 692 | value_( static_cast<value_type>( T::check_value( n, false ) ) ) | 687 | value_( static_cast<value_type>( T::check_value( n ) ) ) |
650 | 693 | { | 688 | { |
651 | 694 | } | 689 | } |
652 | 695 | 690 | ||
653 | 696 | template<class T> | 691 | template<class T> |
654 | 697 | inline IntegerImpl<T>::IntegerImpl( unsigned long long n ) : | 692 | inline IntegerImpl<T>::IntegerImpl( unsigned long long n ) : |
656 | 698 | value_( static_cast<value_type>( T::check_value( n, false ) ) ) | 693 | value_( static_cast<value_type>( T::check_value( n ) ) ) |
657 | 699 | { | 694 | { |
658 | 700 | } | 695 | } |
659 | 701 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 696 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
660 | @@ -703,9 +698,9 @@ | |||
661 | 703 | template<class T> | 698 | template<class T> |
662 | 704 | inline IntegerImpl<T>::IntegerImpl( float n ) : | 699 | inline IntegerImpl<T>::IntegerImpl( float n ) : |
663 | 705 | #ifdef ZORBA_WITH_BIG_INTEGER | 700 | #ifdef ZORBA_WITH_BIG_INTEGER |
665 | 706 | value_( static_cast<double>( T::check_value( n, false ) ) ) | 701 | value_( static_cast<double>( T::check_value( n ) ) ) |
666 | 707 | #else | 702 | #else |
668 | 708 | value_( static_cast<value_type>( T::check_value( n, false ) ) ) | 703 | value_( static_cast<value_type>( T::check_value( n ) ) ) |
669 | 709 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 704 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
670 | 710 | { | 705 | { |
671 | 711 | } | 706 | } |
672 | @@ -713,32 +708,32 @@ | |||
673 | 713 | template<class T> | 708 | template<class T> |
674 | 714 | inline IntegerImpl<T>::IntegerImpl( double n ) : | 709 | inline IntegerImpl<T>::IntegerImpl( double n ) : |
675 | 715 | #ifdef ZORBA_WITH_BIG_INTEGER | 710 | #ifdef ZORBA_WITH_BIG_INTEGER |
677 | 716 | value_( T::check_value( n, false ) ) | 711 | value_( T::check_value( n ) ) |
678 | 717 | #else | 712 | #else |
680 | 718 | value_( static_cast<value_type>( T::check_value( n, false ) ) ) | 713 | value_( static_cast<value_type>( T::check_value( n ) ) ) |
681 | 719 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 714 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
682 | 720 | { | 715 | { |
683 | 721 | } | 716 | } |
684 | 722 | 717 | ||
685 | 723 | template<class T> | 718 | template<class T> |
686 | 724 | inline IntegerImpl<T>::IntegerImpl( char const *s ) { | 719 | inline IntegerImpl<T>::IntegerImpl( char const *s ) { |
688 | 725 | parse( s, false ); | 720 | parse( s ); |
689 | 726 | } | 721 | } |
690 | 727 | 722 | ||
691 | 728 | template<class T> | 723 | template<class T> |
692 | 729 | template<class U> | 724 | template<class U> |
693 | 730 | inline IntegerImpl<T>::IntegerImpl( IntegerImpl<U> const &i ) : | 725 | inline IntegerImpl<T>::IntegerImpl( IntegerImpl<U> const &i ) : |
695 | 731 | value_( T::check_value( i.value_, false ) ) | 726 | value_( T::check_value( i.value_ ) ) |
696 | 732 | { | 727 | { |
697 | 733 | } | 728 | } |
698 | 734 | 729 | ||
699 | 735 | ////////// assignment operators /////////////////////////////////////////////// | 730 | ////////// assignment operators /////////////////////////////////////////////// |
700 | 736 | 731 | ||
706 | 737 | #define ZORBA_ASSIGN_OP(N) \ | 732 | #define ZORBA_ASSIGN_OP(N) \ |
707 | 738 | template<class T> inline \ | 733 | template<class T> inline \ |
708 | 739 | IntegerImpl<T>& IntegerImpl<T>::operator=( N n ) { \ | 734 | IntegerImpl<T>& IntegerImpl<T>::operator=( N n ) { \ |
709 | 740 | value_ = static_cast<int_cast_type>( T::check_value( n, false ) ); \ | 735 | value_ = static_cast<int_cast_type>( T::check_value( n ) ); \ |
710 | 741 | return *this; \ | 736 | return *this; \ |
711 | 742 | } | 737 | } |
712 | 743 | 738 | ||
713 | 744 | ZORBA_ASSIGN_OP(char) | 739 | ZORBA_ASSIGN_OP(char) |
714 | @@ -760,14 +755,14 @@ | |||
715 | 760 | 755 | ||
716 | 761 | template<class T> | 756 | template<class T> |
717 | 762 | inline IntegerImpl<T>& IntegerImpl<T>::operator=( char const *s ) { | 757 | inline IntegerImpl<T>& IntegerImpl<T>::operator=( char const *s ) { |
719 | 763 | parse( s, false ); | 758 | parse( s ); |
720 | 764 | return *this; | 759 | return *this; |
721 | 765 | } | 760 | } |
722 | 766 | 761 | ||
723 | 767 | template<class T> | 762 | template<class T> |
724 | 768 | template<class U> | 763 | template<class U> |
725 | 769 | inline IntegerImpl<T>& IntegerImpl<T>::operator=( IntegerImpl<U> const &i ) { | 764 | inline IntegerImpl<T>& IntegerImpl<T>::operator=( IntegerImpl<U> const &i ) { |
727 | 770 | T::check_value( value_ = i.value_, false ); | 765 | T::check_value( value_ = i.value_ ); |
728 | 771 | return *this; | 766 | return *this; |
729 | 772 | } | 767 | } |
730 | 773 | 768 | ||
731 | @@ -888,7 +883,7 @@ | |||
732 | 888 | #define ZORBA_INTEGER_OP(OP) \ | 883 | #define ZORBA_INTEGER_OP(OP) \ |
733 | 889 | template<class T> inline \ | 884 | template<class T> inline \ |
734 | 890 | IntegerImpl<T>& IntegerImpl<T>::operator OP( IntegerImpl<T> const &i ) { \ | 885 | IntegerImpl<T>& IntegerImpl<T>::operator OP( IntegerImpl<T> const &i ) { \ |
736 | 891 | T::check_value( value_ OP i.value_, true ); \ | 886 | T::check_value( value_ OP i.value_ ); \ |
737 | 892 | return *this; \ | 887 | return *this; \ |
738 | 893 | } | 888 | } |
739 | 894 | 889 | ||
740 | @@ -900,15 +895,15 @@ | |||
741 | 900 | 895 | ||
742 | 901 | template<class T> | 896 | template<class T> |
743 | 902 | inline IntegerImpl<T>& IntegerImpl<T>::operator/=( IntegerImpl<T> const &i ) { | 897 | inline IntegerImpl<T>& IntegerImpl<T>::operator/=( IntegerImpl<T> const &i ) { |
745 | 903 | value_ = T::check_value( ftoi( value_ / i.value_ ), true ); | 898 | value_ = T::check_value( ftoi( value_ / i.value_ ) ); |
746 | 904 | return *this; | 899 | return *this; |
747 | 905 | } | 900 | } |
748 | 906 | 901 | ||
754 | 907 | #define ZORBA_INTEGER_OP(OP,N) \ | 902 | #define ZORBA_INTEGER_OP(OP,N) \ |
755 | 908 | template<class T> inline \ | 903 | template<class T> inline \ |
756 | 909 | IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \ | 904 | IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \ |
757 | 910 | T::check_value( value_ OP make_value_type( n ), true ); \ | 905 | T::check_value( value_ OP make_value_type( n ) ); \ |
758 | 911 | return *this; \ | 906 | return *this; \ |
759 | 912 | } | 907 | } |
760 | 913 | 908 | ||
761 | 914 | ZORBA_INTEGER_OP(+=,char) | 909 | ZORBA_INTEGER_OP(+=,char) |
762 | @@ -967,11 +962,11 @@ | |||
763 | 967 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 962 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
764 | 968 | #undef ZORBA_INTEGER_OP | 963 | #undef ZORBA_INTEGER_OP |
765 | 969 | 964 | ||
771 | 970 | #define ZORBA_INTEGER_OP(N) \ | 965 | #define ZORBA_INTEGER_OP(N) \ |
772 | 971 | template<class T> inline \ | 966 | template<class T> inline \ |
773 | 972 | IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \ | 967 | IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \ |
774 | 973 | value_ = T::check_value( ftoi( value_ / make_value_type( n ) ), true ); \ | 968 | value_ = T::check_value( ftoi( value_ / make_value_type( n ) ) ); \ |
775 | 974 | return *this; \ | 969 | return *this; \ |
776 | 975 | } | 970 | } |
777 | 976 | 971 | ||
778 | 977 | ZORBA_INTEGER_OP(char) | 972 | ZORBA_INTEGER_OP(char) |
779 | @@ -998,27 +993,27 @@ | |||
780 | 998 | 993 | ||
781 | 999 | template<class T> | 994 | template<class T> |
782 | 1000 | inline IntegerImpl<T>& IntegerImpl<T>::operator++() { | 995 | inline IntegerImpl<T>& IntegerImpl<T>::operator++() { |
784 | 1001 | T::check_value( ++value_, true ); | 996 | T::check_value( ++value_ ); |
785 | 1002 | return *this; | 997 | return *this; |
786 | 1003 | } | 998 | } |
787 | 1004 | 999 | ||
788 | 1005 | template<class T> | 1000 | template<class T> |
789 | 1006 | inline IntegerImpl<T> IntegerImpl<T>::operator++(int) { | 1001 | inline IntegerImpl<T> IntegerImpl<T>::operator++(int) { |
790 | 1007 | IntegerImpl<T> const result( *this ); | 1002 | IntegerImpl<T> const result( *this ); |
792 | 1008 | T::check_value( ++value_, true ); | 1003 | T::check_value( ++value_ ); |
793 | 1009 | return result; | 1004 | return result; |
794 | 1010 | } | 1005 | } |
795 | 1011 | 1006 | ||
796 | 1012 | template<class T> | 1007 | template<class T> |
797 | 1013 | inline IntegerImpl<T>& IntegerImpl<T>::operator--() { | 1008 | inline IntegerImpl<T>& IntegerImpl<T>::operator--() { |
799 | 1014 | T::check_value( --value_, true ); | 1009 | T::check_value( --value_ ); |
800 | 1015 | return *this; | 1010 | return *this; |
801 | 1016 | } | 1011 | } |
802 | 1017 | 1012 | ||
803 | 1018 | template<class T> | 1013 | template<class T> |
804 | 1019 | inline IntegerImpl<T> IntegerImpl<T>::operator--(int) { | 1014 | inline IntegerImpl<T> IntegerImpl<T>::operator--(int) { |
805 | 1020 | IntegerImpl<T> const result( *this ); | 1015 | IntegerImpl<T> const result( *this ); |
807 | 1021 | T::check_value( --value_, true ); | 1016 | T::check_value( --value_ ); |
808 | 1022 | return result; | 1017 | return result; |
809 | 1023 | } | 1018 | } |
810 | 1024 | 1019 |
Validation queue starting for merge proposal. zorbatest. lambda. nu:8080/ remotequeue/ bug-1178322- 2013-05- 17T19-29- 11.835Z/ log.html
Log at: http://