[Rprotobuf-commits] r427 - pkg/src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Nov 7 10:49:45 CET 2011
Author: romain
Date: 2011-11-07 10:49:44 +0100 (Mon, 07 Nov 2011)
New Revision: 427
Modified:
pkg/src/mutators.cpp
pkg/src/rprotobuf.h
pkg/src/streams.cpp
pkg/src/wrapper_Message.cpp
Log:
int64 related changes
Modified: pkg/src/mutators.cpp
===================================================================
--- pkg/src/mutators.cpp 2011-11-07 08:52:36 UTC (rev 426)
+++ pkg/src/mutators.cpp 2011-11-07 09:49:44 UTC (rev 427)
@@ -100,23 +100,6 @@
return (int32)0 ; // -Wall, should not happen since we only call this when we know it works
}
-
-int64 GET_int64( SEXP x, int index ){
- switch( TYPEOF(x) ){
- case INTSXP:
- return( (int64)INTEGER(x)[index] );
- case REALSXP:
- return( (int64)REAL(x)[index] );
- case LGLSXP:
- return( (int64)LOGICAL(x)[index] );
- case RAWSXP:
- return( (int64)RAW(x)[index] ) ;
- default:
- throwException( "cannot cast SEXP to int64", "CastException" ) ;
- }
- return (int64)0 ; // -Wall, should not happen since we only call this when we know it works
-}
-
uint32 GET_uint32( SEXP x, int index ){
switch( TYPEOF(x) ){
case INTSXP:
@@ -133,18 +116,45 @@
return (uint32)0 ; // -Wall, should not happen since we only call this when we know it works
}
+
+int64 GET_int64( SEXP x, int index ){
+ if( Rf_inherits(x, "int64" ) ){
+ return Rcpp::int64::LongVector<int64_t>(x).get(index) ;
+ } else {
+ switch( TYPEOF(x) ){
+ case INTSXP:
+ return( (int64)INTEGER(x)[index] );
+ case REALSXP:
+ return( (int64)REAL(x)[index] );
+ case LGLSXP:
+ return( (int64)LOGICAL(x)[index] );
+ case RAWSXP:
+ return( (int64)RAW(x)[index] ) ;
+ default:
+ throwException( "cannot cast SEXP to int64", "CastException" ) ;
+ }
+ }
+ return (int64)0 ; // -Wall, should not happen since we only call this when we know it works
+}
+
+
+
uint64 GET_uint64( SEXP x, int index ){
- switch( TYPEOF(x) ){
- case INTSXP:
- return( (uint64)INTEGER(x)[index] );
- case REALSXP:
- return( (uint64)REAL(x)[index] );
- case LGLSXP:
- return( (uint64)LOGICAL(x)[index] );
- case RAWSXP:
- return( (uint64)RAW(x)[index] ) ;
- default:
- throwException( "cannot cast SEXP to uint64", "CastException" ) ;
+ if( Rf_inherits( x, "uint64" ) ){
+ return Rcpp::int64::LongVector<uint64_t>(x).get(index) ;
+ } else {
+ switch( TYPEOF(x) ){
+ case INTSXP:
+ return( (uint64)INTEGER(x)[index] );
+ case REALSXP:
+ return( (uint64)REAL(x)[index] );
+ case LGLSXP:
+ return( (uint64)LOGICAL(x)[index] );
+ case RAWSXP:
+ return( (uint64)RAW(x)[index] ) ;
+ default:
+ throwException( "cannot cast SEXP to uint64", "CastException" ) ;
+ }
}
return (uint64)0 ; // -Wall, should not happen since we only call this when we know it works
}
@@ -583,30 +593,47 @@
case TYPE_SINT64:
case TYPE_SFIXED64:
{
- switch( TYPEOF( value ) ){
- case INTSXP:
- case REALSXP:
- case LGLSXP:
- case RAWSXP:
- {
- int i = 0;
-
- /* in any case, fill the values up to field_size */
- for( ; i<field_size; i++){
- ref->SetRepeatedInt64( message, field_desc, i, GET_int64(value,i) ) ;
- }
-
- /* then add some if needed */
- if( value_size > field_size ){
- for( ; i<value_size; i++){
- ref->AddInt64( message, field_desc, GET_int64(value,i) ) ;
+ if( Rf_inherits( value, "int64") ){
+ Rcpp::int64::LongVector<int64_t> data_int64(value) ;
+
+ int i = 0 ;
+ /* in any case, fill the values up to field_size */
+ for( ; i<field_size; i++){
+ ref->SetRepeatedInt64( message, field_desc, i, data_int64.get(i) ) ;
+ }
+
+ /* then add some if needed */
+ if( value_size > field_size ){
+ for( ; i<value_size; i++){
+ ref->AddInt64( message, field_desc, data_int64.get(i) ) ;
+ }
+ }
+ } else {
+ switch( TYPEOF( value ) ){
+ case INTSXP:
+ case REALSXP:
+ case LGLSXP:
+ case RAWSXP:
+ {
+ int i = 0;
+
+ /* in any case, fill the values up to field_size */
+ for( ; i<field_size; i++){
+ ref->SetRepeatedInt64( message, field_desc, i, GET_int64(value,i) ) ;
}
- }
- break ;
- }
-
- default:
- throwException( "Cannot convert to int64", "ConversionException" ) ;
+
+ /* then add some if needed */
+ if( value_size > field_size ){
+ for( ; i<value_size; i++){
+ ref->AddInt64( message, field_desc, GET_int64(value,i) ) ;
+ }
+ }
+ break ;
+ }
+
+ default:
+ throwException( "Cannot convert to int64", "ConversionException" ) ;
+ }
}
break ;
}
@@ -647,29 +674,47 @@
case TYPE_UINT64:
case TYPE_FIXED64:
{
- switch( TYPEOF( value ) ){
- case INTSXP:
- case REALSXP:
- case LGLSXP:
- case RAWSXP:
- {
-
- int i = 0;
- /* in any case, fill the values up to field_size */
- for( ; i<field_size; i++){
- ref->SetRepeatedUInt64( message, field_desc, i, GET_uint64(value,i) ) ;
- }
-
- /* then add some if needed */
- if( value_size > field_size ){
- for( ; i<value_size; i++){
- ref->AddUInt64( message, field_desc, GET_uint64(value,i) ) ;
+ if( Rf_inherits( value, "uint64" ) ){
+ int i = 0 ;
+ Rcpp::int64::LongVector<uint64_t> data_uint64(value) ;
+
+ /* in any case, fill the values up to field_size */
+ for( ; i<field_size; i++){
+ ref->SetRepeatedUInt64( message, field_desc, i, data_uint64.get(i) ) ;
+ }
+
+ /* then add some if needed */
+ if( value_size > field_size ){
+ for( ; i<value_size; i++){
+ ref->AddUInt64( message, field_desc, data_uint64.get(i) ) ;
+ }
+ }
+
+ } else {
+ switch( TYPEOF( value ) ){
+ case INTSXP:
+ case REALSXP:
+ case LGLSXP:
+ case RAWSXP:
+ {
+
+ int i = 0;
+ /* in any case, fill the values up to field_size */
+ for( ; i<field_size; i++){
+ ref->SetRepeatedUInt64( message, field_desc, i, GET_uint64(value,i) ) ;
}
- }
- break ;
- }
- default:
- throwException( "Cannot convert to int64", "ConversionException" ) ;
+
+ /* then add some if needed */
+ if( value_size > field_size ){
+ for( ; i<value_size; i++){
+ ref->AddUInt64( message, field_desc, GET_uint64(value,i) ) ;
+ }
+ }
+ break ;
+ }
+ default:
+ throwException( "Cannot convert to int64", "ConversionException" ) ;
+ }
}
break ;
}
Modified: pkg/src/rprotobuf.h
===================================================================
--- pkg/src/rprotobuf.h 2011-11-07 08:52:36 UTC (rev 426)
+++ pkg/src/rprotobuf.h 2011-11-07 09:49:44 UTC (rev 427)
@@ -49,9 +49,6 @@
RCPP_ENUM_TRAITS(GPB::FieldDescriptor::CppType)
RCPP_ENUM_TRAITS(GPB::FieldDescriptor::Type)
-//RCPP_TRAITS(GPB::int64,REALSXP)
-//RCPP_TRAITS(GPB::uint64,REALSXP)
-
#include <Rcpp.h>
#include <Rdefines.h>
Modified: pkg/src/streams.cpp
===================================================================
--- pkg/src/streams.cpp 2011-11-07 08:52:36 UTC (rev 426)
+++ pkg/src/streams.cpp 2011-11-07 09:49:44 UTC (rev 427)
@@ -192,15 +192,15 @@
SEXP ZeroCopyInputStream_ReadLittleEndian64( SEXP xp){
GPB::io::CodedInputStream* coded_stream = GET_CIS(xp) ;
uint64 res = 0 ;
- if( !coded_stream->ReadVarint64( &res ) ) Rf_error( "error reading little endian int32" ) ;
- return Rf_ScalarReal( (double)res ) ;
+ if( !coded_stream->ReadVarint64( &res ) ) Rf_error( "error reading little endian int64" ) ;
+ return Rcpp::int64::LongVector<uint64_t>( res ) ;
}
SEXP ZeroCopyInputStream_ReadVarint64( SEXP xp){
GPB::io::CodedInputStream* coded_stream = GET_CIS(xp) ;
uint64 res = 0 ;
if( !coded_stream->ReadVarint64( &res ) ) Rf_error( "error reading varint64" ) ;
- return Rf_ScalarReal( (double)res ) ;
+ return Rcpp::int64::LongVector<uint64_t>( res ) ;
}
// }}}
Modified: pkg/src/wrapper_Message.cpp
===================================================================
--- pkg/src/wrapper_Message.cpp 2011-11-07 08:52:36 UTC (rev 426)
+++ pkg/src/wrapper_Message.cpp 2011-11-07 09:49:44 UTC (rev 427)
@@ -713,16 +713,24 @@
case TYPE_SINT64:
case TYPE_SFIXED64:
{
- switch( TYPEOF( values ) ){
- case INTSXP:
- case REALSXP:
- case LGLSXP:
- case RAWSXP:
- for( int i=0; i<value_size; i++){
- ref->AddInt64( message, field_desc, GET_int64(values,i) ) ;
- }
- default:
- throwException( "Cannot convert to int64", "ConversionException" ) ;
+ if( Rf_inherits( values, "int64" ) ){
+ Rcpp::int64::LongVector<int64_t> data(values) ;
+ for( int i=0; i<value_size; i++){
+ ref->AddInt64( message, field_desc, data.get(i) ) ;
+ }
+
+ } else {
+ switch( TYPEOF( values ) ){
+ case INTSXP:
+ case REALSXP:
+ case LGLSXP:
+ case RAWSXP:
+ for( int i=0; i<value_size; i++){
+ ref->AddInt64( message, field_desc, GET_int64(values,i) ) ;
+ }
+ default:
+ throwException( "Cannot convert to int64", "ConversionException" ) ;
+ }
}
break ;
}
@@ -754,19 +762,27 @@
case TYPE_UINT64:
case TYPE_FIXED64:
{
- switch( TYPEOF( values ) ){
- case INTSXP:
- case REALSXP:
- case LGLSXP:
- case RAWSXP:
- {
- for( int i=0; i<value_size; i++){
- ref->AddUInt64( message, field_desc, GET_uint64(values,i) ) ;
- }
- break ;
- }
- default:
- throwException( "Cannot convert to int64", "ConversionException" ) ;
+ if(Rf_inherits(values, "uint64" )){
+ Rcpp::int64::LongVector<uint64_t> data(values) ;
+ for( int i=0; i<value_size; i++){
+ ref->AddUInt64( message, field_desc, data.get(i) ) ;
+ }
+
+ } else {
+ switch( TYPEOF( values ) ){
+ case INTSXP:
+ case REALSXP:
+ case LGLSXP:
+ case RAWSXP:
+ {
+ for( int i=0; i<value_size; i++){
+ ref->AddUInt64( message, field_desc, GET_uint64(values,i) ) ;
+ }
+ break ;
+ }
+ default:
+ throwException( "Cannot convert to int64", "ConversionException" ) ;
+ }
}
break ;
}
@@ -962,13 +978,8 @@
case TYPE_INT32:
case TYPE_SINT32:
case TYPE_SFIXED32:
- case TYPE_INT64:
- case TYPE_SINT64:
- case TYPE_SFIXED64:
case TYPE_UINT32:
case TYPE_FIXED32:
- case TYPE_UINT64:
- case TYPE_FIXED64:
case TYPE_ENUM:
{
Rcpp::IntegerVector res(n) ;
@@ -978,6 +989,26 @@
}
return res;
}
+ case TYPE_INT64:
+ case TYPE_SINT64:
+ case TYPE_SFIXED64:
+ {
+ Rcpp::int64::LongVector<int64_t> res(n) ;
+ for( int i=0; i<n; i++){
+ res.set(i, ref->GetRepeatedInt64( *message, field_desc, index[i] ) ) ;
+ }
+ return res ;
+ }
+ case TYPE_FIXED64:
+ case TYPE_UINT64:
+ {
+ Rcpp::int64::LongVector<uint64_t> res(n) ;
+ for( int i=0; i<n; i++){
+ res.set(i, ref->GetRepeatedUInt64( *message, field_desc, index[i] ) ) ;
+ }
+ return res ;
+ }
+
case TYPE_DOUBLE:
case TYPE_FLOAT:
{
@@ -1069,10 +1100,19 @@
case TYPE_SINT64:
case TYPE_SFIXED64:
{
- for( int i=0; i<n; i++){
- ref->SetRepeatedInt64( message, field_desc,
- index[i],
- GET_int64( values, i ) ) ;
+ if( Rf_inherits(values, "int64" ) ){
+ Rcpp::int64::LongVector<int64_t> data(values) ;
+ for( int i=0; i<n; i++){
+ ref->SetRepeatedInt64( message, field_desc,
+ index[i],
+ data.get(i) ) ;
+ }
+ } else {
+ for( int i=0; i<n; i++){
+ ref->SetRepeatedInt64( message, field_desc,
+ index[i],
+ GET_int64( values, i ) ) ;
+ }
}
break ;
}
@@ -1089,10 +1129,19 @@
case TYPE_UINT64:
case TYPE_FIXED64:
{
- for( int i=0; i<n; i++){
- ref->SetRepeatedUInt64( message, field_desc,
- index[i],
- GET_uint64( values, i ) ) ;
+ if( Rf_inherits( values, "uint64" ) ){
+ Rcpp::int64::LongVector<uint64_t> data( values) ;
+ for( int i=0; i<n; i++){
+ ref->SetRepeatedUInt64( message, field_desc,
+ index[i],
+ data.get(i) ) ;
+ }
+ } else {
+ for( int i=0; i<n; i++){
+ ref->SetRepeatedUInt64( message, field_desc,
+ index[i],
+ GET_uint64( values, i ) ) ;
+ }
}
break ;
}
More information about the Rprotobuf-commits
mailing list