[Rcpp-commits] r1716 - in pkg/Rcpp/inst: . include/Rcpp include/Rcpp/vector

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 24 18:43:41 CEST 2010


Author: romain
Date: 2010-06-24 18:43:41 +0200 (Thu, 24 Jun 2010)
New Revision: 1716

Added:
   pkg/Rcpp/inst/include/Rcpp/vector/RangeIndexer.h
Modified:
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/Vector.h
   pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
Log:
factored RangeIndexer out of Vector

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-06-24 15:41:31 UTC (rev 1715)
+++ pkg/Rcpp/inst/ChangeLog	2010-06-24 16:43:41 UTC (rev 1716)
@@ -1,3 +1,9 @@
+2010-06-24  Romain Francois <romain at r-enthusiasts.com>
+
+	* inst/include/Rcpp/vector/RangeIndexer.h: factored the RangeIndexer class
+	out of Vector, so that we can at a later time specialize it for character
+	vectors, lists, etc ...
+
 2010-06-24  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/include/Rcpp/Date.h: add struct tm member variable and

Modified: pkg/Rcpp/inst/include/Rcpp/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Vector.h	2010-06-24 15:41:31 UTC (rev 1715)
+++ pkg/Rcpp/inst/include/Rcpp/Vector.h	2010-06-24 16:43:41 UTC (rev 1716)
@@ -40,6 +40,8 @@
 template <int RTYPE> class MatrixRow ;
 template <int RTYPE> class MatrixColumn ;
 
+#include <Rcpp/vector/RangeIndexer.h>
+
 #include <Rcpp/vector/Vector.h>
 
 #include <Rcpp/vector/proxy.h>

Added: pkg/Rcpp/inst/include/Rcpp/vector/RangeIndexer.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/RangeIndexer.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/vector/RangeIndexer.h	2010-06-24 16:43:41 UTC (rev 1716)
@@ -0,0 +1,96 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// RangeIndexer.h: Rcpp R/C++ interface class library --
+//
+// Copyright (C) 2010	Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp 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.
+//
+// Rcpp 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 Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp__vector__RangeIndexer_h
+#define Rcpp__vector__RangeIndexer_h
+
+namespace internal{
+
+template <int RTYPE, typename VECTOR>
+class RangeIndexer {
+	typedef typename VECTOR::Proxy Proxy ;
+	
+	// TODO: check if the indexer is valid
+	RangeIndexer( VECTOR& vec_, const Rcpp::Range& range_) : 
+		vec(vec_), range(range_) {}
+	
+		// TODO: size exceptions
+	template <bool NA, typename T>	
+	RangeIndexer& operator=( const Rcpp::VectorBase<RTYPE,NA,T>& x){
+		int n = size() ;
+		for( int i=0; i<n; i++){
+			vec[ range[i] ] = x[i] ;
+		}
+		return *this ;
+	}
+	
+	template <bool NA, typename T>	
+	RangeIndexer& operator+=( const Rcpp::VectorBase<RTYPE,NA,T>& x){
+		int n = size() ;
+		for( int i=0; i<n; i++){
+			vec[ range[i] ] += x[i] ;
+		}
+		return *this ;
+	}
+	
+	template <bool NA, typename T>	
+	RangeIndexer& operator*=( const Rcpp::VectorBase<RTYPE,NA,T>& x){
+		int n = size() ;
+		for( int i=0; i<n; i++){
+			vec[ range[i] ] *= x[i] ;
+		}
+		return *this ;
+	}
+	
+	template <bool NA, typename T>	
+	RangeIndexer& operator-=( const Rcpp::VectorBase<RTYPE,NA,T>& x){
+		int n = size() ;
+		for( int i=0; i<n; i++){
+			vec[ range[i] ] -= x[i] ;
+		}
+		return *this ;
+	}
+	
+	template <bool NA, typename T>	
+	RangeIndexer& operator/=( const Rcpp::VectorBase<RTYPE,NA,T>& x){
+		int n = size() ;
+		for( int i=0; i<n; i++){
+			vec[ range[i] ] /= x[i] ;
+		}
+		return *this ;
+	}
+	
+	inline Proxy operator[]( int i ){
+		return vec[ range[i] ] ;
+	}
+	
+	inline int size(){
+		return range.size() ;
+	}
+	
+private:
+	VECTOR& vec ;
+	const Rcpp::Range& range ;
+} ;
+	
+}
+
+#endif

Modified: pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2010-06-24 15:41:31 UTC (rev 1715)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2010-06-24 16:43:41 UTC (rev 1716)
@@ -666,47 +666,10 @@
 
 public:
 	
-	class RangeIndexer {
-	public:
-		
-			// TODO: check if the indexer is valid
-		RangeIndexer( Vector& vec_, const Range& range_) : 
-			vec(vec_), range(range_) {}
-		
-			// TODO: size exceptions
-		template <bool NA, typename T>	
-		RangeIndexer& operator=( const VectorBase<RTYPE,NA,T>& x){
-			int n = size() ;
-			for( int i=0; i<n; i++){
-				vec[ range[i] ] = x[i] ;
-			}
-			return *this ;
-		}
-		
-		template <bool NA, typename T>	
-		RangeIndexer& operator+=( const VectorBase<RTYPE,NA,T>& x){
-			int n = size() ;
-			for( int i=0; i<n; i++){
-				vec[ range[i] ] += x[i] ;
-			}
-			return *this ;
-		}
-		
-		inline Proxy operator[]( int i ){
-			return vec[ range[i] ] ;
-		}
-		
-		inline int size(){
-			return range.size() ;
-		}
-		
-	private:
-		Vector& vec ;
-		const Range& range ;
-	} ;
+	typedef internal::RangeIndexer<RTYPE,Vector> Indexer ;
 	
-	inline RangeIndexer operator[]( const Range& range ){
-		return RangeIndexer( const_cast<Vector&>(*this), range );
+	inline Indexer operator[]( const Range& range ){
+		return Indexer( const_cast<Vector&>(*this), range );
 	}
 	
 } ; /* Vector */



More information about the Rcpp-commits mailing list