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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 17 10:49:52 CET 2011


Author: romain
Date: 2011-11-17 10:49:50 +0100 (Thu, 17 Nov 2011)
New Revision: 3376

Added:
   pkg/int64/inst/include/int64/long_traits.h
Modified:
   pkg/int64/inst/include/int64/LongVector.h
   pkg/int64/inst/include/int64/arith.h
   pkg/int64/inst/include/int64/as_character.h
   pkg/int64/inst/include/int64/compare.h
   pkg/int64/inst/include/int64/int64.h
   pkg/int64/inst/include/int64/math.h
   pkg/int64/inst/include/int64/read_string.h
   pkg/int64/inst/include/int64/summary.h
   pkg/int64/src/int64.cpp
Log:
attempt to fix issue reported by clang

Modified: pkg/int64/inst/include/int64/LongVector.h
===================================================================
--- pkg/int64/inst/include/int64/LongVector.h	2011-11-17 07:28:32 UTC (rev 3375)
+++ pkg/int64/inst/include/int64/LongVector.h	2011-11-17 09:49:50 UTC (rev 3376)
@@ -29,17 +29,12 @@
 namespace int64{
     
     template <class LONG>
-    class LongVector {
+    class LongVector : public internal::long_traits<LONG> {
     private :
         SEXP data ;
         
     public:
-        static LONG min ; 
-        static LONG max ;
-        static LONG na  ;
-        static int na_hb ;
-        static int na_lb ;
-            
+        
         LongVector(SEXP x) : data(x) {
             if( Rf_inherits( x, internal::get_class<LONG>().c_str() ) ){
                 data = x ;
@@ -56,7 +51,7 @@
                             for( int i=0; i<n; i++){
                                 if( p_i_x[i] == NA_INTEGER){                   
                                     SET_VECTOR_ELT( y, i, int64::internal::int2(
-                                        na_hb, na_lb    
+                                        na_hb() , na_lb()    
                                     ) ) ;
                                 } else {
                                     tmp = (LONG) p_i_x[i] ;
@@ -80,7 +75,7 @@
                             for( int i=0; i<n; i++){
                                 if( p_i_x[i] == NA_INTEGER){                   
                                     SET_VECTOR_ELT( y, i, int64::internal::int2(
-                                        na_hb, na_lb    
+                                        na_hb(), na_lb()    
                                     ) ) ;
                                 } else {
                                     tmp = (LONG) p_i_x[i] ;
@@ -104,7 +99,7 @@
                             for( int i=0; i<n; i++){
                                 if( R_IsNA(p_d_x[i]) ){
                                     SET_VECTOR_ELT( y, i, int64::internal::int2(
-                                        na_hb, na_lb    
+                                        na_hb(), na_lb()    
                                     ) ) ;
                                 } else {
                                     tmp = (LONG) p_d_x[i] ;
@@ -128,7 +123,7 @@
                             for( int i=0; i<n; i++){
                                 if( !strcmp("NA", CHAR(STRING_ELT(x,i)) ) ){
                                     SET_VECTOR_ELT( y, i, int64::internal::int2(
-                                        na_hb, na_lb    
+                                        na_hb(), na_lb()    
                                     ) ) ;
                                 } else{ 
                                     tmp = internal::read_string<LONG>( CHAR(STRING_ELT(x,i)) ) ;
@@ -240,15 +235,18 @@
             int* p_res = INTEGER(res) ;
             for( int i=0; i<n; i++){
                 p = INTEGER(VECTOR_ELT(data, i)) ;
-                p_res[i] = p[0] == na_hb && p[1] == na_lb ;
+                p_res[i] = p[0] == na_hb() && p[1] == na_lb() ;
             }
             UNPROTECT(1) ; // res
             return res; 
         }
         
+        inline int na_lb(){ return internal::long_traits<LONG>::na_lb(); }
+        inline int na_hb(){ return internal::long_traits<LONG>::na_hb(); }
+        
+        
     } ;
 
-    
 }
 
 

Modified: pkg/int64/inst/include/int64/arith.h
===================================================================
--- pkg/int64/inst/include/int64/arith.h	2011-11-17 07:28:32 UTC (rev 3375)
+++ pkg/int64/inst/include/int64/arith.h	2011-11-17 09:49:50 UTC (rev 3376)
@@ -32,7 +32,7 @@
     namespace internal{
 
 template <typename T> inline T plus(T x1,T x2){ 
-    const T na = int64::LongVector<T>::na ;
+    const T na = int64::LongVector<T>::na() ;
     if( x1 == na || x2 == na ){
         return na ;
     }
@@ -44,7 +44,7 @@
     return na ;
 }        
 template <typename T> inline T minus(T x1,T x2){ 
-    const T na = int64::LongVector<T>::na ;
+    const T na = int64::LongVector<T>::na() ;
     if( x1 == na || x2 == na){
         return na ;
     }
@@ -56,12 +56,12 @@
     return na ;
 }
 template <> inline uint64_t minus<uint64_t>( uint64_t x1, uint64_t x2){
-    const uint64_t na = int64::LongVector<uint64_t>::na ;
+    const uint64_t na = int64::LongVector<uint64_t>::na() ;
     if( x1 == na || x2 == na || x2 > x1) return na ;
     return x1 - x2 ;
 }
 template <typename T> inline T times(T x1,T x2){ 
-    const T na = int64::LongVector<T>::na ;
+    const T na = int64::LongVector<T>::na() ;
     if( x1 == na || x2 == na){
         return na ;
     }
@@ -73,21 +73,21 @@
     return na ;
 }        
 template <typename T> inline T divide(T x1,T x2){ 
-    const T na = int64::LongVector<T>::na ;
+    const T na = int64::LongVector<T>::na() ;
     if( x1 == na || x2 == na ){
         return na ;
     }
     return x1/x2 ;
 }        
 template <typename T> inline T modulo(T x1,T x2){ 
-    const T na = int64::LongVector<T>::na ;
+    const T na = int64::LongVector<T>::na() ;
     if( x1 == na || x2 == na ){
         return na ;
     }
     return x1 % x2 ;
 }        
 template <typename T> inline T int_div(T x1,T x2){ 
-    const T na = int64::LongVector<T>::na ;
+    const T na = int64::LongVector<T>::na() ;
     if( x1 == na || x2 == na ){
         return na ;
     }

Modified: pkg/int64/inst/include/int64/as_character.h
===================================================================
--- pkg/int64/inst/include/int64/as_character.h	2011-11-17 07:28:32 UTC (rev 3375)
+++ pkg/int64/inst/include/int64/as_character.h	2011-11-17 09:49:50 UTC (rev 3376)
@@ -36,7 +36,7 @@
     LONG tmp ;
     for( int i=0; i<n; i++){
         tmp = data.get(i) ;
-        if( tmp == int64::LongVector<LONG>::na ){
+        if( tmp == long_traits<LONG>::na() ){
             stream << "NA" ;
         } else {
             stream << data.get(i) ;

Modified: pkg/int64/inst/include/int64/compare.h
===================================================================
--- pkg/int64/inst/include/int64/compare.h	2011-11-17 07:28:32 UTC (rev 3375)
+++ pkg/int64/inst/include/int64/compare.h	2011-11-17 09:49:50 UTC (rev 3376)
@@ -33,7 +33,7 @@
         
 template <typename LONG, bool Fun(LONG x1, LONG x2)>
 SEXP compare_long_long(SEXP e1, SEXP e2){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     int64::LongVector<LONG> x1( e1 ) ;
     int64::LongVector<LONG> x2( e2 ) ;
     

Modified: pkg/int64/inst/include/int64/int64.h
===================================================================
--- pkg/int64/inst/include/int64/int64.h	2011-11-17 07:28:32 UTC (rev 3375)
+++ pkg/int64/inst/include/int64/int64.h	2011-11-17 09:49:50 UTC (rev 3376)
@@ -32,6 +32,7 @@
 #include <int64/read_string_forward.h>
 #include <int64/get_long.h>
 #include <int64/get_bits.h>
+#include <int64/long_traits.h>
 #include <int64/get_class.h>
 #include <int64/LongVector.h>
 #include <int64/read_string.h>

Added: pkg/int64/inst/include/int64/long_traits.h
===================================================================
--- pkg/int64/inst/include/int64/long_traits.h	                        (rev 0)
+++ pkg/int64/inst/include/int64/long_traits.h	2011-11-17 09:49:50 UTC (rev 3376)
@@ -0,0 +1,52 @@
+// long_traits.h: int64 64 bit integers
+//    
+// Copyright (C) 2011 Romain Francois
+// Copyright (C) 2011 Google Inc.  All rights reserved.
+//
+// This file is part of int64.
+//
+// int64 is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// int64 is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with int64.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef int64_long_traits_h
+#define int64_long_traits_h
+
+namespace int64{
+    namespace internal{
+       
+        template <typename LONG>
+        struct long_traits ;
+        
+        template<>
+        struct long_traits<int64_t>{
+            static inline int64_t min   () { return std::numeric_limits<int64_t>::min() + 1 ;                        }
+            static inline int64_t max   () { return std::numeric_limits<int64_t>::max() ;                            }
+            static inline int64_t na    () { return std::numeric_limits<int64_t>::min() ;                            }
+            static inline int     na_hb () { return get_high_bits<int64_t>( std::numeric_limits<int64_t>::min()  );  }
+            static inline int     na_lb () { return get_low_bits<int64_t>( std::numeric_limits<int64_t>::min()  );   }
+        } ;
+        
+        template<>
+        struct long_traits<uint64_t>{
+            static inline uint64_t min  () { return 0 ;                        }
+            static inline uint64_t max  () { return std::numeric_limits<uint64_t>::max() - 1;                            }
+            static inline uint64_t na   () { return std::numeric_limits<uint64_t>::max() ;                            }
+            static inline int     na_hb () { return get_high_bits<uint64_t>( std::numeric_limits<uint64_t>::max()  );  }
+            static inline int     na_lb () { return get_low_bits<uint64_t>( std::numeric_limits<uint64_t>::max()  );   }
+        } ;
+        
+    }
+}
+
+
+#endif

Modified: pkg/int64/inst/include/int64/math.h
===================================================================
--- pkg/int64/inst/include/int64/math.h	2011-11-17 07:28:32 UTC (rev 3375)
+++ pkg/int64/inst/include/int64/math.h	2011-11-17 09:49:50 UTC (rev 3376)
@@ -26,7 +26,7 @@
       
 template <typename LONG>
 SEXP abs( SEXP x ){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     int64::LongVector<LONG> data(x) ;
     int n = data.size() ;
     LONG tmp ;
@@ -43,7 +43,7 @@
      
 template <typename LONG>
 SEXP sign( SEXP x){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     int64::LongVector<LONG> data(x) ;
     int n = data.size() ;
     LONG tmp ;
@@ -63,7 +63,7 @@
 
 template <typename LONG>
 SEXP cummax( SEXP x){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     int64::LongVector<LONG> data(x) ;
     int n = data.size() ;
     int64::LongVector<LONG> res(n, na) ;
@@ -82,7 +82,7 @@
 
 template <typename LONG>
 SEXP cummin( SEXP x){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     int64::LongVector<LONG> data(x) ;
     int n = data.size() ;
     int64::LongVector<LONG> res(n, na) ;
@@ -101,7 +101,7 @@
 
 template <typename LONG>
 SEXP cumprod( SEXP x){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     int64::LongVector<LONG> data(x) ;
     int n = data.size() ;
     int64::LongVector<LONG> res(n, na) ;
@@ -121,7 +121,7 @@
 
 template <typename LONG>
 SEXP cumsum( SEXP x){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     int64::LongVector<LONG> data(x) ;
     int n = data.size() ;
     int64::LongVector<LONG> res(x) ;

Modified: pkg/int64/inst/include/int64/read_string.h
===================================================================
--- pkg/int64/inst/include/int64/read_string.h	2011-11-17 07:28:32 UTC (rev 3375)
+++ pkg/int64/inst/include/int64/read_string.h	2011-11-17 09:49:50 UTC (rev 3376)
@@ -29,7 +29,7 @@
         errno = 0 ;
         int64_t res = strtoll( s, NULL, 0 ) ;
         if( errno == ERANGE ) {
-            res = int64::LongVector<int64_t>::na ;
+            res = int64::LongVector<int64_t>::na() ;
             int64_naflag = true ;
         }
         return res ;
@@ -40,7 +40,7 @@
         errno = 0 ;
         uint64_t res = strtoull( s, NULL, 0 ) ;
         if( errno == ERANGE ) {
-            res = int64::LongVector<uint64_t>::na ;
+            res = int64::LongVector<uint64_t>::na() ;
             int64_naflag = true ;
         }
         return res ;

Modified: pkg/int64/inst/include/int64/summary.h
===================================================================
--- pkg/int64/inst/include/int64/summary.h	2011-11-17 07:28:32 UTC (rev 3375)
+++ pkg/int64/inst/include/int64/summary.h	2011-11-17 09:49:50 UTC (rev 3376)
@@ -26,7 +26,7 @@
 
 template <typename LONG>
 SEXP summary__min( const int64::LongVector<LONG>& data){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     LONG x = data.get(0) ;
     if( x == na ) return int64::internal::new_long<LONG>( na ) ;
     LONG tmp = x ;
@@ -44,7 +44,7 @@
 
 template <typename LONG>
 SEXP summary__max( const int64::LongVector<LONG>& data){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     LONG x = data.get(0) ;
     LONG tmp = x ;
     int n = data.size() ;
@@ -61,7 +61,7 @@
 
 template <typename LONG>
 SEXP summary__range( const int64::LongVector<LONG>& data){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     LONG min = data.get(0) ;
     LONG max = data.get(0) ;
     if( min == na ) return int64::internal::new_long_2<LONG>( na, na) ;
@@ -80,7 +80,7 @@
 
 template <typename LONG>
 SEXP summary__prod( const int64::LongVector<LONG>& data){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     LONG res = data.get(0) ;
     if( res == na ) return int64::internal::new_long<LONG>( na ) ;
     int n = data.size() ;
@@ -95,7 +95,7 @@
 
 template <typename LONG>
 SEXP summary__sum( const int64::LongVector<LONG>& data){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     LONG res = data.get(0) ;
     if( res == na ) return int64::internal::new_long<LONG>( na ) ;
     int n = data.size() ;
@@ -112,7 +112,7 @@
 
 template <typename LONG>
 SEXP summary__any( const int64::LongVector<LONG>& data){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     int n = data.size() ;
     int res = 0 ;
     bool seen_na = false ;
@@ -137,7 +137,7 @@
 
 template <typename LONG>
 SEXP summary__all( const int64::LongVector<LONG>& data){
-    const LONG na = int64::LongVector<LONG>::na ;
+    const LONG na = long_traits<LONG>::na() ;
     int n = data.size() ;
     int res = 1 ;
     LONG tmp ;

Modified: pkg/int64/src/int64.cpp
===================================================================
--- pkg/int64/src/int64.cpp	2011-11-17 07:28:32 UTC (rev 3375)
+++ pkg/int64/src/int64.cpp	2011-11-17 09:49:50 UTC (rev 3376)
@@ -23,18 +23,6 @@
 
 namespace int64{
     
-    template<> int64_t LongVector<int64_t>::min = std::numeric_limits<int64_t>::min() + 1;
-    template<> int64_t LongVector<int64_t>::max = std::numeric_limits<int64_t>::max() ;
-    template<> int64_t LongVector<int64_t>::na  = std::numeric_limits<int64_t>::min() ;
-    template<> int LongVector<int64_t>::na_hb = int64::internal::get_high_bits<int64_t>( int64::LongVector<int64_t>::na ) ;
-    template<> int LongVector<int64_t>::na_lb = int64::internal::get_low_bits<int64_t>(  int64::LongVector<int64_t>::na ) ;
-    
-    template<> uint64_t LongVector<uint64_t>::min = 0 ;
-    template<> uint64_t LongVector<uint64_t>::max = std::numeric_limits<uint64_t>::max() - 1 ;
-    template<> uint64_t LongVector<uint64_t>::na  = std::numeric_limits<uint64_t>::max() ;
-    template<> int LongVector<uint64_t>::na_hb = int64::internal::get_high_bits<uint64_t>( int64::LongVector<uint64_t>::na ) ;
-    template<> int LongVector<uint64_t>::na_lb = int64::internal::get_low_bits<uint64_t>(  int64::LongVector<uint64_t>::na ) ;
-    
     namespace internal{
         
         
@@ -150,13 +138,13 @@
         return res ;
     } else if( ! strcmp( type, "int64" ) ){
         return int64::internal::new_long_2<int64_t>( 
-            int64::LongVector<int64_t>::min , 
-            int64::LongVector<int64_t>::max 
+            int64::internal::long_traits<int64_t>::min() , 
+            int64::internal::long_traits<int64_t>::max() 
             ) ;
     } else if( !strcmp( type, "uint64" ) ){
         return int64::internal::new_long_2<uint64_t>( 
-            int64::LongVector<uint64_t>::min, 
-            int64::LongVector<uint64_t>::max
+            int64::internal::long_traits<uint64_t>::min(), 
+            int64::internal::long_traits<uint64_t>::max()
             ) ;                                    
     }
     



More information about the Rcpp-commits mailing list