[Rprotobuf-commits] r514 - in pkg: . src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 28 00:02:05 CEST 2013


Author: murray
Date: 2013-08-28 00:02:04 +0200 (Wed, 28 Aug 2013)
New Revision: 514

Modified:
   pkg/ChangeLog
   pkg/src/mutators.cpp
Log:
Add support for setting int64 fields as R character vectors that are
converted to int64 or uint64 C++ types with std::stringstream.  This
allows the user to get around the lack of 64-bit integer support in R
when working interactively with RProtoBufs where a large precision
number or identifier needs to be stored.



Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2013-08-22 06:33:45 UTC (rev 513)
+++ pkg/ChangeLog	2013-08-27 22:02:04 UTC (rev 514)
@@ -1,3 +1,13 @@
+2013-08-27  Murray Stokely  <murray at FreeBSD.org>
+
+	* src/mutators.cpp (rprotobuf): Add support for setting int64
+	  fields as R character vectors that are converted to int64 or
+	  uint64 C++ types with std::stringstream.  This allows the user
+	  to get around the lack of 64-bit integer support in R when working
+	  interactively with RProtoBufs where a large precision number or
+	  identifier needs to be stored.
+
+
 2013-08-21  Murray Stokely  <murray at FreeBSD.org>
 
 	* inst/unitTests/runit.addressbook.R (test.ascii): Add more tests.

Modified: pkg/src/mutators.cpp
===================================================================
--- pkg/src/mutators.cpp	2013-08-22 06:33:45 UTC (rev 513)
+++ pkg/src/mutators.cpp	2013-08-27 22:02:04 UTC (rev 514)
@@ -110,6 +110,16 @@
 			return( (int64)LOGICAL(x)[index] );
 		case RAWSXP:
 			return( (int64)RAW(x)[index] ) ;
+		case STRSXP: {
+			const string int64str = CHAR(STRING_ELT(x, index));
+			std::stringstream ss(int64str);
+			int64 ret;
+			if ((ss >> ret).fail() || !(ss>>std::ws).eof()) {
+				throwException("Provided STRSXP cannot be cast to int64",
+							   "CastException");
+			}
+			return ret;
+		}
 		default:
 			throwException( "cannot cast SEXP to int64", "CastException" ) ; 
 	}
@@ -136,12 +146,22 @@
 	switch( TYPEOF(x) ){
 		case INTSXP: 
 			return( (uint64)INTEGER(x)[index] );
-		case REALSXP: 
+		case REALSXP:
 			return( (uint64)REAL(x)[index] );
 		case LGLSXP:
 			return( (uint64)LOGICAL(x)[index] );
 		case RAWSXP:
 			return( (uint64)RAW(x)[index] ) ;
+		case STRSXP: {
+			const string int64str = CHAR(STRING_ELT(x, index));
+			std::stringstream ss(int64str);
+			uint64 ret;
+			if ((ss >> ret).fail() || !(ss>>std::ws).eof()) {
+				throwException(" Provided STRSXP cannot be cast to uint64",
+							   "CastException");
+			}
+			return ret;
+		}
 		default:
 			throwException( "cannot cast SEXP to uint64", "CastException" ) ; 
 	}
@@ -596,11 +616,12 @@
     		case TYPE_SINT64:
     		case TYPE_SFIXED64:
     			{
-    				switch( TYPEOF( value ) ){
-    					case INTSXP:
-    					case REALSXP:
-    					case LGLSXP:
-    					case RAWSXP:	
+					switch( TYPEOF( value ) ){
+						case INTSXP:
+						case REALSXP:
+						case LGLSXP:
+						case RAWSXP:
+						case STRSXP: // For int64, we support chars.
     						{
     							int i = 0;
 
@@ -664,7 +685,8 @@
 	   					case INTSXP:
     					case REALSXP:
     					case LGLSXP:
-    					case RAWSXP:	
+    					case RAWSXP:
+						case STRSXP: // For int64, we support chars.
     						{
     							
     							int i = 0;



More information about the Rprotobuf-commits mailing list