[Rprotobuf-commits] r429 - pkg/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 7 11:16:23 CET 2011


Author: romain
Date: 2011-11-07 11:16:22 +0100 (Mon, 07 Nov 2011)
New Revision: 429

Modified:
   pkg/src/wrapper_Message.cpp
Log:
int64 related changes

Modified: pkg/src/wrapper_Message.cpp
===================================================================
--- pkg/src/wrapper_Message.cpp	2011-11-07 09:54:02 UTC (rev 428)
+++ pkg/src/wrapper_Message.cpp	2011-11-07 10:16:22 UTC (rev 429)
@@ -7,33 +7,6 @@
 
 /* helpers */
 
-	/* this is only to be called for repeated fields */
-	int MESSAGE_GET_REPEATED_INT( GPB::Message* message, GPB::FieldDescriptor* field_desc, int index ){
-		
-		const GPB::Reflection* ref = message->GetReflection() ; 
-		
-		switch( field_desc->type() ){
-			case TYPE_INT32:
-    		case TYPE_SINT32:
-    		case TYPE_SFIXED32:
-    			return (int) ref->GetRepeatedInt32( *message, field_desc, index ) ;
-    		case TYPE_INT64:
-    		case TYPE_SINT64:
-    		case TYPE_SFIXED64:
-    			return (int) ref->GetRepeatedInt64( *message, field_desc, index ) ;
-    		case TYPE_UINT32:
-    		case TYPE_FIXED32:
-    			return (int) ref->GetRepeatedUInt32( *message, field_desc, index ) ;
-    		case TYPE_UINT64:
-    		case TYPE_FIXED64:
-    			return (int) ref->GetRepeatedUInt64( *message, field_desc, index ) ;
-    		case TYPE_ENUM:
-    			return ref->GetRepeatedEnum( *message, field_desc, index )->number() ;
-    		default:
-    			throwException( "cannot cast to int", "CastException" ) ; 
-		}
-		return 0 ; // -Wall
-	}
 	
 	/* this is only to be called for repeated fields */
 	double MESSAGE_GET_REPEATED_DOUBLE( GPB::Message* message, GPB::FieldDescriptor* field_desc, int index ){
@@ -973,28 +946,42 @@
 		}
 		
 		int n = index.size() ; 
+		const GPB::Reflection* ref = message->GetReflection() ; 
+		
 		switch( field_desc->type() ){
 			
     		case TYPE_INT32:
     		case TYPE_SINT32:
     		case TYPE_SFIXED32:
+    		    {
+    		        Rcpp::IntegerVector res(n) ;
+    		        for( int i=0; i<n; i++){
+    		            res[i] = ref->GetRepeatedInt32( *message, field_desc, index[i] ) ;
+    		        }
+    		        return res ;
+    		    }
 			case TYPE_UINT32:
 	    	case TYPE_FIXED32:
-	    	case TYPE_ENUM:
 	    		{
 	    			Rcpp::IntegerVector res(n) ;
 	    			for( int i=0; i<n; i++){
-						res[i] = MESSAGE_GET_REPEATED_INT( 
-							message, field_desc, index[i] ) ;
+						res[i] = (int)ref->GetRepeatedUInt32( *message, field_desc, index[i] ) ;
 					}
 					return res; 
 				}
+		    case TYPE_ENUM:
+		        {
+		           Rcpp::IntegerVector res(n) ;
+	    			for( int i=0; i<n; i++){
+						res[i] = (int)ref->GetRepeatedEnum( *message, field_desc, index[i] )->number() ;
+					}
+					return res;
+		        }
 		    case TYPE_INT64:
     		case TYPE_SINT64:
     		case TYPE_SFIXED64:
     		    {
     		        Rcpp::int64::LongVector<int64_t> res(n) ;
-    		        const GPB::Reflection* ref = message->GetReflection() ; 
     		        for( int i=0; i<n; i++){
     		          res.set(i, ref->GetRepeatedInt64( *message, field_desc, index[i] ) ) ;  
     		        }
@@ -1003,7 +990,6 @@
 			case TYPE_FIXED64:
 	    	case TYPE_UINT64:
 	    	    {
-	    	        const GPB::Reflection* ref = message->GetReflection() ; 
 	    	        Rcpp::int64::LongVector<uint64_t> res(n) ;
     		        for( int i=0; i<n; i++){
     		          res.set(i, ref->GetRepeatedUInt64( *message, field_desc, index[i] ) ) ;  



More information about the Rprotobuf-commits mailing list