[Rcpp-commits] r2213 - pkg/Rcpp/inst/include/Rcpp/sugar/operators

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 27 15:34:44 CEST 2010


Author: romain
Date: 2010-09-27 15:34:44 +0200 (Mon, 27 Sep 2010)
New Revision: 2213

Modified:
   pkg/Rcpp/inst/include/Rcpp/sugar/operators/plus.h
Log:
simplified plus.h thanks to Extractor trait

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/operators/plus.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/operators/plus.h	2010-09-27 13:30:38 UTC (rev 2212)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/operators/plus.h	2010-09-27 13:34:44 UTC (rev 2213)
@@ -32,8 +32,11 @@
 		typedef typename Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T> LHS_TYPE ;
 		typedef typename Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T> RHS_TYPE ;
 		
+		typedef typename Rcpp::traits::Extractor< RTYPE, LHS_NA, LHS_T>::type LHS_EXT ;
+		typedef typename Rcpp::traits::Extractor< RTYPE, RHS_NA, RHS_T>::type RHS_EXT ;
+		
 		Plus_Vector_Vector( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_ ) : 
-			lhs(lhs_.get_ref()), rhs(rhs_.get_ref()){}
+			lhs(lhs_.get_ref()), rhs(rhs_.get_ref()) {}
 		
 		inline STORAGE operator[]( int i ) const {
 			STORAGE lhs_ = lhs[i] ;
@@ -45,8 +48,8 @@
 		inline int size() const { return lhs.size() ; }
 		
 	private:
-		const LHS_T& lhs ;
-		const RHS_T& rhs ;
+		const LHS_EXT& lhs ;
+		const RHS_EXT& rhs ;
 	} ;	
 	
 	// specialization LHS_NA = false
@@ -57,6 +60,9 @@
 		typedef typename Rcpp::VectorBase<RTYPE,false,LHS_T> LHS_TYPE ;
 		typedef typename Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T> RHS_TYPE ;
 		
+		typedef typename Rcpp::traits::Extractor< RTYPE, false, LHS_T>::type LHS_EXT ;
+		typedef typename Rcpp::traits::Extractor< RTYPE, RHS_NA, RHS_T>::type RHS_EXT ;
+		
 		Plus_Vector_Vector( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_ ) : 
 			lhs(lhs_.get_ref()), rhs(rhs_.get_ref()){}
 		
@@ -69,8 +75,8 @@
 		inline int size() const { return lhs.size() ; }
 		
 	private:
-		const LHS_T& lhs ;
-		const RHS_T& rhs ;
+		const LHS_EXT& lhs ;
+		const RHS_EXT& rhs ;
 	} ;	
 
 	// specialization for RHS_NA = false 
@@ -81,6 +87,9 @@
 		typedef typename Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T> LHS_TYPE ;
 		typedef typename Rcpp::VectorBase<RTYPE,false,RHS_T> RHS_TYPE ;
 		
+		typedef typename Rcpp::traits::Extractor< RTYPE, LHS_NA, LHS_T>::type LHS_EXT ;
+		typedef typename Rcpp::traits::Extractor< RTYPE, false, RHS_T>::type RHS_EXT ;
+		
 		Plus_Vector_Vector( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_ ) : 
 			lhs(lhs_.get_ref()), rhs(rhs_.get_ref()){}
 		
@@ -93,8 +102,8 @@
 		inline int size() const { return lhs.size() ; }
 		
 	private:
-		const LHS_T& lhs ;
-		const RHS_T& rhs ;
+		const LHS_EXT& lhs ;
+		const RHS_EXT& rhs ;
 	} ;	
 
 
@@ -106,6 +115,9 @@
 		typedef typename Rcpp::VectorBase<RTYPE,false,LHS_T> LHS_TYPE ;
 		typedef typename Rcpp::VectorBase<RTYPE,false,RHS_T> RHS_TYPE ;
 		
+		typedef typename Rcpp::traits::Extractor< RTYPE, false, LHS_T>::type LHS_EXT ;
+		typedef typename Rcpp::traits::Extractor< RTYPE, false, RHS_T>::type RHS_EXT ;
+		                                                     
 		Plus_Vector_Vector( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_ ) : 
 			lhs(lhs_.get_ref()), rhs(rhs_.get_ref()){}
 		
@@ -116,8 +128,8 @@
 		inline int size() const { return lhs.size() ; }
 		
 	private:
-		const LHS_T& lhs ;
-		const RHS_T& rhs ;
+		const LHS_EXT& lhs ;
+		const RHS_EXT& rhs ;
 	} ;	
 	
 	
@@ -128,6 +140,8 @@
 		typedef typename Rcpp::VectorBase<RTYPE,NA,T> VEC_TYPE ;
 		typedef typename traits::storage_type<RTYPE>::type STORAGE ;
 		
+		typedef typename Rcpp::traits::Extractor< RTYPE, NA, T>::type EXT ;
+		
 		Plus_Vector_Primitive( const VEC_TYPE& lhs_, STORAGE rhs_ ) : 
 			lhs(lhs_.get_ref()), rhs(rhs_), rhs_na( Rcpp::traits::is_na<RTYPE>(rhs_) )
 			{}
@@ -141,56 +155,21 @@
 		inline int size() const { return lhs.size() ; }
 		
 	private:
-		const T& lhs ;
+		const EXT& lhs ;
 		STORAGE rhs ;
 		bool rhs_na ;
 		
 	} ;
 	
 	
-	// very special version that is used when the vector expression is 
-	// actually a vector. In that case we use its iterator (usually pointer)
-	// directly instead of adding the overhead of operator[]
-	template <int RTYPE>
-	class Plus_Vector_Primitive<RTYPE,true,Rcpp::Vector<RTYPE> > : 
-	    public Rcpp::VectorBase<RTYPE,true, Plus_Vector_Primitive<RTYPE,true,Rcpp::Vector<RTYPE> > > {
-	public:
-	    
-	    typedef typename Rcpp::Vector<RTYPE>::iterator iterator ;
-		typedef typename Rcpp::VectorBase<RTYPE,true,Rcpp::Vector<RTYPE> > VEC_TYPE ;
-		typedef typename traits::storage_type<RTYPE>::type STORAGE ;
-		
-		Plus_Vector_Primitive( const VEC_TYPE& lhs_, STORAGE rhs_ ) : 
-			lhs(lhs_.get_ref().begin())
-			, rhs(rhs_)
-			, rhs_na( Rcpp::traits::is_na<RTYPE>(rhs_) )
-			, n( lhs_.size() )
-			{}
-		
-		inline STORAGE operator[]( int i ) const {
-			if( rhs_na ) return rhs ;
-			STORAGE x = lhs[i] ;
-			return Rcpp::traits::is_na<RTYPE>(x) ? x : (x + rhs) ;
-		}
-		
-		inline int size() const { return n ; }
-		
-	private:
-		iterator lhs ;
-	    STORAGE rhs ;
-		bool rhs_na ;
-		int n ;
-		
-	} ;
-	
-	
-	
 	template <int RTYPE, typename T>
 	class Plus_Vector_Primitive<RTYPE,false,T> : public Rcpp::VectorBase<RTYPE,false, Plus_Vector_Primitive<RTYPE,false,T> > {
 	public:
 		typedef typename Rcpp::VectorBase<RTYPE,false,T> VEC_TYPE ;
 		typedef typename traits::storage_type<RTYPE>::type STORAGE ;
 		
+		typedef typename Rcpp::traits::Extractor< RTYPE, false, T>::type EXT ;
+		
 		Plus_Vector_Primitive( const VEC_TYPE& lhs_, STORAGE rhs_ ) : 
 			lhs(lhs_.get_ref()), rhs(rhs_), rhs_na( Rcpp::traits::is_na<RTYPE>(rhs_) ) {}
 		
@@ -201,7 +180,7 @@
 		inline int size() const { return lhs.size() ; }
 		
 	private:
-		const T& lhs ;
+		const EXT& lhs ;
 		STORAGE rhs ;
 		bool rhs_na ;
 		
@@ -219,7 +198,8 @@
 	public:
 		typedef typename Rcpp::VectorBase<RTYPE,NA,T> VEC_TYPE ;
 		typedef typename traits::storage_type<RTYPE>::type STORAGE ;
-		
+		typedef typename Rcpp::traits::Extractor< RTYPE, NA, T>::type EXT ;
+		   
 		Plus_Vector_Primitive_nona( const VEC_TYPE& lhs_, STORAGE rhs_ ) : 
 			lhs(lhs_.get_ref()), rhs(rhs_)
 			{}
@@ -232,51 +212,20 @@
 		inline int size() const { return lhs.size() ; }
 		
 	private:
-		const T& lhs ;
+		const EXT& lhs ;
 		STORAGE rhs ;
 		
 	} ;
 
 	
-	// very special version that is used when the vector expression is 
-	// actually a vector. In that case we use its iterator (usually pointer)
-	// directly instead of adding the overhead of operator[]
-	template <int RTYPE>
-	class Plus_Vector_Primitive_nona<RTYPE,true,Rcpp::Vector<RTYPE> > : 
-	    public Rcpp::VectorBase<RTYPE,true, Plus_Vector_Primitive_nona<RTYPE,true,Rcpp::Vector<RTYPE> > > {
-	public:
-	    
-	    typedef typename Rcpp::Vector<RTYPE>::iterator iterator ;
-		typedef typename Rcpp::VectorBase<RTYPE,true,Rcpp::Vector<RTYPE> > VEC_TYPE ;
-		typedef typename traits::storage_type<RTYPE>::type STORAGE ;
-		
-		Plus_Vector_Primitive_nona( const VEC_TYPE& lhs_, STORAGE rhs_ ) : 
-			lhs(lhs_.get_ref().begin())
-			, rhs(rhs_)
-			, n( lhs_.size() )
-			{}
-		
-		inline STORAGE operator[]( int i ) const {
-			STORAGE x = lhs[i] ;
-			return Rcpp::traits::is_na<RTYPE>(x) ? x : (x + rhs) ;
-		}
-		
-		inline int size() const { return n ; }
-		
-	private:
-		iterator lhs ;
-	    STORAGE rhs ;
-		int n ;
-		
-	} ;
-	
-	
 	template <int RTYPE, typename T>
 	class Plus_Vector_Primitive_nona<RTYPE,false,T> : public Rcpp::VectorBase<RTYPE,false, Plus_Vector_Primitive_nona<RTYPE,false,T> > {
 	public:
 		typedef typename Rcpp::VectorBase<RTYPE,false,T> VEC_TYPE ;
 		typedef typename traits::storage_type<RTYPE>::type STORAGE ;
 		
+		typedef typename Rcpp::traits::Extractor< RTYPE, false, T>::type EXT ;
+		
 		Plus_Vector_Primitive_nona( const VEC_TYPE& lhs_, STORAGE rhs_ ) : 
 			lhs(lhs_.get_ref()), rhs(rhs_) {}
 		
@@ -287,7 +236,7 @@
 		inline int size() const { return lhs.size() ; }
 		
 	private:
-		const T& lhs ;
+		const EXT& lhs ;
 		STORAGE rhs ;
 		
 	} ;



More information about the Rcpp-commits mailing list