Merge lp:~zorba-coders/zorba/bug-1178322 into lp:zorba

Proposed by Paul J. Lucas
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
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.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
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/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug-1178322-2013-05-17T19-29-11.835Z is finished. The
  final status was:

  14 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
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/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug-1178322-2013-05-18T14-46-45.055Z is finished. The
  final status was:

  3 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
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/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug-1178322-2013-05-20T20-52-46.921Z is finished. The
  final status was:

  2 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1178322-2013-05-20T23-28-42.183Z is finished. The final status was:

All tests succeeded!

Revision history for this message
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.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1178322-2013-05-21T00-02-41.571Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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
6 if (!state->theContextNode->isNode())
7 {
8- assert(false);
9+ //assert(false);
10 throw XQUERY_EXCEPTION(err::XPTY0020, ERROR_LOC(loc));
11 }
12 }
13
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 xs_decimal const n(strval.c_str());
19 aFactory->createDecimal(result, n);
20 }
21- catch (const std::exception& )
22+ catch (const std::invalid_argument& )
23+ {
24+ throwFOCA0002Exception(strval, errInfo);
25+ }
26+ catch (const std::range_error& )
27 {
28 throwFORG0001Exception(strval, errInfo);
29 }
30@@ -401,12 +405,12 @@
31 }
32 catch (const std::invalid_argument& )
33 {
34+ throwFOCA0002Exception(strval, errInfo);
35+ }
36+ catch (const std::range_error& )
37+ {
38 throwFORG0001Exception(strval, errInfo);
39 }
40- catch (const std::range_error& )
41- {
42- RAISE_ERROR(err::FOAR0002, errInfo.theLoc, ERROR_PARAMS(strval));
43- }
44 }
45
46
47@@ -419,11 +423,11 @@
48 }
49 catch ( std::invalid_argument const& )
50 {
51- throwFORG0001Exception(strval, errInfo);
52+ throwFOCA0002Exception(strval, errInfo);
53 }
54 catch ( std::range_error const& )
55 {
56- RAISE_ERROR(err::FOAR0002, errInfo.theLoc, ERROR_PARAMS(strval));
57+ throwFORG0001Exception(strval, errInfo);
58 }
59 }
60
61@@ -993,15 +997,16 @@
62
63 T1_TO_T2(flt, int)
64 {
65- xs_float const f( aItem->getFloatValue() );
66- if ( !f.isFinite() )
67- throwFOCA0002Exception(aItem->getStringValue(), errInfo);
68 try
69 {
70- xs_integer const n( f );
71+ xs_integer const n( aItem->getFloatValue() );
72 aFactory->createInteger(result, n);
73 }
74- catch (const std::exception&)
75+ catch ( std::invalid_argument const& )
76+ {
77+ throwFOCA0002Exception(aItem->getStringValue(), errInfo);
78+ }
79+ catch (const std::range_error&)
80 {
81 throwFOCA0003Exception(aItem->getStringValue(), errInfo);
82 }
83@@ -1050,15 +1055,16 @@
84
85 T1_TO_T2(dbl, int)
86 {
87- xs_double const d( aItem->getDoubleValue() );
88- if ( !d.isFinite() )
89- throwFOCA0002Exception(aItem->getStringValue(), errInfo);
90 try
91 {
92- xs_integer const n( d );
93+ xs_integer const n( aItem->getDoubleValue() );
94 aFactory->createInteger(result, n);
95 }
96- catch (const std::exception& )
97+ catch ( std::invalid_argument const& )
98+ {
99+ throwFOCA0002Exception(aItem->getStringValue(), errInfo);
100+ }
101+ catch (const std::range_error&)
102 {
103 throwFOCA0003Exception(aItem->getStringValue(), errInfo);
104 }
105@@ -1679,10 +1685,14 @@
106 xs_nonNegativeInteger const n(aItem->getIntegerValue());
107 aFactory->createNonNegativeInteger(result, n);
108 }
109- catch (const std::exception& )
110+ catch ( std::invalid_argument const& )
111 {
112 throwFOCA0002Exception(aItem->getStringValue(), errInfo);
113 }
114+ catch ( std::range_error const& )
115+ {
116+ throwFORG0001Exception(aItem->getStringValue(), errInfo);
117+ }
118 }
119
120
121
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 Decimal::value_type const Decimal::round_precision_limit( 64 );
127
128 void Decimal::parse( char const *s, value_type *result, int parse_options ) {
129- if ( !*s )
130- throw invalid_argument( "empty string" );
131+ if ( !*s ) {
132+ //
133+ // In an ideal world, this would throw invalid_argument. The XQuery spec
134+ // wants FORG0001 to be raised, but invalid_argument is being mapped to
135+ // FOCA0002; instead, range_error is mapped to FORG0001, so we throw
136+ // range_error.
137+ //
138+ throw range_error( "empty string" );
139+ }
140
141 s = ascii::trim_start_space( s );
142 char const *const first_non_ws = s;
143@@ -60,7 +67,9 @@
144 ++s;
145 }
146 if ( *s )
147- throw invalid_argument( BUILD_STRING( '"', *s, "\": invalid character" ) );
148+ throw range_error(
149+ BUILD_STRING( '"', *s, "\": invalid value for integer" )
150+ );
151
152 if ( first_trailing_ws ) {
153 ptrdiff_t const size = first_trailing_ws - first_non_ws;
154
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 significant_digits : max_precision();
160 }
161
162-template<typename FloatType>
163-bool FloatImpl<FloatType>::parse_etc( char const *s ) {
164+template<typename F>
165+bool FloatImpl<F>::parse_etc( char const *s ) {
166 if ( strncmp( s, "INF", 3 ) == 0 ) {
167- value_ = FloatImpl<FloatType>::pos_inf().value_;
168+ value_ = FloatImpl<F>::pos_inf().value_;
169 s += 3;
170 } else if ( strncmp( s, "-INF", 4 ) == 0 ) {
171- value_ = FloatImpl<FloatType>::neg_inf().value_;
172+ value_ = FloatImpl<F>::neg_inf().value_;
173 s += 4;
174 } else if ( strncmp( s, "NaN", 3 ) == 0 ) {
175- value_ = FloatImpl<FloatType>::nan().value_;
176+ value_ = FloatImpl<F>::nan().value_;
177 s += 3;
178 } else if ( strncmp( s, "+INF", 4 ) == 0 ) { // allowed by XSD 1.1
179- value_ = FloatImpl<FloatType>::pos_inf().value_;
180+ value_ = FloatImpl<F>::pos_inf().value_;
181 s += 4;
182 } else
183 return false;
184@@ -154,17 +154,22 @@
185 parse( temp.c_str() );
186 }
187
188-template FloatImpl<float>::FloatImpl( Integer const& );
189-template FloatImpl<float>::FloatImpl( NegativeInteger const& );
190-template FloatImpl<float>::FloatImpl( NonNegativeInteger const& );
191-template FloatImpl<float>::FloatImpl( NonPositiveInteger const& );
192-template FloatImpl<float>::FloatImpl( PositiveInteger const& );
193-
194-template FloatImpl<double>::FloatImpl( Integer const& );
195-template FloatImpl<double>::FloatImpl( NegativeInteger const& );
196-template FloatImpl<double>::FloatImpl( NonNegativeInteger const& );
197-template FloatImpl<double>::FloatImpl( NonPositiveInteger const& );
198-template FloatImpl<double>::FloatImpl( PositiveInteger const& );
199+#define ZORBA_INSTANTIATE(F,I) \
200+ template FloatImpl<F>::FloatImpl( I const& )
201+
202+
203+ZORBA_INSTANTIATE(float,Integer);
204+ZORBA_INSTANTIATE(float,NegativeInteger);
205+ZORBA_INSTANTIATE(float,NonNegativeInteger);
206+ZORBA_INSTANTIATE(float,NonPositiveInteger);
207+ZORBA_INSTANTIATE(float,PositiveInteger);
208+
209+ZORBA_INSTANTIATE(double,Integer);
210+ZORBA_INSTANTIATE(double,NegativeInteger);
211+ZORBA_INSTANTIATE(double,NonNegativeInteger);
212+ZORBA_INSTANTIATE(double,NonPositiveInteger);
213+ZORBA_INSTANTIATE(double,PositiveInteger);
214+#undef ZORBA_INSTANTIATE
215
216 ////////// assignment operators ///////////////////////////////////////////////
217
218@@ -343,7 +348,7 @@
219 zstring FloatImpl<F>::toIntegerString() const {
220 if ( isNaN() )
221 return nan_str();
222- if (isPosInf() )
223+ if ( isPosInf() )
224 return pos_inf_str();
225 if ( isNegInf() )
226 return neg_inf_str();
227
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 void parse( char const* );
233 bool parse_etc( char const* );
234
235+ friend class Decimal;
236 template<class T> friend class IntegerImpl;
237- friend class Decimal;
238-
239 friend class FloatImpl<float>;
240 friend class FloatImpl<double>;
241 };
242
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
248 ///////////////////////////////////////////////////////////////////////////////
249
250-void integer_traits::throw_error( string const &what, bool throw_range_error ) {
251- if ( throw_range_error )
252- throw range_error( what );
253- throw invalid_argument( what );
254-}
255-
256-void integer_traits::throw_error( MAPM const &n, char const *op,
257- bool throw_range_error ) {
258+void integer_traits::throw_error( MAPM const &n, char const *op ) {
259 unique_ptr<char[]> const buf( new char[ n.exponent() + 3 ] );
260 n.toIntegerString( buf.get() );
261 string const what( BUILD_STRING( buf.get(), ": not ", op, " 0" ) );
262- throw_error( what, throw_range_error );
263+ throw range_error( what );
264 }
265
266 ///////////////////////////////////////////////////////////////////////////////
267@@ -60,20 +53,25 @@
268 value_type const i = d;
269 if ( i != d )
270 throw range_error(
271- BUILD_STRING( '"', d, "\": value too large for integer" )
272+ BUILD_STRING( '"', d, "\": value too large/small for integer" )
273 );
274 return i;
275 }
276 #endif /* ZORBA_WITH_BIG_INTEGER */
277
278 template<class T>
279-void IntegerImpl<T>::parse( char const *s, bool throw_range_error ) {
280+void IntegerImpl<T>::parse( char const *s ) {
281+ try {
282 #ifdef ZORBA_WITH_BIG_INTEGER
283- Decimal::parse( s, &value_, Decimal::parse_integer );
284+ Decimal::parse( s, &value_, Decimal::parse_integer );
285 #else
286- value_ = ztd::aton<value_type>( s );
287+ value_ = ztd::aton<value_type>( s );
288 #endif /* ZORBA_WITH_BIG_INTEGER */
289- T::check_value( value_, throw_range_error );
290+ }
291+ catch ( invalid_argument const &e ) {
292+ throw range_error( e.what() );
293+ }
294+ T::check_value( value_ );
295 }
296
297 ////////// constructors ///////////////////////////////////////////////////////
298@@ -83,7 +81,7 @@
299 IntegerImpl<T>::IntegerImpl( long long n ) {
300 ascii::itoa_buf_type buf;
301 value_ = ascii::itoa( n, buf );
302- T::check_value( value_, false );
303+ T::check_value( value_ );
304 }
305
306 #if ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG
307@@ -91,7 +89,7 @@
308 IntegerImpl<T>::IntegerImpl( unsigned int n ) {
309 ascii::itoa_buf_type buf;
310 value_ = ascii::itoa( n, buf );
311- T::check_value( value_, false );
312+ T::check_value( value_ );
313 }
314 #endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */
315
316@@ -99,34 +97,34 @@
317 IntegerImpl<T>::IntegerImpl( unsigned long n ) {
318 ascii::itoa_buf_type buf;
319 value_ = ascii::itoa( n, buf );
320- T::check_value( value_, false );
321+ T::check_value( value_ );
322 }
323
324 template<class T>
325 IntegerImpl<T>::IntegerImpl( unsigned long long n ) {
326 ascii::itoa_buf_type buf;
327 value_ = ascii::itoa( n, buf );
328- T::check_value( value_, false );
329+ T::check_value( value_ );
330 }
331 #endif /* ZORBA_WITH_BIG_INTEGER */
332
333 template<class T>
334 IntegerImpl<T>::IntegerImpl( Decimal const &d ) {
335- value_ = T::check_value( ftoi( d.value_ ), false );
336+ value_ = T::check_value( ftoi( d.value_ ) );
337 }
338
339 template<class T>
340 IntegerImpl<T>::IntegerImpl( Double const &d ) {
341 if ( !d.isFinite() )
342- throw std::invalid_argument( "not finite" );
343- value_ = T::check_value( ftoi( d.getNumber() ), false );
344+ throw invalid_argument( "not finite" );
345+ value_ = T::check_value( ftoi( d.getNumber() ) );
346 }
347
348 template<class T>
349 IntegerImpl<T>::IntegerImpl( Float const &f ) {
350 if ( !f.isFinite() )
351- throw std::invalid_argument( "not finite" );
352- value_ = T::check_value( ftoi( f.getNumber() ), false );
353+ throw invalid_argument( "not finite" );
354+ value_ = T::check_value( ftoi( f.getNumber() ) );
355 }
356
357 ////////// assignment operators ///////////////////////////////////////////////
358@@ -136,7 +134,7 @@
359 IntegerImpl<T>& IntegerImpl<T>::operator=( long long n ) {
360 ascii::itoa_buf_type buf;
361 value_ = ascii::itoa( n, buf );
362- T::check_value( value_, true );
363+ T::check_value( value_ );
364 return *this;
365 }
366
367@@ -144,7 +142,7 @@
368 IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long n ) {
369 ascii::itoa_buf_type buf;
370 value_ = ascii::itoa( n, buf );
371- T::check_value( value_, true );
372+ T::check_value( value_ );
373 return *this;
374 }
375
376@@ -152,30 +150,30 @@
377 IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long long n ) {
378 ascii::itoa_buf_type buf;
379 value_ = ascii::itoa( n, buf );
380- T::check_value( value_, true );
381+ T::check_value( value_ );
382 return *this;
383 }
384 #endif /* ZORBA_WITH_BIG_INTEGER */
385
386 template<class T>
387 IntegerImpl<T>& IntegerImpl<T>::operator=( Decimal const &d ) {
388- value_ = T::check_value( ftoi( d.value_ ), true );
389+ value_ = T::check_value( ftoi( d.value_ ) );
390 return *this;
391 }
392
393 template<class T>
394 IntegerImpl<T>& IntegerImpl<T>::operator=( Double const &d ) {
395 if ( !d.isFinite() )
396- throw std::invalid_argument( "not finite" );
397- value_ = T::check_value( ftoi( d.getNumber() ), true );
398+ throw invalid_argument( "not finite" );
399+ value_ = T::check_value( ftoi( d.getNumber() ) );
400 return *this;
401 }
402
403 template<class T>
404 IntegerImpl<T>& IntegerImpl<T>::operator=( Float const &f ) {
405 if ( !f.isFinite() )
406- throw std::invalid_argument( "not finite" );
407- value_ = T::check_value( ftoi( f.getNumber() ), true );
408+ throw invalid_argument( "not finite" );
409+ value_ = T::check_value( ftoi( f.getNumber() ) );
410 return *this;
411 }
412
413@@ -275,7 +273,7 @@
414 IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \
415 ascii::itoa_buf_type buf; \
416 value_type const temp( ascii::itoa( n, buf ) ); \
417- T::check_value( value_ OP temp, true ); \
418+ T::check_value( value_ OP temp ); \
419 return *this; \
420 }
421
422@@ -294,12 +292,12 @@
423 #undef ZORBA_INTEGER_OP
424
425 #define ZORBA_INTEGER_OP(N) \
426- template<class T> \
427- IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \
428- ascii::itoa_buf_type buf; \
429- value_type const temp( ascii::itoa( n, buf ) ); \
430- T::check_value( value_ = ftoi( value_ / temp ), true ); \
431- return *this; \
432+ template<class T> \
433+ IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \
434+ ascii::itoa_buf_type buf; \
435+ value_type const temp( ascii::itoa( n, buf ) ); \
436+ T::check_value( value_ = ftoi( value_ / temp ) ); \
437+ return *this; \
438 }
439
440 ZORBA_INTEGER_OP(long long)
441
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 static int const default_value = 0;
447
448 template<typename ValueType>
449- static ValueType check_value( ValueType n, bool ) {
450+ static ValueType check_value( ValueType n ) {
451 return n;
452 }
453
454- static MAPM const& check_value( MAPM const &n, bool ) {
455+ static MAPM const& check_value( MAPM const &n ) {
456 return n;
457 }
458
459 protected:
460- static void throw_error( std::string const&, bool );
461-
462 template<typename ValueType>
463- static void throw_error( ValueType n, char const *op,
464- bool throw_range_error ) {
465+ static void throw_error( ValueType n, char const *op ) {
466 std::string const what( BUILD_STRING( n, ": not ", op, " 0" ) );
467- throw_error( what, throw_range_error );
468+ throw std::range_error( what );
469 }
470
471- static void throw_error( MAPM const &n, char const *op,
472- bool throw_range_error );
473+ static void throw_error( MAPM const &n, char const *op );
474 };
475
476 struct nonPositive_traits : integer_traits {
477 template<typename ValueType>
478- static ValueType check_value( ValueType n, bool throw_range_error ) {
479+ static ValueType check_value( ValueType n ) {
480 if ( !ztd::le0( n ) )
481- throw_error( n, "<=", throw_range_error );
482+ throw_error( n, "<=" );
483 return n;
484 }
485- static MAPM const& check_value( MAPM const &n, bool throw_range_error ) {
486+ static MAPM const& check_value( MAPM const &n ) {
487 if ( !(n.sign() <= 0) )
488- throw_error( n, "<=", throw_range_error );
489+ throw_error( n, "<=" );
490 return n;
491 }
492 };
493@@ -95,28 +91,28 @@
494 static int const default_value = -1;
495
496 template<typename ValueType>
497- static ValueType check_value( ValueType n, bool throw_range_error ) {
498+ static ValueType check_value( ValueType n ) {
499 if ( !ztd::lt0( n ) )
500- throw_error( n, "<", throw_range_error );
501+ throw_error( n, "<" );
502 return n;
503 }
504- static MAPM const& check_value( MAPM const &n, bool throw_range_error ) {
505+ static MAPM const& check_value( MAPM const &n ) {
506 if ( !(n.sign() < 0) )
507- throw_error( n, "<", throw_range_error );
508+ throw_error( n, "<" );
509 return n;
510 }
511 };
512
513 struct nonNegative_traits : integer_traits {
514 template<typename ValueType>
515- static ValueType check_value( ValueType n, bool throw_range_error ) {
516+ static ValueType check_value( ValueType n ) {
517 if ( !ztd::ge0( n ) )
518- throw_error( n, ">=", throw_range_error );
519+ throw_error( n, ">=" );
520 return n;
521 }
522- static MAPM const& check_value( MAPM const &n, bool throw_range_error ) {
523+ static MAPM const& check_value( MAPM const &n ) {
524 if ( !(n.sign() >= 0) )
525- throw_error( n, ">=", throw_range_error );
526+ throw_error( n, ">=" );
527 return n;
528 }
529 };
530@@ -125,14 +121,14 @@
531 static int const default_value = 1;
532
533 template<typename ValueType>
534- static ValueType check_value( ValueType n, bool throw_range_error ) {
535+ static ValueType check_value( ValueType n ) {
536 if ( !ztd::gt0( n ) )
537- throw_error( n, ">", throw_range_error );
538+ throw_error( n, ">" );
539 return n;
540 }
541- static MAPM const& check_value( MAPM const &n, bool throw_range_error ) {
542+ static MAPM const& check_value( MAPM const &n ) {
543 if ( !(n.sign() > 0) )
544- throw_error( n, ">", throw_range_error );
545+ throw_error( n, ">" );
546 return n;
547 }
548 };
549@@ -174,8 +170,7 @@
550 * whitespace is ignored.
551 * @throw std::invalid_argument if \a s does not contain a valid integer.
552 * @throw std::range_error if \a s contains an integer that either underflows
553- * or overflows the smallest or largest representable integer (only when not
554- * compiled with ZORBA_WITH_BIG_INTEGER).
555+ * or overflows the smallest or largest representable/legal integer.
556 */
557 explicit IntegerImpl( char const *s );
558
559@@ -596,7 +591,7 @@
560 }
561 #endif /* ZORBA_WITH_BIG_INTEGER */
562
563- void parse( char const *s, bool throw_range_error );
564+ void parse( char const *s );
565
566 friend class Decimal;
567 template<typename F> friend class FloatImpl;
568@@ -623,51 +618,51 @@
569
570 template<class T>
571 inline IntegerImpl<T>::IntegerImpl( char c ) :
572- value_( static_cast<long>( T::check_value( c, false ) ) )
573+ value_( static_cast<long>( T::check_value( c ) ) )
574 {
575 }
576
577 template<class T>
578 inline IntegerImpl<T>::IntegerImpl( signed char c ) :
579- value_( static_cast<long>( T::check_value( c, false ) ) )
580+ value_( static_cast<long>( T::check_value( c ) ) )
581 {
582 }
583
584 template<class T>
585 inline IntegerImpl<T>::IntegerImpl( short n ) :
586- value_( static_cast<long>( T::check_value( n, false ) ) )
587+ value_( static_cast<long>( T::check_value( n ) ) )
588 {
589 }
590
591 template<class T>
592 inline IntegerImpl<T>::IntegerImpl( int n ) :
593- value_( static_cast<long>( T::check_value( n, false ) ) )
594+ value_( static_cast<long>( T::check_value( n ) ) )
595 {
596 }
597
598 template<class T>
599 inline IntegerImpl<T>::IntegerImpl( long n ) :
600- value_( T::check_value( n, false ) )
601+ value_( T::check_value( n ) )
602 {
603 }
604
605 #ifndef ZORBA_WITH_BIG_INTEGER
606 template<class T>
607 inline IntegerImpl<T>::IntegerImpl( long long n ) :
608- value_( T::check_value( n, false ) )
609+ value_( T::check_value( n ) )
610 {
611 }
612 #endif /* ZORBA_WITH_BIG_INTEGER */
613
614 template<class T>
615 inline IntegerImpl<T>::IntegerImpl( unsigned char c ) :
616- value_( static_cast<long>( (unsigned long)T::check_value( c, false ) ) )
617+ value_( static_cast<long>( (unsigned long)T::check_value( c ) ) )
618 {
619 }
620
621 template<class T>
622 inline IntegerImpl<T>::IntegerImpl( unsigned short n ) :
623- value_( static_cast<long>( (unsigned long)T::check_value( n, false ) ) )
624+ value_( static_cast<long>( (unsigned long)T::check_value( n ) ) )
625 {
626 }
627
628@@ -675,7 +670,7 @@
629 #if ZORBA_SIZEOF_INT != ZORBA_SIZEOF_LONG
630 template<class T>
631 inline IntegerImpl<T>::IntegerImpl( unsigned int n ) :
632- value_( static_cast<long>( (unsigned long)T::check_value( n, false ) ) )
633+ value_( static_cast<long>( (unsigned long)T::check_value( n ) ) )
634 {
635 }
636 #endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */
637@@ -683,19 +678,19 @@
638
639 template<class T>
640 inline IntegerImpl<T>::IntegerImpl( unsigned int n ) :
641- value_( static_cast<value_type>( T::check_value( n, false ) ) )
642+ value_( static_cast<value_type>( T::check_value( n ) ) )
643 {
644 }
645
646 template<class T>
647 inline IntegerImpl<T>::IntegerImpl( unsigned long n ) :
648- value_( static_cast<value_type>( T::check_value( n, false ) ) )
649+ value_( static_cast<value_type>( T::check_value( n ) ) )
650 {
651 }
652
653 template<class T>
654 inline IntegerImpl<T>::IntegerImpl( unsigned long long n ) :
655- value_( static_cast<value_type>( T::check_value( n, false ) ) )
656+ value_( static_cast<value_type>( T::check_value( n ) ) )
657 {
658 }
659 #endif /* ZORBA_WITH_BIG_INTEGER */
660@@ -703,9 +698,9 @@
661 template<class T>
662 inline IntegerImpl<T>::IntegerImpl( float n ) :
663 #ifdef ZORBA_WITH_BIG_INTEGER
664- value_( static_cast<double>( T::check_value( n, false ) ) )
665+ value_( static_cast<double>( T::check_value( n ) ) )
666 #else
667- value_( static_cast<value_type>( T::check_value( n, false ) ) )
668+ value_( static_cast<value_type>( T::check_value( n ) ) )
669 #endif /* ZORBA_WITH_BIG_INTEGER */
670 {
671 }
672@@ -713,32 +708,32 @@
673 template<class T>
674 inline IntegerImpl<T>::IntegerImpl( double n ) :
675 #ifdef ZORBA_WITH_BIG_INTEGER
676- value_( T::check_value( n, false ) )
677+ value_( T::check_value( n ) )
678 #else
679- value_( static_cast<value_type>( T::check_value( n, false ) ) )
680+ value_( static_cast<value_type>( T::check_value( n ) ) )
681 #endif /* ZORBA_WITH_BIG_INTEGER */
682 {
683 }
684
685 template<class T>
686 inline IntegerImpl<T>::IntegerImpl( char const *s ) {
687- parse( s, false );
688+ parse( s );
689 }
690
691 template<class T>
692 template<class U>
693 inline IntegerImpl<T>::IntegerImpl( IntegerImpl<U> const &i ) :
694- value_( T::check_value( i.value_, false ) )
695+ value_( T::check_value( i.value_ ) )
696 {
697 }
698
699 ////////// assignment operators ///////////////////////////////////////////////
700
701-#define ZORBA_ASSIGN_OP(N) \
702- template<class T> inline \
703- IntegerImpl<T>& IntegerImpl<T>::operator=( N n ) { \
704- value_ = static_cast<int_cast_type>( T::check_value( n, false ) ); \
705- return *this; \
706+#define ZORBA_ASSIGN_OP(N) \
707+ template<class T> inline \
708+ IntegerImpl<T>& IntegerImpl<T>::operator=( N n ) { \
709+ value_ = static_cast<int_cast_type>( T::check_value( n ) ); \
710+ return *this; \
711 }
712
713 ZORBA_ASSIGN_OP(char)
714@@ -760,14 +755,14 @@
715
716 template<class T>
717 inline IntegerImpl<T>& IntegerImpl<T>::operator=( char const *s ) {
718- parse( s, false );
719+ parse( s );
720 return *this;
721 }
722
723 template<class T>
724 template<class U>
725 inline IntegerImpl<T>& IntegerImpl<T>::operator=( IntegerImpl<U> const &i ) {
726- T::check_value( value_ = i.value_, false );
727+ T::check_value( value_ = i.value_ );
728 return *this;
729 }
730
731@@ -888,7 +883,7 @@
732 #define ZORBA_INTEGER_OP(OP) \
733 template<class T> inline \
734 IntegerImpl<T>& IntegerImpl<T>::operator OP( IntegerImpl<T> const &i ) { \
735- T::check_value( value_ OP i.value_, true ); \
736+ T::check_value( value_ OP i.value_ ); \
737 return *this; \
738 }
739
740@@ -900,15 +895,15 @@
741
742 template<class T>
743 inline IntegerImpl<T>& IntegerImpl<T>::operator/=( IntegerImpl<T> const &i ) {
744- value_ = T::check_value( ftoi( value_ / i.value_ ), true );
745+ value_ = T::check_value( ftoi( value_ / i.value_ ) );
746 return *this;
747 }
748
749-#define ZORBA_INTEGER_OP(OP,N) \
750- template<class T> inline \
751- IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \
752- T::check_value( value_ OP make_value_type( n ), true ); \
753- return *this; \
754+#define ZORBA_INTEGER_OP(OP,N) \
755+ template<class T> inline \
756+ IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \
757+ T::check_value( value_ OP make_value_type( n ) ); \
758+ return *this; \
759 }
760
761 ZORBA_INTEGER_OP(+=,char)
762@@ -967,11 +962,11 @@
763 #endif /* ZORBA_WITH_BIG_INTEGER */
764 #undef ZORBA_INTEGER_OP
765
766-#define ZORBA_INTEGER_OP(N) \
767- template<class T> inline \
768- IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \
769- value_ = T::check_value( ftoi( value_ / make_value_type( n ) ), true ); \
770- return *this; \
771+#define ZORBA_INTEGER_OP(N) \
772+ template<class T> inline \
773+ IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \
774+ value_ = T::check_value( ftoi( value_ / make_value_type( n ) ) ); \
775+ return *this; \
776 }
777
778 ZORBA_INTEGER_OP(char)
779@@ -998,27 +993,27 @@
780
781 template<class T>
782 inline IntegerImpl<T>& IntegerImpl<T>::operator++() {
783- T::check_value( ++value_, true );
784+ T::check_value( ++value_ );
785 return *this;
786 }
787
788 template<class T>
789 inline IntegerImpl<T> IntegerImpl<T>::operator++(int) {
790 IntegerImpl<T> const result( *this );
791- T::check_value( ++value_, true );
792+ T::check_value( ++value_ );
793 return result;
794 }
795
796 template<class T>
797 inline IntegerImpl<T>& IntegerImpl<T>::operator--() {
798- T::check_value( --value_, true );
799+ T::check_value( --value_ );
800 return *this;
801 }
802
803 template<class T>
804 inline IntegerImpl<T> IntegerImpl<T>::operator--(int) {
805 IntegerImpl<T> const result( *this );
806- T::check_value( --value_, true );
807+ T::check_value( --value_ );
808 return result;
809 }
810

Subscribers

People subscribed via source and target branches