Till Westmann has proposed merging lp:~zorba-coders/zorba/more-numconversions 
into lp:zorba.

Commit message:
add to_xs_unsignedByte and to_xs_unsignedShort

Requested reviews:
  Till Westmann (tillw)
  Matthias Brantner (matthias-brantner)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/more-numconversions/+merge/132208

add to_xs_unsignedByte and to_xs_unsignedShort
-- 
https://code.launchpad.net/~zorba-coders/zorba/more-numconversions/+merge/132208
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/zorbatypes/integer.h'
--- src/zorbatypes/integer.h	2012-09-19 21:16:15 +0000
+++ src/zorbatypes/integer.h	2012-10-30 21:29:21 +0000
@@ -524,6 +524,8 @@
 
   friend xs_int to_xs_int( INTEGER_IMPL_LL const& );
   friend xs_long to_xs_long( INTEGER_IMPL_LL const& );
+  friend xs_unsignedByte to_xs_unsignedByte( INTEGER_IMPL_LL const& );
+  friend xs_unsignedShort to_xs_unsignedShort( INTEGER_IMPL_LL const& );
   friend xs_unsignedInt to_xs_unsignedInt( INTEGER_IMPL_LL const& );
   friend xs_unsignedLong to_xs_unsignedLong( INTEGER_IMPL_LL const& );
 

=== modified file 'src/zorbatypes/numconversions.cpp'
--- src/zorbatypes/numconversions.cpp	2012-09-19 21:16:15 +0000
+++ src/zorbatypes/numconversions.cpp	2012-10-30 21:29:21 +0000
@@ -70,6 +70,28 @@
 }
 #endif /* ZORBA_WITH_BIG_INTEGER */
 
+xs_unsignedByte to_xs_unsignedByte( xs_integer const &i ) {
+#ifdef ZORBA_WITH_BIG_INTEGER
+  zstring const temp( i.toString() );
+  return ztd::aton<xs_unsignedByte>( temp.c_str() );
+#else
+  if ( i.is_xs_unsignedByte() )
+    return static_cast<xs_unsignedByte>( i.value_ );
+  throw RANGE_ERROR( i, "xs:unsignedByte" );
+#endif /* ZORBA_WITH_BIG_INTEGER */
+}
+
+xs_unsignedShort to_xs_unsignedShort( xs_integer const &i ) {
+#ifdef ZORBA_WITH_BIG_INTEGER
+  zstring const temp( i.toString() );
+  return ztd::aton<xs_unsignedShort>( temp.c_str() );
+#else
+  if ( i.is_xs_unsignedShort() )
+    return static_cast<xs_unsignedShort>( i.value_ );
+  throw RANGE_ERROR( i, "xs:unsignedShort" );
+#endif /* ZORBA_WITH_BIG_INTEGER */
+}
+
 xs_unsignedInt to_xs_unsignedInt( xs_integer const &i ) {
 #ifdef ZORBA_WITH_BIG_INTEGER
   zstring const temp( i.toString() );

=== modified file 'src/zorbatypes/numconversions.h'
--- src/zorbatypes/numconversions.h	2012-09-19 21:16:15 +0000
+++ src/zorbatypes/numconversions.h	2012-10-30 21:29:21 +0000
@@ -69,6 +69,26 @@
 #endif /* ZORBA_WITH_BIG_INTEGER */
 
 /**
+ * Converts an \c xs:integer value to an \c xs:unsignedByte.
+ *
+ * @param i The \c xs:integer value to convert.
+ * @return Returns said value.
+ * @throws std::range_error if the \c xs:integer value can not be accurately
+ * represented as an \c xs:unsignedByte.
+ */
+xs_unsignedByte to_xs_unsignedByte( xs_integer const &i );
+
+/**
+ * Converts an \c xs:integer value to an \c xs:unsignedShort.
+ *
+ * @param i The \c xs:integer value to convert.
+ * @return Returns said value.
+ * @throws std::range_error if the \c xs:integer value can not be accurately
+ * represented as an \c xs:unsignedShort.
+ */
+xs_unsignedShort to_xs_unsignedShort( xs_integer const &i );
+
+/**
  * Converts an \c xs:integer value to an \c xs:unsignedInt.
  *
  * @param i The \c xs:integer value to convert.

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to