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
=== modified file 'src/runtime/core/path_iterators.cpp'
--- src/runtime/core/path_iterators.cpp 2013-04-09 13:08:21 +0000
+++ src/runtime/core/path_iterators.cpp 2013-05-20 23:18:26 +0000
@@ -1145,7 +1145,7 @@
1145 1145
1146 if (!state->theContextNode->isNode())1146 if (!state->theContextNode->isNode())
1147 {1147 {
1148 assert(false);1148 //assert(false);
1149 throw XQUERY_EXCEPTION(err::XPTY0020, ERROR_LOC(loc));1149 throw XQUERY_EXCEPTION(err::XPTY0020, ERROR_LOC(loc));
1150 }1150 }
1151 }1151 }
11521152
=== modified file 'src/types/casting.cpp'
--- src/types/casting.cpp 2013-05-16 22:26:07 +0000
+++ src/types/casting.cpp 2013-05-20 23:18:26 +0000
@@ -385,7 +385,11 @@
385 xs_decimal const n(strval.c_str());385 xs_decimal const n(strval.c_str());
386 aFactory->createDecimal(result, n);386 aFactory->createDecimal(result, n);
387 }387 }
388 catch (const std::exception& ) 388 catch (const std::invalid_argument& )
389 {
390 throwFOCA0002Exception(strval, errInfo);
391 }
392 catch (const std::range_error& )
389 {393 {
390 throwFORG0001Exception(strval, errInfo);394 throwFORG0001Exception(strval, errInfo);
391 }395 }
@@ -401,12 +405,12 @@
401 }405 }
402 catch (const std::invalid_argument& ) 406 catch (const std::invalid_argument& )
403 {407 {
408 throwFOCA0002Exception(strval, errInfo);
409 }
410 catch (const std::range_error& )
411 {
404 throwFORG0001Exception(strval, errInfo);412 throwFORG0001Exception(strval, errInfo);
405 }413 }
406 catch (const std::range_error& )
407 {
408 RAISE_ERROR(err::FOAR0002, errInfo.theLoc, ERROR_PARAMS(strval));
409 }
410}414}
411415
412416
@@ -419,11 +423,11 @@
419 }423 }
420 catch ( std::invalid_argument const& )424 catch ( std::invalid_argument const& )
421 {425 {
422 throwFORG0001Exception(strval, errInfo);426 throwFOCA0002Exception(strval, errInfo);
423 }427 }
424 catch ( std::range_error const& )428 catch ( std::range_error const& )
425 {429 {
426 RAISE_ERROR(err::FOAR0002, errInfo.theLoc, ERROR_PARAMS(strval));430 throwFORG0001Exception(strval, errInfo);
427 }431 }
428}432}
429433
@@ -993,15 +997,16 @@
993997
994T1_TO_T2(flt, int)998T1_TO_T2(flt, int)
995{999{
996 xs_float const f( aItem->getFloatValue() );
997 if ( !f.isFinite() )
998 throwFOCA0002Exception(aItem->getStringValue(), errInfo);
999 try 1000 try
1000 {1001 {
1001 xs_integer const n( f );1002 xs_integer const n( aItem->getFloatValue() );
1002 aFactory->createInteger(result, n);1003 aFactory->createInteger(result, n);
1003 }1004 }
1004 catch (const std::exception&) 1005 catch ( std::invalid_argument const& )
1006 {
1007 throwFOCA0002Exception(aItem->getStringValue(), errInfo);
1008 }
1009 catch (const std::range_error&)
1005 {1010 {
1006 throwFOCA0003Exception(aItem->getStringValue(), errInfo);1011 throwFOCA0003Exception(aItem->getStringValue(), errInfo);
1007 }1012 }
@@ -1050,15 +1055,16 @@
10501055
1051T1_TO_T2(dbl, int)1056T1_TO_T2(dbl, int)
1052{1057{
1053 xs_double const d( aItem->getDoubleValue() );
1054 if ( !d.isFinite() )
1055 throwFOCA0002Exception(aItem->getStringValue(), errInfo);
1056 try 1058 try
1057 {1059 {
1058 xs_integer const n( d );1060 xs_integer const n( aItem->getDoubleValue() );
1059 aFactory->createInteger(result, n);1061 aFactory->createInteger(result, n);
1060 }1062 }
1061 catch (const std::exception& ) 1063 catch ( std::invalid_argument const& )
1064 {
1065 throwFOCA0002Exception(aItem->getStringValue(), errInfo);
1066 }
1067 catch (const std::range_error&)
1062 {1068 {
1063 throwFOCA0003Exception(aItem->getStringValue(), errInfo);1069 throwFOCA0003Exception(aItem->getStringValue(), errInfo);
1064 }1070 }
@@ -1679,10 +1685,14 @@
1679 xs_nonNegativeInteger const n(aItem->getIntegerValue());1685 xs_nonNegativeInteger const n(aItem->getIntegerValue());
1680 aFactory->createNonNegativeInteger(result, n);1686 aFactory->createNonNegativeInteger(result, n);
1681 }1687 }
1682 catch (const std::exception& ) 1688 catch ( std::invalid_argument const& )
1683 {1689 {
1684 throwFOCA0002Exception(aItem->getStringValue(), errInfo);1690 throwFOCA0002Exception(aItem->getStringValue(), errInfo);
1685 }1691 }
1692 catch ( std::range_error const& )
1693 {
1694 throwFORG0001Exception(aItem->getStringValue(), errInfo);
1695 }
1686}1696}
16871697
16881698
16891699
=== modified file 'src/zorbatypes/decimal.cpp'
--- src/zorbatypes/decimal.cpp 2013-05-15 23:22:01 +0000
+++ src/zorbatypes/decimal.cpp 2013-05-20 23:18:26 +0000
@@ -36,8 +36,15 @@
36Decimal::value_type const Decimal::round_precision_limit( 64 );36Decimal::value_type const Decimal::round_precision_limit( 64 );
3737
38void Decimal::parse( char const *s, value_type *result, int parse_options ) {38void Decimal::parse( char const *s, value_type *result, int parse_options ) {
39 if ( !*s )39 if ( !*s ) {
40 throw invalid_argument( "empty string" );40 //
41 // In an ideal world, this would throw invalid_argument. The XQuery spec
42 // wants FORG0001 to be raised, but invalid_argument is being mapped to
43 // FOCA0002; instead, range_error is mapped to FORG0001, so we throw
44 // range_error.
45 //
46 throw range_error( "empty string" );
47 }
4148
42 s = ascii::trim_start_space( s );49 s = ascii::trim_start_space( s );
43 char const *const first_non_ws = s;50 char const *const first_non_ws = s;
@@ -60,7 +67,9 @@
60 ++s;67 ++s;
61 }68 }
62 if ( *s )69 if ( *s )
63 throw invalid_argument( BUILD_STRING( '"', *s, "\": invalid character" ) );70 throw range_error(
71 BUILD_STRING( '"', *s, "\": invalid value for integer" )
72 );
6473
65 if ( first_trailing_ws ) {74 if ( first_trailing_ws ) {
66 ptrdiff_t const size = first_trailing_ws - first_non_ws;75 ptrdiff_t const size = first_trailing_ws - first_non_ws;
6776
=== modified file 'src/zorbatypes/float.cpp'
--- src/zorbatypes/float.cpp 2013-05-15 23:22:01 +0000
+++ src/zorbatypes/float.cpp 2013-05-20 23:18:26 +0000
@@ -119,19 +119,19 @@
119 significant_digits : max_precision();119 significant_digits : max_precision();
120}120}
121121
122template<typename FloatType>122template<typename F>
123bool FloatImpl<FloatType>::parse_etc( char const *s ) {123bool FloatImpl<F>::parse_etc( char const *s ) {
124 if ( strncmp( s, "INF", 3 ) == 0 ) {124 if ( strncmp( s, "INF", 3 ) == 0 ) {
125 value_ = FloatImpl<FloatType>::pos_inf().value_;125 value_ = FloatImpl<F>::pos_inf().value_;
126 s += 3;126 s += 3;
127 } else if ( strncmp( s, "-INF", 4 ) == 0 ) {127 } else if ( strncmp( s, "-INF", 4 ) == 0 ) {
128 value_ = FloatImpl<FloatType>::neg_inf().value_;128 value_ = FloatImpl<F>::neg_inf().value_;
129 s += 4;129 s += 4;
130 } else if ( strncmp( s, "NaN", 3 ) == 0 ) {130 } else if ( strncmp( s, "NaN", 3 ) == 0 ) {
131 value_ = FloatImpl<FloatType>::nan().value_;131 value_ = FloatImpl<F>::nan().value_;
132 s += 3;132 s += 3;
133 } else if ( strncmp( s, "+INF", 4 ) == 0 ) { // allowed by XSD 1.1133 } else if ( strncmp( s, "+INF", 4 ) == 0 ) { // allowed by XSD 1.1
134 value_ = FloatImpl<FloatType>::pos_inf().value_;134 value_ = FloatImpl<F>::pos_inf().value_;
135 s += 4;135 s += 4;
136 } else136 } else
137 return false;137 return false;
@@ -154,17 +154,22 @@
154 parse( temp.c_str() );154 parse( temp.c_str() );
155}155}
156156
157template FloatImpl<float>::FloatImpl( Integer const& );157#define ZORBA_INSTANTIATE(F,I) \
158template FloatImpl<float>::FloatImpl( NegativeInteger const& );158 template FloatImpl<F>::FloatImpl( I const& )
159template FloatImpl<float>::FloatImpl( NonNegativeInteger const& );159
160template FloatImpl<float>::FloatImpl( NonPositiveInteger const& );160
161template FloatImpl<float>::FloatImpl( PositiveInteger const& );161ZORBA_INSTANTIATE(float,Integer);
162162ZORBA_INSTANTIATE(float,NegativeInteger);
163template FloatImpl<double>::FloatImpl( Integer const& );163ZORBA_INSTANTIATE(float,NonNegativeInteger);
164template FloatImpl<double>::FloatImpl( NegativeInteger const& );164ZORBA_INSTANTIATE(float,NonPositiveInteger);
165template FloatImpl<double>::FloatImpl( NonNegativeInteger const& );165ZORBA_INSTANTIATE(float,PositiveInteger);
166template FloatImpl<double>::FloatImpl( NonPositiveInteger const& );166
167template FloatImpl<double>::FloatImpl( PositiveInteger const& );167ZORBA_INSTANTIATE(double,Integer);
168ZORBA_INSTANTIATE(double,NegativeInteger);
169ZORBA_INSTANTIATE(double,NonNegativeInteger);
170ZORBA_INSTANTIATE(double,NonPositiveInteger);
171ZORBA_INSTANTIATE(double,PositiveInteger);
172#undef ZORBA_INSTANTIATE
168173
169////////// assignment operators ///////////////////////////////////////////////174////////// assignment operators ///////////////////////////////////////////////
170175
@@ -343,7 +348,7 @@
343zstring FloatImpl<F>::toIntegerString() const {348zstring FloatImpl<F>::toIntegerString() const {
344 if ( isNaN() )349 if ( isNaN() )
345 return nan_str();350 return nan_str();
346 if (isPosInf() )351 if ( isPosInf() )
347 return pos_inf_str();352 return pos_inf_str();
348 if ( isNegInf() )353 if ( isNegInf() )
349 return neg_inf_str();354 return neg_inf_str();
350355
=== modified file 'src/zorbatypes/float.h'
--- src/zorbatypes/float.h 2013-05-15 23:22:01 +0000
+++ src/zorbatypes/float.h 2013-05-20 23:18:26 +0000
@@ -292,9 +292,8 @@
292 void parse( char const* );292 void parse( char const* );
293 bool parse_etc( char const* );293 bool parse_etc( char const* );
294294
295 friend class Decimal;
295 template<class T> friend class IntegerImpl;296 template<class T> friend class IntegerImpl;
296 friend class Decimal;
297
298 friend class FloatImpl<float>;297 friend class FloatImpl<float>;
299 friend class FloatImpl<double>;298 friend class FloatImpl<double>;
300};299};
301300
=== modified file 'src/zorbatypes/integer.cpp'
--- src/zorbatypes/integer.cpp 2013-05-16 00:07:00 +0000
+++ src/zorbatypes/integer.cpp 2013-05-20 23:18:26 +0000
@@ -37,18 +37,11 @@
3737
38///////////////////////////////////////////////////////////////////////////////38///////////////////////////////////////////////////////////////////////////////
3939
40void integer_traits::throw_error( string const &what, bool throw_range_error ) {40void integer_traits::throw_error( MAPM const &n, char const *op ) {
41 if ( throw_range_error )
42 throw range_error( what );
43 throw invalid_argument( what );
44}
45
46void integer_traits::throw_error( MAPM const &n, char const *op,
47 bool throw_range_error ) {
48 unique_ptr<char[]> const buf( new char[ n.exponent() + 3 ] );41 unique_ptr<char[]> const buf( new char[ n.exponent() + 3 ] );
49 n.toIntegerString( buf.get() );42 n.toIntegerString( buf.get() );
50 string const what( BUILD_STRING( buf.get(), ": not ", op, " 0" ) );43 string const what( BUILD_STRING( buf.get(), ": not ", op, " 0" ) );
51 throw_error( what, throw_range_error );44 throw range_error( what );
52}45}
5346
54///////////////////////////////////////////////////////////////////////////////47///////////////////////////////////////////////////////////////////////////////
@@ -60,20 +53,25 @@
60 value_type const i = d;53 value_type const i = d;
61 if ( i != d )54 if ( i != d )
62 throw range_error(55 throw range_error(
63 BUILD_STRING( '"', d, "\": value too large for integer" )56 BUILD_STRING( '"', d, "\": value too large/small for integer" )
64 );57 );
65 return i;58 return i;
66}59}
67#endif /* ZORBA_WITH_BIG_INTEGER */60#endif /* ZORBA_WITH_BIG_INTEGER */
6861
69template<class T>62template<class T>
70void IntegerImpl<T>::parse( char const *s, bool throw_range_error ) {63void IntegerImpl<T>::parse( char const *s ) {
64 try {
71#ifdef ZORBA_WITH_BIG_INTEGER65#ifdef ZORBA_WITH_BIG_INTEGER
72 Decimal::parse( s, &value_, Decimal::parse_integer );66 Decimal::parse( s, &value_, Decimal::parse_integer );
73#else67#else
74 value_ = ztd::aton<value_type>( s );68 value_ = ztd::aton<value_type>( s );
75#endif /* ZORBA_WITH_BIG_INTEGER */69#endif /* ZORBA_WITH_BIG_INTEGER */
76 T::check_value( value_, throw_range_error );70 }
71 catch ( invalid_argument const &e ) {
72 throw range_error( e.what() );
73 }
74 T::check_value( value_ );
77}75}
7876
79////////// constructors ///////////////////////////////////////////////////////77////////// constructors ///////////////////////////////////////////////////////
@@ -83,7 +81,7 @@
83IntegerImpl<T>::IntegerImpl( long long n ) {81IntegerImpl<T>::IntegerImpl( long long n ) {
84 ascii::itoa_buf_type buf;82 ascii::itoa_buf_type buf;
85 value_ = ascii::itoa( n, buf );83 value_ = ascii::itoa( n, buf );
86 T::check_value( value_, false );84 T::check_value( value_ );
87}85}
8886
89#if ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG87#if ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG
@@ -91,7 +89,7 @@
91IntegerImpl<T>::IntegerImpl( unsigned int n ) {89IntegerImpl<T>::IntegerImpl( unsigned int n ) {
92 ascii::itoa_buf_type buf;90 ascii::itoa_buf_type buf;
93 value_ = ascii::itoa( n, buf );91 value_ = ascii::itoa( n, buf );
94 T::check_value( value_, false );92 T::check_value( value_ );
95}93}
96#endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */94#endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */
9795
@@ -99,34 +97,34 @@
99IntegerImpl<T>::IntegerImpl( unsigned long n ) {97IntegerImpl<T>::IntegerImpl( unsigned long n ) {
100 ascii::itoa_buf_type buf;98 ascii::itoa_buf_type buf;
101 value_ = ascii::itoa( n, buf );99 value_ = ascii::itoa( n, buf );
102 T::check_value( value_, false );100 T::check_value( value_ );
103}101}
104102
105template<class T>103template<class T>
106IntegerImpl<T>::IntegerImpl( unsigned long long n ) {104IntegerImpl<T>::IntegerImpl( unsigned long long n ) {
107 ascii::itoa_buf_type buf;105 ascii::itoa_buf_type buf;
108 value_ = ascii::itoa( n, buf );106 value_ = ascii::itoa( n, buf );
109 T::check_value( value_, false );107 T::check_value( value_ );
110}108}
111#endif /* ZORBA_WITH_BIG_INTEGER */109#endif /* ZORBA_WITH_BIG_INTEGER */
112110
113template<class T>111template<class T>
114IntegerImpl<T>::IntegerImpl( Decimal const &d ) {112IntegerImpl<T>::IntegerImpl( Decimal const &d ) {
115 value_ = T::check_value( ftoi( d.value_ ), false );113 value_ = T::check_value( ftoi( d.value_ ) );
116}114}
117115
118template<class T>116template<class T>
119IntegerImpl<T>::IntegerImpl( Double const &d ) {117IntegerImpl<T>::IntegerImpl( Double const &d ) {
120 if ( !d.isFinite() )118 if ( !d.isFinite() )
121 throw std::invalid_argument( "not finite" );119 throw invalid_argument( "not finite" );
122 value_ = T::check_value( ftoi( d.getNumber() ), false );120 value_ = T::check_value( ftoi( d.getNumber() ) );
123}121}
124122
125template<class T>123template<class T>
126IntegerImpl<T>::IntegerImpl( Float const &f ) {124IntegerImpl<T>::IntegerImpl( Float const &f ) {
127 if ( !f.isFinite() )125 if ( !f.isFinite() )
128 throw std::invalid_argument( "not finite" );126 throw invalid_argument( "not finite" );
129 value_ = T::check_value( ftoi( f.getNumber() ), false );127 value_ = T::check_value( ftoi( f.getNumber() ) );
130}128}
131129
132////////// assignment operators ///////////////////////////////////////////////130////////// assignment operators ///////////////////////////////////////////////
@@ -136,7 +134,7 @@
136IntegerImpl<T>& IntegerImpl<T>::operator=( long long n ) {134IntegerImpl<T>& IntegerImpl<T>::operator=( long long n ) {
137 ascii::itoa_buf_type buf;135 ascii::itoa_buf_type buf;
138 value_ = ascii::itoa( n, buf );136 value_ = ascii::itoa( n, buf );
139 T::check_value( value_, true );137 T::check_value( value_ );
140 return *this;138 return *this;
141}139}
142140
@@ -144,7 +142,7 @@
144IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long n ) {142IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long n ) {
145 ascii::itoa_buf_type buf;143 ascii::itoa_buf_type buf;
146 value_ = ascii::itoa( n, buf );144 value_ = ascii::itoa( n, buf );
147 T::check_value( value_, true );145 T::check_value( value_ );
148 return *this;146 return *this;
149}147}
150148
@@ -152,30 +150,30 @@
152IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long long n ) {150IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long long n ) {
153 ascii::itoa_buf_type buf;151 ascii::itoa_buf_type buf;
154 value_ = ascii::itoa( n, buf );152 value_ = ascii::itoa( n, buf );
155 T::check_value( value_, true );153 T::check_value( value_ );
156 return *this;154 return *this;
157}155}
158#endif /* ZORBA_WITH_BIG_INTEGER */156#endif /* ZORBA_WITH_BIG_INTEGER */
159157
160template<class T>158template<class T>
161IntegerImpl<T>& IntegerImpl<T>::operator=( Decimal const &d ) {159IntegerImpl<T>& IntegerImpl<T>::operator=( Decimal const &d ) {
162 value_ = T::check_value( ftoi( d.value_ ), true );160 value_ = T::check_value( ftoi( d.value_ ) );
163 return *this;161 return *this;
164}162}
165163
166template<class T>164template<class T>
167IntegerImpl<T>& IntegerImpl<T>::operator=( Double const &d ) {165IntegerImpl<T>& IntegerImpl<T>::operator=( Double const &d ) {
168 if ( !d.isFinite() )166 if ( !d.isFinite() )
169 throw std::invalid_argument( "not finite" );167 throw invalid_argument( "not finite" );
170 value_ = T::check_value( ftoi( d.getNumber() ), true );168 value_ = T::check_value( ftoi( d.getNumber() ) );
171 return *this;169 return *this;
172}170}
173171
174template<class T>172template<class T>
175IntegerImpl<T>& IntegerImpl<T>::operator=( Float const &f ) {173IntegerImpl<T>& IntegerImpl<T>::operator=( Float const &f ) {
176 if ( !f.isFinite() )174 if ( !f.isFinite() )
177 throw std::invalid_argument( "not finite" );175 throw invalid_argument( "not finite" );
178 value_ = T::check_value( ftoi( f.getNumber() ), true );176 value_ = T::check_value( ftoi( f.getNumber() ) );
179 return *this;177 return *this;
180}178}
181179
@@ -275,7 +273,7 @@
275 IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \273 IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \
276 ascii::itoa_buf_type buf; \274 ascii::itoa_buf_type buf; \
277 value_type const temp( ascii::itoa( n, buf ) ); \275 value_type const temp( ascii::itoa( n, buf ) ); \
278 T::check_value( value_ OP temp, true ); \276 T::check_value( value_ OP temp ); \
279 return *this; \277 return *this; \
280 }278 }
281279
@@ -294,12 +292,12 @@
294#undef ZORBA_INTEGER_OP292#undef ZORBA_INTEGER_OP
295293
296#define ZORBA_INTEGER_OP(N) \294#define ZORBA_INTEGER_OP(N) \
297 template<class T> \295 template<class T> \
298 IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \296 IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \
299 ascii::itoa_buf_type buf; \297 ascii::itoa_buf_type buf; \
300 value_type const temp( ascii::itoa( n, buf ) ); \298 value_type const temp( ascii::itoa( n, buf ) ); \
301 T::check_value( value_ = ftoi( value_ / temp ), true ); \299 T::check_value( value_ = ftoi( value_ / temp ) ); \
302 return *this; \300 return *this; \
303 }301 }
304302
305ZORBA_INTEGER_OP(long long)303ZORBA_INTEGER_OP(long long)
306304
=== modified file 'src/zorbatypes/integer.h'
--- src/zorbatypes/integer.h 2013-05-16 19:05:52 +0000
+++ src/zorbatypes/integer.h 2013-05-20 23:18:26 +0000
@@ -55,38 +55,34 @@
55 static int const default_value = 0;55 static int const default_value = 0;
5656
57 template<typename ValueType>57 template<typename ValueType>
58 static ValueType check_value( ValueType n, bool ) {58 static ValueType check_value( ValueType n ) {
59 return n;59 return n;
60 }60 }
6161
62 static MAPM const& check_value( MAPM const &n, bool ) {62 static MAPM const& check_value( MAPM const &n ) {
63 return n;63 return n;
64 }64 }
6565
66protected:66protected:
67 static void throw_error( std::string const&, bool );
68
69 template<typename ValueType>67 template<typename ValueType>
70 static void throw_error( ValueType n, char const *op,68 static void throw_error( ValueType n, char const *op ) {
71 bool throw_range_error ) {
72 std::string const what( BUILD_STRING( n, ": not ", op, " 0" ) );69 std::string const what( BUILD_STRING( n, ": not ", op, " 0" ) );
73 throw_error( what, throw_range_error );70 throw std::range_error( what );
74 }71 }
7572
76 static void throw_error( MAPM const &n, char const *op,73 static void throw_error( MAPM const &n, char const *op );
77 bool throw_range_error );
78};74};
7975
80struct nonPositive_traits : integer_traits {76struct nonPositive_traits : integer_traits {
81 template<typename ValueType>77 template<typename ValueType>
82 static ValueType check_value( ValueType n, bool throw_range_error ) {78 static ValueType check_value( ValueType n ) {
83 if ( !ztd::le0( n ) )79 if ( !ztd::le0( n ) )
84 throw_error( n, "<=", throw_range_error );80 throw_error( n, "<=" );
85 return n;81 return n;
86 }82 }
87 static MAPM const& check_value( MAPM const &n, bool throw_range_error ) {83 static MAPM const& check_value( MAPM const &n ) {
88 if ( !(n.sign() <= 0) )84 if ( !(n.sign() <= 0) )
89 throw_error( n, "<=", throw_range_error );85 throw_error( n, "<=" );
90 return n;86 return n;
91 }87 }
92};88};
@@ -95,28 +91,28 @@
95 static int const default_value = -1;91 static int const default_value = -1;
9692
97 template<typename ValueType>93 template<typename ValueType>
98 static ValueType check_value( ValueType n, bool throw_range_error ) {94 static ValueType check_value( ValueType n ) {
99 if ( !ztd::lt0( n ) )95 if ( !ztd::lt0( n ) )
100 throw_error( n, "<", throw_range_error );96 throw_error( n, "<" );
101 return n;97 return n;
102 }98 }
103 static MAPM const& check_value( MAPM const &n, bool throw_range_error ) {99 static MAPM const& check_value( MAPM const &n ) {
104 if ( !(n.sign() < 0) )100 if ( !(n.sign() < 0) )
105 throw_error( n, "<", throw_range_error );101 throw_error( n, "<" );
106 return n;102 return n;
107 }103 }
108};104};
109105
110struct nonNegative_traits : integer_traits {106struct nonNegative_traits : integer_traits {
111 template<typename ValueType>107 template<typename ValueType>
112 static ValueType check_value( ValueType n, bool throw_range_error ) {108 static ValueType check_value( ValueType n ) {
113 if ( !ztd::ge0( n ) )109 if ( !ztd::ge0( n ) )
114 throw_error( n, ">=", throw_range_error );110 throw_error( n, ">=" );
115 return n;111 return n;
116 }112 }
117 static MAPM const& check_value( MAPM const &n, bool throw_range_error ) {113 static MAPM const& check_value( MAPM const &n ) {
118 if ( !(n.sign() >= 0) )114 if ( !(n.sign() >= 0) )
119 throw_error( n, ">=", throw_range_error );115 throw_error( n, ">=" );
120 return n;116 return n;
121 }117 }
122};118};
@@ -125,14 +121,14 @@
125 static int const default_value = 1;121 static int const default_value = 1;
126122
127 template<typename ValueType>123 template<typename ValueType>
128 static ValueType check_value( ValueType n, bool throw_range_error ) {124 static ValueType check_value( ValueType n ) {
129 if ( !ztd::gt0( n ) )125 if ( !ztd::gt0( n ) )
130 throw_error( n, ">", throw_range_error );126 throw_error( n, ">" );
131 return n;127 return n;
132 }128 }
133 static MAPM const& check_value( MAPM const &n, bool throw_range_error ) {129 static MAPM const& check_value( MAPM const &n ) {
134 if ( !(n.sign() > 0) )130 if ( !(n.sign() > 0) )
135 throw_error( n, ">", throw_range_error );131 throw_error( n, ">" );
136 return n;132 return n;
137 }133 }
138};134};
@@ -174,8 +170,7 @@
174 * whitespace is ignored.170 * whitespace is ignored.
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.
176 * @throw std::range_error if \a s contains an integer that either underflows172 * @throw std::range_error if \a s contains an integer that either underflows
177 * or overflows the smallest or largest representable integer (only when not173 * or overflows the smallest or largest representable/legal integer.
178 * compiled with ZORBA_WITH_BIG_INTEGER).
179 */174 */
180 explicit IntegerImpl( char const *s );175 explicit IntegerImpl( char const *s );
181176
@@ -596,7 +591,7 @@
596 }591 }
597#endif /* ZORBA_WITH_BIG_INTEGER */592#endif /* ZORBA_WITH_BIG_INTEGER */
598593
599 void parse( char const *s, bool throw_range_error );594 void parse( char const *s );
600595
601 friend class Decimal;596 friend class Decimal;
602 template<typename F> friend class FloatImpl;597 template<typename F> friend class FloatImpl;
@@ -623,51 +618,51 @@
623618
624template<class T>619template<class T>
625inline IntegerImpl<T>::IntegerImpl( char c ) :620inline IntegerImpl<T>::IntegerImpl( char c ) :
626 value_( static_cast<long>( T::check_value( c, false ) ) )621 value_( static_cast<long>( T::check_value( c ) ) )
627{622{
628}623}
629624
630template<class T>625template<class T>
631inline IntegerImpl<T>::IntegerImpl( signed char c ) :626inline IntegerImpl<T>::IntegerImpl( signed char c ) :
632 value_( static_cast<long>( T::check_value( c, false ) ) )627 value_( static_cast<long>( T::check_value( c ) ) )
633{628{
634}629}
635630
636template<class T>631template<class T>
637inline IntegerImpl<T>::IntegerImpl( short n ) :632inline IntegerImpl<T>::IntegerImpl( short n ) :
638 value_( static_cast<long>( T::check_value( n, false ) ) )633 value_( static_cast<long>( T::check_value( n ) ) )
639{634{
640}635}
641636
642template<class T>637template<class T>
643inline IntegerImpl<T>::IntegerImpl( int n ) :638inline IntegerImpl<T>::IntegerImpl( int n ) :
644 value_( static_cast<long>( T::check_value( n, false ) ) )639 value_( static_cast<long>( T::check_value( n ) ) )
645{640{
646}641}
647642
648template<class T>643template<class T>
649inline IntegerImpl<T>::IntegerImpl( long n ) :644inline IntegerImpl<T>::IntegerImpl( long n ) :
650 value_( T::check_value( n, false ) )645 value_( T::check_value( n ) )
651{646{
652}647}
653648
654#ifndef ZORBA_WITH_BIG_INTEGER649#ifndef ZORBA_WITH_BIG_INTEGER
655template<class T>650template<class T>
656inline IntegerImpl<T>::IntegerImpl( long long n ) :651inline IntegerImpl<T>::IntegerImpl( long long n ) :
657 value_( T::check_value( n, false ) )652 value_( T::check_value( n ) )
658{653{
659}654}
660#endif /* ZORBA_WITH_BIG_INTEGER */655#endif /* ZORBA_WITH_BIG_INTEGER */
661656
662template<class T>657template<class T>
663inline IntegerImpl<T>::IntegerImpl( unsigned char c ) :658inline IntegerImpl<T>::IntegerImpl( unsigned char c ) :
664 value_( static_cast<long>( (unsigned long)T::check_value( c, false ) ) )659 value_( static_cast<long>( (unsigned long)T::check_value( c ) ) )
665{660{
666}661}
667662
668template<class T>663template<class T>
669inline IntegerImpl<T>::IntegerImpl( unsigned short n ) :664inline IntegerImpl<T>::IntegerImpl( unsigned short n ) :
670 value_( static_cast<long>( (unsigned long)T::check_value( n, false ) ) )665 value_( static_cast<long>( (unsigned long)T::check_value( n ) ) )
671{666{
672}667}
673668
@@ -675,7 +670,7 @@
675#if ZORBA_SIZEOF_INT != ZORBA_SIZEOF_LONG670#if ZORBA_SIZEOF_INT != ZORBA_SIZEOF_LONG
676template<class T>671template<class T>
677inline IntegerImpl<T>::IntegerImpl( unsigned int n ) :672inline IntegerImpl<T>::IntegerImpl( unsigned int n ) :
678 value_( static_cast<long>( (unsigned long)T::check_value( n, false ) ) )673 value_( static_cast<long>( (unsigned long)T::check_value( n ) ) )
679{674{
680}675}
681#endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */676#endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */
@@ -683,19 +678,19 @@
683678
684template<class T>679template<class T>
685inline IntegerImpl<T>::IntegerImpl( unsigned int n ) :680inline IntegerImpl<T>::IntegerImpl( unsigned int n ) :
686 value_( static_cast<value_type>( T::check_value( n, false ) ) )681 value_( static_cast<value_type>( T::check_value( n ) ) )
687{682{
688}683}
689684
690template<class T>685template<class T>
691inline IntegerImpl<T>::IntegerImpl( unsigned long n ) :686inline IntegerImpl<T>::IntegerImpl( unsigned long n ) :
692 value_( static_cast<value_type>( T::check_value( n, false ) ) )687 value_( static_cast<value_type>( T::check_value( n ) ) )
693{688{
694}689}
695690
696template<class T>691template<class T>
697inline IntegerImpl<T>::IntegerImpl( unsigned long long n ) :692inline IntegerImpl<T>::IntegerImpl( unsigned long long n ) :
698 value_( static_cast<value_type>( T::check_value( n, false ) ) )693 value_( static_cast<value_type>( T::check_value( n ) ) )
699{694{
700}695}
701#endif /* ZORBA_WITH_BIG_INTEGER */696#endif /* ZORBA_WITH_BIG_INTEGER */
@@ -703,9 +698,9 @@
703template<class T>698template<class T>
704inline IntegerImpl<T>::IntegerImpl( float n ) :699inline IntegerImpl<T>::IntegerImpl( float n ) :
705#ifdef ZORBA_WITH_BIG_INTEGER700#ifdef ZORBA_WITH_BIG_INTEGER
706 value_( static_cast<double>( T::check_value( n, false ) ) )701 value_( static_cast<double>( T::check_value( n ) ) )
707#else702#else
708 value_( static_cast<value_type>( T::check_value( n, false ) ) )703 value_( static_cast<value_type>( T::check_value( n ) ) )
709#endif /* ZORBA_WITH_BIG_INTEGER */704#endif /* ZORBA_WITH_BIG_INTEGER */
710{705{
711}706}
@@ -713,32 +708,32 @@
713template<class T>708template<class T>
714inline IntegerImpl<T>::IntegerImpl( double n ) :709inline IntegerImpl<T>::IntegerImpl( double n ) :
715#ifdef ZORBA_WITH_BIG_INTEGER710#ifdef ZORBA_WITH_BIG_INTEGER
716 value_( T::check_value( n, false ) )711 value_( T::check_value( n ) )
717#else712#else
718 value_( static_cast<value_type>( T::check_value( n, false ) ) )713 value_( static_cast<value_type>( T::check_value( n ) ) )
719#endif /* ZORBA_WITH_BIG_INTEGER */714#endif /* ZORBA_WITH_BIG_INTEGER */
720{715{
721}716}
722717
723template<class T>718template<class T>
724inline IntegerImpl<T>::IntegerImpl( char const *s ) {719inline IntegerImpl<T>::IntegerImpl( char const *s ) {
725 parse( s, false );720 parse( s );
726}721}
727722
728template<class T>723template<class T>
729template<class U>724template<class U>
730inline IntegerImpl<T>::IntegerImpl( IntegerImpl<U> const &i ) :725inline IntegerImpl<T>::IntegerImpl( IntegerImpl<U> const &i ) :
731 value_( T::check_value( i.value_, false ) )726 value_( T::check_value( i.value_ ) )
732{727{
733}728}
734729
735////////// assignment operators ///////////////////////////////////////////////730////////// assignment operators ///////////////////////////////////////////////
736731
737#define ZORBA_ASSIGN_OP(N) \732#define ZORBA_ASSIGN_OP(N) \
738 template<class T> inline \733 template<class T> inline \
739 IntegerImpl<T>& IntegerImpl<T>::operator=( N n ) { \734 IntegerImpl<T>& IntegerImpl<T>::operator=( N n ) { \
740 value_ = static_cast<int_cast_type>( T::check_value( n, false ) ); \735 value_ = static_cast<int_cast_type>( T::check_value( n ) ); \
741 return *this; \736 return *this; \
742 }737 }
743738
744ZORBA_ASSIGN_OP(char)739ZORBA_ASSIGN_OP(char)
@@ -760,14 +755,14 @@
760755
761template<class T>756template<class T>
762inline IntegerImpl<T>& IntegerImpl<T>::operator=( char const *s ) {757inline IntegerImpl<T>& IntegerImpl<T>::operator=( char const *s ) {
763 parse( s, false );758 parse( s );
764 return *this;759 return *this;
765}760}
766761
767template<class T>762template<class T>
768template<class U>763template<class U>
769inline IntegerImpl<T>& IntegerImpl<T>::operator=( IntegerImpl<U> const &i ) {764inline IntegerImpl<T>& IntegerImpl<T>::operator=( IntegerImpl<U> const &i ) {
770 T::check_value( value_ = i.value_, false );765 T::check_value( value_ = i.value_ );
771 return *this;766 return *this;
772}767}
773768
@@ -888,7 +883,7 @@
888#define ZORBA_INTEGER_OP(OP) \883#define ZORBA_INTEGER_OP(OP) \
889 template<class T> inline \884 template<class T> inline \
890 IntegerImpl<T>& IntegerImpl<T>::operator OP( IntegerImpl<T> const &i ) { \885 IntegerImpl<T>& IntegerImpl<T>::operator OP( IntegerImpl<T> const &i ) { \
891 T::check_value( value_ OP i.value_, true ); \886 T::check_value( value_ OP i.value_ ); \
892 return *this; \887 return *this; \
893 }888 }
894889
@@ -900,15 +895,15 @@
900895
901template<class T>896template<class T>
902inline IntegerImpl<T>& IntegerImpl<T>::operator/=( IntegerImpl<T> const &i ) {897inline IntegerImpl<T>& IntegerImpl<T>::operator/=( IntegerImpl<T> const &i ) {
903 value_ = T::check_value( ftoi( value_ / i.value_ ), true );898 value_ = T::check_value( ftoi( value_ / i.value_ ) );
904 return *this;899 return *this;
905}900}
906901
907#define ZORBA_INTEGER_OP(OP,N) \902#define ZORBA_INTEGER_OP(OP,N) \
908 template<class T> inline \903 template<class T> inline \
909 IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \904 IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \
910 T::check_value( value_ OP make_value_type( n ), true ); \905 T::check_value( value_ OP make_value_type( n ) ); \
911 return *this; \906 return *this; \
912 }907 }
913908
914ZORBA_INTEGER_OP(+=,char)909ZORBA_INTEGER_OP(+=,char)
@@ -967,11 +962,11 @@
967#endif /* ZORBA_WITH_BIG_INTEGER */962#endif /* ZORBA_WITH_BIG_INTEGER */
968#undef ZORBA_INTEGER_OP963#undef ZORBA_INTEGER_OP
969964
970#define ZORBA_INTEGER_OP(N) \965#define ZORBA_INTEGER_OP(N) \
971 template<class T> inline \966 template<class T> inline \
972 IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \967 IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \
973 value_ = T::check_value( ftoi( value_ / make_value_type( n ) ), true ); \968 value_ = T::check_value( ftoi( value_ / make_value_type( n ) ) ); \
974 return *this; \969 return *this; \
975 }970 }
976971
977ZORBA_INTEGER_OP(char)972ZORBA_INTEGER_OP(char)
@@ -998,27 +993,27 @@
998993
999template<class T>994template<class T>
1000inline IntegerImpl<T>& IntegerImpl<T>::operator++() {995inline IntegerImpl<T>& IntegerImpl<T>::operator++() {
1001 T::check_value( ++value_, true );996 T::check_value( ++value_ );
1002 return *this;997 return *this;
1003}998}
1004999
1005template<class T>1000template<class T>
1006inline IntegerImpl<T> IntegerImpl<T>::operator++(int) {1001inline IntegerImpl<T> IntegerImpl<T>::operator++(int) {
1007 IntegerImpl<T> const result( *this );1002 IntegerImpl<T> const result( *this );
1008 T::check_value( ++value_, true );1003 T::check_value( ++value_ );
1009 return result;1004 return result;
1010}1005}
10111006
1012template<class T>1007template<class T>
1013inline IntegerImpl<T>& IntegerImpl<T>::operator--() {1008inline IntegerImpl<T>& IntegerImpl<T>::operator--() {
1014 T::check_value( --value_, true );1009 T::check_value( --value_ );
1015 return *this;1010 return *this;
1016}1011}
10171012
1018template<class T>1013template<class T>
1019inline IntegerImpl<T> IntegerImpl<T>::operator--(int) {1014inline IntegerImpl<T> IntegerImpl<T>::operator--(int) {
1020 IntegerImpl<T> const result( *this );1015 IntegerImpl<T> const result( *this );
1021 T::check_value( --value_, true );1016 T::check_value( --value_ );
1022 return result;1017 return result;
1023}1018}
10241019

Subscribers

People subscribed via source and target branches