[Rcpp-commits] r3242 - in pkg/int64: . inst/include inst/include/int64 src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Oct 29 16:28:48 CEST 2011


Author: romain
Date: 2011-10-29 16:28:47 +0200 (Sat, 29 Oct 2011)
New Revision: 3242

Modified:
   pkg/int64/DESCRIPTION
   pkg/int64/inst/include/int64.h
   pkg/int64/inst/include/int64/format_binary.h
   pkg/int64/src/int64.cpp
Log:
some C++ifying

Modified: pkg/int64/DESCRIPTION
===================================================================
--- pkg/int64/DESCRIPTION	2011-10-29 14:06:57 UTC (rev 3241)
+++ pkg/int64/DESCRIPTION	2011-10-29 14:28:47 UTC (rev 3242)
@@ -1,7 +1,7 @@
 Package: int64
 Type: Package
 Title: 64 bit integer types
-Version: 1.0
+Version: 1.0.0
 Date: 2011-10-21
 Author: Romain Francois, sponsored by the Google Open Source Programs Office
 Maintainer: Romain Francois <romain at r-enthusiasts.com>

Modified: pkg/int64/inst/include/int64/format_binary.h
===================================================================
--- pkg/int64/inst/include/int64/format_binary.h	2011-10-29 14:06:57 UTC (rev 3241)
+++ pkg/int64/inst/include/int64/format_binary.h	2011-10-29 14:28:47 UTC (rev 3242)
@@ -25,20 +25,19 @@
     namespace internal{
 
         template <typename T>
-        inline std::string format_binary__impl(T x) {
+        inline const char* format_binary__impl(T x) {
             const int SIZE = sizeof(T)*8 ;
-            static char b[SIZE+1];
-            b[SIZE+1] = '\0';
-        
+            static std::string b( SIZE, '0' ) ;
+            
             for (int z = 0; z < SIZE; z++) {
                 b[SIZE-1-z] = ((x>>z) & 0x1) ? '1' : '0';
             }
         
-            return b;
+            return b.c_str() ;
         }    
         
         template <>
-        inline std::string format_binary__impl<double>(double x){
+        inline const char* format_binary__impl<double>(double x){
                 int64_t* y = (int64_t*)&x ;
                 return format_binary__impl<int64_t>(*y) ;
         }
@@ -54,7 +53,7 @@
             for( int i=0; i<n; i++){
                 p_x = INTEGER( VECTOR_ELT( data, i) ) ;
                 tmp = int64::internal::get_long<LONG>( p_x[0], p_x[1] ) ;
-                SET_STRING_ELT( res, i, Rf_mkChar( format_binary__impl(tmp).c_str()) ) ;
+                SET_STRING_ELT( res, i, Rf_mkChar( format_binary__impl(tmp) ) ) ;
             }
             UNPROTECT(1) ; // res
             return res ;

Modified: pkg/int64/inst/include/int64.h
===================================================================
--- pkg/int64/inst/include/int64.h	2011-10-29 14:06:57 UTC (rev 3241)
+++ pkg/int64/inst/include/int64.h	2011-10-29 14:28:47 UTC (rev 3242)
@@ -24,7 +24,7 @@
 #define R_NO_REMAP
 #include <R.h>
 #include <Rinternals.h>
-
+#include <stdint.h>
 #include <string>
 
 #include <int64/int64.h>

Modified: pkg/int64/src/int64.cpp
===================================================================
--- pkg/int64/src/int64.cpp	2011-10-29 14:06:57 UTC (rev 3241)
+++ pkg/int64/src/int64.cpp	2011-10-29 14:28:47 UTC (rev 3242)
@@ -19,7 +19,8 @@
 // along with int64.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <int64.h>
-        
+#include <limits>
+
 namespace int64{
     namespace internal{
         
@@ -42,7 +43,7 @@
                 {
                     int* data = INTEGER(x) ;
                     for( int i=0; i<n; i++){
-                        SET_STRING_ELT( res, i, Rf_mkChar( int64::internal::format_binary__impl<int>( data[i] ).c_str() ) ) ;
+                        SET_STRING_ELT( res, i, Rf_mkChar( int64::internal::format_binary__impl<int>( data[i] ) ) ) ;
                     }
                     break ;
                 }
@@ -50,7 +51,7 @@
                 {
                     double* p_x = REAL(x) ;
                     for( int i=0; i<n; i++){
-                        SET_STRING_ELT( res, i, Rf_mkChar( int64::internal::format_binary__impl<double>( p_x[i] ).c_str() ) );
+                        SET_STRING_ELT( res, i, Rf_mkChar( int64::internal::format_binary__impl<double>( p_x[i] ) ) );
                     }      
                     break ;
                 }



More information about the Rcpp-commits mailing list