[Rcpp-commits] r3295 - in pkg/Rcpp: . inst/include/Rcpp inst/include/Rcpp/traits

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Nov 6 19:55:27 CET 2011


Author: romain
Date: 2011-11-06 19:55:26 +0100 (Sun, 06 Nov 2011)
New Revision: 3295

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/as.h
   pkg/Rcpp/inst/include/Rcpp/traits/r_type_traits.h
Log:
dealing with as<int64_t> and as<uint64_t>

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2011-11-06 18:05:57 UTC (rev 3294)
+++ pkg/Rcpp/ChangeLog	2011-11-06 18:55:26 UTC (rev 3295)
@@ -5,6 +5,7 @@
 	Before const_method could only deal with actual const methods of the class,
 	e.g. OUT Class::foo( ... ) const 
 	* include/Rcpp/modules/Module_generated_Pointer_CppMethod.h: idem
+	* include/Rcpp/as.h: deal with as<int64_t> and as<uint64_t>
 
 2011-10-31  Romain Francois  <romain at r-enthusiasts.com>
 

Modified: pkg/Rcpp/inst/include/Rcpp/as.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/as.h	2011-11-06 18:05:57 UTC (rev 3294)
+++ pkg/Rcpp/inst/include/Rcpp/as.h	2011-11-06 18:55:26 UTC (rev 3295)
@@ -53,6 +53,32 @@
             return exporter.get() ;
         }
         
+        template <typename T> T as(SEXP x, ::Rcpp::traits::r_type_int64_tag){
+            if( Rf_inherits( x,  "int64" ) ){
+                Rcpp::int64::LongVector<int64_t> data(x) ;
+                return data.get(0) ;
+            } else if( TYPEOF(x) == INTSXP ){
+                return (int64_t)INTEGER(x)[0] ;   
+            } else if( TYPEOF(x) == REALSXP ){
+                return (int64_t)REAL(x)[0] ;    
+            } else {
+                Rf_error("expexting an int64_t, an integer or a numeric value") ;   
+            }
+        }
+        
+        template <typename T> T as(SEXP x, ::Rcpp::traits::r_type_uint64_tag){
+            if( Rf_inherits( x,  "uint64" ) ){
+                Rcpp::int64::LongVector<uint64_t> data(x) ;
+                return data.get(0) ;
+            } else if( TYPEOF(x) == INTSXP ){
+                return (uint64_t)INTEGER(x)[0] ;   
+            } else if( TYPEOF(x) == REALSXP ){
+                return (uint64_t)REAL(x)[0] ;    
+            } else {
+                Rf_error("expexting an uint64, an integer or a numeric value") ;   
+            }
+        }
+        
     }
         
         

Modified: pkg/Rcpp/inst/include/Rcpp/traits/r_type_traits.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/traits/r_type_traits.h	2011-11-06 18:05:57 UTC (rev 3294)
+++ pkg/Rcpp/inst/include/Rcpp/traits/r_type_traits.h	2011-11-06 18:55:26 UTC (rev 3295)
@@ -60,6 +60,7 @@
 struct r_type_pairstring_generic_tag{} ;
 
 struct r_type_int64_tag{} ;
+struct r_type_uint64_tag{} ;
 
 /**
  * R type trait. Helps wrap.
@@ -136,7 +137,7 @@
 
 
 template<> struct r_type_traits<int64_t>{ typedef r_type_int64_tag r_category; } ;
-template<> struct r_type_traits<uint64_t>{ typedef r_type_int64_tag r_category ; } ;
+template<> struct r_type_traits<uint64_t>{ typedef r_type_uint64_tag r_category ; } ;
 
 
 } // traits



More information about the Rcpp-commits mailing list